/php/lib/course/course_section.class.php
PHP | 254 lines | 110 code | 35 blank | 109 comment | 2 complexity | 25638812b5371a8761aa6a083a6dd59d MD5 | raw file
- <?php
- namespace application\weblcms;
-
- use common\libraries\Utilities;
- use common\libraries\EqualityCondition;
- use common\libraries\DataClass;
- use common\libraries\Translation;
-
- /**
- * This class defines a course section in which tools can be arranged
- *
- * @package application\weblcms;
- *
- * @author Sven Vanpoucke - Hogeschool Gent
- */
- class CourseSection extends DataClass
- {
- const CLASS_NAME = __CLASS__;
-
- /****************************************************************************************************************
- * Table Properties *
- ****************************************************************************************************************/
-
- const PROPERTY_COURSE_CODE = 'course_id';
- const PROPERTY_NAME = 'name';
- const PROPERTY_TYPE = 'type';
- const PROPERTY_VISIBLE = 'visible';
- const PROPERTY_DISPLAY_ORDER = 'display_order';
-
- /****************************************************************************************************************
- * Type Definitions *
- ****************************************************************************************************************/
-
- const TYPE_DISABLED = '0';
- const TYPE_DISABLED_NAME = 'disabled';
-
- const TYPE_TOOL = '1';
- const TYPE_TOOL_NAME = 'tool';
-
- const TYPE_LINK = '2';
- const TYPE_LINK_NAME = 'link';
-
- const TYPE_ADMIN = '3';
- const TYPE_ADMIN_NAME = 'admin';
-
- const TYPE_CUSTOM = '4';
- const TYPE_CUSTOM_NAME = 'custom';
-
- private static $type_name_mapping = array(self :: TYPE_DISABLED => self :: TYPE_DISABLED_NAME,
- self :: TYPE_TOOL => self :: TYPE_TOOL_NAME,
- self :: TYPE_LINK => self :: TYPE_LINK_NAME,
- self :: TYPE_ADMIN => self :: TYPE_ADMIN_NAME,
- self :: TYPE_CUSTOM => self :: TYPE_CUSTOM_NAME
- );
-
- /****************************************************************************************************************
- * Type Mapping Functionality *
- ****************************************************************************************************************/
-
- /**
- * Returns the type from the given type name
- *
- * @param String $type_name
- *
- * @return int
- */
- static function get_type_from_type_name($type_name)
- {
- $type = array_search($type_name, self :: $type_name_mapping);
-
- if(!$type)
- {
- throw new \Exception(Translation :: get('CouldNotFindSectionTypeName', array('TYPE_NAME' => $type_name)));
- }
-
- return $type;
- }
-
- /**
- * Returns the type name from a given type
- *
- * @param int $type
- *
- * @return String
- */
- static function get_type_name_from_type($type)
- {
- if(!array_key_exists($type, self :: $type_name_mapping))
- {
- throw new \Exception(Translation :: get('CouldNotFindSectionType', array('TYPE' => $type)));
- }
-
- return self :: $type_name_mapping[$type];
- }
-
- /****************************************************************************************************************
- * Inherited Functionality *
- ****************************************************************************************************************/
-
- /**
- * Returns the default properties of this dataclass
- *
- * @return String[] - The property names.
- */
- static function get_default_property_names($extended_property_names = array())
- {
- return parent :: get_default_property_names(array(self :: PROPERTY_COURSE_CODE, self :: PROPERTY_NAME,
- self :: PROPERTY_TYPE, self :: PROPERTY_VISIBLE, self :: PROPERTY_DISPLAY_ORDER));
- }
-
- /**
- * Returns the datamanager for this dataclass
- *
- * @return WeblcmsDataManager
- */
- function get_data_manager()
- {
- return WeblcmsDataManager :: get_instance();
- }
-
- /**
- * Returns the table name of this dataclass
- *
- * @return String
- */
- static function get_table_name()
- {
- return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
- }
-
- /****************************************************************************************************************
- * Manipulation functionality *
- ****************************************************************************************************************/
-
- /**
- * Fils the display order with an automatic value and creates the object in the storage unit
- *
- * @return boolean
- */
- function create()
- {
- $condition = new EqualityCondition(self :: PROPERTY_COURSE_CODE, $this->get_course_code());
- $sort = $this->get_data_manager()->retrieve_next_sort_value(self :: get_table_name(),
- self :: PROPERTY_DISPLAY_ORDER, $condition);
- $this->set_display_order($sort);
-
- return parent :: create();
- }
-
- /****************************************************************************************************************
- * Getters and Setters *
- ****************************************************************************************************************/
-
- /**
- * Returns the course_code property of this object
- *
- * @return String
- */
- function get_course_code()
- {
- return $this->get_default_property(self :: PROPERTY_COURSE_CODE);
- }
-
- /**
- * Sets the course_code property of this object
- *
- * @param String $course_code
- */
- function set_course_code($course_code)
- {
- $this->set_default_property(self :: PROPERTY_COURSE_CODE, $course_code);
- }
-
- /**
- * Returns the name property of this object
- *
- * @return String
- */
- function get_name()
- {
- return $this->get_default_property(self :: PROPERTY_NAME);
- }
-
- /**
- * Sets the name property of this object
- *
- * @param String $name
- */
- function set_name($name)
- {
- $this->set_default_property(self :: PROPERTY_NAME, $name);
- }
-
- /**
- * Returns the type property of this object
- *
- * @return int
- */
- function get_type()
- {
- return $this->get_default_property(self :: PROPERTY_TYPE);
- }
-
- /**
- * Sets the type property of this object
- *
- * @param int $type
- */
- function set_type($type)
- {
- $this->set_default_property(self :: PROPERTY_TYPE, $type);
- }
-
- /**
- * Returns the tool_id property of this object
- *
- * @return boolean
- */
- function is_visible()
- {
- return $this->get_default_property(self :: PROPERTY_VISIBLE);
- }
-
- /**
- * Sets the visible property of this object
- *
- * @param boolean $visible
- */
- function set_visible($visible)
- {
- $this->set_default_property(self :: PROPERTY_VISIBLE, $visible);
- }
-
- /**
- * Returns the display_order property of this object
- *
- * @return int
- */
- function get_display_order()
- {
- return $this->get_default_property(self :: PROPERTY_DISPLAY_ORDER);
- }
-
- /**
- * Sets the display_order property of this object
- *
- * @param int $display_order
- */
- function set_display_order($display_order)
- {
- $this->set_default_property(self :: PROPERTY_DISPLAY_ORDER, $display_order);
- }
- }
- ?>