PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/entities/platform_group_entity.class.php

https://bitbucket.org/chamilo/chamilo-rights-dev/
PHP | 235 lines | 116 code | 29 blank | 90 comment | 3 complexity | 618e34b5fab48bdfd88fd05ef2e628a5 MD5 | raw file
  1. <?php
  2. namespace rights;
  3. use common\libraries\Theme;
  4. use common\libraries\Path;
  5. use common\libraries\EqualityCondition;
  6. use common\libraries\Translation;
  7. use common\libraries\Utilities;
  8. use common\libraries\AdvancedElementFinderElement;
  9. use common\libraries\AdvancedElementFinderElementType;
  10. use group\GroupDataManager;
  11. use group\Group;
  12. use group\GroupRelUser;
  13. use group\GroupManager;
  14. require_once dirname(__FILE__) . '/platform_group/location_platform_group_cell_renderer.class.php';
  15. require_once dirname(__FILE__) . '/platform_group/location_platform_group_column_model.class.php';
  16. require_once dirname(__FILE__) . '/nested_rights_entity.class.php';
  17. /**
  18. * Class that describes the platform groups for the rights editor
  19. *
  20. * @author Sven Vanpoucke
  21. */
  22. class PlatformGroupEntity implements NestedRightsEntity
  23. {
  24. const ENTITY_NAME = 'group';
  25. const ENTITY_TYPE = 2;
  26. private $platform_group_cache;
  27. private static $instance;
  28. static function get_instance()
  29. {
  30. if (! isset(self :: $instance))
  31. {
  32. self :: $instance = new self();
  33. }
  34. return self :: $instance;
  35. }
  36. /**
  37. * Retrieves the items for this entity
  38. *
  39. * @param Condition $condition
  40. * @param int $offset
  41. * @param int $count
  42. * @param Array $order_property
  43. * @return ObjectResultSet
  44. */
  45. function retrieve_entity_items($condition = null, $offset = null, $count = null, $order_property = null)
  46. {
  47. $condition = $this->get_condition($condition);
  48. return GroupDataManager :: get_instance()->retrieve_groups($condition, $offset, $count, $order_property);
  49. }
  50. /**
  51. * Retrieves the entity item ids relevant for a given user (direct subscribed platformgroups and their parents)
  52. * @param integer $user_id
  53. * @return array
  54. */
  55. function retrieve_entity_item_ids_linked_to_user($user_id)
  56. {
  57. if (is_null($this->platform_group_cache[$user_id]))
  58. {
  59. $gdm = GroupDataManager :: get_instance();
  60. $this->platform_group_cache[$user_id] = $gdm->retrieve_all_subscribed_groups_array($user_id, true);
  61. }
  62. return $this->platform_group_cache[$user_id];
  63. }
  64. /**
  65. * Counts the items for this entity
  66. *
  67. * @param Condition $condition
  68. * @return int
  69. */
  70. function count_entity_items($condition = null)
  71. {
  72. $condition = $this->get_condition($condition);
  73. return GroupDataManager :: get_instance()->count_groups($condition);
  74. }
  75. /**
  76. * Returns the name of this entity
  77. *
  78. * @return String
  79. */
  80. function get_entity_name()
  81. {
  82. return self :: ENTITY_NAME;
  83. }
  84. /**
  85. * Returns the translated name of this entiry for displaying purposes only!
  86. * @return String Translated name of the entity
  87. */
  88. function get_entity_translated_name()
  89. {
  90. return Translation :: get(Utilities :: underscores_to_camelcase(self :: ENTITY_NAME));
  91. }
  92. /**
  93. * Returns the type of this entity
  94. *
  95. * @return int
  96. */
  97. function get_entity_type()
  98. {
  99. return self :: ENTITY_TYPE;
  100. }
  101. /**
  102. * Returns the path to the icon of the entity
  103. *
  104. * @return String
  105. */
  106. function get_entity_icon()
  107. {
  108. return Theme :: get_image_path('common\extensions\rights_editor_manager') . 'place_group.png';
  109. }
  110. /**
  111. * Returns the cell renderer of this entity
  112. *
  113. * @param Application $browser
  114. * @return LocationPlatformGroupBrowserTableCellRenderer
  115. */
  116. function get_entity_cell_renderer($browser)
  117. {
  118. return new LocationPlatformGroupBrowserTableCellRenderer($browser);
  119. }
  120. /**
  121. * Returns the column model of this entity
  122. *
  123. * @param Application $browser
  124. * @return LocationPlatformGroupBrowserTableColumnModel
  125. */
  126. function get_entity_column_model($browser)
  127. {
  128. return new LocationPlatformGroupBrowserTableColumnModel($browser);
  129. }
  130. /**
  131. * Returns the property for the ID column of this entity
  132. * @return String
  133. */
  134. function get_id_property()
  135. {
  136. return Group :: PROPERTY_ID;
  137. }
  138. /**
  139. * Returns the property for the PARENT column of this entity
  140. * @return String
  141. */
  142. function get_parent_property()
  143. {
  144. return Group :: PROPERTY_PARENT;
  145. }
  146. /**
  147. * Returns the property for the TITLE column of this entity
  148. * @return String
  149. */
  150. function get_title_property()
  151. {
  152. return Group :: PROPERTY_NAME;
  153. }
  154. /**
  155. * Returns the root ids for this entity
  156. * @return Array<int>
  157. */
  158. function get_root_ids()
  159. {
  160. return array(GroupDataManager :: get_root_group()->get_id());
  161. }
  162. /**
  163. * Returns the properties on which can be searched
  164. *
  165. * @return Array
  166. */
  167. function get_search_properties()
  168. {
  169. return array(Group :: PROPERTY_NAME, Group :: PROPERTY_CODE);
  170. }
  171. /**
  172. * Returns the xml feed which will be used for the element finder and for the ajax tree menu
  173. */
  174. function get_xml_feed()
  175. {
  176. return Path :: get(WEB_PATH) . 'group/php/xml_feeds/xml_group_menu_feed.php';
  177. }
  178. /**
  179. * Function that can be filled in extensions of this class to limit the platform groups
  180. * @return Condition
  181. */
  182. public function get_condition($condition)
  183. {
  184. return $condition;
  185. }
  186. /**
  187. * Retrieves the type for the advanced element finder for the simple rights editor
  188. */
  189. function get_element_finder_type()
  190. {
  191. return new AdvancedElementFinderElementType('platform_groups', Translation :: get('PlatformGroups'), GroupManager :: APPLICATION_NAME, 'platform_groups_feed', array());
  192. }
  193. /**
  194. * Retrieves an element for the advanced element finder for the simple rights editor with the given id
  195. */
  196. function get_element_finder_element($id)
  197. {
  198. $group = GroupDataManager :: get_instance()->retrieve_group($id);
  199. if (! $group)
  200. {
  201. return null;
  202. }
  203. return new AdvancedElementFinderElement(self :: ENTITY_TYPE . '_' . $id, 'type type_group', $group->get_name(), $group->get_code());
  204. }
  205. }
  206. ?>