PageRenderTime 80ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/weblcms_manager/weblcms_manager.class.php

https://bitbucket.org/chamilo/chamilo-app-weblcms/
PHP | 1746 lines | 1189 code | 144 blank | 413 comment | 47 complexity | 17feb9f83fd42e3cce9c9a97924b66e6 MD5 | raw file
  1. <?php
  2. namespace application\weblcms;
  3. use application\weblcms\tool\user\SubscribeGroupBrowserTable;
  4. use application\weblcms\tool\user\SubscribedUserBrowserTable;
  5. use common\libraries\ObjectTable;
  6. use common\libraries\DynamicAction;
  7. use common\libraries\Filesystem;
  8. use common\libraries\Redirect;
  9. use common\libraries\Display;
  10. use common\libraries\Application;
  11. use common\libraries\Theme;
  12. use common\libraries\Session;
  13. use common\libraries\Breadcrumb;
  14. use common\libraries\BreadcrumbTrail;
  15. use common\libraries\Utilities;
  16. use common\libraries\EqualityCondition;
  17. use common\libraries\Request;
  18. use common\libraries\WebApplication;
  19. use common\libraries\Translation;
  20. use user\UserDataManager;
  21. use HTML_Table;
  22. /**
  23. * $Id: weblcms_manager.class.php 218 2009-11-13 14:21:26Z kariboe $
  24. * @package application.lib.weblcms.weblcms_manager
  25. */
  26. require_once dirname(__FILE__) . '/weblcms_search_form.class.php';
  27. require_once dirname(__FILE__) . '/../category_manager/content_object_publication_category.class.php';
  28. require_once dirname(__FILE__) . '/../tool/tool.class.php';
  29. require_once dirname(__FILE__) . '/../tool/tool_component.class.php';
  30. require_once dirname(__FILE__) . '/../tool_list_renderer.class.php';
  31. require_once dirname(__FILE__) . '/../course/course.class.php';
  32. require_once dirname(__FILE__) . '/../course/course_request.class.php';
  33. require_once dirname(__FILE__) . '/../course/course_create_request.class.php';
  34. require_once dirname(__FILE__) . '/../course/course_settings.class.php';
  35. require_once dirname(__FILE__) . '/../course/course_rights.class.php';
  36. require_once dirname(__FILE__) . '/../course/course_group_subscribe_right.class.php';
  37. require_once dirname(__FILE__) . '/../course/course_group_unsubscribe_right.class.php';
  38. require_once dirname(__FILE__) . '/../course/course_user_relation.class.php';
  39. require_once dirname(__FILE__) . '/../course_group/course_group.class.php';
  40. require_once dirname(__FILE__) . '/component/admin_course_browser/admin_course_browser_table.class.php';
  41. require_once dirname(__FILE__) . '/component/admin_course_type_browser/admin_course_type_browser_table.class.php';
  42. //require_once dirname(__FILE__) . '/component/subscribed_user_browser/subscribed_user_browser_table.class.php';
  43. //require_once dirname(__FILE__) . '/component/subscribe_group_browser/subscribe_group_browser_table.class.php';
  44. require_once dirname(__FILE__) . '/component/admin_request_browser/admin_request_browser_table.class.php';
  45. require_once dirname(__FILE__) . '/../weblcms_rights.class.php';
  46. require_once dirname(__FILE__) . '/../course_type/course_type.class.php';
  47. require_once dirname(__FILE__) . '/../course_type/course_type_layout.class.php';
  48. require_once dirname(__FILE__) . '/../course_type/course_type_settings.class.php';
  49. require_once dirname(__FILE__) . '/../course_type/course_type_tool.class.php';
  50. require_once dirname(__FILE__) . '/../course_type/course_type_rights.class.php';
  51. require_once dirname(__FILE__) . '/../course_type/course_type_group_subscribe_right.class.php';
  52. require_once dirname(__FILE__) . '/../course_type/course_type_group_unsubscribe_right.class.php';
  53. require_once dirname(__FILE__) . '/../course_type/course_type_group_creation_right.class.php';
  54. require_once dirname(__FILE__) . '/../course_type/course_type_user_category.class.php';
  55. /**
  56. ==============================================================================
  57. * This is an application that creates a fully fledged web-based learning
  58. * content management system. The Web-LCMS is based on so-called "tools",
  59. * which each represent a segment in the application.
  60. *
  61. * @author Tim De Pauw
  62. ==============================================================================
  63. */
  64. class WeblcmsManager extends WebApplication
  65. {
  66. const APPLICATION_NAME = 'weblcms';
  67. const PARAM_REQUEST_TYPE = 'request_type';
  68. const PARAM_REQUEST_VIEW = 'request_view';
  69. const PARAM_REQUEST = 'request';
  70. const PARAM_REMOVE_SELECTED_REQUESTS = 'removed selected requests';
  71. const PARAM_COURSE = 'course';
  72. const PARAM_CATEGORY = 'publication_category';
  73. const PARAM_COURSE_CATEGORY_ID = 'category';
  74. const PARAM_COURSE_USER = 'course';
  75. const PARAM_COURSE_GROUP = 'course_group';
  76. const PARAM_COURSE_TYPE_USER_CATEGORY_ID = 'user_category';
  77. const PARAM_COURSE_TYPE = 'course_type';
  78. const PARAM_USERS = 'users';
  79. const PARAM_GROUP = 'group';
  80. const PARAM_TYPE = 'type';
  81. const PARAM_ACTIVE = 'active';
  82. const PARAM_TOOL = 'tool';
  83. const PARAM_COMPONENT_ACTION = 'action';
  84. const PARAM_DIRECTION = 'direction';
  85. const PARAM_REMOVE_SELECTED = 'remove_selected';
  86. const PARAM_REMOVE_SELECTED_COURSE_TYPES = 'remove selected coursetypes';
  87. const PARAM_ACTIVATE_SELECTED_COURSE_TYPES = 'activate selected coursetypes';
  88. const PARAM_DEACTIVATE_SELECTED_COURSE_TYPES = 'deactivate selected coursetypes';
  89. const PARAM_CHANGE_COURSE_TYPE_SELECTED_COURSES = 'Change Coursetype selected courses';
  90. const PARAM_UNSUBSCRIBE_SELECTED = 'unsubscribe_selected';
  91. const PARAM_SUBSCRIBE_SELECTED = 'subscribe_selected';
  92. const PARAM_SUBSCRIBE_SELECTED_AS_STUDENT = 'subscribe_selected_as_student';
  93. const PARAM_SUBSCRIBE_SELECTED_AS_ADMIN = 'subscribe_selected_as_admin';
  94. const PARAM_SUBSCRIBE_SELECTED_GROUP = 'subscribe_selected_group_admin';
  95. const PARAM_TOOL_ACTION = 'tool_action';
  96. const PARAM_STATUS = 'user_status';
  97. const PARAM_EXTRA = 'extra';
  98. const PARAM_PUBLICATION = 'publication';
  99. const PARAM_ALLOW_SELECTED_REQUESTS = 'allow_selected_requests';
  100. const PARAM_REFUSE_SELECTED_REQUESTS = 'refuse_selected_requests';
  101. const ACTION_SUBSCRIBE = 'subscribe';
  102. const ACTION_CHANGE_COURSE_TYPE_FROM_COURSE = 'course_change_course_type';
  103. const ACTION_SUBSCRIBE_GROUP = 'group_subscribe';
  104. const ACTION_UNSUBSCRIBE_GROUP = 'group_unsubscribe';
  105. const ACTION_SUBSCRIBE_GROUP_USERS = 'group_users_subscribe';
  106. const ACTION_VIEW_WEBLCMS_HOME = 'home';
  107. const ACTION_VIEW_COURSE = 'course_viewer';
  108. const ACTION_CREATE_COURSE = 'course_creator';
  109. const ACTION_IMPORT_COURSES = 'course_importer';
  110. const ACTION_IMPORT_COURSE_USERS = 'course_user_importer';
  111. const ACTION_DELETE_COURSE = 'course_deleter';
  112. const ACTION_DELETE_COURSES_BY_COURSE_TYPE = 'course_type_courses_deleter';
  113. const ACTION_MANAGER_SORT = 'sorter';
  114. const ACTION_MANAGER_SUBSCRIBE = 'subscribe';
  115. const ACTION_MANAGER_UNSUBSCRIBE = 'unsubscribe';
  116. const ACTION_COURSE_CATEGORY_MANAGER = 'course_category_manager';
  117. const ACTION_ADMIN_COURSE_BROWSER = 'admin_course_browser';
  118. const ACTION_SELECT_COURSE_TYPE = 'course_type_selector';
  119. const ACTION_DELETE_COURSE_TYPE = 'course_type_deleter';
  120. const ACTION_VIEW_COURSE_TYPE = 'course_type_viewer';
  121. const ACTION_CHANGE_ACTIVATION = 'active_changer';
  122. const ACTION_CHANGE_ACTIVE = 'activity_changer';
  123. const ACTION_ADMIN_COURSE_TYPE_CREATOR = 'admin_course_type_creator';
  124. const ACTION_ADMIN_COURSE_TYPE_BROWSER = 'admin_course_type_browser';
  125. const ACTION_COURSE_EDITOR_REQUEST = 'course_request_editor';
  126. const ACTION_COURSE_SUBSCRIBE_CREATE_REQUEST = 'course_subscribe_request_creator';
  127. const ACTION_ADMIN_REQUEST_BROWSER = 'admin_request_browser';
  128. const ACTION_COURSE_REQUEST_DELETER = 'course_request_deleter';
  129. const ACTION_COURSE_ALLOWING_REQUEST = 'course_request_allow';
  130. const ACTION_COURSE_REFUSE_REQUEST = 'course_request_refuse';
  131. const ACTION_VIEW_REQUEST = 'course_request_viewer';
  132. const ACTION_PUBLISH_INTRODUCTION = 'introduction_publisher';
  133. const ACTION_DELETE_INTRODUCTION = 'introduction_deleter';
  134. const ACTION_EDIT_INTRODUCTION = 'introduction_editor';
  135. const ACTION_REPORTING = 'reporting';
  136. const ACTION_COURSE_CODE = 'course_code_subscriber';
  137. const ACTION_COURSE_CREATE_REQUEST_CREATOR = 'course_create_request_creator';
  138. const ACTION_RENDER_BLOCK = 'block';
  139. const DEFAULT_ACTION = self :: ACTION_VIEW_WEBLCMS_HOME;
  140. /**
  141. * The tools that this course offers.
  142. */
  143. private $tools;
  144. /**
  145. * The sections that this application offers.
  146. */
  147. private $sections;
  148. /**
  149. * The class of the tool currently active in this application
  150. */
  151. private $tool_class;
  152. /**
  153. * The course object of the course currently active in this application
  154. */
  155. private $course;
  156. /**
  157. * The course_type object of the course currently active in this application
  158. */
  159. private $course_type;
  160. /**
  161. * The course_group object of the course_group currently active in this application
  162. */
  163. private $course_group;
  164. private $search_form;
  165. private $request;
  166. /**
  167. * The new publications for each tool are cached here
  168. * @var Array[tool] = new publications count
  169. */
  170. private static $new_publications;
  171. /**
  172. * Constructor. Optionally takes a default tool; otherwise, it is taken
  173. * from the query string.
  174. * @param Tool $tool The default tool, or null if none.
  175. */
  176. function __construct($user)
  177. {
  178. parent :: __construct($user);
  179. // $this->set_parameter(self :: PARAM_ACTION, Request :: get(self :: PARAM_ACTION));
  180. // $this->set_parameter(self :: PARAM_CATEGORY, Request :: get(self :: PARAM_CATEGORY));
  181. // $this->set_parameter(self :: PARAM_COURSE, Request :: get(self :: PARAM_COURSE));
  182. //$this->parse_input_from_table();
  183. $this->course_type = $this->load_course_type();
  184. $this->tools = array();
  185. $this->course = new Course();
  186. $this->load_course();
  187. $this->course_group = null;
  188. $this->load_course_group();
  189. $this->sections = array();
  190. $this->load_sections();
  191. if (! is_null($this->get_user()))
  192. $this->subscribe_user_to_allowed_courses($this->get_user_id());
  193. }
  194. /**
  195. * Renders the weblcms block and returns it.
  196. */
  197. function render_block($block)
  198. {
  199. $weblcms_block = WeblcmsBlock :: factory($this, $block);
  200. return $weblcms_block->run();
  201. }
  202. function set_tool_class($class)
  203. {
  204. return $this->tool_class = $class;
  205. }
  206. /**
  207. * Gets the identifier of the current tool
  208. * @return string The identifier of current tool
  209. */
  210. function get_tool_id()
  211. {
  212. return $this->get_parameter(self :: PARAM_TOOL);
  213. }
  214. /**
  215. * Retrieves the change active url
  216. * @return the change active component url
  217. */
  218. function get_change_active_url($type, $course_type_id)
  219. {
  220. $parameters = array();
  221. $parameters[self :: PARAM_ACTION] = self :: ACTION_CHANGE_ACTIVE;
  222. $parameters[self :: PARAM_TYPE] = $type;
  223. $parameters[self :: PARAM_COURSE_TYPE] = $course_type_id;
  224. return $this->get_url($parameters);
  225. }
  226. /**
  227. * Gets the user object for a given user
  228. * @param int $user_id
  229. * @return User
  230. */
  231. function get_user_info($user_id)
  232. {
  233. return UserDataManager :: get_instance()->retrieve_user($user_id);
  234. }
  235. /**
  236. * Returns the course that is being used.
  237. * @return string The course.
  238. */
  239. function get_course()
  240. {
  241. return $this->course;
  242. }
  243. /**
  244. * Sets the course
  245. * @param Course $course
  246. */
  247. function set_course($course)
  248. {
  249. $this->course = $course;
  250. }
  251. function set_course_type($course_type)
  252. {
  253. $this->course_type = $course_type;
  254. }
  255. function set_request($request)
  256. {
  257. $this->request = $request;
  258. }
  259. //function set_course_type($course_type)
  260. //{
  261. // $this->course_type = $course_type;
  262. //}
  263. /**
  264. * Returns the identifier of the course that is being used.
  265. * @return string The course identifier.
  266. */
  267. function get_course_id()
  268. {
  269. if ($this->course == null)
  270. return 0;
  271. return $this->course->get_id();
  272. }
  273. /*
  274. function get_course_type_id()
  275. {
  276. if($this->course_type == null)
  277. return 0;
  278. return $this->course_type->get_id();
  279. }
  280. */
  281. /**
  282. * Returns the course_group that is being used.
  283. * @return string The course_group.
  284. */
  285. function get_course_group()
  286. {
  287. return $this->course_group;
  288. }
  289. function get_course_type_deleting_all_courses_url($course_type)
  290. {
  291. return $this->get_url(array(
  292. self :: PARAM_ACTION => self :: ACTION_DELETE_COURSES_BY_COURSE_TYPE,
  293. self :: PARAM_COURSE_TYPE => $course_type->get_id()));
  294. }
  295. /**
  296. * Returns the course_group that is being used.
  297. * @return string The course_group.
  298. */
  299. function get_course_type()
  300. {
  301. return $this->course_type;
  302. }
  303. function get_request()
  304. {
  305. return $this->request;
  306. }
  307. function get_course_changing_course_type_url($course)
  308. {
  309. return $this->get_url(array(
  310. self :: PARAM_ACTION => self :: ACTION_CHANGE_COURSE_TYPE_FROM_COURSE,
  311. self :: PARAM_COURSE => $course->get_id()));
  312. }
  313. function get_course_type_deleting_url($course_type)
  314. {
  315. return $this->get_url(array(
  316. self :: PARAM_ACTION => self :: ACTION_DELETE_COURSE_TYPE,
  317. self :: PARAM_COURSE_TYPE => $course_type->get_id()));
  318. }
  319. function get_course_type_editing_url($course_type)
  320. {
  321. return $this->get_url(array(
  322. self :: PARAM_ACTION => self :: ACTION_ADMIN_COURSE_TYPE_CREATOR,
  323. self :: PARAM_COURSE_TYPE => $course_type->get_id(),
  324. self :: PARAM_TOOL => 'course_type_settings',
  325. 'previous' => 'admin'));
  326. }
  327. function get_course_request_deleting_url($request, $request_type, $request_view)
  328. {
  329. return $this->get_url(array(
  330. self :: PARAM_ACTION => self :: ACTION_COURSE_REQUEST_DELETER,
  331. self :: PARAM_REQUEST => $request->get_id(),
  332. self :: PARAM_REQUEST_TYPE => $request_type,
  333. self :: PARAM_REQUEST_VIEW => $request_view));
  334. }
  335. function get_course_request_allowing_url($request, $request_type, $request_view)
  336. {
  337. return $this->get_url(array(
  338. self :: PARAM_ACTION => self :: ACTION_COURSE_ALLOWING_REQUEST,
  339. self :: PARAM_REQUEST => $request->get_id(),
  340. self :: PARAM_REQUEST_TYPE => $request_type,
  341. self :: PARAM_REQUEST_VIEW => $request_view));
  342. }
  343. function get_course_request_viewing_url($request, $request_type, $request_view)
  344. {
  345. return $this->get_url(array(
  346. self :: PARAM_ACTION => self :: ACTION_VIEW_REQUEST,
  347. self :: PARAM_REQUEST => $request->get_id(),
  348. self :: PARAM_REQUEST_TYPE => $request_type));
  349. }
  350. function get_course_request_refuse_url($request, $request_type, $request_view)
  351. {
  352. return $this->get_url(array(
  353. self :: PARAM_ACTION => self :: ACTION_COURSE_REFUSE_REQUEST,
  354. self :: PARAM_REQUEST => $request->get_id(),
  355. self :: PARAM_REQUEST_TYPE => $request_type,
  356. self :: PARAM_REQUEST_VIEW => $request_view));
  357. }
  358. function get_course_type_maintenance_url($course_type)
  359. {
  360. //return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_VIEW_COURSE, self :: PARAM_COURSE => $course->get_id(), self :: PARAM_TOOL => 'maintenance'));
  361. return null;
  362. }
  363. function get_course_type_viewing_url($course_type)
  364. {
  365. return $this->get_url(array(
  366. self :: PARAM_ACTION => self :: ACTION_VIEW_COURSE_TYPE,
  367. self :: PARAM_COURSE_TYPE => $course_type->get_id()));
  368. }
  369. function get_home_url()
  370. {
  371. return $this->get_url(array(self :: PARAM_ACTION => self :: ACTION_VIEW_WEBLCMS_HOME));
  372. }
  373. /**
  374. * Sets the course_group
  375. * @param CourseGroup $course_group
  376. */
  377. function set_course_group($course_group)
  378. {
  379. $this->course_group = $course_group;
  380. }
  381. /**
  382. * Gets a list of all course_groups of the current active course in which the
  383. * current user is subscribed.
  384. */
  385. function get_course_groups()
  386. {
  387. $wdm = WeblcmsDataManager :: get_instance();
  388. $course_groups = $wdm->retrieve_course_groups_from_user($this->get_user_id(), $this->get_course_id())->as_array();
  389. return $course_groups;
  390. }
  391. /**
  392. * Makes a category tree ready for displaying by adding a prefix to the
  393. * category title based on the level of that category in the tree structure.
  394. * @param array $tree The category tree
  395. * @param array $categories In this array the new category titles (with
  396. * prefix) will be stored. The keys in this array are the category ids, the
  397. * values are the new titles
  398. * @param int $level The current level in the tree structure
  399. */
  400. private static function translate_category_tree($tree, $categories, $level = 0)
  401. {
  402. foreach ($tree as $node)
  403. {
  404. $obj = $node['obj'];
  405. $prefix = ($level ? str_repeat('&nbsp;&nbsp;&nbsp;', $level) . '&mdash; ' : '');
  406. $categories[$obj->get_id()] = $prefix . $obj->get_title();
  407. $subtree = $node['sub'];
  408. if (is_array($subtree) && count($subtree))
  409. {
  410. self :: translate_category_tree($subtree, $categories, $level + 1);
  411. }
  412. }
  413. }
  414. /**
  415. * Gets a category
  416. * @param int $id The id of the requested category
  417. * @return LearningPublicationCategory The requested category
  418. */
  419. function get_category($id)
  420. {
  421. return WeblcmsDataManager :: get_instance()->retrieve_content_object_publication_category($id);
  422. }
  423. /**
  424. * Displays the header of this application
  425. * @param array $breadcrumbs The breadcrumbs which should be displayed
  426. */
  427. /*function display_header($breadcrumbtrail = null, $display_search = false, $display_title = true)
  428. {
  429. if (is_null($breadcrumbtrail))
  430. {
  431. $breadcrumbtrail = BreadcrumbTrail :: get_instance();
  432. if($breadcrumbtrail->size() == 1)
  433. {
  434. $breadcrumbtrail->add(new Breadcrumb($this->get_url(), Translation :: get(Utilities :: underscores_to_camelcase($this->get_application_name()))));
  435. }
  436. }
  437. $tool = $this->get_parameter(self :: PARAM_TOOL);
  438. $course = $this->get_parameter(self :: PARAM_COURSE);
  439. $action = $this->get_parameter(self :: PARAM_ACTION);
  440. if (isset($this->tool_class))
  441. {
  442. $tool = str_replace('_tool', '', Tool :: class_to_type($this->tool_class));
  443. $js_file = dirname(__FILE__) . '/tool/' . $tool . '/' . $tool . '.js';
  444. if (file_exists($js_file))
  445. {
  446. $htmlHeadXtra[] = '<script type="text/javascript" src="application/lib/weblcms/tool/' . $tool . '/' . $tool . '.js"></script>';
  447. }
  448. }
  449. $title = $breadcrumbtrail->get_last()->get_name();
  450. $title_short = $title;
  451. if (strlen($title_short) > 53)
  452. {
  453. $title_short = substr($title_short, 0, 50) . '&hellip;';
  454. }
  455. Display :: header($breadcrumbtrail);
  456. if ($course && is_object($this->course) && $action == self :: ACTION_VIEW_COURSE)
  457. {
  458. //echo '<h3 style="float: left;">'.htmlentities($this->course->get_name()).'</h3>';
  459. echo '<h3 style="float: left;">' . htmlentities($title) . '</h3>';
  460. // TODO: Add department name and url here somewhere ?
  461. }
  462. else
  463. {
  464. echo '<h3 style="float: left;">' . htmlentities($title) . '</h3>';
  465. if ($display_search)
  466. {
  467. $this->display_search_form();
  468. }
  469. }
  470. if ($msg = Request :: get(Application :: PARAM_MESSAGE))
  471. {
  472. echo '<br />';
  473. $this->display_message($msg);
  474. }
  475. if ($msg = Request :: get(Application :: PARAM_ERROR_MESSAGE))
  476. {
  477. echo '<br />';
  478. $this->display_error_message($msg);
  479. }
  480. echo '<div class="clear">&nbsp;</div>';
  481. }*/
  482. /**
  483. * Displays the footer of this application
  484. */
  485. function display_footer()
  486. {
  487. Display :: footer();
  488. }
  489. /**
  490. * Returns the names of the tools known to this application.
  491. * @return array The tools.
  492. */
  493. function get_registered_tools()
  494. {
  495. return $this->tools;
  496. }
  497. /**
  498. * Returns the names of the sections known to this application.
  499. * @return array The tools.
  500. */
  501. function get_registered_sections()
  502. {
  503. if(is_null($this->sections))
  504. {
  505. $this->load_sections();
  506. }
  507. return $this->sections;
  508. }
  509. function get_tool_properties($tool)
  510. {
  511. return $this->tools[$tool];
  512. }
  513. /**
  514. * Loads the tools available to the course.
  515. */
  516. function load_tools($order_by_name = false)
  517. {
  518. if (! is_null($this->get_course_id()))
  519. {
  520. $wdm = WeblcmsDataManager :: get_instance();
  521. $this->tools = $wdm->get_course_modules($this->get_course_id(), $order_by_name);
  522. // foreach ($this->tools as $index => $tool)
  523. // {
  524. // require_once dirname(__FILE__) . '/../tool/' . $tool->name . '/' . $tool->name . '_tool.class.php';
  525. // }
  526. }
  527. }
  528. /**
  529. * Loads the sections installed on the system.
  530. */
  531. function load_sections()
  532. {
  533. if (! is_null($this->get_course_id()))
  534. {
  535. $wdm = WeblcmsDataManager :: get_instance();
  536. $condition = new EqualityCondition(CourseSection :: PROPERTY_COURSE_CODE, $this->get_course_id());
  537. $sections = $wdm->retrieve_course_sections($condition);
  538. while ($section = $sections->next_result())
  539. {
  540. //$type = isset($section->type) ? $section->type : '';
  541. $this->sections[] = $section;
  542. }
  543. }
  544. }
  545. /**
  546. * Loads the current course into the system.
  547. */
  548. public function load_course($id = null)
  549. {
  550. if ($id == null)
  551. $id = Request :: get(self :: PARAM_COURSE);
  552. $wdm = WeblcmsDataManager :: get_instance();
  553. if (! is_null($id) && ! is_array($id) && $id != '')
  554. {
  555. $this->course = $wdm->retrieve_course($id);
  556. if (! $this->course)
  557. $this->redirect(Translation :: get('CourseCorrupt') . " ID: " . $id, true, array(
  558. 'go' => WeblcmsManager :: ACTION_VIEW_WEBLCMS_HOME), array(), false, Redirect :: TYPE_LINK);
  559. }
  560. else
  561. {
  562. $this->course = $wdm->retrieve_empty_course();
  563. $this->course->set_course_type($this->course_type);
  564. }
  565. $this->load_tools(true);
  566. $this->course->set_tools($this->tools);
  567. }
  568. /**
  569. * Loads the current course_group into the system.
  570. */
  571. private function load_course_group()
  572. {
  573. if (! is_null($this->get_parameter(self :: PARAM_COURSE_GROUP)) && strlen($this->get_parameter(self :: PARAM_COURSE_GROUP) > 0))
  574. {
  575. $wdm = WeblcmsDataManager :: get_instance();
  576. $this->course_group = $wdm->retrieve_course_group($this->get_parameter(self :: PARAM_COURSE_GROUP));
  577. }
  578. }
  579. /**
  580. * Loads the current course_type into the system.
  581. */
  582. private function load_course_type($id = null)
  583. {
  584. $course_type = null;
  585. if (is_null($id))
  586. $id = Request :: get(self :: PARAM_COURSE_TYPE);
  587. $wdm = WeblcmsDataManager :: get_instance();
  588. if (! is_null($id) && strlen($id) > 0)
  589. {
  590. $course_type = $wdm->retrieve_course_type($id);
  591. }
  592. else
  593. {
  594. $course_type = $wdm->retrieve_empty_course_type();
  595. }
  596. return $course_type;
  597. }
  598. /**
  599. * Determines whether or not the given name is a valid tool name.
  600. * @param string $name The name to evaluate.
  601. * @return True if the name is a valid tool name, false otherwise.
  602. */
  603. static function is_tool_name($name)
  604. {
  605. return (preg_match('/^[a-z][a-z_]+$/', $name) > 0);
  606. }
  607. /*
  608. * Inherited
  609. */
  610. function retrieve_max_sort_value($table, $column, $condition = null)
  611. {
  612. return WeblcmsDataManager :: get_instance()->retrieve_max_sort_value($table, $column, $condition);
  613. }
  614. /*
  615. * Inherited
  616. */
  617. static function content_object_is_published($object_id)
  618. {
  619. return WeblcmsDataManager :: get_instance()->content_object_is_published($object_id);
  620. }
  621. /*
  622. * Inherited
  623. */
  624. static function any_content_object_is_published($object_ids)
  625. {
  626. return WeblcmsDataManager :: get_instance()->any_content_object_is_published($object_ids);
  627. }
  628. /*
  629. * Inherited
  630. */
  631. static function get_content_object_publication_attributes($object_id, $type = null, $offset = null, $count = null, $order_property = null)
  632. {
  633. return WeblcmsDataManager :: get_instance()->get_content_object_publication_attributes(null, $object_id, $type, $offset, $count, $order_property);
  634. }
  635. /*
  636. * Inherited
  637. */
  638. static function get_content_object_publication_attribute($publication_id)
  639. {
  640. return WeblcmsDataManager :: get_instance()->get_content_object_publication_attribute($publication_id);
  641. }
  642. /*
  643. * Inherited
  644. */
  645. static function delete_content_object_publications($object_id)
  646. {
  647. return WeblcmsDataManager :: get_instance()->delete_content_object_publications($object_id);
  648. }
  649. static function delete_content_object_publication($publication_id)
  650. {
  651. $publication = WeblcmsDataManager :: get_instance()->retrieve_content_object_publication($publication_id);
  652. if(!$publication)
  653. {
  654. return false;
  655. }
  656. return $publication->delete();
  657. }
  658. /*
  659. * Inherited
  660. */
  661. static function update_content_object_publication_id($publication_attr)
  662. {
  663. return WeblcmsDataManager :: get_instance()->update_content_object_publication_id($publication_attr);
  664. }
  665. /**
  666. * Inherited
  667. */
  668. static function count_publication_attributes($user = null, $object_id = null, $condition = null)
  669. {
  670. return WeblcmsDataManager :: get_instance()->count_publication_attributes($user, $object_id, $condition);
  671. }
  672. /**
  673. * Inherited
  674. */
  675. static function get_content_object_publication_locations($content_object, $user = null)
  676. {
  677. $locations = array();
  678. $type = $content_object->get_type();
  679. //$courses = $this->retrieve_courses($user->get_id());
  680. $conditions = WeblcmsDataManager :: get_user_courses_condition($user);
  681. $courses = WeblcmsDataManager :: get_instance()->retrieve_user_courses($conditions);
  682. while ($course = $courses->next_result())
  683. {
  684. if ($course->is_course_admin($user)) //u can only publish in the course of u are course admin/ also documents in dropboxes
  685. $c[] = $course;
  686. }
  687. $directory = dirname(__FILE__) . '/../../../tool/';
  688. $tools = Filesystem :: get_directory_content($directory, Filesystem :: LIST_DIRECTORIES, false);
  689. foreach ($tools as $tool)
  690. {
  691. $path = $directory . $tool . '/php/' . $tool . '_tool.class.php';
  692. if (! file_exists($path))
  693. continue;
  694. require_once $path;
  695. $class = Tool :: get_tool_type_namespace($tool) . '\\' . Utilities :: underscores_to_camelcase($tool) . 'Tool';
  696. $obj = new $class(new self());
  697. $types[$tool] = $obj->get_allowed_types();
  698. }
  699. foreach ($types as $tool => $allowed_types)
  700. {
  701. if (in_array($type, $allowed_types))
  702. {
  703. $user = Session :: get_user_id();
  704. foreach ($c as $course)
  705. $locations[$course->get_id() . '-' . $tool] = 'Course: ' . $course->get_name() . ' (' . $course->get_visual() . ')' . ' - Tool: ' . $tool;
  706. }
  707. }
  708. return $locations;
  709. }
  710. static function publish_content_object($content_object, $location, $attributes)
  711. {
  712. $location_split = split('-', $location);
  713. $course = $location_split[0];
  714. $tool = $location_split[1]; //echo $location;
  715. $dm = WeblcmsDataManager :: get_instance();
  716. $do = $dm->get_next_content_object_publication_display_order_index($course, $tool, 0);
  717. $pub = new ContentObjectPublication();
  718. $pub->set_content_object_id($content_object->get_id());
  719. $pub->set_course_id($course);
  720. $pub->set_tool($tool);
  721. $pub->set_publisher_id(Session :: get_user_id());
  722. $pub->set_display_order_index($do);
  723. $pub->set_publication_date(time());
  724. $pub->set_modified_date(time());
  725. $pub->set_hidden($attributes[ContentObjectPublication :: PROPERTY_HIDDEN]);
  726. if (is_null($pub->is_hidden()))
  727. $pub->set_hidden(0);
  728. if ($attributes['forever'] == 0)
  729. {
  730. $pub->set_from_date(Utilities :: time_from_datepicker($attributes['from_date']));
  731. $pub->set_to_date(Utilities :: time_from_datepicker($attributes['to_date']));
  732. }
  733. $pub->create();
  734. $course = $dm->retrieve_course($course);
  735. return Translation :: get('PublicationCreated') . ': <b>' . Translation :: get('Course') . '</b>: ' . $course->get_name() . ' - <b>' . Translation :: get('Tool') . '</b>: ' . $tool;
  736. }
  737. static function add_publication_attributes_elements($form)
  738. {
  739. $form->addElement('category', Translation :: get('PublicationDetails'));
  740. $form->addElement('checkbox', self :: APPLICATION_NAME . '_opt_' . ContentObjectPublication :: PROPERTY_HIDDEN, Translation :: get('Hidden'));
  741. $form->add_forever_or_timewindow('PublicationPeriod', self :: APPLICATION_NAME . '_opt_');
  742. $form->addElement('category');
  743. $form->addElement('html', '<br />');
  744. $defaults[self :: APPLICATION_NAME . '_opt_forever'] = 1;
  745. $form->setDefaults($defaults);
  746. }
  747. /**
  748. * Count the number of courses
  749. * @param Condition $condition
  750. * @return int
  751. */
  752. function count_courses($condition = null)
  753. {
  754. return WeblcmsDataManager :: get_instance()->count_courses($condition);
  755. }
  756. function count_course_types($condition = null)
  757. {
  758. return WeblcmsDataManager :: get_instance()->count_course_types($condition);
  759. }
  760. function count_requests($condition = null)
  761. {
  762. return WeblcmsDataManager :: get_instance()->count_requests($condition);
  763. }
  764. function count_course_create_requests($condition = null)
  765. {
  766. return WeblcmsDataManager :: get_instance()->count_course_create_requests($condition);
  767. }
  768. function count_requests_by_course($condition = null)
  769. {
  770. return WeblcmsDataManager :: get_instance()->count_requests_by_course($condition);
  771. }
  772. function subscribe_user_to_allowed_courses($user_id)
  773. {
  774. return WeblcmsDataManager :: get_instance()->subscribe_user_to_allowed_courses($user_id);
  775. }
  776. /**
  777. * Count the number of course categories
  778. * @param Condition $condition
  779. * @return int
  780. */
  781. function count_course_categories($condition = null)
  782. {
  783. return WeblcmsDataManager :: get_instance()->count_course_categories($condition);
  784. }
  785. /**
  786. * Count the number of courses th user is subscribed to
  787. * @param Condition $condition
  788. * @return int
  789. */
  790. function count_user_courses($condition = null)
  791. {
  792. return WeblcmsDataManager :: get_instance()->count_user_courses($condition);
  793. }
  794. /**
  795. * Count the number of course user categories
  796. * @param Condition $condition
  797. * @return int
  798. */
  799. function count_course_user_categories($condition = null)
  800. {
  801. return WeblcmsDataManager :: get_instance()->count_course_user_categories($condition);
  802. }
  803. /**
  804. * Retrieves the course categories that match the criteria from persistent storage.
  805. * @param string $parent The parent of the course category.
  806. * @return DatabaseCourseCategoryResultSet The resultset of course category.
  807. */
  808. function retrieve_course_categories($conditions = null, $offset = null, $count = null, $order_by = null)
  809. {
  810. return WeblcmsDataManager :: get_instance()->retrieve_course_categories($conditions, $offset, $count, $order_by);
  811. }
  812. /**
  813. * Retrieves the personal course categories for a given user.
  814. * @return DatabaseUserCourseCategoryResultSet The resultset of course categories.
  815. */
  816. function retrieve_course_user_categories($conditions = null, $offset = null, $count = null, $order_property = null)
  817. {
  818. return WeblcmsDataManager :: get_instance()->retrieve_course_user_categories($conditions, $offset, $count, $order_property);
  819. }
  820. /**
  821. * Retrieves a personal course category for the user.
  822. * @return CourseUserCategory The course user category.
  823. */
  824. function retrieve_course_user_category($condition = null)
  825. {
  826. return WeblcmsDataManager :: get_instance()->retrieve_course_user_category($condition);
  827. }
  828. function retrieve_course_type_user_category($condition = null)
  829. {
  830. return WeblcmsDataManager :: get_instance()->retrieve_course_type_user_category($condition);
  831. }
  832. /**
  833. * Retrieves a personal course category for the user according to
  834. * @param int $user_id
  835. * @param int $sort
  836. * @param string $direction
  837. * @return CourseUserCategory The course user category.
  838. */
  839. function retrieve_course_type_user_category_at_sort($user_id, $course_type_id, $sort, $direction)
  840. {
  841. return WeblcmsDataManager :: get_instance()->retrieve_course_type_user_category_at_sort($user_id, $course_type_id, $sort, $direction);
  842. }
  843. /**
  844. * Retrieves a single course from persistent storage.
  845. * @param string $course_code The alphanumerical identifier of the course.
  846. * @return Course The course.
  847. */
  848. function retrieve_course($course_code)
  849. {
  850. return WeblcmsDataManager :: get_instance()->retrieve_course($course_code);
  851. }
  852. function retrieve_requests_by_course($id)
  853. {
  854. return WeblcmsDataManager :: get_instance()->retrieve_requests_by_course($id);
  855. }
  856. function retrieve_course_type($course_type_id)
  857. {
  858. return WeblcmsDataManager :: get_instance()->retrieve_course_type($course_type_id);
  859. }
  860. function retrieve_course_type_user_categories($condition = null, $offset = null, $count = null, $order_property = null)
  861. {
  862. return WeblcmsDataManager :: get_instance()->retrieve_course_type_user_categories($condition, $offset, $count, $order_property);
  863. }
  864. function retrieve_course_types($condition = null, $offset = null, $count = null, $order_property = null)
  865. {
  866. return WeblcmsDataManager :: get_instance()->retrieve_course_types($condition, $offset, $count, $order_property);
  867. }
  868. function retrieve_requests($condition = null, $offset = null, $count = null, $order_property = null)
  869. {
  870. return WeblcmsDataManager :: get_instance()->retrieve_requests($condition, $offset, $count, $order_property);
  871. }
  872. function retrieve_course_create_requests($condition = null, $offset = null, $count = null, $order_property = null)
  873. {
  874. return WeblcmsDataManager :: get_instance()->retrieve_course_create_requests($condition, $offset, $count, $order_property);
  875. }
  876. function retrieve_active_course_types()
  877. {
  878. return WeblcmsDataManager :: get_instance()->retrieve_active_course_types();
  879. }
  880. function count_active_course_types()
  881. {
  882. return WeblcmsDataManager :: get_instance()->count_active_course_type();
  883. }
  884. /**
  885. * Retrieves a single course category from persistent storage.
  886. * @param string $category_code The alphanumerical identifier of the course category.
  887. * @return CourseCategory The course category.
  888. */
  889. function retrieve_course_category($course_category)
  890. {
  891. return WeblcmsDataManager :: get_instance()->retrieve_course_category($course_category);
  892. }
  893. /**
  894. * Retrieves a single course user relation from persistent storage.
  895. * @param string $course_code
  896. * @param int $user_id
  897. * @return CourseCategory The course category.
  898. */
  899. function retrieve_course_user_relation($course_code, $user_id)
  900. {
  901. return WeblcmsDataManager :: get_instance()->retrieve_course_user_relation($course_code, $user_id);
  902. }
  903. /**
  904. * Retrieves the next course user relation according to.
  905. * @param int $user_id
  906. * @param int $category_id
  907. * @param int $sort
  908. * @param string $direction
  909. * @return CourseUserRelationResultSet
  910. */
  911. function retrieve_course_user_relation_at_sort($user_id, $course_type_id, $category_id, $sort, $direction)
  912. {
  913. return WeblcmsDataManager :: get_instance()->retrieve_course_user_relation_at_sort($user_id, $course_type_id, $category_id, $sort, $direction);
  914. }
  915. /**
  916. * Retrieves a set of course user relations
  917. * @param int $user_id
  918. * @param string $course_user_category
  919. */
  920. function retrieve_course_user_relations($condition = null, $offset = null, $count = null, $order_property = null)
  921. {
  922. return WeblcmsDataManager :: get_instance()->retrieve_course_user_relations($condition, $offset, $count, $order_property);
  923. }
  924. /**
  925. * Retrieve a series of courses
  926. * @param User $user
  927. * @param string $category
  928. * @param Condition $condition
  929. * @param array $order_by
  930. * @param int $offset
  931. * @param int $max_objects
  932. * @return CourseResultSet
  933. */
  934. function retrieve_courses($condition = null, $offset = null, $count = null, $order_property = null)
  935. {
  936. return WeblcmsDataManager :: get_instance()->retrieve_courses($condition, $offset, $count, $order_property);
  937. }
  938. /**
  939. * Retrieve a series of courses for a specific user + the relation
  940. * @param Condition $condition
  941. * @param array $order_by
  942. * @param int $offset
  943. * @param int $max_objects
  944. * @return CourseResultSet
  945. */
  946. function retrieve_user_courses($condition = null, $offset = null, $count = null, $order_property = null)
  947. {
  948. return WeblcmsDataManager :: get_instance()->retrieve_user_courses($condition, $offset, $count, $order_property);
  949. }
  950. /**
  951. * Gets the date of the last visit of current user to the current location
  952. * @param string $tool If $tool equals null, current active tool will be
  953. * taken into account. If no tool is given or no tool is active the date of
  954. * last visit to the course homepage will be returned.
  955. * @param int $category_id The category in the given tool of which the last
  956. * visit date is requested. If $category_id equals null, the current active
  957. * category will be used.
  958. * @return int
  959. */
  960. function get_last_visit_date($tool = null, $category_id = null)
  961. {
  962. if (is_null($tool))
  963. {
  964. $tool = $this->get_parameter(self :: PARAM_TOOL);
  965. }
  966. if (is_null($category_id))
  967. {
  968. $category_id = $this->get_parameter(self :: PARAM_CATEGORY);
  969. if (is_null($category_id))
  970. {
  971. $category_id = 0;
  972. }
  973. }
  974. $wdm = WeblcmsDataManager :: get_instance();
  975. $date = $wdm->get_last_visit_date($this->get_course_id(), $this->get_user_id(), $tool, $category_id);
  976. return $date;
  977. }
  978. /**
  979. * Determines if a tool has new publications since the last time the
  980. * current user visited the tool.
  981. * @param string $tool
  982. * @param Course $course
  983. */
  984. function tool_has_new_publications($tool, Course $course = null)
  985. {
  986. if ($course == null)
  987. {
  988. $course = $this->get_course();
  989. }
  990. return WeblcmsDataManager :: tool_has_new_publications($tool, $this->get_user(), $course);
  991. }
  992. /**
  993. * Returns the url to the course's page
  994. * @param Course $course
  995. * @return String
  996. */
  997. function get_course_viewing_url($course)
  998. {
  999. return $this->get_url(array(
  1000. self :: PARAM_ACTION => self :: ACTION_VIEW_COURSE,
  1001. self :: PARAM_COURSE => $course->get_id()));
  1002. }
  1003. function retrieve_request($id)
  1004. {
  1005. return WeblcmsDataManager :: get_instance()->retrieve_request($id);
  1006. }
  1007. function retrieve_course_create_request($id)
  1008. {
  1009. return WeblcmsDataManager :: get_instance()->retrieve_course_create_request($id);
  1010. }
  1011. /**
  1012. * Returns the link to the course's page
  1013. * @param Course $course
  1014. * @return String
  1015. */
  1016. function get_course_viewing_link($course, $encode = false)
  1017. {
  1018. return $this->get_link(array(
  1019. self :: PARAM_ACTION => self :: ACTION_VIEW_COURSE,
  1020. self :: PARAM_COURSE => $course->get_id()), $encode);
  1021. }
  1022. /**
  1023. * Returns the editing url for the course
  1024. * @param Course $course
  1025. * @return String
  1026. */
  1027. function get_course_editing_url($course)
  1028. {
  1029. return $this->get_url(array(
  1030. self :: PARAM_ACTION => self :: ACTION_CREATE_COURSE,
  1031. self :: PARAM_COURSE => $course->get_id(),
  1032. self :: PARAM_TOOL => 'course_settings',
  1033. 'previous' => 'admin'));
  1034. }
  1035. /**
  1036. * Returns the deleting url for the course
  1037. * @param Course $course
  1038. * @return String
  1039. */
  1040. function get_course_deleting_url($course)
  1041. {
  1042. return $this->get_url(array(
  1043. self :: PARAM_ACTION => self :: ACTION_DELETE_COURSE,
  1044. self :: PARAM_COURSE => $course->get_id()));
  1045. }
  1046. /**
  1047. * Returns the maintenance url for the course
  1048. * @param Course $course
  1049. * @return String
  1050. */
  1051. function get_course_maintenance_url($course)
  1052. {
  1053. return $this->get_url(array(
  1054. self :: PARAM_ACTION => self :: ACTION_VIEW_COURSE,
  1055. self :: PARAM_COURSE => $course->get_id(),
  1056. self :: PARAM_TOOL => 'maintenance'));
  1057. }
  1058. /**
  1059. * Returns the subscription url for the course
  1060. * @param Course $course
  1061. * @return String
  1062. */
  1063. function get_course_subscription_url($course)
  1064. {
  1065. return $this->get_url(array(
  1066. self :: PARAM_ACTION => self :: ACTION_MANAGER_SUBSCRIBE,
  1067. self :: PARAM_COURSE => $course->get_id()));
  1068. }
  1069. function get_course_request_form_url($course)
  1070. {
  1071. return $this->get_url(array(
  1072. self :: PARAM_ACTION => self :: ACTION_COURSE_SUBSCRIBE_CREATE_REQUEST,
  1073. self :: PARAM_COURSE => $course->get_id()));
  1074. }
  1075. function get_course_code_url($course)
  1076. {
  1077. return $this->get_url(array(
  1078. self :: PARAM_ACTION => self :: ACTION_COURSE_CODE,
  1079. self :: PARAM_COURSE => $course->get_id()));
  1080. }
  1081. /**
  1082. * Returns the unsubscription url for the course
  1083. * @param Course $course
  1084. * @return String
  1085. */
  1086. function get_course_unsubscription_url($course)
  1087. {
  1088. return $this->get_url(array(
  1089. self :: PARAM_ACTION => self :: ACTION_MANAGER_UNSUBSCRIBE,
  1090. self :: PARAM_COURSE => $course->get_id()));
  1091. }
  1092. /**
  1093. * Returns the editing url for the course user category
  1094. * @param CourseUsercategory $course_user_category
  1095. * @return String
  1096. */
  1097. function get_course_user_category_edit_url(CourseTypeUserCategory $course_type_user_category)
  1098. {
  1099. return $this->get_url(array(
  1100. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1101. self :: PARAM_COMPONENT_ACTION => 'edit',
  1102. self :: PARAM_COURSE_TYPE_USER_CATEGORY_ID => $course_type_user_category->get_id()));
  1103. }
  1104. /**
  1105. * Returns the creating url for a course user category
  1106. * @return String
  1107. */
  1108. function get_course_user_category_add_url()
  1109. {
  1110. return $this->get_url(array(
  1111. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1112. self :: PARAM_COMPONENT_ACTION => 'add'));
  1113. }
  1114. /**
  1115. * Returns the moving url for the course user category
  1116. * @param CourseUserCategory $course_user_category
  1117. * @param string $direction
  1118. * @return String
  1119. */
  1120. function get_course_user_category_move_url(CourseTypeUserCategory $course_type_user_category, $direction)
  1121. {
  1122. return $this->get_url(array(
  1123. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1124. self :: PARAM_COMPONENT_ACTION => 'movecat',
  1125. self :: PARAM_DIRECTION => $direction,
  1126. self :: PARAM_COURSE_TYPE_USER_CATEGORY_ID => $course_type_user_category->get_id()));
  1127. }
  1128. /**
  1129. * Returns the deleting url for the course user category
  1130. * @param CourseUserCategory $course_user_category
  1131. * @return String
  1132. */
  1133. function get_course_user_category_delete_url(CourseTypeUserCategory $course_type_user_category)
  1134. {
  1135. return $this->get_url(array(
  1136. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1137. self :: PARAM_COMPONENT_ACTION => 'delete',
  1138. self :: PARAM_COURSE_TYPE_USER_CATEGORY_ID => $course_type_user_category->get_id()));
  1139. }
  1140. /**
  1141. * Returns the editing url for the course category
  1142. * @param CourseCategory $course_category
  1143. * @return String
  1144. */
  1145. function get_course_category_edit_url($course_category)
  1146. {
  1147. return $this->get_url(array(
  1148. self :: PARAM_ACTION => self :: ACTION_COURSE_CATEGORY_MANAGER,
  1149. self :: PARAM_COMPONENT_ACTION => 'edit',
  1150. self :: PARAM_COURSE_CATEGORY => $course_category->get_code()));
  1151. }
  1152. /**
  1153. * Returns the creating url for a course category
  1154. * @return String
  1155. */
  1156. function get_course_category_add_url()
  1157. {
  1158. return $this->get_url(array(
  1159. self :: PARAM_ACTION => self :: ACTION_COURSE_CATEGORY_MANAGER,
  1160. self :: PARAM_COMPONENT_ACTION => 'add'));
  1161. }
  1162. /**
  1163. * Returns the deleting url for the course category
  1164. * @param CourseCategory $course_category
  1165. * @return String
  1166. */
  1167. function get_course_category_delete_url($coursecategory)
  1168. {
  1169. return $this->get_url(array(
  1170. self :: PARAM_ACTION => self :: ACTION_COURSE_CATEGORY_MANAGER,
  1171. self :: PARAM_COMPONENT_ACTION => 'delete',
  1172. self :: PARAM_COURSE_CATEGORY_ID => $coursecategory->get_code()));
  1173. }
  1174. /**
  1175. * Returns the editing url for the course user relation
  1176. * @param Course $course
  1177. * @return String
  1178. */
  1179. function get_course_user_edit_url(CourseTypeUserCategory $course_type_user_category, Course $course)
  1180. {
  1181. if ($course_type_user_category)
  1182. {
  1183. $course_type_user_category_id = $course_type_user_category->get_id();
  1184. }
  1185. return $this->get_url(array(
  1186. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1187. self :: PARAM_COMPONENT_ACTION => 'assign',
  1188. self :: PARAM_COURSE => $course->get_id(),
  1189. self :: PARAM_COURSE_TYPE_USER_CATEGORY_ID => $course_type_user_category_id));
  1190. }
  1191. /**
  1192. * Returns the moving url for the course user relation
  1193. * @param Course $course
  1194. * @param string $direction
  1195. * @return String
  1196. */
  1197. function get_course_user_move_url(CourseTypeUserCategory $course_type_user_category, Course $course, $direction)
  1198. {
  1199. return $this->get_url(array(
  1200. self :: PARAM_ACTION => self :: ACTION_MANAGER_SORT,
  1201. self :: PARAM_COMPONENT_ACTION => 'move',
  1202. self :: PARAM_DIRECTION => $direction,
  1203. self :: PARAM_COURSE => $course->get_id(),
  1204. self :: PARAM_COURSE_TYPE_USER_CATEGORY_ID => $course_type_user_category->get_id()));
  1205. }
  1206. /**
  1207. * Checks whether subscription to the course is allowed for the current user
  1208. * @param Course $course
  1209. * @return boolean
  1210. */
  1211. function course_subscription_allowed($course)
  1212. {
  1213. return WeblcmsDataManager :: course_subscription_allowed($course, $this->get_user());
  1214. }
  1215. /**
  1216. * Checks whether unsubscription from the course is allowed for the current user
  1217. * @param Course $course
  1218. * @return boolean
  1219. */
  1220. function course_unsubscription_allowed($course)
  1221. {
  1222. return WeblcmsDataManager :: course_unsubscription_allowed($course, $this->get_user());
  1223. }
  1224. /**
  1225. * Checks whether the user is subscribed to the given course
  1226. * @param Course $course
  1227. * @param User $user
  1228. * @return boolean
  1229. */
  1230. function is_subscribed($course, $user)
  1231. {
  1232. $wdm = WeblcmsDataManager :: get_instance();
  1233. return $wdm->is_subscribed($course, $user);
  1234. }
  1235. function is_teacher($course, $user)
  1236. {
  1237. if ($user != null && $course != null)
  1238. {
  1239. $relation = $this->retrieve_course_user_relation($course->get_id(), $user->get_id());
  1240. if (($relation && $relation->get_status() == 1) || $user->is_platform_admin())
  1241. {
  1242. return true;
  1243. }
  1244. else
  1245. {
  1246. return WeblcmsDataManager :: is_teacher_through_platform_groups($course, $user);
  1247. }
  1248. }
  1249. return false;
  1250. }
  1251. /**
  1252. * Subscribe a user to a course.
  1253. * @param Course $course
  1254. * @param int $status
  1255. * @param int $tutor_id
  1256. * @param int $user_id
  1257. * @return boolean
  1258. */
  1259. function subscribe_user_to_course($course, $status, $tutor_id, $user_id)
  1260. {
  1261. $wdm = WeblcmsDataManager :: get_instance();
  1262. return $wdm->subscribe_user_to_course($course, $status, $tutor_id, $user_id);
  1263. }
  1264. /**
  1265. * Unsubscribe a user from a course.
  1266. * @param Course $course
  1267. * @param int $user_id
  1268. * @return boolean
  1269. */
  1270. function unsubscribe_user_from_course($course, $user_id)
  1271. {
  1272. //first delete the user from course groups
  1273. $wdm = WeblcmsDataManager :: get_instance();
  1274. $success = true;
  1275. $course_groups = $wdm->retrieve_course_groups_from_user($user_id, $course->get_id());
  1276. while($course_group = $course_groups->next_result())
  1277. {
  1278. $success &= $wdm->unsubscribe_users_from_course_groups($user_id, $course_group);
  1279. }
  1280. //unsubscribe the user from the course
  1281. return ($success && $wdm->unsubscribe_user_from_course($course, $user_id));
  1282. }
  1283. /**
  1284. * Subscribe a group to a course.
  1285. * @param Course $course
  1286. * @param int $group_id
  1287. * @return boolean
  1288. */
  1289. function subscribe_group_to_course($course, $group_id, $status)
  1290. {
  1291. $wdm = WeblcmsDataManager :: get_instance();
  1292. return $wdm->subscribe_group_to_course($course, $group_id, $status);
  1293. }
  1294. /**
  1295. * Unsubscribe a group from a course.
  1296. * @param Course $course
  1297. * @param int $user_id
  1298. * @return boolean
  1299. */
  1300. function unsubscribe_group_from_course($course, $group_id)
  1301. {
  1302. $wdm = WeblcmsDataManager :: get_instance();
  1303. return $wdm->unsubscribe_group_from_course($course, $group_id);
  1304. }
  1305. /**
  1306. * @todo Clean this up. It's all SortableTable's fault. :-(
  1307. */
  1308. private function parse_input_from_table()
  1309. {
  1310. $action = $_POST['action'];
  1311. if (isset($action))
  1312. {
  1313. $action = $_POST['action'];
  1314. $selected_request_id = $_POST[AdminRequestBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1315. if (empty($selected_request_id))
  1316. {
  1317. $selected_request_id = array();
  1318. }
  1319. elseif (! is_array($selected_request_id))
  1320. {
  1321. $selected_request_id = array($selected_request_id);
  1322. }
  1323. $selected_course_ids = $_POST[AdminCourseBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1324. if (empty($selected_course_ids))
  1325. {
  1326. $selected_course_ids = array();
  1327. }
  1328. elseif (! is_array($selected_course_ids))
  1329. {
  1330. $selected_course_ids = array($selected_course_ids);
  1331. }
  1332. $selected_user_ids = $_POST[SubscribedUserBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1333. if (empty($selected_user_ids))
  1334. {
  1335. $selected_user_ids = array();
  1336. }
  1337. elseif (! is_array($selected_user_ids))
  1338. {
  1339. $selected_user_ids = array($selected_user_ids);
  1340. }
  1341. $selected_group_ids = $_POST[SubscribeGroupBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1342. if (empty($selected_group_ids))
  1343. {
  1344. $selected_group_ids = array();
  1345. }
  1346. elseif (! is_array($selected_group_ids))
  1347. {
  1348. $selected_group_ids = array($selected_group_ids);
  1349. }
  1350. $selected_course_type_ids = $_POST[AdminCourseTypeBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1351. if (empty($selected_course_type_ids))
  1352. {
  1353. $selected_course_type_ids = array();
  1354. }
  1355. elseif (! is_array($selected_course_type_ids))
  1356. {
  1357. $selected_course_type_ids = array($selected_course_type_ids);
  1358. }
  1359. $selected_course_type_id = $_POST[AdminCourseTypeBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
  1360. if ($action == 'enable' || $action == 'disable')
  1361. {
  1362. $this->redirect('url', null, null, array(
  1363. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_CHANGE_ACTIVE,
  1364. WeblcmsManager :: PARAM_COURSE_TYPE => $selected_course_type_id,
  1365. WeblcmsManager :: PARAM_TYPE => 'course_type',
  1366. WeblcmsManager :: PARAM_EXTRA => $action));
  1367. }
  1368. switch ($action)
  1369. {
  1370. case self :: PARAM_REMOVE_SELECTED :
  1371. $this->set_action(self :: ACTION_DELETE_COURSE);
  1372. Request :: set_get(self :: PARAM_COURSE, $selected_course_ids);
  1373. break;
  1374. case self :: PARAM_UNSUBSCRIBE_SELECTED :
  1375. $this->set_action(self :: ACTION_MANAGER_UNSUBSCRIBE);
  1376. Request :: set_get(self :: PARAM_USERS, $selected_user_ids);
  1377. break;
  1378. case self :: PARAM_SUBSCRIBE_SELECTED_AS_STUDENT :
  1379. $this->set_action(self :: ACTION_MANAGER_SUBSCRIBE);
  1380. Request :: set_get(self :: PARAM_USERS, $selected_user_ids);
  1381. Request :: set_get(self :: PARAM_STATUS, 5);
  1382. break;
  1383. case self :: PARAM_SUBSCRIBE_SELECTED_AS_ADMIN :
  1384. $this->set_action(self :: ACTION_MANAGER_SUBSCRIBE);
  1385. Request :: set_get(self :: PARAM_USERS, $selected_user_ids);
  1386. Request :: set_get(self :: PARAM_STATUS, 1);
  1387. break;
  1388. case self :: PARAM_SUBSCRIBE_SELECTED_GROUP :
  1389. $this->set_action(self :: ACTION_SUBSCRIBE_GROUP_USERS);
  1390. Request :: set_get(WeblcmsManager :: PARAM_GROUP, $selected_group_ids);
  1391. Request :: set_get(self :: PARAM_STATUS, 1);
  1392. break;
  1393. case self :: PARAM_REMOVE_SELECTED_COURSE_TYPES :
  1394. $this->set_action(self :: ACTION_DELETE_COURSE_TYPE);
  1395. Request :: set_get(self :: PARAM_COURSE_TYPE, $selected_course_type_ids);
  1396. break;
  1397. case self :: PARAM_ACTIVATE_SELECTED_COURSE_TYPES :
  1398. $this->set_action(self :: ACTION_CHANGE_ACTIVATION);
  1399. Request :: set_get(self :: PARAM_COURSE_TYPE, $selected_course_type_ids);
  1400. Request :: set_get(self :: PARAM_ACTIVE, 1);
  1401. break;
  1402. case self :: PARAM_DEACTIVATE_SELECTED_COURSE_TYPES :
  1403. $this->set_action(self :: ACTION_CHANGE_ACTIVATION);
  1404. Request :: set_get(self :: PARAM_COURSE_TYPE, $selected_course_type_ids);
  1405. Request :: set_get(self :: PARAM_ACTIVE, 0);
  1406. break;
  1407. case self :: PARAM_CHANGE_COURSE_TYPE_SELECTED_COURSES :
  1408. $this->set_action(self :: ACTION_CHANGE_COURSE_TYPE_FROM_COURSE);
  1409. Request :: set_get(self :: PARAM_MESSAGE, null);
  1410. Request :: set_get(self :: PARAM_ERROR_MESSAGE, null);
  1411. Request :: set_get(self :: PARAM_WARNING_MESSAGE, null);
  1412. Request :: set_get(self :: PARAM_COURSE, $selected_course_ids);
  1413. break;
  1414. case self :: PARAM_REMOVE_SELECTED_REQUESTS :
  1415. $this->set_action(self :: ACTION_COURSE_REQUEST_DELETER);
  1416. Request :: set_get(self :: PARAM_REQUEST, $selected_request_id);
  1417. break;
  1418. case self :: PARAM_ALLOW_SELECTED_REQUESTS :
  1419. $this->set_action(self :: ACTION_COURSE_ALLOWING_REQUEST);
  1420. Request :: set_get(self :: PARAM_REQUEST, $selected_request_id);
  1421. break;
  1422. case self :: PARAM_REFUSE_SELECTED_REQUESTS :
  1423. $this->set_action(self :: ACTION_COURSE_REFUSE_REQUEST);
  1424. Request :: set_get(self :: PARAM_REQUEST, $selected_request_id);
  1425. break;
  1426. }
  1427. }
  1428. }
  1429. /**
  1430. * Gets the search form.
  1431. * @return RepositorySearchForm The search form.
  1432. */
  1433. private function get_search_form()
  1434. {
  1435. if (! isset($this->search_form))
  1436. {
  1437. $this->search_form = new WeblcmsSearchForm($this, $this->get_url());
  1438. }
  1439. return $this->search_form;
  1440. }
  1441. /**
  1442. * Gets the search condition
  1443. * @return Condition
  1444. */
  1445. function get_search_condition()
  1446. {
  1447. return $this->get_search_form()->get_condition();
  1448. }
  1449. /**
  1450. * Returns whether the search form has validated
  1451. * @return boolean
  1452. */
  1453. function get_search_validate()
  1454. {
  1455. return $this->get_search_form()->validate();
  1456. }
  1457. /**
  1458. * Gets the search parameter
  1459. * @param string $name
  1460. * @return string
  1461. */
  1462. function get_search_parameter($name)
  1463. {
  1464. return $this->search_parameters[$name];
  1465. }
  1466. /**
  1467. * Displays the search form
  1468. */
  1469. private function display_search_form()
  1470. {
  1471. echo $this->get_search_form()->display();
  1472. }
  1473. /**
  1474. * Returns a list of actions available to the admin.
  1475. * @param User $user The current user.
  1476. * @return Array $info Contains all possible actions.
  1477. */
  1478. public static function get_application_platform_admin_links()
  1479. {
  1480. $links = array();
  1481. $links[] = new DynamicAction(Translation :: get('CourseTypeList'), Translation :: get('CourseTypeListDescription'), Theme :: get_image_path() . 'admin/list.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1482. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_TYPE_BROWSER)));
  1483. $links[] = new DynamicAction(Translation :: get('CreateCourseType'), Translation :: get('CreateTypeDescription'), Theme :: get_image_path() . 'admin/add.png', Redirect :: get_link(self :: APPLICATION_NAME, array(Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_TYPE_CREATOR)));
  1484. $links[] = new DynamicAction(Translation :: get('CourseList'), Translation :: get('ListDescription'), Theme :: get_image_path() . 'admin/list.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1485. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_BROWSER)));
  1486. $links[] = new DynamicAction(Translation :: get('CreateCourse'), Translation :: get('CreateDescription'), Theme :: get_image_path() . 'admin/add.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1487. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_CREATE_COURSE)));
  1488. $links[] = new DynamicAction(Translation :: get('Import'), Translation :: get('ImportDescription'), Theme :: get_image_path() . 'admin/import.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1489. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_IMPORT_COURSES)));
  1490. $links[] = new DynamicAction(Translation :: get('RequestList'), Translation :: get('RequestDescription'), Theme :: get_image_path() . 'admin/list.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1491. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_REQUEST_BROWSER)));
  1492. $links[] = new DynamicAction(Translation :: get('CourseCategoryManagement'), Translation :: get('CourseCategoryManagementDescription'), Theme :: get_image_path() . 'admin/category.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1493. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_COURSE_CATEGORY_MANAGER)));
  1494. $links[] = new DynamicAction(Translation :: get('UserImport'), Translation :: get('UserImportDescription'), Theme :: get_image_path() . 'admin/import.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
  1495. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_IMPORT_COURSE_USERS)));
  1496. $info = parent :: get_application_platform_admin_links(self :: APPLICATION_NAME);
  1497. $info['links'] = $links;
  1498. $info['search'] = Redirect :: get_link(self :: APPLICATION_NAME, array(
  1499. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_BROWSER));
  1500. return $info;
  1501. }
  1502. /**
  1503. * Gets the available links to display in the platform admin
  1504. * @retun array of links and actions
  1505. */
  1506. public function get_application_platform_import_links()
  1507. {
  1508. $links = array();
  1509. $links[] = array(
  1510. 'name' => Translation :: get('ImportCourses'),
  1511. 'description' => Translation :: get('ImportCoursesDescription'),
  1512. 'url' => $this->get_link(array(Application :: PARAM_ACTION => WeblcmsManager :: ACTION_IMPORT_COURSES)));
  1513. $links[] = array(
  1514. 'name' => Translation :: get('ImportCourseUsers'),
  1515. 'description' => Translation :: get('ImportCourseUsersDescription'),
  1516. 'url' => $this->get_link(array(
  1517. Application :: PARAM_ACTION => WeblcmsManager :: ACTION_IMPORT_COURSE_USERS)));
  1518. return $links;
  1519. }
  1520. function get_reporting_url($params)
  1521. {
  1522. $array = array(
  1523. Application :: PARAM_APPLICATION => self :: APPLICATION_NAME,
  1524. self :: PARAM_TOOL => null,
  1525. self :: PARAM_ACTION => self :: ACTION_REPORTING);
  1526. $array = array_merge($array, $params);
  1527. return $this->get_url($array);
  1528. }
  1529. /**
  1530. * Helper function for the Application class,
  1531. * pending access to class constants via variables in PHP 5.3
  1532. * e.g. $name = $class :: APPLICATION_NAME
  1533. *
  1534. * DO NOT USE IN THIS APPLICATION'S CONTEXT
  1535. * Instead use:
  1536. * - self :: APPLICATION_NAME in the context of this class
  1537. * - YourApplicationManager :: APPLICATION_NAME in all other application classes
  1538. */
  1539. function get_application_name()
  1540. {
  1541. return self :: APPLICATION_NAME;
  1542. }
  1543. /**
  1544. * Returns html of additional user information for the user view
  1545. *
  1546. * @param User $user
  1547. */
  1548. function get_additional_user_information($user)
  1549. {
  1550. $html = array();
  1551. $table = new HTML_Table(array('class' => 'data_table'));
  1552. $