/ansel/lib/Gallery/Decorator/Date.php

https://github.com/ewandor/horde · PHP · 194 lines · 76 code · 14 blank · 104 comment · 6 complexity · 9d9114c70330d26c899ce56fdfd06643 MD5 · raw file

  1. <?php
  2. /**
  3. * A decorator around an Ansel_Gallery to allow multiple date groupings
  4. * to access the same Ansel_Gallery instance.
  5. *
  6. * Copyright 2008-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. * @author Michael J. Rubinsky <mrubinsk@horde.org>
  12. * @package Ansel
  13. */
  14. class Ansel_Gallery_Decorator_Date
  15. {
  16. /**
  17. * The gallery mode helper
  18. *
  19. * @var Ansel_GalleryMode_Base object
  20. */
  21. protected $_modeHelper;
  22. /**
  23. * The gallery we are decorating
  24. *
  25. * @var Ansel_Gallery
  26. */
  27. protected $_gallery;
  28. /**
  29. * An array of image ids that this gallery contains
  30. *
  31. * @var array
  32. */
  33. protected $_images;
  34. /**
  35. * The Ansel_Gallery_Date constructor.
  36. *
  37. * The client code (Ansel_GalleryMode_Date) needs to call the setDate()
  38. * method on the new GalleryMode_Date object before it's used.
  39. *
  40. * @param Ansel_Gallery $gallery The gallery we are decorating.
  41. * @param array $images An array of image ids that this grouping
  42. * contains.
  43. */
  44. public function __construct(Ansel_Gallery $gallery, $images = array())
  45. {
  46. $this->_gallery = $gallery;
  47. $this->_modeHelper = new Ansel_GalleryMode_Date($this);
  48. $this->data = $this->_gallery->data;
  49. $this->_images = $images;
  50. }
  51. /**
  52. * Magic method - pass thru methods to the wrapped Ansel_Gallery:: or to
  53. * the Ansel_GalleryMode_Base:: handler.
  54. *
  55. * @param string $method
  56. * @param array $args
  57. *
  58. * @return mixed
  59. */
  60. public function __call($method, $args)
  61. {
  62. switch ($method) {
  63. case 'getGalleryChildren':
  64. case 'countGalleryChildren':
  65. case 'listImages':
  66. case 'getImages':
  67. case 'hasSubGalleries':
  68. case 'getDate':
  69. case 'setDate':
  70. return call_user_func_array(array($this->_modeHelper, $method), $args);
  71. default:
  72. return call_user_func_array(array($this->_gallery, $method), $args);
  73. }
  74. }
  75. public function __get($property)
  76. {
  77. switch ($property) {
  78. case 'id':
  79. return $this->_gallery->id;
  80. }
  81. }
  82. /**
  83. * Output the HTML for this gallery's tile.
  84. *
  85. * @param Ansel_Gallery $parent The parent Ansel_Gallery object
  86. * @param Ansel_Style $style A gallery style to use.
  87. * @param boolean $mini Force the use of a mini thumbnail?
  88. * @param array $params Any additional parameters the Ansel_Tile
  89. * object may need.
  90. */
  91. public function getTile($parent = null, $style = null, $mini = false, $params = array())
  92. {
  93. if (!is_null($parent) && is_null($style)) {
  94. $style = $parent->getStyle();
  95. }
  96. return Ansel_Tile_DateGallery::getTile($this, $style, $mini, $params);
  97. }
  98. /**
  99. * Return the most recently added images in this gallery.
  100. *
  101. * @param integer $limit The maximum number of images to return.
  102. *
  103. * @return array An array of Ansel_Image objects
  104. */
  105. public function getRecentImages($limit = 10)
  106. {
  107. return $GLOBALS['injector']->getInstance('Ansel_Storage')
  108. ->getRecentImages(array($this->_gallery->id), $limit);
  109. }
  110. /**
  111. * Returns the image in this gallery corresponding to the given id.
  112. *
  113. * @param integer $id The ID of the image to retrieve.
  114. *
  115. * @return Ansel_Image The image object corresponding to the given id.
  116. */
  117. public function getImage($id)
  118. {
  119. return $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id);
  120. }
  121. /**
  122. * Returns the number of images in this gallery and, optionally, all
  123. * sub-galleries.
  124. *
  125. * @param boolean $subgalleries Determines whether subgalleries should
  126. * be counted or not.
  127. *
  128. * @return integer number of images in this gallery
  129. */
  130. public function countImages($subgalleries = false)
  131. {
  132. return count($this->_images);
  133. }
  134. /**
  135. * Returns the key image for this gallery.
  136. *
  137. * @param Ansel_Style $style Force the use of this style, if it's available
  138. *
  139. * @return mixed The image_id of the key image or false.
  140. */
  141. public function getKeyImage($style = null)
  142. {
  143. if (count($this->_images)) {
  144. return reset($this->_images);
  145. } else {
  146. return 0;
  147. }
  148. }
  149. /**
  150. * Return a count of the number of children this share has
  151. *
  152. * @param string $user The user to use for checking perms
  153. * @param integer $perm A Horde_Perms::* constant
  154. * @param boolean $allLevels Count grandchildren or just children
  155. *
  156. * @return integer The number of child shares
  157. */
  158. public function countChildren($user, $perm = Horde_Perms::SHOW, $allLevels = true)
  159. {
  160. return $this->_gallery->getShareOb()->countShares($user, $perm, null, $this, $allLevels);
  161. }
  162. /**
  163. * Returns a child's direct parent
  164. *
  165. * @return Ansel_Gallery The direct parent Horde_Share_Object
  166. */
  167. public function getParent()
  168. {
  169. return $this->_gallery->getParent($this);
  170. }
  171. /**
  172. * Returns all image ids that this grouping contains.
  173. *
  174. * @array
  175. */
  176. public function getImagesByGrouping()
  177. {
  178. return $this->_images;
  179. }
  180. }