Ansel_Gallery::setParent PHP Method

setParent() public method

Sets this gallery's parent gallery.
public setParent ( mixed $parent )
$parent mixed An Ansel_Gallery or a gallery_id.
    public function setParent($parent)
    {
        /* Make sure we have a gallery object */
        if (!is_null($parent) && !$parent instanceof Ansel_Gallery) {
            $parent = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($parent);
        }
        /* Check this now since we don't know if we are updating the DB or not */
        $old = $this->getParent();
        $reset_has_subgalleries = false;
        if (!is_null($old)) {
            $vMode = $old->get('view_mode');
            if ($vMode != 'Normal') {
                $old->set('view_mode', 'Normal');
            }
            $cnt = $old->countGalleryChildren(Horde_Perms::READ, true);
            if ($vMode != 'Normal') {
                $old->set('view_mode', $vMode);
            }
            if ($cnt == 1) {
                /* Count is 1, and we are about to delete it */
                $reset_has_subgalleries = true;
                if (!$old->countImages()) {
                    $old->resetKeyImage();
                }
            }
        }
        /* Call the parent class method */
        try {
            $this->_share->setParent(!is_null($parent) ? $parent->getShare() : null);
        } catch (Horde_Share_Exception $e) {
            throw new Ansel_Exception($e);
        }
        /* Tell the parent the good news */
        if (!is_null($parent) && !$parent->get('has_subgalleries')) {
            $parent->set('has_subgalleries', '1', true);
        }
        Horde::log('Ansel_Gallery parent successfully set', 'DEBUG');
        /* Gallery parent changed, safe to change the parent's attributes */
        if ($reset_has_subgalleries) {
            $old->set('has_subgalleries', 0, true);
        }
    }