Beispiel #1
0
 /**
  * Creates a new gallery/album under the given
  * parent album.  The name/title and description
  * will be keyed off of the given event object.
  *
  * @param string $parentAlbum
  * @param Event or Person $bean
  * @param string $name a title to specify (optional -- will use getTitle if not specified)
  * @return int id of the created/found album or null if not created
  */
 public function createAlbum($parent, $bean, $name = null)
 {
     global $mosConfig_absolute_path, $gallery;
     global $logger;
     $logger->debug(get_class($this) . "::createAlbum({$parent}, {$bean}, {$name})");
     $parentId = null;
     if ($name) {
         $pathname = strtolower(preg_replace("/ /", '_', $name));
         $title = $name;
     } else {
         $pathname = strtolower(preg_replace("/ /", '_', $bean->getTitle()));
         $title = $bean->getTitle();
     }
     $summary = '';
     $description = '';
     $keywords = '';
     $albumId = null;
     // get the parent album id
     $ret = $this->initGalleryApi();
     list($ret, $tree) = GalleryCoreApi::fetchAlbumTree();
     $name = constant("GalleryService::PARENT_" . strtoupper($parent) . "_ALBUM");
     $logger->debug("Looking for Parent Album Name:" . $name);
     foreach ($tree as $key => $value) {
         list($ret, $album) = GalleryCoreApi::loadEntitiesById($key);
         if (strtolower($album->getPathComponent()) == strtolower($name)) {
             $parentId = $key;
             // we have a matching parent
             break;
         }
     }
     $logger->debug("Found Parent Album ID:" . $parentId);
     // see if there is already an album by path
     list($ret, $current) = GalleryCoreApi::fetchChildIdByPathComponent($parentId, $pathname);
     if ($current) {
         $albumId = $current;
     } else {
         // create the new album
         list($ret, $created) = GalleryCoreApi::createAlbum($parentId, $pathname, $title, $summary, $description, $keywords);
         $albumId = $created ? $created->getId() : '';
         // now create the child highlight album
         if ($albumId) {
             list($ret, $hlCreated) = GalleryCoreApi::createAlbum($albumId, strtolower(CHILD_HIGHLIGHT_ALBUM), CHILD_HIGHTLIGHT_ALBUM, $summary, $description, $keywords);
             $highlightId = $hlCreated ? $hlCreated->getId() : "";
         }
     }
     $logger->debug("Created album with id: " . $albumId . " and highlights id: " . $highlightId);
     /* Complete our transaction */
     if ($gallery->isStorageInitialized()) {
         $storage =& $gallery->getStorage();
         $ret = $storage->commitTransaction();
     }
     return $albumId;
 }