Ansel_Gallery::toJson PHP Method

toJson() public method

Returns a json representation of this gallery.
public toJson ( boolean $full = false ) : StdClass
$full boolean Return all information (subgalleries and images)?
return StdClass An object describing the gallery
'id' - gallery id
'p'  - gallery's parent's id (null if top level)
'pn' - gallery's parent's name (null if top level)
'n'  - gallery name
'dc' - date created
'dm' - date modified
'd'  - description
'ki' - key image
'sg' - an object with the following properties:
     'n'  - gallery name
     'dc' - date created
     'dm' - date modified
     'd'  - description
     'ki' - key image

 'imgs' - an array of image objects with the following properties:
     'id'  - the image id
     'url' - the image url
    public function toJson($full = false)
    {
        // @TODO: Support date grouped galleries
        $vMode = $this->get('view_mode');
        if ($vMode != 'Normal') {
            $this->_setModeHelper('Normal');
        }
        $style = Ansel::getStyleDefinition('ansel_mobile');
        $json = new StdClass();
        $json->id = $this->id;
        $json->n = $this->get('name');
        $json->dc = $this->get('date_created');
        $json->dm = $this->get('last_modified');
        $json->d = $this->get('desc');
        $json->ki = Ansel::getImageUrl($this->getKeyImage($style), 'thumb', false, $style)->toString(true);
        $json->imgs = array();
        // Parent
        $parents = $this->getParents();
        if (empty($parents)) {
            $json->p = null;
            $json->pn = null;
        } else {
            $p = array_pop($parents);
            $json->p = $p->id;
            $json->pn = $p->get('name');
        }
        if ($full) {
            $json->tiny = $GLOBALS['conf']['image']['tiny'] && ($GLOBALS['conf']['vfs']['src'] == 'direct' || $this->_share->hasPermission('', Horde_Perms::READ));
            $json->sg = array();
            if ($this->hasSubGalleries()) {
                $sgs = $this->getChildren($GLOBALS['registry']->getAuth(), Horde_Perms::READ, false);
                //GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->id, 'all_levels' => false));
                foreach ($sgs as $g) {
                    $json->sg[] = $g->toJson();
                }
            }
            $images = $this->getImages();
            foreach ($images as $img) {
                $i = new StdClass();
                $i->id = $img->id;
                $i->url = Ansel::getImageUrl($img->id, 'thumb', false, $style)->toString(true);
                $i->screen = Ansel::getImageUrl($img->id, 'screen', $json->tiny, Ansel::getStyleDefinition('ansel_default'))->toString(true);
                $i->fn = $img->filename;
                $json->imgs[] = $i;
            }
        }
        if ($vMode != 'Normal') {
            $this->_setModeHelper($vMode);
        }
        return $json;
    }