PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/repository_manager/component/browser/shared_content_objects_browser/repository_shared_content_objects_browser_table_cell_renderer.class.php

https://bitbucket.org/chamilo/chamilo-repository-dev/
PHP | 186 lines | 134 code | 27 blank | 25 comment | 10 complexity | c660cfe592eb9e9e30fe98bbcf87d3d5 MD5 | raw file
  1. <?php
  2. namespace repository;
  3. use common\libraries;
  4. use common\libraries\Translation;
  5. use common\libraries\Utilities;
  6. use common\libraries\ToolbarItem;
  7. use common\libraries\Toolbar;
  8. use common\libraries\Theme;
  9. use common\libraries\DatetimeUtilities;
  10. use common\libraries\ComplexContentObjectSupport;
  11. use user\UserDataManager;
  12. use group\GroupManager;
  13. use rights\UserEntity;
  14. use rights\PlatformGroupEntity;
  15. use group\GroupDataManager;
  16. /**
  17. * $Id: repository_shared_content_objects_browser_table_cell_renderer.class.php 204 2009-11-13 12:51:30Z kariboe $
  18. * @package repository.lib.repository_manager.component.browser.shared_content_objects_browser
  19. */
  20. require_once dirname(__FILE__) . '/repository_shared_content_objects_browser_table_column_model.class.php';
  21. require_once dirname(__FILE__) . '/../../../../content_object_table/default_shared_content_objects_table_cell_renderer.class.php';
  22. /**
  23. * Cell rendere for the learning object browser table
  24. */
  25. class RepositorySharedContentObjectsBrowserTableCellRenderer extends DefaultSharedContentObjectsTableCellRenderer
  26. {
  27. /**
  28. * The repository browser component
  29. */
  30. private $browser;
  31. /**
  32. * Constructor
  33. * @param RepositoryManagerBrowserComponent $browser
  34. */
  35. function __construct($browser)
  36. {
  37. parent :: __construct();
  38. $this->browser = $browser;
  39. }
  40. // Inherited
  41. function render_cell($column, $content_object)
  42. {
  43. if ($column === RepositorySharedContentObjectsBrowserTableColumnModel :: get_sharing_column())
  44. {
  45. return $this->get_sharing_links($content_object);
  46. }
  47. elseif ($column === RepositorySharedContentObjectsBrowserTableColumnModel :: get_rights_column())
  48. {
  49. return $this->get_rights_links($content_object);
  50. }
  51. switch ($column->get_name())
  52. {
  53. case ContentObject :: PROPERTY_TYPE :
  54. return '<a href="' . htmlentities($this->browser->get_type_filter_url($content_object->get_type())) . '">' . parent :: render_cell($column, $content_object) . '</a>';
  55. case ContentObject :: PROPERTY_TITLE :
  56. $title = parent :: render_cell($column, $content_object);
  57. $title_short = Utilities :: truncate_string($title, 53, false);
  58. /*if ($this->browser->has_right($content_object->get_id(), RepositoryRights :: VIEW_RIGHT))
  59. return '<a href="' . htmlentities($this->browser->get_content_object_viewing_url($content_object)) . '" title="' . $title . '">' . $title_short . '</a>';
  60. else*/
  61. return $title_short;
  62. case ContentObject :: PROPERTY_MODIFICATION_DATE :
  63. return DatetimeUtilities :: format_locale_date(Translation :: get('DateFormatShort', null, Utilities :: COMMON_LIBRARIES) . ', ' . Translation :: get('TimeNoSecFormat', null, Utilities :: COMMON_LIBRARIES), $content_object->get_modification_date());
  64. case ContentObject :: PROPERTY_OWNER_ID :
  65. return UserDataManager :: get_instance()->retrieve_user($content_object->get_owner_id())->get_fullname();
  66. case Translation :: get('SharedWith') :
  67. return $this->get_shared_users_groups($content_object);
  68. }
  69. return parent :: render_cell($column, $content_object);
  70. }
  71. /**
  72. * Gets the action links to display
  73. * @param ContentObject $content_object The learning object for which the
  74. * action links should be returned
  75. * @return string A HTML representation of the action links
  76. */
  77. private function get_sharing_links($content_object)
  78. {
  79. $user = $this->browser->get_user();
  80. $toolbar = new Toolbar();
  81. $copy_right = RepositoryRights :: get_instance()->is_allowed_in_user_subtree(RepositoryRights :: COPY_RIGHT, $content_object->get_id(), RepositoryRights :: TYPE_USER_CONTENT_OBJECT, $content_object->get_owner_id());
  82. $collaborate_right = RepositoryRights :: get_instance()->is_allowed_in_user_subtree(RepositoryRights :: COLLABORATE_RIGHT, $content_object->get_id(), RepositoryRights :: TYPE_USER_CONTENT_OBJECT, $content_object->get_owner_id());
  83. $use_right = RepositoryRights :: get_instance()->is_allowed_in_user_subtree(RepositoryRights :: USE_RIGHT, $content_object->get_id(), RepositoryRights :: TYPE_USER_CONTENT_OBJECT, $content_object->get_owner_id());
  84. $view_right = RepositoryRights :: get_instance()->is_allowed_in_user_subtree(RepositoryRights :: VIEW_RIGHT, $content_object->get_id(), RepositoryRights :: TYPE_USER_CONTENT_OBJECT, $content_object->get_owner_id());
  85. if ($view_right)
  86. {
  87. $toolbar->add_item(new ToolbarItem(Translation :: get('View', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_visible.png', $this->browser->get_content_object_viewing_url($content_object), ToolbarItem :: DISPLAY_ICON));
  88. }
  89. else
  90. {
  91. $toolbar->add_item(new ToolbarItem(Translation :: get('ViewNotAvailable', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_visible_na.png', null, ToolbarItem :: DISPLAY_ICON));
  92. }
  93. if ($use_right)
  94. {
  95. $toolbar->add_item(new ToolbarItem(Translation :: get('Publish', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_publish.png', $this->browser->get_publish_content_object_url($content_object), ToolbarItem :: DISPLAY_ICON));
  96. }
  97. else
  98. {
  99. $toolbar->add_item(new ToolbarItem(Translation :: get('PublishNotAvailable', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_publish_na.png', null, ToolbarItem :: DISPLAY_ICON));
  100. }
  101. if ($collaborate_right)
  102. {
  103. $toolbar->add_item(new ToolbarItem(Translation :: get('Edit', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_edit.png', $this->browser->get_content_object_editing_url($content_object), ToolbarItem :: DISPLAY_ICON));
  104. }
  105. else
  106. {
  107. $toolbar->add_item(new ToolbarItem(Translation :: get('EditNotAvailable', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_edit_na.png', null, ToolbarItem :: DISPLAY_ICON));
  108. }
  109. if ($copy_right)
  110. {
  111. $toolbar->add_item(new ToolbarItem(Translation :: get('Copy', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_reuse.png', $this->browser->get_copy_content_object_url($content_object->get_id(), $this->browser->get_user_id()), ToolbarItem :: DISPLAY_ICON));
  112. }
  113. else
  114. {
  115. $toolbar->add_item(new ToolbarItem(Translation :: get('CopyNotAvailable', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_reuse_na.png', null, ToolbarItem :: DISPLAY_ICON));
  116. }
  117. return $toolbar->as_html();
  118. }
  119. private function get_rights_links($content_object)
  120. {
  121. $user = $this->browser->get_user();
  122. if ($user->get_id() == $content_object->get_owner_id())
  123. {
  124. $toolbar = new Toolbar();
  125. $toolbar->add_item(new ToolbarItem(Translation :: get('EditShareRights'), Theme :: get_common_image_path() . 'action_rights.png', $this->browser->get_share_content_objects_url($content_object->get_id()), ToolbarItem :: DISPLAY_ICON));
  126. //$toolbar->add_item(new ToolbarItem(Translation :: get('Unshare', null, Utilities :: COMMON_LIBRARIES), Theme :: get_common_image_path() . 'action_unshare.png', $this->browser->get_content_object_share_deleter_url($content_object->get_id(), null), ToolbarItem :: DISPLAY_ICON));
  127. return $toolbar->as_html();
  128. }
  129. else
  130. {
  131. return null;
  132. }
  133. }
  134. private function get_shared_users_groups($content_object)
  135. {
  136. $target_entities = RepositoryRights :: get_instance()->get_share_target_entities_overview($content_object->get_id(), RepositoryRights :: TYPE_USER_CONTENT_OBJECT, $content_object->get_owner_id());
  137. $shared_users = array_unique($target_entities[UserEntity :: ENTITY_TYPE]);
  138. $shared_groups = array_unique($target_entities[PlatformGroupEntity :: ENTITY_TYPE]);
  139. $html = array();
  140. $html[] = '<select>';
  141. foreach ($shared_users as $user_id)
  142. {
  143. $user_name = UserDataManager :: get_instance()->retrieve_user($user_id)->get_fullname();
  144. $html[] = '<option value="u_' . $user_id . '">' . $user_name . '</option>';
  145. }
  146. if (count($shared_users) > 0 && count($shared_groups) > 0)
  147. {
  148. $html[] = '<option disabled="disabled">---------------------</option>';
  149. }
  150. foreach ($shared_groups as $group_id)
  151. {
  152. $group_name = GroupDataManager :: get_instance()->retrieve_group($group_id)->get_name();
  153. $html[] = '<option value="g_' . $group_id . '">[' . strtoupper(Translation :: get('GroupShort', null, GroupManager :: APPLICATION_NAME)) . '] ' . $group_name . '</option>';
  154. }
  155. $html[] = '</select>';
  156. return implode("\n", $html);
  157. }
  158. }
  159. ?>