urn $this->context()->isAdmin();
}
function get_may_publish()
{
return $this->publishing_rights;
}
function get_may_view_galleries()
{
return $this->may_view;
}
function get_may_add_gallery()
{
return $this->gallery_rights;
}
function get_may_view_images()
{
if ($this->context()->adminImagesBrowseable()) {
return true;
}
return $this->image_rights;
}
function get_may_add_image()
{
if ($this->no_images) {
return false;
}
return $this->image_rights;
}
function get_may_edit_users()
{
return $this->context()->isAdmin();
}
private $_status_icons = null;
function get_status_icons()
{
if ($this->_status_icons === null) {
$_ = $this->getModel()->Node->getStrings();
$icons = array();
if ($this->locked) {
$icons[] = array('type' => 'locked',
'label' => $_->GALLERY_LOCKED);
}
if (!$this->published) {
$icons[] = array('type' => 'draft',
'label' => $_->GALLERY_UNPUBLISHED);
}
if ($this->hidden) {
$icons[] = array('type' => 'hidden',
'label' => $_->GALLERY_HIDDEN);
}
$this->_status_icons = $icons;
}
return $this->_status_icons;
}
private $_effective_status_icons = null;
function get_effective_status_icons()
{
if ($this->_effective_status_icons === null) {
$_ = $this->getModel()->Node->getStrings();
$locked = $unpublished = $hidden = false;
foreach ($this->parents as $parent) {
if ($parent->locked) {
$locked = true;
}
if (!$parent->published) {
$unpublished = true;
}
if ($parent->hidden) {
$hidden = true;
}
}
if ($this->locked) {
$locked = true;
}
if (!$this->published) {
$unpublished = true;
}
if ($this->hidden) {
$hidden = true;
}
$icons = array();
if ($locked) {
$icons[] = array('type' => 'locked',
'label' => $_->GALLERY_LOCKED);
}
if ($unpublished) {
$icons[] = array('type' => 'draft',
'label' => $_->GALLERY_UNPUBLISHED);
}
if ($hidden) {
$icons[] = array('type' => 'hidden',
'label' => $_->GALLERY_HIDDEN);
}
$this->_effective_status_icons = $icons;
}
return $this->_effective_status_icons;
}
function get_path_galleries()
{
$items = array();
foreach ($this->parents as $parent) {
$items[] = $parent;
}
$items[] = $this;
return $items;
}
function get_title_with_parents()
{
$titles = array();
foreach ($this->parents as $parent) {
$titles[] = $parent->title;
}
$titles[] = $this->title;
return implode(': ', $titles);
}
function get_publishing_rights($init=true)
{
if ($init) {
if ($this->context()->isAdmin()) {
return true;
}
$this->model()->initUsers();
}
if ($this->_allow_publish) {
return true;
}
if ($this->parent) {
return $this->parent->get_publishing_rights(false);
}
return false;
}
function get_gallery_rights($init=true)
{
if ($init) {
if ($this->context()->isAdmin()) {
return true;
}
$this->model()->initUsers();
}
if ($this->_allow_galleries) {
return true;
}
if ($this->parent) {
return $this->parent->get_gallery_rights(false);
}
return false;
}
function get_image_rights($init=true)
{
if ($init) {
if ($this->context()->isAdmin()) {
return true;
}
$this->model()->initUsers();
}
if ($this->_allow_images) {
return true;
}
if ($this->parent) {
return $this->parent->get_image_rights(false);
}
return false;
}
function get_parents()
{
if ($this->_parents === null) {
$this->loadParents();
}
return $this->_parents;
}
function get_ids_path()
{
return $this->parent_path . $this->id;
}
function getParentKeys()
{
if ($this->_parent_keys === null) {
$this->loadParents();
}
return $this->_parent_keys;
}
function isPublic()
{
if (!$this->published || $this->locked) {
return false;
}
foreach ($this->parents as $parent) {
if ($parent->locked || !$parent->published) {
return false;
}
}
return true;
}
function getRandomImage($count=null)
{
$lang = $this->getModel()->Node->site->request->language;
$id = $this->id;
$parpath = $this->parent_path;
$path = $parpath . $id . '/';
$gmod = $this->getModel();
$qg = $gmod->createQuery();
$qg->select('id');
$qg->filter('parent_path', $path . '%', 'like');
$qg->filter('published', true);
$qg->filter('locked', false);
$imod = $this->getModel('image');
$q = $imod->createQuery();
$q2 = $q->cond('or');
$q2->filter('gallery', $id);
$q2->filterSubselect('gallery', $qg, 'in');
$q->filterCompound($q2);
$q->filter('published', true);
$q->filter('locked', false);
$q->joinOnField('version');
$q->order(null, null, 'rand()');
if ($count) {
$q->limit($count);
} else {
$q->limit(1);
}
$images = $imod->findAll($q);
if (!$images) {
return null;
}
if ($count !== null && $count != 1) {
return $images;
}
$image = $images[0];
if (!$image) {
return null;
}
return $image;
}
function countImages($draft=false)
{
$id = $this->id;
$parpath = $this->parent_path;
$path = $parpath . $id . '/';
$gmod = $this->getModel('gallery');
$gq = $gmod->createQuery();
$gq->select('id');
$gq->filter('parent_path', $path . '%', 'like');
if (!$draft) {
$gq->filter('published', true);
$gq->filter('locked', false);
}
$imod = $this->getModel('image');
$q = $imod->createQuery();
$q2 = $q->cond('or');
$q2->filter('gallery', $id);
$q2->filterSubselect('gallery', $gq, 'in');
$q->filterCompound($q2);
if (!$draft) {
$q->filter('published', true);
$q->filter('locked', false);
}
$q->joinOnField('version');
$q->filter('version', null, '<>');
$q->selectAs('id', 'count', 'COUNT(%s)');
$images = $imod->findAllToArray($q);
if (!$images || !$images[0]) {
return 0;
}
return $images[0]['count'];
}
private function loadParents()
{
$this->_parents = array();
$this->_parent_keys = array();
$path = $this->parent_path;
if (!$path) {
return;
}
$ids = array_map('intval', array_filter(explode('/', $path)));
$this->_parent_keys = $ids;
if (!$ids) {
return;
}
$model = $this->getModel();
$q = $model->createQuery();
$q->filter('id', $ids, 'in');
$items = array();
foreach($model->findAll($q) as $item) {
$items[$item->id] = $item;
}
$parents = array();
foreach ($ids as $id) {
$parents[] = $items[$id];
}
$this->_parents = $parents;
}
}
?>