GalleryItem * @g2 GalleryFileSystemEntity * @g2 * @g2 1 * @g2 2 * @g2 * @g2 * * @package GalleryCore * @subpackage Classes * @author Bharat Mediratta * @version $Revision: 17580 $ * @abstract */ class GalleryItem extends GalleryFileSystemEntity { /** * Can this item contain children? * @var boolean * * @g2 * @g2 canContainChildren * @g2 BOOLEAN * @g2 * @g2 READ * @g2 */ var $canContainChildren; /** * The (long) description of this item * @var string * * @g2 * @g2 description * @g2 TEXT * @g2 SMALL * @g2 FULL * @g2 */ var $description; /** * A set of keywords that describe this item * @var string * * @g2 * @g2 keywords * @g2 STRING * @g2 LARGE * @g2 * @g2 FULL * @g2 */ var $keywords; /** * The id of the User who owns this item * @var int * * @g2 * @g2 ownerId * @g2 INTEGER * @g2 * @g2 * @g2 */ var $ownerId; /** * The renderer for drawing this item * @var string * * @g2 * @g2 renderer * @g2 STRING * @g2 MEDIUM * @g2 */ var $renderer; /** * The summary of this item * @var string * * @g2 * @g2 summary * @g2 STRING * @g2 LARGE * @g2 * @g2 FULL * @g2 */ var $summary; /** * The (short) title of this item * @var string * * @g2 * @g2 title * @g2 STRING * @g2 MEDIUM * @g2 * @g2 FULL * @g2 */ var $title; /** * Date and time marking the beginning of the view count * @var int * * @g2 * @g2 viewedSinceTimestamp * @g2 INTEGER * @g2 * @g2 READ * @g2 */ var $viewedSinceTimestamp; /** * Date and time when this item was originally captured (i.e. photographed, filmed, etc) * @var int * * @g2 * @g2 originationTimestamp * @g2 INTEGER * @g2 * @g2 FULL * @g2 */ var $originationTimestamp; /** * Create a new instance of this GalleryEntity in the persistent store. * Let the parent do its work, then add any initialization specific to this class. * * @param int $parentId the id of the GalleryEntity parent of this object * @param string $path the path component of this new object * @param boolean $canContainChildren (optional) Used for legal path component characters. * Defaults to false. * @return GalleryStatus a status code */ function create($parentId, $path, $canContainChildren=false) { global $gallery; if (!isset($path) || !isset($parentId)) { return GalleryCoreApi::error(ERROR_BAD_PARAMETER); } list ($ret, $parent) = GalleryCoreApi::loadEntitiesById($parentId, 'GalleryItem'); if ($ret) { return $ret; } if (!$parent->getCanContainChildren()) { return GalleryCoreApi::error(ERROR_ILLEGAL_CHILD); } $ret = parent::create($parentId, $path, $canContainChildren); if ($ret) { return $ret; } /* Record the owner */ $this->setOwnerId($gallery->getActiveUserId()); /* Initialize the viewedSince timestamp */ $this->setViewedSinceTimestamp(time()); /* By default, items can't contain children */ $this->setCanContainChildren($canContainChildren); /* Origination timestamp defaults to now */ $this->setOriginationTimestamp(time()); /* Init other fields */ $this->setTitle(null); $this->setSummary(null); $this->setDescription(null); $this->setKeywords(null); $this->setRenderer(null); return null; } /** * Create a root level instance of this GalleryEntity in the persistent store. * Let the parent do its work, then add any initialization specific to this class. * * @return GalleryStatus a status code */ function createRoot() { global $gallery; $ret = parent::createRoot(); if ($ret) { return $ret; } /* Record the owner */ $this->setOwnerId($gallery->getActiveUserId()); /* Initialize the viewedSince timestamp */ $this->setViewedSinceTimestamp(time()); /* Origination timestamp defaults to now */ $this->setOriginationTimestamp(time()); return null; } /** * @see GalleryEntity::createLink */ function createLink($entity, $parentId) { global $gallery; $ret = parent::createLink($entity, $parentId); if ($ret) { return $ret; } list ($ret, $parent) = GalleryCoreApi::loadEntitiesById($parentId, 'GalleryItem'); if ($ret) { return $ret; } if (!$parent->getCanContainChildren()) { return GalleryCoreApi::error(ERROR_ILLEGAL_CHILD); } /* Record the owner */ $this->setOwnerId($gallery->getActiveUserId()); /* Initialize the viewedSince timestamp */ $this->setViewedSinceTimestamp(time()); /* By default, items can't contain children */ $this->setCanContainChildren(false); /* Copy over anything else from the target entity */ $this->setDescription($entity->getDescription()); $this->setKeywords($entity->getKeywords()); $this->setSummary($entity->getSummary()); $this->setTitle($entity->getTitle()); $this->setOriginationTimestamp($entity->getOriginationTimestamp()); $this->setRenderer($entity->getRenderer()); return null; } /** * Delete this GalleryEntity. Delete all of its children also, if it has any. * @return GalleryStatus a status code */ function delete() { global $gallery; $storage =& $gallery->getStorage(); /* Delete any children */ $query = ' SELECT [GalleryChildEntity::id] FROM [GalleryChildEntity] WHERE [GalleryChildEntity::parentId] = ? '; list ($ret, $searchResults) = $gallery->search($query, array($this->getId())); if ($ret) { return $ret; } $i = 0; while ($result = $searchResults->nextResult()) { $ret = GalleryCoreApi::deleteEntityById($result[0], 'GalleryChildEntity'); /* * Deletes can cascade in interesting ways. For example, deleting a derivative will * get rid of any other derivatives that are sourced to it, so it's possible that * deleting children here can lead to a MISSING_OBJECT result unless we re-run the * parent/child query each time. Easier to just ignore the MISSING_OBJECT error * since we only care that it's gone. */ if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) { return $ret; } if (!(++$i % 30)) { $ret = $storage->checkPoint(); if ($ret) { return $ret; } } } /* Delete myself */ $ret = parent::delete(); if ($ret) { return $ret; } /* Remove all my attributes */ $ret = GalleryCoreApi::removeItemAttributes($this->getId()); if ($ret) { return $ret; } if ($this->getParentId()) { $event = GalleryCoreApi::newEvent('Gallery::ViewableTreeChange'); $event->setData(array('userId' => null, 'itemId' => $this->getParentId())); list ($ret) = GalleryCoreApi::postEvent($event); if ($ret) { return $ret; } /* Instruct G2 to "touch" modification timestamp of parent album at end of request */ $gallery->addShutdownAction(array('GalleryCoreApi', 'updateModificationTimestamp'), array($this->getParentId())); } return null; } /** * Move item to a new parent * * @param int $newParentId the id of the new parent GalleryItem * @return GalleryStatus a status code */ function move($newParentId) { $parentId = $this->getParentId(); $ret = parent::move($newParentId); if ($ret) { return $ret; } $event = GalleryCoreApi::newEvent('Gallery::ViewableTreeChange'); $event->setData(array('userId' => null, 'itemId' => empty($parentId) ? $this->getParentId() : array($parentId, $this->getParentId()))); list ($ret) = GalleryCoreApi::postEvent($event); if ($ret) { return $ret; } /* Set the new parent sequence */ list ($ret, $newParentSequence) = GalleryCoreApi::fetchParentSequence($this->getParentId()); if ($ret) { return $ret; } $newParentSequence[] = $this->getParentId(); $ret = GalleryCoreApi::setParentSequence($this->getId(), $newParentSequence); if ($ret) { return $ret; } return null; } /** * Save the changes to this GalleryItem. * * @return GalleryStatus a status code */ function save($postEvent=true) { global $gallery; $isNew = $this->testPersistentFlag(STORAGE_FLAG_NEWLY_CREATED); $changedParent = $this->isModified('parentId'); if ($changedParent) { $oldParentId = $this->getOriginalValue('parentId'); } $setAclId = 0; if ($isNew && $this->getParentId()) { list ($ret, $setAclId) = GalleryCoreApi::fetchAccessListId($this->getParentId()); if ($ret) { return $ret; } } /* Save myself */ $ret = parent::save($postEvent, $setAclId); if ($ret) { return $ret; } if ($isNew) { if ($this->getParentId()) { list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($this->getParentId()); if ($ret) { return $ret; } $parentSequence[] = $this->getParentId(); } else { $parentSequence = array(); } /* Create an empty attribute entry */ $ret = GalleryCoreApi::createItemAttributes($this->getId(), $parentSequence); if ($ret) { return $ret; } if ($this->getParentId()) { $event = GalleryCoreApi::newEvent('Gallery::ViewableTreeChange'); $event->setData(array('userId' => null, 'itemId' => $this->getParentId())); list ($ret) = GalleryCoreApi::postEvent($event); if ($ret) { return $ret; } } } if (($isNew || $changedParent) && $this->getParentId()) { /* Instruct G2 to "touch" modification timestamp of parent album at end of request */ $gallery->addShutdownAction(array('GalleryCoreApi', 'updateModificationTimestamp'), array($this->getParentId())); } if (!empty($oldParentId)) { $gallery->addShutdownAction(array('GalleryCoreApi', 'updateModificationTimestamp'), array($oldParentId)); } return null; } /** * @see GalleryEntity::getClassName */ function getClassName() { return 'GalleryItem'; } function getCanContainChildren() { return $this->canContainChildren; } function setCanContainChildren($canContainChildren) { $this->canContainChildren = $canContainChildren; } function getDescription() { return $this->description; } function setDescription($description) { $this->description = $description; } function getKeywords() { return $this->keywords; } function setKeywords($keywords) { $this->keywords = $keywords; } function getOwnerId() { return $this->ownerId; } function setOwnerId($ownerId) { $this->ownerId = $ownerId; } function getRenderer() { return $this->renderer; } function setRenderer($renderer) { $this->renderer = $renderer; } function getSummary() { return $this->summary; } function setSummary($summary) { $this->summary = $summary; } function getTitle() { return $this->title; } function setTitle($title) { $this->title = $title; } function getViewedSinceTimestamp() { return $this->viewedSinceTimestamp; } function setViewedSinceTimestamp($viewedSinceTimestamp) { $this->viewedSinceTimestamp = $viewedSinceTimestamp; } function getOriginationTimestamp() { return $this->originationTimestamp; } function setOriginationTimestamp($originationTimestamp) { $this->originationTimestamp = $originationTimestamp; } } ?>