*/ /** * Load the parent class */ GalleryCoreApi::requireOnce('modules/core/classes/GalleryFileSystemEntity.class'); /** * Abstract base class for all objects in the Gallery * composite tree * * Container for all functionality and data common objects that * Gallery can deal with. Each GalleryItem has the capacity * to own other GalleryItems in a parent-child relationship. * That capacity can be enabled or disabled by subclasses of * GalleryItem. * * @g2 GalleryItem * @g2 GalleryFileSystemEntity * @g2 * @g2 1 * @g2 1 * @g2 * @g2 * * @package GalleryCore * @abstract */ class GalleryItem extends GalleryFileSystemEntity { /** * Can this item contain children? * * @g2 * @g2 canContainChildren * @g2 BOOLEAN * @g2 * @g2 * * @var int $canContainChildren * @access public */ var $canContainChildren; /** * The (long) description of this item * * @g2 * @g2 description * @g2 TEXT * @g2 SMALL * @g2 * * @var int $description * @access public */ var $description; /** * A set of keywords that describe this item * * @g2 * @g2 keywords * @g2 STRING * @g2 LARGE * @g2 * @g2 * * @var string $keywords * @access public */ var $keywords; /** * The id of the User who owns this item * * @g2 * @g2 ownerId * @g2 INTEGER * @g2 * @g2 * @g2 * * @var int $ownerId * @access public */ var $ownerId; /** * The summary of this item * * @g2 * @g2 summary * @g2 STRING * @g2 LARGE * @g2 * @g2 * * @var int $summary * @access public */ var $summary; /** * The (short) title of this item * * @g2 * @g2 title * @g2 STRING * @g2 MEDIUM * @g2 * @g2 * * @var int $title * @access public */ var $title; /** * Date and time marking the beginning of the view count * * @g2 * @g2 viewedSinceTimestamp * @g2 INTEGER * @g2 * @g2 * * @var int $viewedSinceTimestamp * @access public */ var $viewedSinceTimestamp; /** * Date and time when this item was originally captured (i.e. photographed, filmed, etc) * * @g2 * @g2 originationTimestamp * @g2 INTEGER * @g2 * @g2 * * @var int $originationTimestamp * @access public */ 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 the id of the GalleryEntity parent of this object * @param string the path component of this new object * @param int the id of the parent object * @return object GalleryStatus a status code */ function create($parentId, $path) { global $gallery; if (!isset($path) || !isset($parentId)) { return GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__); } list($ret, $parent) = GalleryCoreApi::loadEntitiesById($parentId); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if (!$parent->getCanContainChildren()) { return GalleryCoreApi::error(ERROR_ILLEGAL_CHILD, __FILE__, __LINE__); } $ret = parent::create($parentId, $path); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } /* Record the owner */ $this->setOwnerId($gallery->getActiveUserId()); /* Initialize the viewedSince timestamp */ $this->setViewedSinceTimestamp(time()); /* By default, items can't contain children */ $this->setCanContainChildren(false); /* Origination timestamp defaults to now */ $this->setOriginationTimestamp(time()); /* Init other fields */ $this->setTitle(null); $this->setSummary(null); $this->setDescription(null); $this->setKeywords(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. * * @param string the path component of this new object * @return object GalleryStatus a status code */ function createRoot() { global $gallery; $ret = parent::createRoot(); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } /* 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->wrap(__FILE__, __LINE__); } list($ret, $parent) = GalleryCoreApi::loadEntitiesById($parentId); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if (!$parent->getCanContainChildren()) { return GalleryCoreApi::error(ERROR_ILLEGAL_CHILD, __FILE__, __LINE__); } /* 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()); return null; } /** * Delete this GalleryEntity * * Delete all of its children also, if it has any * * @access public * @return object GalleryStatus a status code */ function delete() { global $gallery; /* 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->wrap(__FILE__, __LINE__); } while ($result = $searchResults->nextResult()) { $ret = GalleryCoreApi::deleteEntityById($result[0]); /* * 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->wrap(__FILE__, __LINE__); } } /* Delete myself */ $ret = parent::delete(); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } /* Remove all my attributes */ $ret = GalleryCoreApi::removeItemAttributes($this->getId()); if ($ret) { return $ret2->wrap(__FILE__, __LINE__); } 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->wrap(__FILE__, __LINE__); } /* 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 * * @access public * @param int the id of the new parent GalleryItem * @return object GalleryStatus a status code */ function move($newParentId) { $parentId = $this->getParentId(); $ret = parent::move($newParentId); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $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->wrap(__FILE__, __LINE__); } return null; } /** * Save the changes to this GalleryItem. * * @return object 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->wrap(__FILE__, __LINE__); } } /* Save myself */ $ret = parent::save($postEvent, $setAclId); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if ($isNew) { if ($this->getParentId()) { list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($this->getParentId()); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } $parentSequence[] = $this->getParentId(); } else { $parentSequence = array(); } /* Create an empty attribute entry */ $ret = GalleryCoreApi::createItemAttributes($this->getId(), $parentSequence); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } 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->wrap(__FILE__, __LINE__); } } } 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 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; } } ?>