/** * This is a singleton class, thus an instance must be created by this method * * @access public * * @param mixed $uid: The unique identifier of the document to parse or URL of XML file * @param integer $pid: If > 0, then only document with this PID gets loaded * @param boolean $forceReload: Force reloading the document instead of returning the cached instance * * @return &tx_dlf_document Instance of this class */ public static function &getInstance($uid, $pid = 0, $forceReload = FALSE) { // Sanitize input. $pid = max(intval($pid), 0); if (!$forceReload) { $regObj = md5($uid); if (is_object(self::$registry[$regObj]) && self::$registry[$regObj] instanceof self) { // Check if instance has given PID. if (!$pid || !self::$registry[$regObj]->pid || $pid == self::$registry[$regObj]->pid) { // Return singleton instance if available. return self::$registry[$regObj]; } } else { // Check the user's session... $sessionData = tx_dlf_helper::loadFromSession(get_called_class()); if (is_object($sessionData[$regObj]) && $sessionData[$regObj] instanceof self) { // Check if instance has given PID. if (!$pid || !$sessionData[$regObj]->pid || $pid == $sessionData[$regObj]->pid) { // ...and restore registry. self::$registry[$regObj] = $sessionData[$regObj]; return self::$registry[$regObj]; } } } } // Create new instance... $instance = new self($uid, $pid); // ...and save it to registry. if ($instance->ready) { self::$registry[md5($instance->uid)] = $instance; if ($instance->uid != $instance->location) { self::$registry[md5($instance->location)] = $instance; } // Load extension configuration $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']); // Save registry to session if caching is enabled. if (!empty($extConf['caching'])) { tx_dlf_helper::saveToSession(self::$registry, get_class($instance)); } } // Return new instance. return $instance; }
/** * This is the constructor * * @access public * * @param array $elements: Array of documents initially setting up the list * @param array $metadata: Array of initial metadata * * @return void */ public function __construct(array $elements = array(), array $metadata = array()) { if (empty($elements) && empty($metadata)) { // Let's check the user's session. $sessionData = tx_dlf_helper::loadFromSession(get_class($this)); // Restore list from session data. if (is_array($sessionData)) { if (is_array($sessionData[0])) { $this->elements = $sessionData[0]; } if (is_array($sessionData[1])) { $this->metadata = $sessionData[1]; } } } else { // Add metadata to the list. $this->metadata = $metadata; // Add initial set of elements to the list. $this->elements = $elements; } $this->count = count($this->elements); }