/php/lib/tool/component/rights_editor.class.php
PHP | 316 lines | 241 code | 52 blank | 23 comment | 22 complexity | 7b7299f2ca82292b830067baa15f4c61 MD5 | raw file
- <?php
- namespace application\weblcms;
- use common\libraries\Application;
- use common\libraries\BreadcrumbTrail;
- use common\libraries\Request;
- use common\libraries\Translation;
- use common\libraries\Utilities;
- use common\libraries\Display;
- use common\libraries\EqualityCondition;
- use common\libraries\AndCondition;
- use common\libraries\InequalityCondition;
- use group\Group;
- use group\GroupDataManager;
- use group\GroupRelUser;
- use rights\TemplateEntity;
- use rights\RightsManager;
- use common\extensions\new_rights_editor_manager\RightsEditorManager;
- /**
- * $Id: reporting_viewer.class.php 216 2009-11-13 14:08:06Z kariboe $
- * @package application.lib.weblcms.tool.component
- */
- /**
- * Description of reporting_template_viewerclass
- *
- * @author Sven Vanpoucke
- */
- class ToolComponentRightsEditorComponent extends ToolComponent
- {
-
- const ADDITIONAL_INFORMATION_OBJECT_SEPARATOR = ' | '; // use <br /> to put each object on a different line
-
- const LOCATION_TYPE_OBJECT = 'Objects';
- const LOCATION_TYPE_LOCATIONS = 'Locations';
- /**
- * Runs this component and displays its output.
- */
- function run()
- {
- $course = $this->get_course();
- if (!$course->is_course_admin($this->get_user()) && !$this->get_user()->is_platform_admin())
- {
- $this->display_header();
- Display :: error_message(Translation :: get('NotAllowed', null, Utilities:: COMMON_LIBRARIES));
- $this->display_footer();
- exit();
- }
- $trail = BreadcrumbTrail :: get_instance();
- $location = $this->get_locations();
-
- RightsEditorManager :: launch($this, WeblcmsManager :: APPLICATION_NAME, $location, $this->get_entities());
- }
- function get_available_rights($location)
- {
- return $this->get_parent()->get_available_rights($location);
- }
- function get_additional_information()
- {
- $publication_ids = Request :: get(WeblcmsManager :: PARAM_PUBLICATION);
- if(! is_array($publication_ids))
- {
- $publication_ids = array($publication_ids);
- }
-
- if(count($publication_ids) > 0 && isset($publication_ids[0]))
- {
- $type = self :: LOCATION_TYPE_OBJECT;
- }
- else
- {
- $type = self :: LOCATION_TYPE_LOCATIONS;
- }
-
- $info = array();
-
- $translation_context = Application :: determine_namespace(RightsManager :: APPLICATION_NAME);
-
- $info[] = Translation :: get("YouAreEditingRightsFor", array("TYPE" => Translation :: get($type, null, $translation_context)), $translation_context);
- $info[] = '<br/>';
-
- switch($type)
- {
- case self :: LOCATION_TYPE_OBJECT :
- $publication_ids = Request :: get(WeblcmsManager :: PARAM_PUBLICATION);
- if(! is_array($publication_ids))
- {
- $publication_ids = array($publication_ids);
- }
- foreach($publication_ids as $publication_id)
- {
- $publication = WeblcmsDataManager :: get_instance()->retrieve_content_object_publication($publication_id);
- if($publication)
- {
- $content_object = $publication->get_content_object();
- if($content_object)
- {
- $info[] = '<a href="' . $this->get_publication_rights_editor_url($publication_id) . '">';
- $info[] = $content_object->get_title();
- $info[] = '</a>';
- $info[] = self :: ADDITIONAL_INFORMATION_OBJECT_SEPARATOR;
- }
- }
- }
- break;
- case self :: LOCATION_TYPE_LOCATIONS :
- // course link
- $course = WeblcmsDataManager :: get_instance()->retrieve_course(Request :: get(WeblcmsManager :: PARAM_COURSE));
- if($course)
- {
- $info[] = '<a href="' . $this->get_course_rights_editor_url() . '">';
- $info[] = $course->get_name();
- $info[] = '</a>';
- $info[] .= ' > ';
- }
-
- // tool link (only displayed if tool is not the Rights tool)
- $tool = Translation :: get(Utilities :: underscores_to_camelcase(Request :: get(WeblcmsManager :: PARAM_TOOL)));
- if($tool && strtolower($tool) != strtolower(Tool :: class_to_type(RightsTool)))
- {
- $info[] = '<a href="' . $this->get_tool_rights_editor_url() . '">';
- $info[] .= $tool;
- $info[] = '</a>';
- $info[] .= ' > ';
-
- // categories
- $category_id = Request :: get(WeblcmsManager :: PARAM_CATEGORY);
- if($category_id)
- {
- // get the given category
- $category = WeblcmsDataManager :: get_instance()->retrieve_content_object_publication_category($category_id);
- if($category)
- {
- // shift in the parents -> build categories in reverse order, from bottom to root
- $index = count($info);
- while($category)
- {
- // construct the single link
- $category_link = array();
- $category_link[] = '<a href="' . $this->get_category_rights_editor_url($category->get_id()) . '">';
- $category_link[] = $category->get_name();
- $category_link[] = '</a>';
- $category_link[] = ' > ';
-
- // shift the link into the info array after document
- array_splice($info, $index, 0, $category_link);
- // parent
- $category = WeblcmsDataManager :: get_instance()->retrieve_content_object_publication_category($category->get_parent());
- }
- }
- }
- }
- break;
- }
-
- //remove last separator, or '<br/>' if no objects were found
- array_pop($info);
-
- return implode("\n", $info);
- }
-
- function add_category_string($category, $array)
- {
- if($category)
- {
- $info[] = '<a href="' . $this->get_category_rights_editor_url($category->get_id()) . '">';
- $array[] .= $category->get_name();
- $info[] = '</a>';
- $array[] .= ' > ';
- }
- }
- function get_additional_parameters()
- {
- return array(WeblcmsManager :: PARAM_PUBLICATION, WeblcmsManager :: PARAM_CATEGORY);
- }
- function get_entities()
- {
- $wdm = WeblcmsDataManager::get_instance();
- $relation_condition = new EqualityCondition(CourseGroupRelation :: PROPERTY_COURSE_ID, $this->get_course_id());
- $platform_group_relations = $wdm->retrieve_course_group_relations($relation_condition);
- $limited_users = array();
- while ($platform_group_relation = $platform_group_relations->next_result())
- {
- $platform_group_id = $platform_group_relation->get_group_id();
- $subscribed_platform_group_ids[] = $platform_group_id;
- $limited_platform_groups[] = $platform_group_id;
- //get the users in that platform group
- $eq_condition = new EqualityCondition(GroupRelUser :: PROPERTY_GROUP_ID, $platform_group_id);
- $group_rel_users_dataset = GroupDataManager :: get_instance()->retrieve_group_rel_users($eq_condition);
- while ($group_rel_user = $group_rel_users_dataset->next_result())
- {
- $limited_users[] = $group_rel_user->get_user_id();
- }
- $group = GroupDataManager :: get_instance()->retrieve_group($platform_group_id);
- if(!$group)
- {
- continue;
- }
-
- $children_conditions = array();
- $children_conditions[] = new InequalityCondition(Group :: PROPERTY_LEFT_VALUE,
- InequalityCondition :: GREATER_THAN, $group->get_left_value());
- $children_conditions[] = new InequalityCondition(Group :: PROPERTY_RIGHT_VALUE,
- InequalityCondition :: LESS_THAN, $group->get_right_value());
- $children_condition = new AndCondition($children_conditions);
- //retrieve the subgroups subscribed implicitly
- $child_groups = GroupDataManager :: get_instance()->retrieve_groups($children_condition);
- while ($cgroup = $child_groups->next_result())
- {
- $limited_platform_groups[] = $cgroup->get_id();
- $eq_condition = new EqualityCondition(GroupRelUser :: PROPERTY_GROUP_ID, $cgroup->get_id());
- $group_rel_users_dataset = GroupDataManager :: get_instance()->retrieve_group_rel_users($eq_condition);
- while ($group_rel_user = $group_rel_users_dataset->next_result())
- {
- $limited_users[] = $group_rel_user->get_user_id();
- }
- }
- }
- $conditions = array();
- $conditions[] = new EqualityCondition(CourseUserRelation :: PROPERTY_COURSE,
- $this->get_course_id());
- $conditions[] = new EqualityCondition(CourseUserRelation :: PROPERTY_STATUS,
- CourseUserRelation :: STATUS_STUDENT);
- $condition = new AndCondition($conditions);
- $relations = WeblcmsDataManager :: get_instance()->retrieve_course_user_relations($condition);
- while ($relation = $relations->next_result())
- {
- $limited_users[] = $relation->get_user();
- }
- $limited_users[] = $this->get_user_id();
- $excluded_users[] = $this->get_user_id();
- $limited_platform_groups[] = 1;
- $excluded_platform_groups[] = 1;
- $entities = array();
- $user_entity = new CourseUserEntity($this->get_course_id());
- $user_entity->exclude_users($excluded_users);
- $user_entity->limit_users($limited_users);
- $entities[CourseUserEntity :: ENTITY_TYPE] = $user_entity;
- $entities[CourseGroupEntity :: ENTITY_TYPE] = new CourseGroupEntity($this->get_course_id());
- if(!empty($subscribed_platform_group_ids))
- {
- $group_entity = new CoursePlatformGroupEntity($this->get_course_id());
- $group_entity->set_subscribed_platform_group_ids($subscribed_platform_group_ids);
- $group_entity->exclude_groups($excluded_platform_groups);
- $group_entity->limit_groups($limited_platform_groups);
- $entities[CoursePlatformGroupEntity :: ENTITY_TYPE] = $group_entity;
- }
- $entities[TemplateEntity :: ENTITY_TYPE] = new TemplateEntity();
- return $entities;
- }
-
- function get_course_rights_editor_url()
- {
- return $this->get_url(array(
- WeblcmsManager :: PARAM_TOOL => Tool :: class_to_type(RightsTool),
- Tool :: PARAM_ACTION => Tool :: ACTION_EDIT_RIGHTS,
- WeblcmsManager :: PARAM_CATEGORY => null
- ));
- }
-
- function get_tool_rights_editor_url()
- {
- return $this->get_url(array(
- Tool :: PARAM_ACTION => Tool :: ACTION_EDIT_RIGHTS,
- WeblcmsManager :: PARAM_CATEGORY => null
- ));
- }
-
- function get_category_rights_editor_url($category_id)
- {
- return $this->get_url(array(
- Tool :: PARAM_ACTION => Tool :: ACTION_EDIT_RIGHTS,
- WeblcmsManager :: PARAM_CATEGORY => $category_id
- ));
- }
-
- function get_publication_rights_editor_url($publication_id)
- {
- return $this->get_url(array(
- Tool :: PARAM_ACTION => Tool :: ACTION_EDIT_RIGHTS,
- WeblcmsManager :: PARAM_PUBLICATION => $publication_id
- ));
- }
- }
- ?>