Overview

Packages

  • Ansel
  • None

Classes

  • Ansel
  • Ansel_Ajax_Application
  • Ansel_Ajax_Imple_EditCaption
  • Ansel_Ajax_Imple_EditFaces
  • Ansel_Ajax_Imple_EditGalleryFaces
  • Ansel_Ajax_Imple_Embed
  • Ansel_Ajax_Imple_GallerySlugCheck
  • Ansel_Ajax_Imple_ImageSaveGeotag
  • Ansel_Ajax_Imple_LocationAutoCompleter
  • Ansel_Ajax_Imple_MapLayerSelect
  • Ansel_Ajax_Imple_TagActions
  • Ansel_Ajax_Imple_ToggleGalleryActions
  • Ansel_Ajax_Imple_ToggleOtherGalleries
  • Ansel_Ajax_Imple_UploadNotification
  • Ansel_Api
  • Ansel_Exception
  • Ansel_Faces
  • Ansel_Faces_Base
  • Ansel_Faces_Facedetect
  • Ansel_Faces_User
  • Ansel_Factory_Faces
  • Ansel_Factory_Storage
  • Ansel_Factory_Styles
  • Ansel_Form_Ecard
  • Ansel_Form_Image
  • Ansel_Form_ImageDate
  • Ansel_Form_Upload
  • Ansel_Gallery
  • Ansel_Gallery_Decorator_Date
  • Ansel_GalleryMode_Base
  • Ansel_GalleryMode_Date
  • Ansel_GalleryMode_Normal
  • Ansel_Image
  • Ansel_ImageGenerator
  • Ansel_ImageGenerator_Mini
  • Ansel_ImageGenerator_PolaroidThumb
  • Ansel_ImageGenerator_PolaroidThumbStack
  • Ansel_ImageGenerator_RoundedThumb
  • Ansel_ImageGenerator_RoundedThumbStack
  • Ansel_ImageGenerator_Screen
  • Ansel_ImageGenerator_ShadowThumb
  • Ansel_ImageGenerator_ShadowThumbStack
  • Ansel_ImageGenerator_SquareThumb
  • Ansel_ImageGenerator_Thumb
  • Ansel_LoginTasks_SystemTask_Upgrade
  • Ansel_Report
  • Ansel_Report_letter
  • Ansel_Report_mail
  • Ansel_Report_tickets
  • Ansel_Search
  • Ansel_Search_exif
  • Ansel_Search_Tag
  • Ansel_Storage
  • Ansel_Style
  • Ansel_Tagger
  • Ansel_Test
  • Ansel_Tile_DateGallery
  • Ansel_Tile_Gallery
  • Ansel_Tile_Image
  • Ansel_View_Ansel
  • Ansel_View_Base
  • Ansel_View_EmbeddedRenderer_GalleryLink
  • Ansel_View_EmbeddedRenderer_Mini
  • Ansel_View_EmbeddedRenderer_Slideshow
  • Ansel_View_Gallery
  • Ansel_View_GalleryProperties
  • Ansel_View_GalleryRenderer_Base
  • Ansel_View_GalleryRenderer_Gallery
  • Ansel_View_GalleryRenderer_GalleryLightbox
  • Ansel_View_Image
  • Ansel_View_List
  • Ansel_View_Results
  • Ansel_View_Slideshow
  • Ansel_View_Upload
  • Ansel_Widget
  • Ansel_Widget_Actions
  • Ansel_Widget_Base
  • Ansel_Widget_GalleryFaces
  • Ansel_Widget_Geotag
  • Ansel_Widget_ImageFaces
  • Ansel_Widget_Links
  • Ansel_Widget_OtherGalleries
  • Ansel_Widget_OwnerFaces
  • Ansel_Widget_SimilarPhotos
  • Ansel_Widget_Tags
  • Ansel_XPPublisher
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Ansel_View_Results:: class wraps display of images/galleries from
  4:  * multiple parent sources..
  5:  *
  6:  * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @TODO: Should extend Base, not Ansel
 12:  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/gpl GPL
 15:  * @package  Ansel
 16:  */
 17: class Ansel_View_Results extends Ansel_View_Ansel
 18: {
 19:     /**
 20:      * Instance of our tag search
 21:      *
 22:      * @var Ansel_Tag_Search
 23:      */
 24:     protected $_search;
 25: 
 26:     /**
 27:      * Gallery owner id
 28:      *
 29:      * @var string
 30:      */
 31:     protected $_owner;
 32: 
 33:     /**
 34:      * The current page
 35:      *
 36:      * @var integer
 37:      */
 38:     private $_page;
 39: 
 40:     /**
 41:      * Number of resources per page.
 42:      *
 43:      * @var integer
 44:      */
 45:     private $_perPage;
 46: 
 47:     /**
 48:      * Contructor.
 49:      *
 50:      * Also handles any actions from the view.
 51:      *
 52:      * @return Ansel_View_Results
 53:      */
 54:     public function __construct()
 55:     {
 56:         global $prefs, $conf;
 57: 
 58:         $notification = $GLOBALS['injector']->getInstance('Horde_Notification');
 59:         $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
 60: 
 61:         $this->_owner = Horde_Util::getFormData('owner', '');
 62:         //@TODO: Inject the search object when we have more then just a tag search
 63:         $this->_search = new Ansel_Search_Tag($GLOBALS['injector']->getInstance('Ansel_Tagger'), null, $this->_owner);
 64:         $this->_page = Horde_Util::getFormData('page', 0);
 65:         $action = Horde_Util::getFormData('actionID', '');
 66:         $image_id = Horde_Util::getFormData('image');
 67:         $vars = Horde_Variables::getDefaultVariables();
 68: 
 69:         /* Number perpage from prefs or config. */
 70:         $this->_perPage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']);
 71: 
 72:         switch ($action) {
 73:         /*  Image related actions */
 74:         case 'delete':
 75:              if (is_array($image_id)) {
 76:                  $images = array_keys($image_id);
 77:              } else {
 78:                  $images = array($image_id);
 79:              }
 80: 
 81:              foreach ($images as $image) {
 82:                  $img = $ansel_storage->getImage($image);
 83:                  $gallery = $ansel_storage->getgallery($img->gallery);
 84:                  if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
 85:                      $notification->push(
 86:                         sprintf(_("Access denied deleting photos from \"%s\"."), $image), 'horde.error');
 87:                  } else {
 88:                      try {
 89:                          $gallery->removeImage($image);
 90:                          $notification->push(_("Deleted the photo."), 'horde.success');
 91:                      } catch (Ansel_Exception $e) {
 92:                         $notification->push(
 93:                             sprintf(_("There was a problem deleting photos: %s"), $e->getMessage()), 'horde.error');
 94:                      }
 95:                  }
 96:              }
 97: 
 98:              Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
 99:              exit;
100: 
101:         case 'move':
102:             if (is_array($image_id)) {
103:                 $images = array_keys($image_id);
104:             } else {
105:                 $images = array($image_id);
106:             }
107: 
108:             // Move the images if we're provided with at least one
109:             // valid image ID.
110:             $newGallery = Horde_Util::getFormData('new_gallery');
111:             if ($images && $newGallery) {
112:                 try {
113:                     $newGallery = $ansel_storage->getGallery($newGallery);
114:                     // Group by gallery first, then process in bulk by gallery.
115:                     $galleries = array();
116:                     foreach ($images as $image) {
117:                         $img = $ansel_storage->getImage($image);
118:                         $galleries[$img->gallery][] = $image;
119:                     }
120:                     foreach ($galleries as $gallery_id => $images) {
121:                         $gallery = $ansel_storage->getGallery($gallery_id);
122:                         try {
123:                             $result = $gallery->moveImagesTo($images, $newGallery);
124:                             $notification->push(
125:                                 sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
126:                                                  "Moved %d photos from \"%s\" to \"%s\"",
127:                                                  count($images)),
128:                                         count($images), $gallery->get('name'),
129:                                         $newGallery->get('name')),
130:                                 'horde.success');
131:                         } catch (Exception $e) {
132:                             $notification->push($e->getMessage(), 'horde.error');
133:                         }
134:                     }
135:                 } catch (Ansel_Exception $e) {
136:                     $notification->push(_("Bad input."), 'horde.error');
137:                 }
138:             }
139: 
140:             Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
141:             exit;
142: 
143:         case 'copy':
144:             if (is_array($image_id)) {
145:                 $images = array_keys($image_id);
146:             } else {
147:                 $images = array($image_id);
148:             }
149: 
150:             $newGallery = Horde_Util::getFormData('new_gallery');
151:             if ($images && $newGallery) {
152:                 try {
153:                     /* Group by gallery first, then process in bulk by gallery. */
154:                     $newGallery = $ansel_storage->getGallery($newGallery);
155:                     $galleries = array();
156:                     foreach ($images as $image) {
157:                         $img = $ansel_storage->getImage($image);
158:                         $galleries[$img->gallery][] = $image;
159:                     }
160:                     foreach ($galleries as $gallery_id => $images) {
161:                         $gallery = $ansel_storage->getGallery($gallery_id);
162:                         try {
163:                             $result = $gallery->copyImagesTo($images, $newGallery);
164:                             $notification->push(
165:                                 sprintf(ngettext("Copied %d photo from %s to %s",
166:                                                  "Copied %d photos from %s to %s",
167:                                                  count($images)),
168:                                         count($images), $gallery->get('name'),
169:                                         $newGallery->get('name')),
170:                                 'horde.success');
171:                         } catch (Exception $e) {
172:                             $notification->push($e->getMessage(), 'horde.error');
173:                         }
174:                     }
175:                 } catch (Ansel_Exception $e) {
176:                     $notification->push(_("Bad input."), 'horde.error');
177:                 }
178:             }
179:             Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
180:             exit;
181: 
182:         /* Tag related actions */
183:         case 'remove':
184:             $tag = Horde_Util::getFormData('tag');
185:             if (isset($tag)) {
186:                 $this->_search->removeTag($tag);
187:                 $this->_search->save();
188:             }
189:             break;
190: 
191:         case 'add':
192:         default:
193:             $tag = Horde_Util::getFormData('tag');
194:             if (isset($tag)) {
195:                 $this->_search->addTag($tag);
196:                 $this->_search->save();
197:             }
198:             break;
199:         }
200: 
201:         /* Check for empty tag search and redirect if empty */
202:         if ($this->_search->tagCount() < 1) {
203:             Horde::url('browse.php', true)->redirect();
204:             exit;
205:         }
206:     }
207: 
208:     /**
209:      * Return the title for this view.
210:      *
211:      * @return string The title for this view.
212:      */
213:     public function getTitle()
214:     {
215:         return (!empty($this->_owner))
216:                 ? sprintf(_("Searching %s's photos tagged: "), $this->_owner)
217:                 : _("Searching all photos tagged: ");
218:     }
219: 
220:     /**
221:      * Get the HTML representing this view.
222:      *
223:      * @return string  The HTML
224:      */
225:     public function html()
226:     {
227:         global $conf, $prefs;
228: 
229:         /* Ansel Storage*/
230:         $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
231: 
232:         // Get the slice of galleries/images to view on this page.
233:         try {
234:             $results = $this->_search->getSlice($this->_page, $this->_perPage);
235:         } catch (Ansel_Exception $e) {
236:             Horde::logMessage($e->getMessage(), 'ERR');
237:             return _("An error has occured retrieving the image. Details have been logged.");
238:         }
239:         $total = $this->_search->count();
240:         $total = $total['galleries'] + $total['images'];
241: 
242:         // The number of resources to display on this page.
243:         $numimages = count($results);
244:         $tilesperrow = $prefs->getValue('tilesperrow');
245: 
246:         // Get any related tags to display.
247:         if ($conf['tags']['relatedtags']) {
248:             $rtags = $this->_search->getRelatedTags();
249:             $rtaghtml = '<ul>';
250: 
251:             $links = Ansel::getTagLinks($rtags, 'add');
252:             foreach ($rtags as $id => $taginfo) {
253:                 if (!empty($this->_owner)) {
254:                     $links[$id]->add('owner', $this->_owner);
255:                 }
256:                 $rtaghtml .= '<li>' . $links[$id]->link(array('title' => sprintf(ngettext("%d photo", "%d photos",$taginfo['total']),$taginfo['total']))) . $taginfo['tag_name'] . '</a></li>';
257:             }
258:             $rtaghtml .= '</ul>';
259:         }
260:         $style = Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle'));
261:         $viewurl = Horde::url('view.php')->add(array('view' => 'Results',
262:                                                      'actionID' => 'add'));
263: 
264:         $vars = Horde_Variables::getDefaultVariables();
265:         $option_move = $option_copy = $ansel_storage->countGalleries($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::EDIT));
266: 
267:         $this->_pagestart = ($this->_page * $this->_perPage) + 1;
268:         $this->_pageend = min($this->_pagestart + $numimages - 1, $this->_pagestart + $this->_perPage - 1);
269:         $this->_pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $total,
270:                                                          'url' => $viewurl,
271:                                                          'perpage' => $this->_perPage));
272:         Horde::startBuffer();
273:         include ANSEL_TEMPLATES . '/view/results.inc';
274:         return Horde::endBuffer();
275:     }
276: 
277:     public function viewType()
278:     {
279:         return 'Results';
280:     }
281: 
282:     public function getGalleryCrumbData()
283:     {
284:         return array();
285:     }
286: 
287: }
288: 
API documentation generated by ApiGen