1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Ansel_Widget_OtherGalleries extends Ansel_Widget_Base
13: {
14: 15: 16: 17: 18: 19:
20: public function attach(Ansel_View_Base $view)
21: {
22: parent::attach($view);
23: $owner = $this->_view->gallery->getIdentity();
24: $name = $owner->getValue('fullname');
25: if (!$name) {
26: $name = $this->_view->gallery->get('owner');
27: }
28: $this->_title = sprintf(_("%s's Galleries"), $name);
29:
30: return true;
31: }
32:
33: 34: 35: 36: 37:
38: public function html()
39: {
40:
41:
42:
43:
44:
45:
46:
47:
48:
49: $widget = $this->_htmlBegin() . $this->_getOtherGalleries() . $this->_htmlEnd();
50:
51:
52:
53:
54: return $widget;
55: }
56:
57: 58: 59: 60: 61:
62: protected function _getOtherGalleries()
63: {
64: $owner = $this->_view->gallery->get('owner');
65:
66:
67: $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('otherAnselGalleries_' . md5($owner), 'Javascript', array('class' => 'anselWidgets'));
68:
69: try {
70: $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')
71: ->listGalleries(array('attributes' => $owner));
72: } catch (Ansel_Exception $e) {
73: Horde::logMessage($e, 'ERR');
74: return '';
75: }
76:
77: $html = '<div style="display:'
78: . (($GLOBALS['prefs']->getValue('show_othergalleries')) ? 'block' : 'none')
79: . ';background:' . $this->_style->background
80: . ';width:100%;max-height:300px;overflow:auto;" id="othergalleries" >';
81:
82: foreach ($galleries as $gallery) {
83: $parents = $gallery->get('parents');
84: if (empty($parents)) {
85: $parent = null;
86: } else {
87: $parents = explode(':', $parents);
88: $parent = array_pop($parents);
89: }
90:
91: $img = (string)Ansel::getImageUrl($gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')), 'mini', true);
92: $link = Ansel::getUrlFor('view', array('gallery' => $gallery->id,
93: 'slug' => $gallery->get('slug'),
94: 'view' => 'Gallery'),
95: true);
96:
97: $tree->addNode($gallery->id, $parent, $gallery->get('name'), null,
98: ($gallery->id == $this->_view->gallery->id),
99: array('icon' => $img, 'url' => $link));
100: }
101:
102: Horde::startBuffer();
103: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('ansel', 'ToggleOtherGalleries'), array(
104: 'bindTo' => 'othergalleries'
105: ));
106:
107: $tree->sort('label');
108: $tree->renderTree();
109: $html .= Horde::endBuffer();
110: $html .= '</div>';
111: $selfurl = Horde::selfUrl(true, true);
112: $html .= '<div class="control">'
113: . $selfurl->add('actionID', 'show_actions')->link(
114: array('id' => 'othergalleries-toggle',
115: 'class' => ($GLOBALS['prefs']->getValue('show_othergalleries') ? 'hide' : 'show')))
116: . ' </a></div>';
117:
118: return $html;
119: }
120:
121: }
122: