Ansel_Api::count PHP Method

count() public method

Returns the number of images in a gallery.
public count ( integer $gallery_id = null, array $params = [] ) : integer
$gallery_id integer The gallery id.
$params array Array of optional parameters:
   (string)scope  Scope to use, if not the default.
   (string)slug   If set, ignore gallery_id and use this as the slug.
return integer The number of images in the gallery.
    public function count($gallery_id = null, array $params = array())
    {
        if (!empty($params['scope'])) {
            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
        }
        try {
            if (!empty($params['slug'])) {
                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryBySlug($params['slug']);
            } else {
                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
            }
            return (int) $gallery->countImages();
        } catch (Ansel_Exception $e) {
            return 0;
        }
    }