PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/code/groupview/SilvercartGroupViewBase.php

https://bitbucket.org/silvercart/silvercart/
PHP | 230 lines | 81 code | 23 blank | 126 comment | 9 complexity | b90b96dc36b1ac0bc60887db65d84dfb MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2010, 2011 pixeltricks GmbH
  4. *
  5. * This file is part of SilverCart.
  6. *
  7. * SilverCart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SilverCart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with SilverCart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @package Silvercart
  21. * @subpackage Groupview
  22. */
  23. /**
  24. * provides the base logic for a group view type.
  25. *
  26. * @package Silvercart
  27. * @subpackage Groupview
  28. * @author Sebastian Diel <sdiel@pixeltricks.de>
  29. * @copyright 2010 pixeltricks GmbH
  30. * @since 14.11.2002
  31. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  32. */
  33. class SilvercartGroupViewBase extends DataObject {
  34. protected $Code;
  35. protected $Image;
  36. protected $active = null;
  37. protected $activeHolder = null;
  38. protected $defaultPreferences = array(
  39. 'code' => '',
  40. 'image' => '',
  41. 'image_active' => '',
  42. 'image_inactive' => '',
  43. 'i18n_key' => '',
  44. 'i18n_default' => '',
  45. );
  46. protected $preferences = array();
  47. /**
  48. * default constructor. reads the preferences from extendet group views and
  49. * initializes the group view object.
  50. *
  51. * @param array $record array of field values
  52. * @param bool $isSingleton true if this is a singleton() object
  53. *
  54. * @return void
  55. *
  56. * @global string $project the name of the userdefined project
  57. *
  58. * @author Sebastian Diel <sdiel@pixeltricks.de>
  59. * @since 14.02.2011
  60. */
  61. public function __construct($record = null, $isSingleton = null) {
  62. parent::__construct($record, $isSingleton);
  63. $this->preferences = $this->preferences();
  64. $this->setCode($this->preferences['code']);
  65. }
  66. /**
  67. * provides the default preferences. Must be overwritten by extensions.
  68. *
  69. * @return array
  70. *
  71. * @author Sebastian Diel <sdiel@pixeltricks.de>
  72. * @since 14.02.2011
  73. * @see self::$defaultPreferences
  74. */
  75. protected function preferences() {
  76. return $this->defaultPreferences;
  77. }
  78. /**
  79. * returns the group views code
  80. *
  81. * @return string
  82. */
  83. public function getCode() {
  84. return $this->Code;
  85. }
  86. /**
  87. * sets the group views code
  88. *
  89. * @param string $Code the group views code
  90. *
  91. * @return void
  92. */
  93. public function setCode($Code) {
  94. $this->Code = $Code;
  95. }
  96. /**
  97. * returns the group views image
  98. *
  99. * @return string
  100. *
  101. * @author Sebastian Diel <sdiel@pixeltricks.de>
  102. * @since 14.02.2011
  103. */
  104. public function Image() {
  105. global $project;
  106. if (!$this->Image) {
  107. if ($this->isActive()) {
  108. $highlightStatus = 'active';
  109. } else {
  110. $highlightStatus = 'inactive';
  111. }
  112. if (is_file(Director::baseFolder() . '/' . $this->preferences['image_' . $highlightStatus])) {
  113. $this->preferences['image'] = Director::absoluteBaseURL() . '/' . $this->preferences['image_' . $highlightStatus];
  114. } elseif (is_file(Director::baseFolder() . '/' . $project . '/images/icons/20x20_group_view_' . $this->preferences['code'] . '_' . $highlightStatus . '.png')) {
  115. $this->preferences['image'] = Director::absoluteBaseURL() . $project . '/images/icons/20x20_group_view_' . $this->preferences['code'] . '_' . $highlightStatus . '.png';
  116. } elseif (is_file(Director::baseFolder() . '/silvercart/images/icons/20x20_group_view_' . $this->preferences['code'] . '_' . $highlightStatus . '.png')) {
  117. $this->preferences['image'] = Director::absoluteBaseURL() . 'silvercart/images/icons/20x20_group_view_' . $this->preferences['code'] . '_' . $highlightStatus . '.png';
  118. } else {
  119. $this->preferences['image'] = '';
  120. }
  121. $this->setImage($this->preferences['image']);
  122. }
  123. return $this->Image;
  124. }
  125. /**
  126. * sets the group views image
  127. *
  128. * @param string $Image the group views image
  129. *
  130. * @return void
  131. */
  132. public function setImage($Image) {
  133. $this->Image = $Image;
  134. }
  135. /**
  136. * returns the group views label
  137. *
  138. * @return string
  139. */
  140. public function getLabel() {
  141. return _t($this->preferences['i18n_key'], $this->preferences['i18n_default']);;
  142. }
  143. /**
  144. * returns, wether the group view is active or not
  145. *
  146. * @return bool
  147. */
  148. public function getActive() {
  149. if (is_null($this->active)) {
  150. $this->setActive($this->Code == SilvercartGroupViewHandler::getActiveGroupView());
  151. }
  152. return $this->active;
  153. }
  154. /**
  155. * sets, wether the group view is active or not
  156. *
  157. * @param bool $active activity of the group view
  158. *
  159. * @return void
  160. */
  161. public function setActive($active) {
  162. $this->active = $active;
  163. }
  164. /**
  165. * returns, wether the group view is active or not
  166. *
  167. * @return bool
  168. */
  169. public function getActiveHolder() {
  170. if (is_null($this->activeHolder)) {
  171. $this->setActiveHolder($this->Code == SilvercartGroupViewHandler::getActiveGroupHolderView());
  172. }
  173. return $this->activeHolder;
  174. }
  175. /**
  176. * sets, wether the group view is active or not
  177. *
  178. * @param bool $activeHolder activity of the group view
  179. *
  180. * @return void
  181. */
  182. public function setActiveHolder($activeHolder) {
  183. $this->activeHolder = $activeHolder;
  184. }
  185. /**
  186. * returns, wether the group view is active or not
  187. *
  188. * @return bool
  189. *
  190. * @author Sebastian Diel <sdiel@pixeltricks.de>
  191. * @since 14.02.2011
  192. */
  193. public function isActive() {
  194. return $this->getActive();
  195. }
  196. /**
  197. * returns, wether the group view is active or not
  198. *
  199. * @return bool
  200. *
  201. * @author Sebastian Diel <sdiel@pixeltricks.de>
  202. * @since 14.02.2011
  203. */
  204. public function isActiveHolder() {
  205. return $this->getActiveHolder();
  206. }
  207. }