/** * * Gets all images linked to an album. If an array of versions is passed in also returns the Image Objects for those versions alongside the Image data. * If count is set this limits the set returned. If count is set to 1 returns a single Imagset object * @param int $albumID * @param array $versions * @param int $count * @return array of objects */ public function get_by_album_id($albumID, $versions = false, $count = false) { $sql = 'SELECT * FROM ' . $this->table . ' WHERE albumID = ' . $this->db->pdb($albumID) . ' ORDER BY ' . $this->default_sort_column . ' ASC'; if ($count) { $sql .= ' LIMIT ' . $this->db->pdb($count); } //if $count has been set to 1, we are only returning 1 image if ($count && $count == 1) { $row = $this->db->get_row($sql); if (is_array($row)) { /* if we have versions is array (otherwise we just return the image objects) */ if (is_array($versions) && PerchUtil::count($versions) > 0) { $PerchGallery_ImageVersions = new PerchGallery_ImageVersions(); /* loop though versions array */ for ($n = 0; $n < sizeOf($versions); $n++) { /* add to row the image objects for versions in the array */ $Version = $PerchGallery_ImageVersions->get_by_key($row['imageID'], $versions[$n]); $row['image_' . $versions[$n]] = $Version; } } $r = $this->return_instance($row); return $r; } return false; } else { $rows = $this->db->get_rows($sql); if (is_array($rows)) { /* if we have versions is array (otherwise we just return the image objects) */ if (is_array($versions) && PerchUtil::count($versions) > 0) { $PerchGallery_ImageVersions = new PerchGallery_ImageVersions(); $PerchGallery_ImageVersions->preload_for_album($albumID); /* loop through returned images */ for ($i = 0; $i < sizeOf($rows); $i++) { /* loop though versions array */ for ($n = 0; $n < sizeOf($versions); $n++) { /* add to row the image objects for versions in the array */ $Version = $PerchGallery_ImageVersions->get_by_key($rows[$i]['imageID'], $versions[$n]); $rows[$i]['image_' . $versions[$n]] = $Version; } } } $r = $this->return_instances($rows); return $r; } } return false; }
/** * * Display images for an album * @param string $slug * @param string $template_listing * @param string $template_image * @param bool $return */ function perch_gallery_album_images($slug, $opts = array(), $return = false) { $default_opts = array('template' => 'a_list_image.html', 'skip-template' => false); $opts = array_merge($default_opts, $opts); if ($opts['skip-template']) { $return = true; } $API = new PerchAPI(1.0, 'perch_gallery'); $Albums = new PerchGallery_Albums($API); $Images = new PerchGallery_Images($API); $Album = $Albums->find_by_slug($slug); if (is_object($Album)) { $album_array = $Album->to_array(); if (is_object($Album)) { $Template = $API->get('Template'); $Template->set('gallery/' . $opts['template'], 'gallery'); $Versions = new PerchGallery_ImageVersions(); $Versions->preload_for_album($Album->albumID()); $list = $Images->get_custom($Album->albumID(), $opts, $Versions); if (PerchUtil::count($list)) { foreach ($list as &$item) { $item = array_merge($album_array, $item); } if ($opts['skip-template']) { return $list; } $r = $Template->render_group($list, true); if ($return) { return $r; } echo $r; return; } } } return false; }