PageRenderTime 25ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/php/lib/course/course_section.class.php

https://bitbucket.org/chamilo/chamilo-app-weblcms-dev/
PHP | 254 lines | 110 code | 35 blank | 109 comment | 2 complexity | 25638812b5371a8761aa6a083a6dd59d MD5 | raw file
  1. <?php
  2. namespace application\weblcms;
  3. use common\libraries\Utilities;
  4. use common\libraries\EqualityCondition;
  5. use common\libraries\DataClass;
  6. use common\libraries\Translation;
  7. /**
  8. * This class defines a course section in which tools can be arranged
  9. *
  10. * @package application\weblcms;
  11. *
  12. * @author Sven Vanpoucke - Hogeschool Gent
  13. */
  14. class CourseSection extends DataClass
  15. {
  16. const CLASS_NAME = __CLASS__;
  17. /****************************************************************************************************************
  18. * Table Properties *
  19. ****************************************************************************************************************/
  20. const PROPERTY_COURSE_CODE = 'course_id';
  21. const PROPERTY_NAME = 'name';
  22. const PROPERTY_TYPE = 'type';
  23. const PROPERTY_VISIBLE = 'visible';
  24. const PROPERTY_DISPLAY_ORDER = 'display_order';
  25. /****************************************************************************************************************
  26. * Type Definitions *
  27. ****************************************************************************************************************/
  28. const TYPE_DISABLED = '0';
  29. const TYPE_DISABLED_NAME = 'disabled';
  30. const TYPE_TOOL = '1';
  31. const TYPE_TOOL_NAME = 'tool';
  32. const TYPE_LINK = '2';
  33. const TYPE_LINK_NAME = 'link';
  34. const TYPE_ADMIN = '3';
  35. const TYPE_ADMIN_NAME = 'admin';
  36. const TYPE_CUSTOM = '4';
  37. const TYPE_CUSTOM_NAME = 'custom';
  38. private static $type_name_mapping = array(self :: TYPE_DISABLED => self :: TYPE_DISABLED_NAME,
  39. self :: TYPE_TOOL => self :: TYPE_TOOL_NAME,
  40. self :: TYPE_LINK => self :: TYPE_LINK_NAME,
  41. self :: TYPE_ADMIN => self :: TYPE_ADMIN_NAME,
  42. self :: TYPE_CUSTOM => self :: TYPE_CUSTOM_NAME
  43. );
  44. /****************************************************************************************************************
  45. * Type Mapping Functionality *
  46. ****************************************************************************************************************/
  47. /**
  48. * Returns the type from the given type name
  49. *
  50. * @param String $type_name
  51. *
  52. * @return int
  53. */
  54. static function get_type_from_type_name($type_name)
  55. {
  56. $type = array_search($type_name, self :: $type_name_mapping);
  57. if(!$type)
  58. {
  59. throw new \Exception(Translation :: get('CouldNotFindSectionTypeName', array('TYPE_NAME' => $type_name)));
  60. }
  61. return $type;
  62. }
  63. /**
  64. * Returns the type name from a given type
  65. *
  66. * @param int $type
  67. *
  68. * @return String
  69. */
  70. static function get_type_name_from_type($type)
  71. {
  72. if(!array_key_exists($type, self :: $type_name_mapping))
  73. {
  74. throw new \Exception(Translation :: get('CouldNotFindSectionType', array('TYPE' => $type)));
  75. }
  76. return self :: $type_name_mapping[$type];
  77. }
  78. /****************************************************************************************************************
  79. * Inherited Functionality *
  80. ****************************************************************************************************************/
  81. /**
  82. * Returns the default properties of this dataclass
  83. *
  84. * @return String[] - The property names.
  85. */
  86. static function get_default_property_names($extended_property_names = array())
  87. {
  88. return parent :: get_default_property_names(array(self :: PROPERTY_COURSE_CODE, self :: PROPERTY_NAME,
  89. self :: PROPERTY_TYPE, self :: PROPERTY_VISIBLE, self :: PROPERTY_DISPLAY_ORDER));
  90. }
  91. /**
  92. * Returns the datamanager for this dataclass
  93. *
  94. * @return WeblcmsDataManager
  95. */
  96. function get_data_manager()
  97. {
  98. return WeblcmsDataManager :: get_instance();
  99. }
  100. /**
  101. * Returns the table name of this dataclass
  102. *
  103. * @return String
  104. */
  105. static function get_table_name()
  106. {
  107. return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
  108. }
  109. /****************************************************************************************************************
  110. * Manipulation functionality *
  111. ****************************************************************************************************************/
  112. /**
  113. * Fils the display order with an automatic value and creates the object in the storage unit
  114. *
  115. * @return boolean
  116. */
  117. function create()
  118. {
  119. $condition = new EqualityCondition(self :: PROPERTY_COURSE_CODE, $this->get_course_code());
  120. $sort = $this->get_data_manager()->retrieve_next_sort_value(self :: get_table_name(),
  121. self :: PROPERTY_DISPLAY_ORDER, $condition);
  122. $this->set_display_order($sort);
  123. return parent :: create();
  124. }
  125. /****************************************************************************************************************
  126. * Getters and Setters *
  127. ****************************************************************************************************************/
  128. /**
  129. * Returns the course_code property of this object
  130. *
  131. * @return String
  132. */
  133. function get_course_code()
  134. {
  135. return $this->get_default_property(self :: PROPERTY_COURSE_CODE);
  136. }
  137. /**
  138. * Sets the course_code property of this object
  139. *
  140. * @param String $course_code
  141. */
  142. function set_course_code($course_code)
  143. {
  144. $this->set_default_property(self :: PROPERTY_COURSE_CODE, $course_code);
  145. }
  146. /**
  147. * Returns the name property of this object
  148. *
  149. * @return String
  150. */
  151. function get_name()
  152. {
  153. return $this->get_default_property(self :: PROPERTY_NAME);
  154. }
  155. /**
  156. * Sets the name property of this object
  157. *
  158. * @param String $name
  159. */
  160. function set_name($name)
  161. {
  162. $this->set_default_property(self :: PROPERTY_NAME, $name);
  163. }
  164. /**
  165. * Returns the type property of this object
  166. *
  167. * @return int
  168. */
  169. function get_type()
  170. {
  171. return $this->get_default_property(self :: PROPERTY_TYPE);
  172. }
  173. /**
  174. * Sets the type property of this object
  175. *
  176. * @param int $type
  177. */
  178. function set_type($type)
  179. {
  180. $this->set_default_property(self :: PROPERTY_TYPE, $type);
  181. }
  182. /**
  183. * Returns the tool_id property of this object
  184. *
  185. * @return boolean
  186. */
  187. function is_visible()
  188. {
  189. return $this->get_default_property(self :: PROPERTY_VISIBLE);
  190. }
  191. /**
  192. * Sets the visible property of this object
  193. *
  194. * @param boolean $visible
  195. */
  196. function set_visible($visible)
  197. {
  198. $this->set_default_property(self :: PROPERTY_VISIBLE, $visible);
  199. }
  200. /**
  201. * Returns the display_order property of this object
  202. *
  203. * @return int
  204. */
  205. function get_display_order()
  206. {
  207. return $this->get_default_property(self :: PROPERTY_DISPLAY_ORDER);
  208. }
  209. /**
  210. * Sets the display_order property of this object
  211. *
  212. * @param int $display_order
  213. */
  214. function set_display_order($display_order)
  215. {
  216. $this->set_default_property(self :: PROPERTY_DISPLAY_ORDER, $display_order);
  217. }
  218. }
  219. ?>