SnapContent Class Reference
[Content Modules]

Base class for all Snap2 content modules. More...

Inheritance diagram for SnapContent:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 copy ()
 Performs deep copy of this content module.
 delete ()
 Deletes any external resources associated with the content.
 getContentSuffix ()
 INSERT BRIEF DESCRIPTION HERE.
 getEditor ($redirectTo="", $showPreview=true)
 Retrieves editor instance for this content.
 getEditorClass ()
 INSERT BRIEF DESCRIPTION HERE.
 getHTML ($params=array())
 Retrieves HTML to embed content in a page.
 getLinkURL ($download=false)
 Retrieves URL for downloading resource.
 getName ()
 Retrieves descriptive name for this type of content.
 getPreview ($mode=TKSnapPreview::MODE_DEFAULT)
 Retrieves preview instance for this content.
 getPreviewClass ()
 INSERT BRIEF DESCRIPTION HERE.
 getRaw ()
 Retrieves raw content to be put into database.
 getTranslator ()
 Retrieves the name of the translator class to be used for this type of object.
 isValid ()
 Returns whether content module is in a valid, consisten state.

Static Public Member Functions

static create ($version)
 Create a new blank content module of the appropriate type.
static getContentModule ($version, $new=false)
 Returns an instance of a content module of the correct type for the given version.
static getContentModuleClass ($version)
 Returns name of content module class.
static getContentName ($type)
 Same as getName(), but static.
static getInitialValue ($type)
 Retrieves the initial value to be stored in the database for a new version.
static getTypeFromSuffix ($suffix)
 Retrieves content type from file suffix.
static isValidType ($type)
 Returns whether given content type is valid.


Detailed Description

Base class for all Snap2 content modules.

A content module represents a chunk of Snap2 content. All operations on content in Snap2 are to be done via a content module, and not by directly manipulating the value of the 'content' field in a SnapVersion.

A content module exists in one of two modes: read-only and new. In read-only mode, the content module represents existing content and that should not be manipulated. In new mode, the content module can be modified and ultimately saved to the database. Both modes allow for the deletion of the content. To modify content, one should create a new content module, uninitialized with existing content (thus putting it in new mode), and then calling content-type specific methods to fill in the content. To get at existing content, simply call SnapVersion::getContentModule. Do not create read-only content modules yourself.


Member Function Documentation

SnapContent::copy (  ) 

Performs deep copy of this content module.

The new content module returned from this method is read-only and is intended to be used when a version is being created as a copy of an existing version.

Returns:
[SnapContent]: deep copy of this content module

static SnapContent::create ( version  )  [static]

Create a new blank content module of the appropriate type.

This content module is meant to be modified and ultimately serialized into the database

Parameters:
$version [SnapVersion]: version to create content module for (really only for type information)
Returns:
[SnapContent]: new content module of appropriate type

SnapContent::delete (  ) 

Deletes any external resources associated with the content.

For content types that have external resources, those must be deleted when a revision of a version is destroyed, or when the version itself is destroyed. When a version is updated the old content is delete()'ed and a new content module is created. When a version is destroyed the content is also delete()'ed. Finally, if a blank content module is created for an update and it is initialized with new data, but the update fails, then the module should be deleted to clean up any external files. These are the only three cases in which delete() needs to be called.

Returns:
[boolean]: success or failure

static SnapContent::getContentModule ( version,
new = false 
) [static]

Returns an instance of a content module of the correct type for the given version.

The content module returned is prefilled with data from the version and cannot be modified. It is meant for queries only.

Parameters:
$version [SnapVersion]: version to retrieve content module for
$new [boolean]: if true, create an empty content module, otherwise, fill it with the content from the version
Returns:
[SnapContent]: new content module of appropriate type

static SnapContent::getContentModuleClass ( version  )  [static]

Returns name of content module class.

Parameters:
$version [SnapVersion]: version to get content module class name for
Returns:
[string]: content module class name

static SnapContent::getContentName ( type  )  [static]

Same as getName(), but static.

Parameters:
$type [int]: content type
Returns:
[string]: descriptive name for content type

SnapContent::getContentSuffix (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

SnapContent::getEditor ( redirectTo = "",
showPreview = true 
)

Retrieves editor instance for this content.

Parameters:
$redirectTo [string]: provide an alternate address to redirect to when exiting the editor
$showPreview [boolean]: whether the editor should include a preview frame
Returns:
[TKSnapEditor]: instance of editor to be embedded in a page

SnapContent::getEditorClass (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

SnapContent::getHTML ( params = array()  ) 

Retrieves HTML to embed content in a page.

The HTML should either embed the content directly, or, at the very least, provide a link for it to be downloaded or some other indication that the content is there.

Parameters:
$params [array]: array of parameters that control the nature of the embed HTML (only relevant for some content types)
Returns:
[string]: HTML for embedding or false if there is some sort of error

static SnapContent::getInitialValue ( type  )  [static]

Retrieves the initial value to be stored in the database for a new version.

When a new version is created, the database must be filled with some initial value before the user has entered anything. So, this function delegates to the appropriate content module to get an appropriate initial value.

Parameters:
$type [int]: content type; should be one of the SnapResource::TYPE_XXX constants
Returns:
[string]: initial content

SnapContent::getLinkURL ( download = false  ) 

Retrieves URL for downloading resource.

Links are of the form '/media/content//path/to/resource.suffix'. Note that there is not and never will be a way to download a particular version. The correct active version will be used.

Returns:
[string]: URL to download resource

SnapContent::getName (  ) 

Retrieves descriptive name for this type of content.

Returns:
[string]: descriptive name for this type of content

SnapContent::getPreview ( mode = TKSnapPreview::MODE_DEFAULT  ) 

Retrieves preview instance for this content.

Returns:
[TKSnapPreview]: instance of preview frame to be embedded in a page

SnapContent::getPreviewClass (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

SnapContent::getRaw (  ) 

Retrieves raw content to be put into database.

This function automatically serializes internal data structures and thus no further processing need be done on the return value

Returns:
[string]: raw serialized content for the database

SnapContent::getTranslator (  ) 

Retrieves the name of the translator class to be used for this type of object.

Returns:
[string]: name of translator class

static SnapContent::getTypeFromSuffix ( suffix  )  [static]

Retrieves content type from file suffix.

Given a file suffix, this function will determine which content type would be used for that suffix. For example, the "xml" suffix will return SnapResource::TYPE_STDXML.

Parameters:
$suffix [string]: file suffix without leading dot
Returns:
[int]: SnapResource content type or false if no content type for given suffix

SnapContent::isValid (  ) 

Returns whether content module is in a valid, consisten state.

Each content module class decides what counts as valid, but in general, a valid content module has all of its internal data structures in a state that they can be serialized and put in the database and later be retrieved and correctly used for displaying and modifying content.

Returns:
[boolean]: whether content module is in a valid state

static SnapContent::isValidType ( type  )  [static]

Returns whether given content type is valid.

Parameters:
$type [int]: content type
Returns:
[boolean]: whether type is valid


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:03:08 2010 for Common by  doxygen 1.5.6