Ansel_Api::searchTags PHP Method

searchTags() public method

The 'raw' results array can be returned instead by setting $raw = true.
public searchTags ( array $names, integer $max = 10, integer $from, string $resource_type = '', string $user = null, boolean $raw = false, string $app = 'ansel' ) : array
$names array An array of tag_names to search for.
$max integer The maximum number of resources to return.
$from integer The number of the resource to start with.
$resource_type string The resource type [gallery, image, '']
$user string Restrict results to resources owned by $user.
$raw boolean Return the raw data?
$app string Application scope to use, if not the default.
return array An array of results:
 'title'    - The title for this resource.
 'desc'     - A terse description of this resource.
 'view_url' - The URL to view this resource.
 'app'      - The Horde application this resource belongs to.
    public function searchTags($names, $max = 10, $from = 0, $resource_type = '', $user = null, $raw = false, $app = 'ansel')
    {
        $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
        $results = $GLOBALS['injector']->getInstance('Ansel_Tagger')->search($names, array('type' => $resource_type, 'user' => $user));
        // Check for error or if we requested the raw data array.
        if ($raw) {
            return $results;
        }
        $return = array();
        if (!empty($results['images'])) {
            foreach ($results['images'] as $image_id) {
                $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
                $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
                $view_url = Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'image' => $image_id, 'view' => 'Image'), true);
                $gurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $image->gallery));
                $return[] = array('title' => $image->filename, 'desc' => $image->caption . ' ' . _("from") . ' ' . $gurl->link() . $g->get('name') . '</a>', 'view_url' => $view_url, 'app' => $app, 'icon' => Ansel::getImageUrl($image_id, 'mini'));
            }
        }
        if (!empty($results['galleries'])) {
            foreach ($results['galleries'] as $gallery) {
                $gal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery);
                $view_url = Horde::url('view.php')->add(array('gallery' => $gallery, 'view' => 'Gallery'));
                $gurl = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery));
                $return[] = array('desc' => $gurl->link() . $gal->get('name') . '</a>', 'view_url' => $view_url, 'app' => $app, 'icon' => Ansel::getImageUrl($gal->getKeyImage(), 'mini'));
            }
        }
        return $return;
    }