1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ansel_View_List extends Ansel_View_Ansel
16: {
17: private $_groupby;
18: private $_owner;
19: private $_special;
20: private $_page;
21: private $_start;
22: private $_g_perPage;
23: private $_numGalleries;
24: private $_galleryList;
25: private $_sortBy;
26: private $_sortDir;
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: public function __construct($params = array())
48: {
49: global $prefs;
50:
51: parent::__construct($params);
52:
53:
54: $notification = $GLOBALS['injector']->getInstance('Horde_Notification');
55:
56:
57: $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
58:
59:
60: $this->_sortBy = !empty($this->_params['sort']) ?
61: $this->_params['sort'] :
62: 'name';
63: $this->_sortDir = isset($this->_params['sort_dir']) ?
64: $this->_params['sort_dir'] :
65: 0;
66:
67:
68: if (empty($this->_params['groupby'])) {
69: $this->_groupby = Horde_Util::getFormData(
70: 'groupby',
71: $prefs->getValue('groupby'));
72: } else {
73: $this->_groupby = $this->_params['groupby'];
74: }
75:
76: if (empty($this->_params['owner'])) {
77: $this->_owner = Horde_Util::getFormData('owner');
78: $this->_owner = empty($this->_owner) ? null : $this->_owner;
79: } else {
80: $this->_owner = $this->_params['owner'];
81: }
82:
83: $this->_special = Horde_Util::getFormData('special');
84: if (!$this->_owner && !$this->_special && $this->_groupby != 'none' ) {
85: Ansel::getUrlFor(
86: 'group',
87: array('groupby' => $this->_groupby))->redirect();
88: exit;
89: }
90:
91:
92: if (isset($this->_params['page'])) {
93: $this->_page = $this->_params['page'];
94: } else {
95: $this->_page = Horde_Util::getFormData('page', 0);
96: }
97:
98: $this->_g_perPage = $this->tilesperpage ?
99: $this->tilesperpage :
100: $prefs->getValue('tilesperpage');
101:
102:
103: if (!empty($this->_params['api']) && is_array($this->_params['gallery_ids'])) {
104: $this->_start = $this->_page * $this->_g_perPage;
105: $this->_numGalleries = count($this->_params['gallery_ids']);
106: if ($this->_numGalleries > $this->_start) {
107: $getThese = array_slice(
108: $this->_params['gallery_ids'],
109: $this->_start,
110: $this->_g_perPage);
111: $this->_galleryList = $ansel_storage->getGalleries($getThese);
112: } else {
113: $this->_galleryList = array();
114: }
115: } else {
116:
117: $filter = array();
118: if (!is_null($this->_owner)) {
119: $filter['owner'] = $this->_owner;
120: }
121:
122: $this->_numGalleries = $ansel_storage->countGalleries(
123: $GLOBALS['registry']->getAuth(),
124: array('attributes' => $filter,
125: 'all_levels' => false,
126: 'tags' => !empty($params['tags']) ? $params['tags'] : null));
127:
128: if ($this->_numGalleries == 0 && empty($this->_params['api'])) {
129: if ($this->_owner && $filter == $this->_owner &&
130: $this->_owner == $GLOBALS['registry']->getAuth()) {
131:
132: $notification->push(_("You have no photo galleries, add one!"), 'horde.message');
133: Horde::url('gallery.php')->add('actionID', 'add')->redirect();
134: exit;
135: }
136: $notification->push(_("There are no photo galleries available."), 'horde.message');
137: $this->_galleryList = array();
138: } else {
139: $this->_galleryList = $ansel_storage->listGalleries(
140: array('attributes' => $filter,
141: 'all_levels' => false,
142: 'from' => $this->_page * $this->_g_perPage,
143: 'count' => $this->_g_perPage,
144: 'sort_by' => $this->_sortBy,
145: 'direction' => $this->_sortDir,
146: 'tags' => !empty($params['tags']) ? $params['tags'] : null));
147: }
148: }
149: }
150:
151: 152: 153: 154: 155:
156: public function getTitle()
157: {
158: if ($this->_owner) {
159: if ($this->_owner == $GLOBALS['registry']->getAuth() &&
160: empty($this->_params['api'])) {
161:
162: return _("My Galleries");
163: } elseif (!empty($GLOBALS['conf']['gallery']['customlabel'])) {
164: $uprefs = $GLOBALS['injector']
165: ->getInstance('Horde_Core_Factory_Prefs')
166: ->create('ansel', array(
167: 'cache' => false,
168: 'owner' => $this->_owner));
169: $fullname = $uprefs->getValue('grouptitle');
170: if (!$fullname) {
171: $identity = $GLOBALS['injector']
172: ->getInstance('Horde_Core_Factory_Identity')
173: ->create($this->_owner);
174: $fullname = $identity->getValue('fullname');
175: if (!$fullname) {
176: $fullname = $this->_owner;
177: }
178: return sprintf(_("%s's Galleries"), $fullname);
179: } else {
180: return $fullname;
181: }
182: } else {
183: return sprintf(_("%s's Galleries"), $this->_owner);
184: }
185: } else {
186: return _("Gallery List");
187: }
188: }
189:
190: 191: 192: 193: 194: 195:
196: public function html()
197: {
198: global $conf, $prefs, $registry;
199:
200: $vars = Horde_Variables::getDefaultVariables();
201: if (!empty($this->_params['page'])) {
202: $vars->add('page', $this->_params['page']);
203: }
204:
205: if (!empty($this->_params['pager_url'])) {
206: $this->_pagerurl = $this->_params['pager_url'];
207: $override = true;
208: } else {
209: $override = false;
210: $this->_pagerurl = Ansel::getUrlFor(
211: 'view',
212: array(
213: 'owner' => $this->_owner,
214: 'special' => $this->_special,
215: 'groupby' => $this->_groupby,
216: 'view' => 'List'));
217: }
218: $p_params = array('num' => $this->_numGalleries,
219: 'url' => $this->_pagerurl,
220: 'perpage' => $this->_g_perPage);
221:
222: if ($override) {
223: $p_params['url_callback'] = null;
224: }
225: $this->_pager = new Horde_Core_Ui_Pager('page', $vars, $p_params);
226: $preserve = array('sort_dir' => $this->_sortDir);
227: if (!empty($this->_sortBy)) {
228: $preserve['sort'] = $this->_sortBy;
229: }
230: $this->_pager->preserve($preserve);
231:
232: if ($this->_numGalleries) {
233: $min = $this->_page * $this->_g_perPage;
234: $max = $min + $this->_g_perPage;
235: if ($max > $this->_numGalleries) {
236: $max = $this->_numGalleries - $min;
237: }
238: $this->_start = $min + 1;
239: $end = min($this->_numGalleries, $min + $this->_g_perPage);
240:
241: if ($this->_owner) {
242: $refresh_link = Ansel::getUrlFor(
243: 'view',
244: array(
245: 'groupby' => $this->_groupby,
246: 'owner' => $this->_owner,
247: 'page' => $this->_page,
248: 'view' => 'List'));
249: } else {
250: $refresh_link = Ansel::getUrlFor(
251: 'view',
252: array(
253: 'view' => 'List',
254: 'groupby' => $this->_groupby,
255: 'page' => $this->_page));
256: }
257:
258: $tilesperrow = $this->tilesperrow ?
259: $this->tilesperrow :
260: $prefs->getValue('tilesperrow');
261:
262:
263: if (empty($this->_params['style'])) {
264: $style = Ansel::getStyleDefinition($prefs->getValue('default_gallerystyle'));
265: } else {
266: $style = Ansel::getStyleDefinition($this->_params['style']);
267: }
268: $count = 0;
269: $width = round(100 / $tilesperrow);
270:
271: Horde::startBuffer();
272: include ANSEL_TEMPLATES . '/view/list.inc';
273: $html = Horde::endBuffer();
274:
275: return $html;
276: }
277:
278: return '';
279: }
280:
281: public function viewType()
282: {
283: return 'List';
284: }
285:
286: 287: 288: 289: 290:
291: public function getGalleryCrumbData()
292: {
293: throw new Horde_Exception('Ansel_View_List::getGalleryCrumbData not implemented.');
294: }
295:
296: }
297: