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

 __construct ($version, $raw=false)
 Base constructor for Snap2 content modules.
 checkMedia ()
 Checks whether on-disk media is available and correct.
 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.

Protected Member Functions

 doCopy ()
 Performs additional work needed for doing a deep copy.
 doDelete ()
 Performs additional work needed for deleting the content.
 doGetHTML ($params)
 Generates HTML for embedding object in page.
 get ($field)
 Retrieves entry from $content field.
 getAll ()
 Retrieves contents of $content field.
 getSuffix ()
 Retrieves the content-dependent file suffix for the resource.
 set ($field, $value)
 Sets an entry in the $content field, checking to see if content module is read-only first.
 setAll ($values)
 Sets all entries in the $content field, checking to see if content module is read-only first.
 validate ()
 Determines whether content module is in a consistent, valid state.

Protected Attributes

 $version


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.

Definition at line 20 of file SnapContent.php5.


Constructor & Destructor Documentation

SnapContent::__construct ( version,
raw = false 
)

Base constructor for Snap2 content modules.

For internal use only.

Parameters:
$version [SnapVersion]: version with which this content module is associated
$raw [string]: raw content from database if this content module is being initialized with existing content (and will thus be read-only), or false if the content module is to represent new, blank content.

Definition at line 51 of file SnapContent.php5.

References $version.


Member Function Documentation

SnapContent::checkMedia (  )  [abstract]

Checks whether on-disk media is available and correct.

For internal use only.

For non-media-based content, this method should always return true. Otherwise, it should check to make sure all files it is responsible for are on disk and readable by the webserver.

Returns:
[boolean]: whether on-disk media is correct

Reimplemented in SnapContentCss, SnapContentHtml, SnapContentInteractivateInstructor, SnapContentInteractivateLesson, SnapContentLessonPlan, SnapContentMediaAgentsheetsApplet, SnapContentMediaDocument, SnapContentMediaFile, SnapContentMediaImage, SnapContentMediaInteractivateApplet, SnapContentMediaNetlogoApplet, and SnapContentXml.

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

Definition at line 270 of file SnapContent.php5.

References doCopy().

Referenced by SnapContentMediaNetlogoApplet::doCopy(), SnapContentMediaFile::doCopy(), and SnapContentMediaAgentsheetsApplet::doCopy().

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

Definition at line 131 of file SnapContent.php5.

References $version.

Referenced by SnapContentMediaInteractivateApplet::uploadApplet().

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

Definition at line 288 of file SnapContent.php5.

References doDelete().

SnapContent::doCopy (  )  [protected]

Performs additional work needed for doing a deep copy.

For internal use only.

Only override this method if you need to copy more than just values stored in the database, such as copying external files

Returns:
[SnapContent]: content module representing the copy

Reimplemented in SnapContentMediaAgentsheetsApplet, SnapContentMediaDocument, SnapContentMediaFile, SnapContentMediaImage, SnapContentMediaInteractivateApplet, and SnapContentMediaNetlogoApplet.

Definition at line 433 of file SnapContent.php5.

References getRaw().

Referenced by copy().

SnapContent::doDelete (  )  [protected]

Performs additional work needed for deleting the content.

For internal use only.

Only override this method if you need to delete external resources

Reimplemented in SnapContentMediaAgentsheetsApplet, SnapContentMediaDocument, SnapContentMediaFile, SnapContentMediaImage, SnapContentMediaInteractivateApplet, and SnapContentMediaNetlogoApplet.

Definition at line 446 of file SnapContent.php5.

Referenced by delete().

SnapContent::doGetHTML ( params  )  [abstract, protected]

Generates HTML for embedding object in page.

For internal use only.

Parameters:
$params [array]: optional arguments (meaning depends on content type)
This method does the work of generating the HTML, which is generally used by translators to display content from the content module.
Returns:
[string]: generated HTML or false if there was an error

Reimplemented in SnapContentCss, SnapContentHtml, SnapContentInteractivateInstructor, SnapContentInteractivateLesson, SnapContentLessonPlan, SnapContentMediaAgentsheetsApplet, SnapContentMediaDocument, SnapContentMediaFile, SnapContentMediaImage, SnapContentMediaInteractivateApplet, SnapContentMediaNetlogoApplet, and SnapContentXml.

Referenced by getHTML().

SnapContent::get ( field  )  [protected]

Retrieves entry from $content field.

For internal use only.

Parameters:
$field [string]: name of field to retrieve
Returns:
[mixed]: null if field is not currently set, value of field otherwise

Definition at line 405 of file SnapContent.php5.

SnapContent::getAll (  )  [protected]

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

Definition at line 95 of file SnapContent.php5.

References $version.

Referenced by SnapVersion::loadContentModule().

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

Definition at line 109 of file SnapContent.php5.

References $version.

static SnapContent::getContentName ( type  )  [static]

Same as getName(), but static.

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

Definition at line 220 of file SnapContent.php5.

SnapContent::getContentSuffix (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 324 of file SnapContent.php5.

References getSuffix().

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

Definition at line 162 of file SnapContent.php5.

SnapContent::getEditorClass (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 174 of file SnapContent.php5.

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

Definition at line 339 of file SnapContent.php5.

References doGetHTML().

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

Definition at line 146 of file SnapContent.php5.

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

Definition at line 300 of file SnapContent.php5.

References getSuffix().

Referenced by SnapContentMediaFile::doGetHTML(), and SnapContentMediaDocument::doGetHTML().

SnapContent::getName (  ) 

Retrieves descriptive name for this type of content.

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

Definition at line 211 of file SnapContent.php5.

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

Retrieves preview instance for this content.

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

Definition at line 182 of file SnapContent.php5.

SnapContent::getPreviewClass (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Definition at line 194 of file SnapContent.php5.

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

Definition at line 252 of file SnapContent.php5.

Referenced by doCopy().

SnapContent::getSuffix (  )  [protected]

Retrieves the content-dependent file suffix for the resource.

For internal use only.

Most resources will have their suffix be listed directly in contentModules.php5. If the suffix is not static, but depends on content, then you need to override this method in your derived class to return the correct suffix based on the content.

Returns:
[string]: file suffix for content

Reimplemented in SnapContentMediaDocument, SnapContentMediaFile, and SnapContentMediaImage.

Definition at line 459 of file SnapContent.php5.

Referenced by getContentSuffix(), and getLinkURL().

SnapContent::getTranslator (  ) 

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

Returns:
[string]: name of translator class

Definition at line 203 of file SnapContent.php5.

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

Definition at line 236 of file SnapContent.php5.

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

Definition at line 352 of file SnapContent.php5.

References validate().

static SnapContent::isValidType ( type  )  [static]

Returns whether given content type is valid.

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

Definition at line 119 of file SnapContent.php5.

Referenced by SnapDirectory::canCreateResource().

SnapContent::set ( field,
value 
) [protected]

Sets an entry in the $content field, checking to see if content module is read-only first.

For internal use only.

Any data that is to be serialized must be stored using set() or setAll(). These methods also prevent modification of a read-only module.

Parameters:
$field [string]: name of field to set (does not have to exist first)
$value [mixed]: value to store in field
Returns:
[boolean]: false if module is read-only, true otherwise

Definition at line 370 of file SnapContent.php5.

References SObject::setError().

SnapContent::setAll ( values  )  [protected]

Sets all entries in the $content field, checking to see if content module is read-only first.

For internal use only.

Same information from set() applies here as well. Note that any existing values in the $content field will be overwritten and only the values in the $values param will be stored.

Parameters:
$values [array]: array of values to store in $content field
Returns:
[boolean]: false if module is read-only, true otherwise

Definition at line 389 of file SnapContent.php5.

References SObject::setError().

Referenced by SnapContentCss::setCSS(), SnapContentHtml::setHTML(), SnapContentLessonPlan::setStandardFields(), and SnapContentXml::setXML().

SnapContent::validate (  )  [abstract, protected]

Determines whether content module is in a consistent, valid state.

For internal use only.

This function should return true if and only if the content module contains content that is self-consistent and ready to be stored in the database, or used to generate HTML

Returns:
[boolean]: whether content is valid

Reimplemented in SnapContentCss, SnapContentHtml, SnapContentInteractivateInstructor, SnapContentInteractivateLesson, SnapContentLessonPlan, SnapContentMediaAgentsheetsApplet, SnapContentMediaDocument, SnapContentMediaFile, SnapContentMediaImage, SnapContentMediaInteractivateApplet, SnapContentMediaNetlogoApplet, and SnapContentXml.

Referenced by isValid().


Member Data Documentation

SnapContent::$version [protected]

For internal use only.

Version associated with this content module

Definition at line 31 of file SnapContent.php5.

Referenced by __construct(), create(), getContentModule(), and getContentModuleClass().


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

Generated on Wed Nov 24 02:06:19 2010 for Common by  doxygen 1.5.6