/php/lib/entities/platform_group_entity.class.php
PHP | 235 lines | 116 code | 29 blank | 90 comment | 3 complexity | 618e34b5fab48bdfd88fd05ef2e628a5 MD5 | raw file
- <?php
-
- namespace rights;
-
- use common\libraries\Theme;
- use common\libraries\Path;
- use common\libraries\EqualityCondition;
- use common\libraries\Translation;
- use common\libraries\Utilities;
- use common\libraries\AdvancedElementFinderElement;
- use common\libraries\AdvancedElementFinderElementType;
-
- use group\GroupDataManager;
- use group\Group;
- use group\GroupRelUser;
- use group\GroupManager;
-
- require_once dirname(__FILE__) . '/platform_group/location_platform_group_cell_renderer.class.php';
- require_once dirname(__FILE__) . '/platform_group/location_platform_group_column_model.class.php';
- require_once dirname(__FILE__) . '/nested_rights_entity.class.php';
-
- /**
- * Class that describes the platform groups for the rights editor
- *
- * @author Sven Vanpoucke
- */
- class PlatformGroupEntity implements NestedRightsEntity
- {
- const ENTITY_NAME = 'group';
- const ENTITY_TYPE = 2;
-
- private $platform_group_cache;
- private static $instance;
-
- static function get_instance()
- {
- if (! isset(self :: $instance))
- {
- self :: $instance = new self();
- }
- return self :: $instance;
- }
-
- /**
- * Retrieves the items for this entity
- *
- * @param Condition $condition
- * @param int $offset
- * @param int $count
- * @param Array $order_property
- * @return ObjectResultSet
- */
- function retrieve_entity_items($condition = null, $offset = null, $count = null, $order_property = null)
- {
- $condition = $this->get_condition($condition);
- return GroupDataManager :: get_instance()->retrieve_groups($condition, $offset, $count, $order_property);
- }
-
- /**
- * Retrieves the entity item ids relevant for a given user (direct subscribed platformgroups and their parents)
- * @param integer $user_id
- * @return array
- */
- function retrieve_entity_item_ids_linked_to_user($user_id)
- {
- if (is_null($this->platform_group_cache[$user_id]))
- {
- $gdm = GroupDataManager :: get_instance();
- $this->platform_group_cache[$user_id] = $gdm->retrieve_all_subscribed_groups_array($user_id, true);
-
- }
- return $this->platform_group_cache[$user_id];
- }
-
- /**
- * Counts the items for this entity
- *
- * @param Condition $condition
- * @return int
- */
- function count_entity_items($condition = null)
- {
- $condition = $this->get_condition($condition);
- return GroupDataManager :: get_instance()->count_groups($condition);
- }
-
- /**
- * Returns the name of this entity
- *
- * @return String
- */
- function get_entity_name()
- {
- return self :: ENTITY_NAME;
- }
-
- /**
- * Returns the translated name of this entiry for displaying purposes only!
- * @return String Translated name of the entity
- */
- function get_entity_translated_name()
- {
- return Translation :: get(Utilities :: underscores_to_camelcase(self :: ENTITY_NAME));
- }
-
- /**
- * Returns the type of this entity
- *
- * @return int
- */
- function get_entity_type()
- {
- return self :: ENTITY_TYPE;
- }
-
- /**
- * Returns the path to the icon of the entity
- *
- * @return String
- */
- function get_entity_icon()
- {
- return Theme :: get_image_path('common\extensions\rights_editor_manager') . 'place_group.png';
- }
-
- /**
- * Returns the cell renderer of this entity
- *
- * @param Application $browser
- * @return LocationPlatformGroupBrowserTableCellRenderer
- */
- function get_entity_cell_renderer($browser)
- {
- return new LocationPlatformGroupBrowserTableCellRenderer($browser);
- }
-
- /**
- * Returns the column model of this entity
- *
- * @param Application $browser
- * @return LocationPlatformGroupBrowserTableColumnModel
- */
- function get_entity_column_model($browser)
- {
- return new LocationPlatformGroupBrowserTableColumnModel($browser);
- }
-
- /**
- * Returns the property for the ID column of this entity
- * @return String
- */
- function get_id_property()
- {
- return Group :: PROPERTY_ID;
- }
-
- /**
- * Returns the property for the PARENT column of this entity
- * @return String
- */
- function get_parent_property()
- {
- return Group :: PROPERTY_PARENT;
- }
-
- /**
- * Returns the property for the TITLE column of this entity
- * @return String
- */
- function get_title_property()
- {
- return Group :: PROPERTY_NAME;
- }
-
- /**
- * Returns the root ids for this entity
- * @return Array<int>
- */
- function get_root_ids()
- {
- return array(GroupDataManager :: get_root_group()->get_id());
- }
-
- /**
- * Returns the properties on which can be searched
- *
- * @return Array
- */
- function get_search_properties()
- {
- return array(Group :: PROPERTY_NAME, Group :: PROPERTY_CODE);
- }
-
- /**
- * Returns the xml feed which will be used for the element finder and for the ajax tree menu
- */
- function get_xml_feed()
- {
- return Path :: get(WEB_PATH) . 'group/php/xml_feeds/xml_group_menu_feed.php';
- }
-
- /**
- * Function that can be filled in extensions of this class to limit the platform groups
- * @return Condition
- */
- public function get_condition($condition)
- {
- return $condition;
- }
-
- /**
- * Retrieves the type for the advanced element finder for the simple rights editor
- */
- function get_element_finder_type()
- {
- return new AdvancedElementFinderElementType('platform_groups', Translation :: get('PlatformGroups'), GroupManager :: APPLICATION_NAME, 'platform_groups_feed', array());
- }
-
- /**
- * Retrieves an element for the advanced element finder for the simple rights editor with the given id
- */
- function get_element_finder_element($id)
- {
- $group = GroupDataManager :: get_instance()->retrieve_group($id);
- if (! $group)
- {
- return null;
- }
-
- return new AdvancedElementFinderElement(self :: ENTITY_TYPE . '_' . $id, 'type type_group', $group->get_name(), $group->get_code());
- }
-
- }
-
- ?>