# HG changeset patch
# User Laurent Opprecht
# Date 1305127124 -7200
# Node ID cc56929793cb43a59fcf08eda8c79b3a9d8c3565
# Parent bbe7de0ac2c936ba503d86d4c0ea917ef55d4d31
course templates
diff -r bbe7de0ac2c9 -r cc56929793cb php/autoloader.class.php
--- a/php/autoloader.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/autoloader.class.php Wed May 11 17:18:44 2011 +0200
@@ -25,6 +25,7 @@
'weblcms_manager' => 'weblcms_manager/weblcms_manager.class.php',
'course_layout' => 'course/course_layout.class.php',
'course_form' => 'course/course_form.class.php',
+ 'course_create_from_template_form' => 'course/course_create_from_template_form.class.php',
'course_group' => 'course_group/course_group.class.php',
'course_group_form' => 'course_group/course_group_form.class.php',
'course_group_subscriptions_form' => 'course_group/course_group_subscriptions_form.class.php',
diff -r bbe7de0ac2c9 -r cc56929793cb php/blocks/type/course_menu.class.php
--- a/php/blocks/type/course_menu.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/blocks/type/course_menu.class.php Wed May 11 17:18:44 2011 +0200
@@ -52,8 +52,9 @@
$html[] = '';
$target = $this->get_link_target();
+ $target = $target ? ' target="' . $target . '"' : '';
- $template = '
';
+ $template = '';
$ADMIN_MENU = $this->display_admin_menu($template);
$USER_MENU = SimpleTemplate::all($template, $this->get_edit_course_menu());
@@ -68,7 +69,7 @@
{
$menu = $this->get_platform_admin_menu();
$result[] = SimpleTemplate::all($template, $menu);
- $result[] = '';
+ $result[] = '';
}
else
{
@@ -96,7 +97,12 @@
$count_direct++;
}
if ($count_direct)
- {
+ {
+ $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_CREATE_COURSE_FROM_TEMPLATE);
+ $TEXT = htmlspecialchars(Translation :: get('QuickCourseCreate'));
+ $IMG = Theme :: get_common_image_path() . 'action_quick_create.png';
+ $result[] = compact('HREF', 'TEXT', 'IMG');
+
$HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_CREATE_COURSE);
$TEXT = htmlspecialchars(Translation :: get('CourseCreate'));
$IMG = Theme :: get_common_image_path() . 'action_create.png';
@@ -140,6 +146,11 @@
function get_platform_admin_menu()
{
$result = array();
+
+ $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_CREATE_COURSE_FROM_TEMPLATE);
+ $TEXT = htmlspecialchars(Translation :: get('QuickCourseCreate'));
+ $IMG = Theme :: get_common_image_path() . 'action_quick_create.png';
+ $result[] = compact('HREF', 'TEXT', 'IMG');
$HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_CREATE_COURSE);
$TEXT = htmlspecialchars(Translation :: get('CourseCreate'));
diff -r bbe7de0ac2c9 -r cc56929793cb php/install/course_settings.xml
--- a/php/install/course_settings.xml Tue May 10 16:17:58 2011 +0200
+++ b/php/install/course_settings.xml Wed May 11 17:18:44 2011 +0200
@@ -5,6 +5,7 @@
+
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/common_form.class.php
--- a/php/lib/course/common_form.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/common_form.class.php Wed May 11 17:18:44 2011 +0200
@@ -127,6 +127,7 @@
$object = $object->get_settings();
$object->set_language($values[CourseSettings :: PROPERTY_LANGUAGE]);
$object->set_visibility($this->parse_checkbox_value($values[CourseSettings :: PROPERTY_VISIBILITY]));
+ $object->set_template($this->parse_checkbox_value($values[CourseSettings :: PROPERTY_TEMPLATE]));
$object->set_access($this->parse_checkbox_value($values[CourseSettings :: PROPERTY_ACCESS]));
if ($values[self :: UNLIMITED_MEMBERS])
$members = 0;
@@ -314,6 +315,7 @@
$settings = $this->object->get_course_type()->get_settings();
$defaults[CourseSettings :: PROPERTY_LANGUAGE] = ! is_null($settings->get_language()) ? $settings->get_language() : LocalSetting :: get('platform_language');
$defaults[CourseSettings :: PROPERTY_VISIBILITY] = ! is_null($settings->get_visibility()) ? $settings->get_visibility() : 1;
+ $defaults[CourseSettings :: PROPERTY_TEMPLATE] = ! is_null($settings->get_template()) ? $settings->get_template() : 0;
$defaults[CourseSettings :: PROPERTY_ACCESS] = ! is_null($settings->get_access()) ? $settings->get_access() : 1;
$defaults[CourseSettings :: PROPERTY_MAX_NUMBER_OF_MEMBERS] = $settings->get_max_number_of_members();
$defaults[self :: UNLIMITED_MEMBERS] = ($settings->get_max_number_of_members() == 0) ? 1 : 0;
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course.class.php
--- a/php/lib/course/course.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course.class.php Wed May 11 17:18:44 2011 +0200
@@ -61,6 +61,7 @@
private $rights;
private $request;
private $course_type = false;
+ private $sections = false;
function __construct($defaultProperties = array(), $optionalProperties = array())
{
@@ -143,8 +144,7 @@
$udm = UserDataManager :: get_instance();
$user = $udm->retrieve_user($titular_id);
return $user->get_lastname() . ' ' . $user->get_firstname();
- }
- else
+ } else
{
return null;
}
@@ -277,6 +277,61 @@
return $this->course_type;
}
+ function get_course_sections()
+ {
+ if ($this->sections === false)
+ {
+ $result = array();
+ $dm = WeblcmsDataManager :: get_instance();
+ $condition = new EqualityCondition(CourseSection :: PROPERTY_COURSE_CODE, $this->get_id());
+ $course_sections = $dm->retrieve_course_sections($condition);
+ $result = $course_sections->as_array();
+ if (empty($result))
+ {
+ $result = $this->default_course_sections();
+ }
+ $this->set_course_sections($result);
+ }
+ return $this->sections;
+ }
+
+ function set_course_sections($value)
+ {
+ $this->sections = $value;
+ $this->sections = $this->sections ? $this->sections : array();
+// foreach ($this->sections as $section)
+// {
+// $section->set_course_code($this->get_id());
+// }
+ }
+
+ function default_course_sections()
+ {
+ $sections = array();
+ $sections[] = array('name' => Translation :: get('SectionTools'), 'type' => 1, 'order' => 1);
+ $sections[] = array('name' => Translation :: get('SectionLinks'), 'type' => 2, 'order' => 2);
+ $sections[] = array('name' => Translation :: get('SectionDisabled'), 'type' => 0, 'order' => 3);
+ $sections[] = array('name' => Translation :: get('SectionCourseAdministration'), 'type' => 3, 'order' => 4);
+
+ $result = array();
+ foreach ($sections as $section)
+ {
+ $course_section = new CourseSection();
+ $course_section->set_course_code($this->get_id());
+ $course_section->set_name($section['name']);
+ $course_section->set_type($section['type']);
+ $course_section->set_visible(true);
+ $result[] = $course_section;
+// if (!$course_section->create())
+// {
+// return false;
+// }
+ }
+ return $result;
+
+// return true;
+ }
+
/**
* Sets the course type id of this course object
* @param int $type The course type id
@@ -444,6 +499,11 @@
return $this->get_course_type()->get_settings()->get_access();
}
+ function get_template()
+ {
+ return $this->get_settings()->get_template();
+ }
+
function get_max_number_of_members()
{
if (!$this->get_max_number_of_members_fixed())
@@ -511,6 +571,11 @@
$this->get_settings()->set_access($this->get_course_type()->get_settings()->get_access());
}
+ function set_template($value)
+ {
+ $this->get_settings()->set_template($value);
+ }
+
function get_max_number_of_members_fixed()
{
if (!is_null($this->get_course_type()))
@@ -1009,39 +1074,49 @@
return false;
}
- if (!$this->initialize_course_sections())
- {
- return false;
- }
-
if (!$this->create_location())
{
return false;
}
- if (!$this->tools)
+ $sections = $this->get_course_sections();
+ foreach ($sections as $section)
{
- $course_type_id = $this->get_course_type_id();
- if (!empty($course_type_id))
+ $section->set_course_code($this->get_id());
+ if (!$section->create())
{
- $this->tools = CourseModule :: convert_tools($this->get_course_type()->get_tools(), $this->get_id(), true);
- }
- else
- {
- $this->tools = CourseModule :: convert_tools(WeblcmsDataManager :: get_tools('basic'), $this->get_id());
- }
- }
- else
- {
- foreach ($this->tools as $tool)
- {
- $tool->set_course_code($this->get_id());
+ return false;
}
}
- if (!$wdm->create_course_modules($this->tools, $this->get_id()))
+ //check if sections created the tools. If it is the case no need
+ //to create them anymore
+ $tools = $wdm->retrieve_course_modules_by_course($this);
+
+ if ($tools->is_empty())
{
- return false;
+ if (!$this->tools)
+ {
+ $course_type_id = $this->get_course_type_id();
+ if (!empty($course_type_id))
+ {
+ $this->tools = CourseModule :: convert_tools($this->get_course_type()->get_tools(), $this->get_id(), true);
+ } else
+ {
+ $this->tools = CourseModule :: convert_tools(WeblcmsDataManager :: get_tools('basic'), $this->get_id());
+ }
+ } else
+ {
+ foreach ($this->tools as $tool)
+ {
+ $tool->set_course_code($this->get_id());
+ }
+ }
+
+ if (!$wdm->create_course_modules($this->tools, $this->get_id()))
+ {
+ return false;
+ }
}
foreach ($this->tools as $tool)
@@ -1053,7 +1128,7 @@
$dropbox->create_dropbox($this->get_id());
}
}
-
+
if (!$this->create_root_course_group())
{
return false;
@@ -1081,7 +1156,7 @@
return false;
}
- return WeblcmsRights::get_instance()-> create_subtree_root_location($this->get_id(), WeblcmsRights :: TREE_TYPE_COURSE);
+ return WeblcmsRights::get_instance()->create_subtree_root_location($this->get_id(), WeblcmsRights :: TREE_TYPE_COURSE);
}
function delete()
@@ -1100,6 +1175,7 @@
}
private $is_course_admin_cache;
+
/**
* Checks whether the given user is a course admin in this course
* @param int $user_id
@@ -1189,30 +1265,6 @@
return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
}
- function initialize_course_sections()
- {
- $sections = array();
- $sections[] = array('name' => Translation :: get('SectionTools'), 'type' => 1, 'order' => 1);
- $sections[] = array('name' => Translation :: get('SectionLinks'), 'type' => 2, 'order' => 2);
- $sections[] = array('name' => Translation :: get('SectionDisabled'), 'type' => 0, 'order' => 3);
- $sections[] = array('name' => Translation :: get('SectionCourseAdministration'), 'type' => 3, 'order' => 4);
-
- foreach ($sections as $section)
- {
- $course_section = new CourseSection();
- $course_section->set_course_code($this->get_id());
- $course_section->set_name($section['name']);
- $course_section->set_type($section['type']);
- $course_section->set_visible(true);
- if (!$course_section->create())
- {
- return false;
- }
- }
-
- return true;
- }
-
function create_root_course_group()
{
$group = new CourseGroup();
@@ -1397,7 +1449,7 @@
function update()
{
$course_group = $this->get_data_manager()->retrieve_course_group_root($this->get_id());
- if($course_group->get_name() != $this->get_name())
+ if ($course_group->get_name() != $this->get_name())
{
$course_group->set_name($this->get_name());
$course_group->update();
@@ -1406,6 +1458,41 @@
return parent :: update();
}
+ /**
+ * Clone the structure of the Course object.
+ * Does not clone/add publications
+ */
+ public function __clone()
+ {
+
+ $settings = clone($this->get_settings());
+ $this->set_settings($settings);
+
+ $layout = clone($this->get_layout_settings());
+ $this->set_layout_settings($layout);
+
+ $rights = clone($this->get_rights());
+ $this->set_rights($rights);
+
+ $sections = Utilities::clone_array($this->get_course_sections());
+ $this->set_course_sections($sections);
+
+// $wdm = WeblcmsDataManager :: get_instance();
+// $tools = $wdm->retrieve_course_modules_by_course($this)->as_array();
+// $tools = Utilities::clone_array($tools);
+//
+//// $tools = array();
+//// foreach ($sections as $section)
+//// {
+//// $tools = array_merge($tools, $section->get_tools());
+//// }
+//
+// $this->set_tools($tools);
+
+ //set it to null only after cloning children
+ $this->set_id(null);
+ }
+
}
?>
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_create_from_template_form.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/php/lib/course/course_create_from_template_form.class.php Wed May 11 17:18:44 2011 +0200
@@ -0,0 +1,370 @@
+user = $user;
+
+ parent :: __construct(CommonForm :: TYPE_CREATE, $course, $action, $parent, 'course_settings', 'post');
+ $this->addElement('html', ResourceManager :: get_instance()->get_resource_html(Path :: get(WEB_APP_PATH) . 'weblcms/resources/javascript/course_form.js'));
+ }
+
+ public function get_course()
+ {
+ return $this->object;
+ }
+
+ function build_basic_form()
+ {
+ $this->addElement('category', Translation :: get('CourseSettings'));
+
+ $this->addElement('hidden', Course :: PROPERTY_ID, '', array('class' => 'course_id'));
+
+ $this->addElement('text', Course :: PROPERTY_NAME, Translation :: get('Title'), array("size" => "50"));
+ $this->addRule(Course :: PROPERTY_NAME, Translation :: get('ThisFieldIsRequired', null, Utilities :: COMMON_LIBRARIES), 'required');
+
+ $this->addElement('text', Course :: PROPERTY_VISUAL, Translation :: get('VisualCode'), array("size" => "50"));
+
+ //categories
+
+ $this->get_categories(0);
+ if (count($this->categories) > 0)
+ {
+ $this->addElement('select', Course :: PROPERTY_CATEGORY, Translation :: get('Category', null, Utilities :: COMMON_LIBRARIES), $this->categories);
+ } else
+ {
+ $category_name = Translation :: get('NoCategories');
+ $this->addElement('static', 'Category_Static', Translation :: get('Category', null, Utilities :: COMMON_LIBRARIES), $category_name);
+ $this->addElement('hidden', Course :: PROPERTY_CATEGORY, 0);
+ }
+
+ $this->addElement('select', Course :: PROPERTY_TITULAR, Translation :: get('Teacher'), $this->get_teachers());
+ $this->addRule(Course :: PROPERTY_TITULAR, Translation :: get('ThisFieldIsRequired', null, Utilities :: COMMON_LIBRARIES), 'required');
+
+ //visibility
+
+ $visibility_disabled = $this->object->get_visibility_fixed();
+ $attr_array = array();
+ if ($visibility_disabled)
+ {
+ $attr_array = array('disabled' => 'disabled');
+ }
+ $this->addElement('checkbox', CourseSettings :: PROPERTY_VISIBILITY, Translation :: get('CourseTypeVisibility'), '', $attr_array);
+
+ $access_disabled = $this->object->get_access_fixed();
+
+ //Accessibility
+ if ($access_disabled)
+ {
+ $access = $this->object->get_access();
+ if ($access)
+ $access_name = Translation :: get('Open', null, Utilities :: COMMON_LIBRARIES);
+ else
+ $access_name = Translation :: get('Closed', null, Utilities :: COMMON_LIBRARIES);
+ $this->addElement('static', 'static_member', Translation :: get('CourseTypeAccess'), $access_name);
+ $this->addElement('hidden', CourseTypeSettings :: PROPERTY_ACCESS, $access);
+ }
+ else
+ {
+ $choices = array();
+ $choices[] = $this->createElement('radio', CourseTypeSettings :: PROPERTY_ACCESS, '', Translation :: get('Open', null, Utilities :: COMMON_LIBRARIES), 1);
+ $choices[] = $this->createElement('radio', CourseTypeSettings :: PROPERTY_ACCESS, '', Translation :: get('Closed', null, Utilities :: COMMON_LIBRARIES), 0);
+ $this->addGroup($choices, 'access_choices', Translation :: get('CourseTypeAccess'), '
', false);
+ }
+
+ $this->addElement('category');
+
+ $this->addElement('category', Translation :: get('Templates'));
+
+ $this->addElement('select', 'template_id', Translation :: get('Template', null, Utilities :: COMMON_LIBRARIES), $this->get_templates(), array('size' => 6, 'style'=> 'min-width:200px;'), array());
+
+ $this->addElement('category');
+
+ $this->addElement('category', Translation :: get('ExternalWebsite'));
+ $this->addElement('text', Course :: PROPERTY_EXTERNAL_NAME, Translation :: get('ExternalName'), array("size" => "50"));
+ $this->addElement('text', Course :: PROPERTY_EXTERNAL_URL, Translation :: get('ExternalUrl'), array("size" => "50"));
+ $this->addRule(Course :: PROPERTY_EXTERNAL_URL, Translation :: get('IncorrectUrl'), 'url');
+ $this->addElement('category');
+ }
+
+ function build_general_settings_form()
+ {
+
+ }
+
+ function build_layout_form()
+ {
+
+ }
+
+ function build_tools_form()
+ {
+
+ }
+
+ function build_rights_form()
+ {
+
+ }
+
+ function fill_tools($tools)
+ {
+
+ }
+
+ function update()
+ {
+
+ }
+
+ private $categories;
+ private $level = 1;
+
+ function get_categories($parent_id)
+ {
+ $wdm = WeblcmsDataManager :: get_instance();
+ $categories = $wdm->retrieve_course_categories(new EqualityCondition(CourseCategory :: PROPERTY_PARENT, $parent_id));
+
+ while ($category = $categories->next_result())
+ {
+ $this->categories[$category->get_id()] = str_repeat('--', $this->level) . ' ' . $category->get_name();
+ $this->level++;
+ $this->get_categories($category->get_id());
+ $this->level--;
+ }
+ }
+
+ private $_templates = null;
+
+ function get_templates()
+ {
+ if (is_null($this->_templates))
+ {
+ $result = array();
+ $wdm = WeblcmsDataManager :: get_instance();
+
+ //public templates
+ $conditions = array();
+ $conditions[] = new EqualityCondition(CourseSettings::PROPERTY_TEMPLATE, true, CourseSettings::get_table_name());
+// $conditions[] = new EqualityCondition(CourseSettings::PROPERTY_ACCESS, true, CourseSettings::get_table_name());
+ $conditions[] = new EqualityCondition(CourseSettings::PROPERTY_VISIBILITY, true, CourseSettings::get_table_name());
+ $conditions[] = new NotCondition(new EqualityCondition(Course::PROPERTY_TITULAR, $this->user->get_id()));
+ $conditions[] = new InequalityCondition(Course::PROPERTY_EXPIRATION_DATE, InequalityCondition::LESS_THAN_OR_EQUAL, time());
+ $condition = new AndCondition($conditions);
+
+ $templates = $wdm->retrieve_courses($condition);
+ if (! $templates->is_empty())
+ {
+ while ($template = $templates->next_result())
+ {
+ $result[$template->get_id()] = $template->get_name();
+ }
+ }
+
+ //user templates
+ $conditions = array();
+ $conditions[] = new EqualityCondition(CourseSettings::PROPERTY_TEMPLATE, true, CourseSettings::get_table_name());
+ $conditions[] = new EqualityCondition(Course::PROPERTY_TITULAR, $this->user->get_id());
+ $conditions[] = new InequalityCondition(Course::PROPERTY_EXPIRATION_DATE, InequalityCondition::LESS_THAN_OR_EQUAL, time());
+ $condition = new AndCondition($conditions);
+
+ $templates = $wdm->retrieve_courses($condition);
+ while ($template = $templates->next_result())
+ {
+ $result[$template->get_id()] = $template->get_name();
+ }
+
+ if(empty($result)){
+ $result[0] = '(' . Translation::get('none') . ')';
+ }
+
+ $this->_templates = $result;
+ }
+ return $this->_templates;
+ }
+
+ private $_teachers = null;
+
+ function get_teachers()
+ {
+ if (!is_null($this->_teachers))
+ {
+ return $this->_teachers;
+ }
+
+ $result = array();
+ if ($this->user->is_platform_admin())
+ {
+
+ $udm = UserDataManager :: get_instance();
+
+ $users = $udm->retrieve_users(new EqualityCondition(User :: PROPERTY_STATUS, 1));
+ while ($user = $users->next_result())
+ {
+ $result[$user->get_id()] = $user->get_lastname() . ' ' . $user->get_firstname();
+ }
+ } else
+ {
+ $user = $this->user;
+ $result[$user->get_id()] = $user->get_lastname() . ' ' . $user->get_firstname();
+ }
+
+ return $this->_teachers = $result;
+ }
+
+ function create()
+ {
+ $values = $this->exportValues();
+ $template_id = $values['template_id'];
+ $wdm = WeblcmsDataManager :: get_instance();
+ $template = $wdm->retrieve_course($template_id);
+ $template = $template ? $template : $wdm->retrieve_empty_course();
+
+ $course = clone($template);
+ $this->object = $course;
+ $this->fill_general_settings($course);
+ $course->create();
+
+ $condition = new EqualityCondition(ContentObjectPublication :: PROPERTY_COURSE_ID, $template->get_id());
+ $publications = $wdm->retrieve_content_object_publications($condition)->as_array();
+ foreach ($publications as $publication)
+ {
+ $parent = $publication->get_category_id();
+
+ $publication->set_id(null);
+ $publication->set_course_id($course->get_id());
+ $publication->set_category_id(0);
+ $result = $publication->create();
+ }
+
+ $course_subscribe_rights = $this->fill_subscribe_rights();
+ foreach ($course_subscribe_rights as $right)
+ {
+ if (!$right->create())
+ {
+ return false;
+ }
+ }
+
+ $course_unsubscribe_rights = $this->fill_unsubscribe_rights();
+ foreach ($course_unsubscribe_rights as $right)
+ {
+ if (!$right->create())
+ {
+ return false;
+ }
+ }
+
+ $user_id = $course->get_titular();
+ return $wdm->subscribe_user_to_course($course, '1', '1', $user_id);
+ }
+
+ function fill_general_settings()
+ {
+ $course = $this->object;
+ $values = $this->exportValues();
+
+ $visual_code = isset($values[Course :: PROPERTY_VISUAL]) ? $values[Course :: PROPERTY_VISUAL] : strtoupper(uniqid());
+ $course->set_visual($visual_code);
+
+
+ if ($course->get_category() != $values[Course :: PROPERTY_CATEGORY])
+ {
+ if ($values[Course :: PROPERTY_CATEGORY])
+ {
+ $new_parent_id = WeblcmsRights :: get_instance()->get_weblcms_location_by_identifier_from_courses_subtree(WeblcmsRights :: TYPE_CATEGORY, $values[Course :: PROPERTY_CATEGORY], $course->get_id());
+ } else
+ {
+ $new_parent_id = WeblcmsRights :: get_instance()->get_courses_subtree_root_id($course->get_id());
+ }
+
+ $location = WeblcmsRights :: get_instance()->get_weblcms_location_by_identifier_from_courses_subtree(WeblcmsRights :: TYPE_COURSE, $course->get_id(), $course->get_id());
+ if ($location)
+ {
+ $location->move($new_parent_id);
+ }
+ }
+
+ $course->set_name($values[Course :: PROPERTY_NAME]);
+ $course->set_category($values[Course :: PROPERTY_CATEGORY]);
+ $course->set_titular($values[Course :: PROPERTY_TITULAR]);
+ $course->set_external_name($values[Course :: PROPERTY_EXTERNAL_NAME]);
+ $course->set_external_url($values[Course :: PROPERTY_EXTERNAL_URL]);
+ $course->set_template(false);
+ return $course;
+ }
+
+ /**
+ * Sets default values. Traditionally, you will want to extend this method
+ * so it sets default for your learning object type's additional
+ * properties.
+ * @param array $defaults Default values for this form's parameters.
+ */
+ function setDefaults($defaults = array())
+ {
+ $course = $this->object;
+ $defaults[Course :: PROPERTY_ID] = $course->get_id();
+ $defaults[Course :: PROPERTY_COURSE_TYPE_ID] = $this->course_type_id;
+ $defaults[Course :: PROPERTY_VISUAL] = $course->get_visual();
+ $defaults[Course :: PROPERTY_TITULAR] = !is_null($course->get_titular()) ? $course->get_titular() : $this->user->get_id();
+ $defaults[Course :: PROPERTY_NAME] = $course->get_name();
+ $defaults[Course :: PROPERTY_CATEGORY] = $course->get_category();
+ $defaults[Course :: PROPERTY_EXTERNAL_NAME] = $course->get_external_name();
+ $defaults[Course :: PROPERTY_EXTERNAL_URL] = $course->get_external_url();
+ $template_key = reset(array_keys($this->get_templates()));
+ $defaults['template_id'] = $template_key;
+
+ parent :: setDefaults($defaults);
+ }
+
+ function can_user_create()
+ {
+ $course_type = $this->object->get_course_type();
+ if (!is_null($course_type) && !empty($course_type))
+ {
+ return $course_type->can_user_create($this->user);
+ } else
+ {
+ return CourseTypeGroupCreationRight :: CREATE_NONE;
+ }
+ }
+
+}
+
+?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_form.class.php
--- a/php/lib/course/course_form.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_form.class.php Wed May 11 17:18:44 2011 +0200
@@ -289,6 +289,7 @@
$attr_array = array('disabled' => 'disabled');
}
$this->addElement('checkbox', CourseSettings :: PROPERTY_VISIBILITY, Translation :: get('CourseTypeVisibility'), '', $attr_array);
+ $this->addElement('checkbox', CourseSettings :: PROPERTY_TEMPLATE, Translation :: get('CourseTemplate'));
$access_disabled = $this->object->get_access_fixed();
//Accessibility
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_layout.class.php
--- a/php/lib/course/course_layout.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_layout.class.php Wed May 11 17:18:44 2011 +0200
@@ -245,4 +245,8 @@
{
return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
}
+
+ public function __clone(){
+ $this->set_course_id(null);
+ }
}
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_module.class.php
--- a/php/lib/course/course_module.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_module.class.php Wed May 11 17:18:44 2011 +0200
@@ -170,7 +170,11 @@
return false;
}
- return WeblcmsRights :: get_instance()->create_location_in_courses_subtree(WeblcmsRights :: TYPE_COURSE_MODULE, $this->get_id(), WeblcmsRights :: get_instance()->get_courses_subtree_root_id($this->get_course_code()), $this->get_course_code());
+ $course_id = $this->get_course_code();
+ $store = WeblcmsRights :: get_instance();
+ $root_id = $store->get_courses_subtree_root_id($course_id);
+ $result = $store->create_location_in_courses_subtree(WeblcmsRights :: TYPE_COURSE_MODULE, $this->get_id(), $root_id, $course_id);
+ return $result;
}
function delete()
@@ -185,6 +189,12 @@
}
return parent :: delete();
}
+
+ public function __clone(){
+ $this->set_id(null);
+ $this->set_course_code(null);
+ $this->set_section(null);
+ }
}
?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_rights.class.php
--- a/php/lib/course/course_rights.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_rights.class.php Wed May 11 17:18:44 2011 +0200
@@ -243,5 +243,9 @@
else
return 0;
}
+
+ public function __clone(){
+ $this->set_course_id(null);
+ }
}
?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_section.class.php
--- a/php/lib/course/course_section.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_section.class.php Wed May 11 17:18:44 2011 +0200
@@ -25,17 +25,33 @@
const PROPERTY_VISIBLE = 'visible';
const PROPERTY_DISPLAY_ORDER = 'display_order';
- /**
- * Get the default properties of all courses.
- * @return array The property names.
+ /**
+ * Get the default properties of all courses.
+ * @return array 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));
}
+
+ private $tools = null;
+
+ public function get_tools(){
+ if(is_null($this->tools)){
+ $wdm = WeblcmsDataManager :: get_instance();
+ $tools = $wdm->retrieve_course_modules_by_section($this);
+ $tools = $tools->as_array();
+ $this->tools = empty($tools) ? array() : $tools;
+ }
+ return $this->tools;
+ }
+
+ public function set_tools($value){
+ $this->tools = $value;
+ }
- /**
- * inherited
+ /**
+ * inherited
*/
function get_data_manager()
{
@@ -100,12 +116,31 @@
$sort = $wdm->retrieve_max_sort_value(self :: get_table_name(), self :: PROPERTY_DISPLAY_ORDER, $condition);
$this->set_display_order($sort + 1);
- return $wdm->create_course_section($this);
+ $result = $wdm->create_course_section($this);
+
+ if($result){
+ foreach($this->tools as $tool){
+ $tool->set_course_code($this->get_course_code());
+ $tool->set_section($this->get_id());
+ if(! $tool->create()){
+ return false;
+ }
+ }
+ }
+
+ return $result;
}
static function get_table_name()
{
return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
}
+
+ public function __clone(){
+ $tools = $this->get_tools();
+ $tools = Utilities::clone_array($tools);
+ $this->set_tools($tools);
+ $this->set_course_code(null);
+ }
}
?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/course/course_settings.class.php
--- a/php/lib/course/course_settings.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/course/course_settings.class.php Wed May 11 17:18:44 2011 +0200
@@ -18,6 +18,7 @@
const PROPERTY_COURSE_ID = 'course_id';
const PROPERTY_LANGUAGE = 'language';
const PROPERTY_VISIBILITY = 'visibility';
+ const PROPERTY_TEMPLATE = 'template';
const PROPERTY_ACCESS = 'access';
const PROPERTY_MAX_NUMBER_OF_MEMBERS = 'max_number_of_members';
@@ -32,7 +33,7 @@
{
if (empty($extended_property_names))
$extended_property_names = array(self :: PROPERTY_COURSE_ID);
- return array_merge($extended_property_names, array(self :: PROPERTY_LANGUAGE, self :: PROPERTY_VISIBILITY, self :: PROPERTY_ACCESS, self :: PROPERTY_MAX_NUMBER_OF_MEMBERS));
+ return array_merge($extended_property_names, array(self :: PROPERTY_LANGUAGE, self :: PROPERTY_VISIBILITY, self :: PROPERTY_ACCESS, self :: PROPERTY_TEMPLATE, self :: PROPERTY_MAX_NUMBER_OF_MEMBERS));
}
/**
@@ -71,6 +72,15 @@
}
/**
+ * Returns true if this course is a template. False otherwise.
+ * @return bool
+ */
+ function get_template()
+ {
+ return $this->get_default_property(self :: PROPERTY_TEMPLATE);
+ }
+
+ /**
* Returns the acces of this course object
* @return boolean the acces Code
*/
@@ -116,6 +126,15 @@
}
/**
+ * Set if this course is template or note.
+ * @param bool $value
+ */
+ function set_template($value)
+ {
+ $this->set_default_property(self :: PROPERTY_TEMPLATE, $value);
+ }
+
+ /**
* Sets the access of this course object
* @param Boolean $access the access
*/
@@ -225,5 +244,9 @@
// $wdm = WeblcmsDataManager :: get_instance();
// return $wdm->is_course_type_admin($this, $user->get_id());
// }
+
+ public function __clone(){
+ $this->set_course_id(null);
+ }
}
?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/data_manager/mdb2.class.php
--- a/php/lib/data_manager/mdb2.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/data_manager/mdb2.class.php Wed May 11 17:18:44 2011 +0200
@@ -849,7 +849,21 @@
$condition = new AndCondition($conditions);
return $this->retrieve_object(CourseModule :: get_table_name(), $condition, array(), CourseModule :: CLASS_NAME);
}
-
+
+ function retrieve_course_modules_by_course($course)
+ {
+ $id = is_object($course) ? $course->get_id() : $course;
+ $condition = new EqualityCondition(CourseModule :: PROPERTY_COURSE_CODE, $id);
+ return $this->retrieve_objects(CourseModule :: get_table_name(), $condition, array(), CourseModule :: CLASS_NAME);
+ }
+
+ function retrieve_course_modules_by_section($section)
+ {
+ $id = is_object($section) ? $section->get_id() : $section;
+ $condition = new EqualityCondition(CourseModule :: PROPERTY_SECTION, $id);
+ return $this->retrieve_objects(CourseModule :: get_table_name(), $condition, array(), CourseModule :: CLASS_NAME);
+ }
+
function retrieve_course_settings($id)
{
$condition = new EqualityCondition(CourseSettings :: PROPERTY_COURSE_ID, $id);
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/weblcms_data_manager.interface.php
--- a/php/lib/weblcms_data_manager.interface.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/weblcms_data_manager.interface.php Wed May 11 17:18:44 2011 +0200
@@ -494,6 +494,8 @@
* @return array The list of available course modules
*/
/* function get_course_modules($course_code); */
+
+
/**
* Gets all course modules
@@ -501,16 +503,29 @@
*/
function get_all_course_modules();
+
+ function retrieve_course($course_code);
+
/**
* Retrieves a single course from persistent storage.
* @param string $course_code The alphanumerical identifier of the course.
* @return Course The course.
*/
- function retrieve_course($course_code);
+ function retrieve_course_by_visual_code($visual_code);
function retrieve_empty_course();
function retrieve_course_module($course_module_id);
+
+ /**
+ * @return ResultSet
+ */
+ function retrieve_course_modules_by_course($course);
+
+ /**
+ * @return ResultSet
+ */
+ function retrieve_course_modules_by_section($section);
function retrieve_course_settings($course_code);
@@ -546,17 +561,17 @@
* @param array $order_by
* @param int $offset
* @param int $max_objects
- * @return CourseResultSet
+ * @return ResultSet
*/
function retrieve_courses($condition = null, $offset = null, $count = null, $order_property = null);
-
+
/**
* Retrieve a series of courses for a specific user + the relation
* @param Condition $condition
* @param array $order_by
* @param int $offset
* @param int $max_objects
- * @return CourseResultSet
+ * @return ResultSet
*/
function retrieve_user_courses($condition = null, $offset = null, $count = null, $order_property = null);
@@ -823,6 +838,9 @@
function count_course_sections($conditions = null);
+ /**
+ * @return ResultSet
+ */
function retrieve_course_sections($condition = null, $offset = null, $count = null, $order_property = null);
//function count_new_publications_from_course($course, $user);
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/weblcms_manager/component/course_creator_from_template.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/php/lib/weblcms_manager/component/course_creator_from_template.class.php Wed May 11 17:18:44 2011 +0200
@@ -0,0 +1,125 @@
+check_access();
+
+ if ($this->get_user()->is_platform_admin())
+ {
+ Header :: set_section('admin');
+ }
+
+ $trail = BreadcrumbTrail :: get_instance();
+
+ $course = $this->get_course();
+ $url = $this->get_url();
+ $form = new CourseCreateFromTemplateForm($course, $this->get_user(), $url, $this);
+
+ if ($form->validate())
+ {
+ $visual_code = $form->exportValue(Course :: PROPERTY_VISUAL);
+ if (WebLcmsDataManager :: get_instance()->retrieve_course_by_visual_code($visual_code))
+ {
+ $this->display_header($trail, false, true);
+ $this->display_error_message(Translation :: get('CourseCodeAlreadyExists'));
+ $form->display();
+ $this->display_footer();
+ } else
+ {
+ $success = $form->create();
+ $course = $form->get_course();
+ $array_filter = array(WeblcmsManager :: PARAM_COURSE);
+ $array_type = array();
+ if ($success === true)
+ {
+ $array_type['go'] = WeblcmsManager :: ACTION_VIEW_COURSE;
+ $array_type['course'] = $course->get_id();
+ $array_filter = array();
+ } else if ($success instanceof Course)//?? what's that
+ {
+ $array_type['course'] = $course->get_id();
+ $array_type['go'] = WeblcmsManager :: ACTION_COURSE_CREATE_REQUEST_CREATOR;
+ $array_filter = null;
+ } else
+ {
+ $array_type['go'] = WeblcmsManager :: ACTION_VIEW_WEBLCMS_HOME;
+ }
+ $this->redirect(Translation :: get($success ? 'CourseSaved' : 'CourseNotSaved'), ($success ? false : true), $array_type, $array_filter);
+ }
+ } else
+ {
+ $this->display_header();
+ echo '
';
+ echo '';
+ $form->display();
+ echo '
';
+ $this->display_footer();
+ }
+ }
+
+ function check_access()
+ {
+ $authorize = $this->get_user()->is_teacher() || $this->get_user()->is_platform_admin();
+
+ if (!$authorize)
+ {
+ $this->display_error_page(Translation :: get('NotAllowed', null, Utilities:: COMMON_LIBRARIES));
+ exit();
+ }
+ }
+
+ function add_additional_breadcrumbs(BreadcrumbTrail $breadcrumbtrail)
+ {
+ $breadcrumbtrail->add_help('weblcms_course_creator');
+
+ if ($this->get_user()->is_platform_admin())
+ {
+ $breadcrumbtrail->add(new Breadcrumb(Redirect :: get_link(AdminManager :: APPLICATION_NAME, array(AdminManager :: PARAM_ACTION => AdminManager :: ACTION_ADMIN_BROWSER), array(), false, Redirect :: TYPE_CORE), Translation :: get('TypeName', null, 'admin')));
+ $breadcrumbtrail->add(new Breadcrumb(Redirect :: get_link(AdminManager :: APPLICATION_NAME, array(AdminManager :: PARAM_ACTION => AdminManager :: ACTION_ADMIN_BROWSER, DynamicTabsRenderer :: PARAM_SELECTED_TAB => WeblcmsManager :: APPLICATION_NAME), array(), false, Redirect :: TYPE_CORE), Translation :: get('Courses')));
+ }
+
+ $course = $this->get_course();
+ $id = $course->get_id();
+
+ if (!$id)
+ {
+ $breadcrumbtrail->add(new Breadcrumb($this->get_url(), Translation :: get('Create', null, Utilities:: COMMON_LIBRARIES)));
+ } else
+ {
+ $breadcrumbtrail->add(new Breadcrumb($this->get_url(array(WeblcmsManager :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_BROWSER), array(WeblcmsManager :: PARAM_COURSE, WeblcmsManager :: PARAM_TOOL)), Translation :: get('CourseList')));
+ $breadcrumbtrail->add(new Breadcrumb($this->get_url(), Translation :: get('Update', null, Utilities:: COMMON_LIBRARIES)));
+ }
+ }
+
+ function get_additional_parameters()
+ {
+ return array(self :: PARAM_COURSE);
+ }
+
+}
+
+?>
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/weblcms_manager/component/home.class.php
--- a/php/lib/weblcms_manager/component/home.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/weblcms_manager/component/home.class.php Wed May 11 17:18:44 2011 +0200
@@ -180,6 +180,7 @@
{
$html = array();
$img_path = htmlspecialchars(Theme :: get_common_image_path());
+ $html[] = '';
$html[] = '';
$html[] = '';
$html[] = '';
diff -r bbe7de0ac2c9 -r cc56929793cb php/lib/weblcms_manager/weblcms_manager.class.php
--- a/php/lib/weblcms_manager/weblcms_manager.class.php Tue May 10 16:17:58 2011 +0200
+++ b/php/lib/weblcms_manager/weblcms_manager.class.php Wed May 11 17:18:44 2011 +0200
@@ -115,6 +115,7 @@
const ACTION_VIEW_WEBLCMS_HOME = 'home';
const ACTION_VIEW_COURSE = 'course_viewer';
const ACTION_CREATE_COURSE = 'course_creator';
+ const ACTION_CREATE_COURSE_FROM_TEMPLATE = 'course_creator_from_template';
const ACTION_IMPORT_COURSES = 'course_importer';
const ACTION_IMPORT_COURSE_USERS = 'course_user_importer';
const ACTION_DELETE_COURSE = 'course_deleter';
@@ -1655,6 +1656,8 @@
Application :: PARAM_ACTION => WeblcmsManager :: ACTION_ADMIN_COURSE_BROWSER)));
$links[] = new DynamicAction(Translation :: get('CreateCourse'), Translation :: get('CreateDescription'), Theme :: get_image_path() . 'admin/add.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
Application :: PARAM_ACTION => WeblcmsManager :: ACTION_CREATE_COURSE)));
+// $links[] = new DynamicAction(Translation :: get('CreateCourse'), Translation :: get('CreateDescription'), Theme :: get_image_path() . 'admin/add.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
+// Application :: PARAM_ACTION => WeblcmsManager :: ACTION_CREATE_COURSE_FROM_TEMPLATE)));
$links[] = new DynamicAction(Translation :: get('Import'), Translation :: get('ImportDescription'), Theme :: get_image_path() . 'admin/import.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
Application :: PARAM_ACTION => WeblcmsManager :: ACTION_IMPORT_COURSES)));
$links[] = new DynamicAction(Translation :: get('RequestList'), Translation :: get('RequestDescription'), Theme :: get_image_path() . 'admin/list.png', Redirect :: get_link(self :: APPLICATION_NAME, array(
diff -r bbe7de0ac2c9 -r cc56929793cb resources/i18n/en.i18n
--- a/resources/i18n/en.i18n Tue May 10 16:17:58 2011 +0200
+++ b/resources/i18n/en.i18n Wed May 11 17:18:44 2011 +0200
@@ -440,4 +440,5 @@
QuestionDetails = "Question details"
SubmittedBy = "Submitted by"
Actions = "Actions"
-ViewProgressUsers = "View progress users"
\ No newline at end of file
+ViewProgressUsers = "View progress users"
+QuickCourseCreate = "Quick course"
\ No newline at end of file
diff -r bbe7de0ac2c9 -r cc56929793cb resources/i18n/fr.i18n
--- a/resources/i18n/fr.i18n Tue May 10 16:17:58 2011 +0200
+++ b/resources/i18n/fr.i18n Wed May 11 17:18:44 2011 +0200
@@ -392,4 +392,5 @@
open_and_closed_seperated = "Ouvert et fermé séparés"
open_only = "Ouvert seulement"
toCourse = "Pour sûr"
-wasNotFoundInTheDatabase = "Pas trouvé dans la base de données"
\ No newline at end of file
+wasNotFoundInTheDatabase = "Pas trouvé dans la base de données"
+QuickCourseCreate="Cours-minute"
\ No newline at end of file