コード例 #1
0
ファイル: Storage.php プロジェクト: horde/horde
 /**
  * Returns a list of Ansel_Images of the most recently added images for the
  * current user.
  *
  * @param array $galleries  An array of gallery ids to search in. If
  *                          left empty, will search all galleries
  *                          with Horde_Perms::SHOW.
  * @param integer $limit    The maximum number of images to return
  * @param string $slugs     An array of gallery slugs.
  * @param string $where     Additional where clause
  *
  * @return array An array of Ansel_Image objects
  * @throws Ansel_Exception
  */
 public function getRecentImages(array $galleries = array(), $limit = 10, array $slugs = array())
 {
     $results = array();
     if (!count($galleries) && !count($slugs)) {
         // Don't need the Ansel_Gallery object, so save some resources and
         // only query the share system.
         foreach ($this->_shares->listShares($GLOBALS['registry']->getAuth()) as $share) {
             $galleries[] = $share->getId();
         }
         if (empty($galleries)) {
             return array();
         }
     }
     if (!count($slugs)) {
         // Searching by gallery_id
         $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images ' . 'WHERE gallery_id IN (' . str_repeat('?, ', count($galleries) - 1) . '?) ';
         $criteria = $galleries;
     } elseif (count($slugs)) {
         // Searching by gallery_slug so we need to join the share table
         $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images LEFT JOIN ' . $this->_shares->getTable() . ' ON ansel_images.gallery_id = ' . $this->_shares->getTable() . '.share_id ' . 'WHERE attribute_slug IN (' . str_repeat('?, ', count($slugs) - 1) . '?) ';
         $criteria = $slugs;
     }
     $sql .= ' ORDER BY image_uploaded_date DESC';
     if ($limit > 0) {
         $sql = $this->_db->addLimitOffset($sql, array('limit' => (int) $limit));
     }
     try {
         $images = $this->_db->select($sql, $criteria);
     } catch (Horde_Db_Exception $e) {
         throw new Ansel_Exception($e);
     }
     $columns = $this->_db->columns('ansel_images');
     foreach ($images as $image) {
         $image['image_filename'] = Horde_String::convertCharset($image['image_filename'], $GLOBALS['conf']['sql']['charset'], 'UTF-8');
         $image['image_caption'] = Horde_String::convertCharset($columns['image_caption']->binaryToString($image['image_caption']), $GLOBALS['conf']['sql']['charset'], 'UTF-8');
         $results[] = new Ansel_Image($image);
     }
     return $results;
 }