Bug #5397

Course type - direct subscribe/unsubscribe not set correctly

Added by Parcifal Aertssen over 10 years ago. Updated over 10 years ago.

Bug resolved
Start date:
Due date:
% Done:


Estimated time:


Even if you set the direct subscribe/unsubscribe right in the course type, this setting is not used when you create courses in bulk (e.g. automated) of this course type. If you change the course type settings, it is also not updated in the course.



Updated by Sven Vanpoucke over 10 years ago

The settings are not added due to the fact that your script that is used for bulk course creation is probably only using course create. You also need to define the settings and the rights:

$setting_values = array();

$setting_values[CourseSettingsController :: SETTING_PARAM_COURSE_SETTINGS] = array();

$setting_values[CourseSettingsController :: SETTING_PARAM_COURSE_SETTINGS]
            [CourseSettingsConnector :: CATEGORY] = $weblcms_course->get_category_id();
$setting_values[CourseSettingsController :: SETTING_PARAM_COURSE_SETTINGS]
            [CourseSettingsConnector :: LANGUAGE] = $weblcms_course->get_language();
$setting_values[CourseSettingsController :: SETTING_PARAM_COURSE_SETTINGS]
            [CourseSettingsConnector :: TITULAR] = $weblcms_course->get_titular_id();

$weblcms_course->create_course_settings_from_values($setting_values, true);

CourseManagementRights :: get_instance()->create_rights_from_values($weblcms_course, array());

Als for the change of the course type settings. The changes are not automatically forced, and are only for new courses. If you want to force a setting / right to the child courses you have to lock that setting / right.


Updated by Parcifal Aertssen over 10 years ago

OK, thanks. I did this on C2.1, but on C3, I - mistakenly - thought that course types would do this for me.


Updated by Sven Vanpoucke over 10 years ago

  • Status changed from New to Bug resolved

We should look into this in the future to see if we can optimize this to once function only. Because this has been made out of a refactoring on the old buggy course types i didn't want to break the api of the course create function, not knowing where this has been used and how bad this could break things, instead i used helper methods to define the settings and rights.


Updated by Parcifal Aertssen over 10 years ago

I get an error when using your code as above:
Fatal error: Call to a member function truncate_values() on a non-object in /var/www/html/chamilo3/application/weblcms/php/lib/course_settings_controller.class.php on line 209


Updated by Parcifal Aertssen over 10 years ago

Ok, you have to create the course first, before the settings ;-)


Updated by Parcifal Aertssen over 10 years ago

How do I convert such code to C3 (without using course types):

like this?
//Course - Rights
$rights = array();
$rights[CourseManagementRights :: DIRECT_SUBSCRIBE_RIGHT] = 2;
$rights[CourseManagementRights :: DIRECT_UNSUBSCRIBE_RIGHT] = 2;
CourseManagementRights :: get_instance()->create_rights_from_values($chamilo_course, $rights);

and how do I convert this?


Updated by Sven Vanpoucke over 10 years ago

Maximum number of members is a course setting for the group tool. You would have to set this by the following lines:

$course_settings['tool_settings']['course_group']['maximum_number_of_members_per_group'] = 5;

This setting is set to 0 by default.

For the usage of the rights you have to define which option you want to use (only for me, for everyone, for nobody, for selected users)
You can do this by adding this to your array:

$rights[CourseManagementRights :: PARAM_RIGHT_OPTION][CourseManagementRights :: DIRECT_SUBSCRIBE_RIGHT] = CourseManagementRights :: RIGHT_OPTION_ALL;

If you select the targets you must also define the targets as an array with entity type and entity id. The entities can be found in application/weblcms/php/lib/rights_entities

$rights[CourseManagementRights :: PARAM_RIGHT_TARGETS][CourseManagementRights :: DIRECT_UNSUBSCRIBE_RIGHT][CoursePlatformGroupEntity :: ENTITY_TYPE] = array(2);

I know it's a bit harder to set, but now the system is generic and it's very easy to add extra rights, extra entities and extra options.

Also available in: Atom PDF