/**
  * items in the form
  *
  * @uses $USER
  */
 public function definition()
 {
     global $USER;
     $this->set_data($this->_customdata['obj']);
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $curs = array();
     if (!empty($USER->id)) {
         // TBD: and/or capability 'block/curr_admin:curriculum:edit|view' ?
         // WAS: 'block/curr_admin:track:create' ???
         $contexts = get_contexts_by_capability_for_user('curriculum', 'block/curr_admin:curriculum:view', $USER->id);
         $curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
     }
     if (empty($this->_customdata['obj']->id)) {
         $curid_options = array();
         if (!empty($curs)) {
             foreach ($curs as $cur) {
                 $curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name;
             }
         }
         $mform->addElement('select', 'curid', get_string('curriculum', 'block_curr_admin') . ':', $curid_options);
         $mform->addRule('curid', get_string('required'), 'required', NULL, 'client');
         $mform->setHelpButton('curid', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin'));
     } else {
         // Track editing, do not allow the user to change curriculum
         $mform->addElement('static', 'curidstatic', get_string('curriculum', 'block_curr_admin') . ':', $curs[$this->_customdata['obj']->curid]->name);
         $mform->setHelpButton('curidstatic', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin'));
         $mform->addElement('hidden', 'curid');
     }
     $mform->addElement('text', 'idnumber', get_string('track_idnumber', 'block_curr_admin') . ':');
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
     $mform->addRule('idnumber', null, 'maxlength', 100);
     $mform->setHelpButton('idnumber', array('trackform/idnumber', get_string('track_idnumber', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('text', 'name', get_string('track_name', 'block_curr_admin') . ':');
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'maxlength', 255);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->setHelpButton('name', array('trackform/name', get_string('track_name', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('textarea', 'description', get_string('track_description', 'block_curr_admin') . ':');
     $mform->setType('description', PARAM_CLEAN);
     $mform->setHelpButton('description', array('trackform/description', get_string('track_description', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'block_curr_admin') . ':', array('optional' => true));
     $mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'block_curr_admin') . ':', array('optional' => true));
     $mform->setHelpButton('startdate', array('trackform/startdate', get_string('startdate', 'block_curr_admin'), 'block_curr_admin'));
     if (!empty($this->_customdata['obj']->id)) {
         $trackassignobj = new trackassignmentclass(array('trackid' => $this->_customdata['obj']->id));
     }
     // Only show auto-create checkbox if the track does not have any classes assigned
     if (!isset($trackassignobj) or 0 == $trackassignobj->count_assigned_classes_from_track()) {
         $mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'block_curr_admin') . ':');
         $mform->setHelpButton('autocreate', array('trackform/autocreate', get_string('track_autocreate', 'block_curr_admin'), 'block_curr_admin'));
     }
     // custom fields
     $fields = field::get_for_context_level('track');
     $fields = $fields ? $fields : array();
     $lastcat = null;
     $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('track', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM);
     require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php';
     foreach ($fields as $rec) {
         $field = new field($rec);
         if (!isset($field->owners['manual'])) {
             continue;
         }
         if ($lastcat != $rec->categoryid) {
             $lastcat = $rec->categoryid;
             $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
         }
         manual_field_add_form_element($this, $context, $field);
     }
     $this->add_action_buttons();
 }
 /**
  * Load the options into the track selection boxes based on the
  * selected course.
  */
 function definition_after_data()
 {
     $mform =& $this->_form;
     $courseid = $mform->getElementValue('courseid');
     if ($courseid) {
         $courseid = (int) array_shift($courseid);
     } else {
         if (!empty($this->_customdata['obj']->courseid)) {
             $courseid = $this->_customdata['obj']->courseid;
         } else {
             if (!empty($this->firstcourse)) {
                 $courseid = $this->firstcourse->id;
             }
         }
     }
     if ($courseid) {
         $unassigned = array();
         $assigned = array();
         // Multi select box for choosing tracks
         $tracks = track_get_listing();
         $tracks = empty($tracks) ? array() : $tracks;
         $curcrsassign = curriculumcourse_get_list_by_course($courseid);
         $curcrsassign = empty($curcrsassign) ? array() : $curcrsassign;
         foreach ($curcrsassign as $recid => $curcrsrec) {
             foreach ($tracks as $trackid => $trackrec) {
                 if ($trackrec->curid == $curcrsrec->curriculumid) {
                     if (!empty($this->_customdata['obj']->id)) {
                         $trkobj = new trackassignmentclass(array('classid' => $this->_customdata['obj']->id, 'trackid' => $trackid));
                         if (!$trkobj->is_class_assigned_to_track()) {
                             $unassigned[$trackid] = $trackrec->name;
                         } else {
                             // Create list for currently assigned tracks
                             $assigned[$trackid] = $trackrec->name;
                         }
                     } else {
                         $unassigned[$trackid] = $trackrec->name;
                     }
                 }
             }
         }
         $temp = array('assignedtrack' => array_keys($assigned));
         $this->set_data($temp);
         $track_el =& $mform->getElement('assignedtrack');
         $track_el->load($assigned);
         $track_el =& $mform->getElement('track');
         $track_el->load($unassigned);
     }
 }
Example #3
0
 /**
  * Returns an array of cluster ids that are associated to the supplied class through tracks and
  * the current user has access to enrol users into
  * 
  * @param   int        $clsid  The class whose association ids we care about
  * @return  int array          The array of accessible cluster ids
  */
 public static function get_allowed_clusters($clsid)
 {
     global $USER;
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     if (cmclasspage::_has_capability('block/curr_admin:class:enrol_cluster_user', $clsid)) {
         global $CURMAN;
         require_once CURMAN_DIRLOCATION . '/lib/usercluster.class.php';
         $cmuserid = cm_get_crlmuserid($USER->id);
         $userclusters = $CURMAN->db->get_records(CLSTUSERTABLE, 'userid', $cmuserid);
         foreach ($userclusters as $usercluster) {
             $allowed_clusters[] = $usercluster->clusterid;
         }
     }
     //we first need to go through tracks to get to clusters
     $track_listing = new trackassignmentclass(array('classid' => $clsid));
     $tracks = $track_listing->get_assigned_tracks();
     //iterate over the track ides, which are the keys of the array
     if (!empty($tracks)) {
         foreach (array_keys($tracks) as $track) {
             //get the clusters and check the context against them
             $clusters = clustertrack::get_clusters($track);
             $allowed_track_clusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
             //append all clusters that are allowed by the available clusters contexts
             foreach ($allowed_track_clusters as $allowed_track_cluster) {
                 $allowed_clusters[] = $allowed_track_cluster;
             }
         }
     }
     return $allowed_clusters;
 }
Example #4
0
 /**
  * Assign a class to a track, this function also creates
  * and assigns the class to the curriculum default track
  *
  * @return TODO: add meaningful return value
  */
 function add()
 {
     global $CURMAN;
     if (empty($this->courseid)) {
         $this->courseid = $CURMAN->db->get_field(CLSTABLE, 'courseid', 'id', $this->classid);
     }
     if ((empty($this->trackid) or empty($this->classid) or empty($this->courseid)) and empty($CURMAN->config->userdefinedtrack)) {
         cm_error('trackid and classid have not been properly initialized');
         return false;
     } elseif ((empty($this->courseid) or empty($this->classid)) and $CURMAN->config->userdefinedtrack) {
         cm_error('courseid has not been properly initialized');
     }
     if (empty($CURMAN->config->userdefinedtrack)) {
         if ($this->is_class_assigned_to_track()) {
             return false;
         }
         // Determine whether class is required
         $curcrsobj = new curriculumcourse(array('curriculumid' => $this->track->curid, 'courseid' => $this->classid));
         // insert assignment record
         $this->data_insert_record();
         if ($this->autoenrol && $this->is_autoenrollable()) {
             // autoenrol all users in the track
             $users = usertrack::get_users($this->trackid);
             if (!empty($users)) {
                 foreach ($users as $user) {
                     $stu_record = new object();
                     $stu_record->userid = $user->userid;
                     $stu_record->user_idnumber = $user->idnumber;
                     $stu_record->classid = $this->classid;
                     $stu_record->enrolmenttime = time();
                     $enrolment = new student($stu_record);
                     // check prerequisites and enrolment limits
                     $enrolment->add(array('prereq' => 1, 'waitlist' => 1));
                 }
             }
         }
     } else {
         // Look for all the curricula course is linked to -
         // then pull up the default system track for each curricula -
         // and add class to each default system track
         $currculums = curriculumcourse_get_list_by_course($this->courseid);
         $currculums = is_array($currculums) ? $currculums : array();
         foreach ($currculums as $recid => $record) {
             // Create default track for curriculum
             $trkojb = new track(array('curid' => $record->curriculumid));
             $trkid = $trkojb->create_default_track();
             // Create track assignment object
             $trkassign = new trackassignmentclass(array('trackid' => $trkid, 'classid' => $this->classid, 'courseid' => $this->courseid));
             // Check if class is already assigned to default track
             if (!$trkassign->is_class_assigned_to_default_track()) {
                 // Determine whether class is required
                 $curcrsobj = new curriculumcourse(array('curriculumid' => $trkassign->track->curid, 'courseid' => $trkassign->courseid));
                 // Get required field and determine if class is autoenrol eligible
                 $trkassign->autoenrol = (1 == $trkassign->cmclass->count_course_assignments($trkassign->cmclass->courseid) and true === $curcrsobj->is_course_required()) ? 1 : 0;
                 // assign class to the curriculum's default track
                 $trkassign->assign_class_to_default_track();
             }
         }
     }
     events_trigger('crlm_track_class_associated', $this);
     return true;
 }
 function get_edit_form($trkassignid)
 {
     $output = '';
     $trkassign = new trackassignmentclass($trkassignid);
     $bc = '<span class="breadcrumb"><a href="index.php?s=trkcls&amp;section=curr' . '&amp;trackid=' . $trkassign->trackid . '">' . get_string('trackasso_genericmanage_crumb', 'block_curr_admin') . '</a> ' . '&raquo; ' . get_string('trackasso_genericedit_crumb', 'block_curr_admin') . '</span>';
     $output .= cm_print_heading_block($bc, '', true);
     $output .= '<br clear="all" />' . "\n";
     $output .= '<form method="post" action="index.php?s=trkcls&amp;section=curr&amp;trackid=' . $trkassign->trackid . '" >' . "\n";
     $output .= '<input type="hidden" name="action" value="update" />' . "\n";
     $output .= '<input type="hidden" name="id" value="' . $trkassign->id . '" />' . "\n";
     $output .= $trkassign->edit_assocation_form_html();
     $output .= '<input type="submit" value="' . get_string('save', 'block_curr_admin') . '">' . "\n";
     $output .= '</form>' . "\n";
     return $output;
 }
 /**
  * Determines whether the current user is allowed to enrol users into the provided class
  *
  * @param   int      $classid  The id of the class we are checking permissions on
  *
  * @return  boolean            Whether the user is allowed to enrol users into the class
  *
  */
 static function can_enrol_into_class($classid)
 {
     global $USER;
     //check the standard capability
     if (cmclasspage::_has_capability('block/curr_admin:class:enrol', $classid) || cmclasspage::_has_capability('block/curr_admin:class:enrol_cluster_user', $classid)) {
         return true;
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id);
     //we first need to go through tracks to get to clusters
     $track_listing = new trackassignmentclass(array('classid' => $classid));
     $tracks = $track_listing->get_assigned_tracks();
     //iterate over the track ides, which are the keys of the array
     if (!empty($tracks)) {
         foreach (array_keys($tracks) as $track) {
             //get the clusters and check the context against them
             $clusters = clustertrack::get_clusters($track);
             if (!empty($clusters)) {
                 foreach ($clusters as $cluster) {
                     if ($context->context_allowed($cluster->clusterid, 'cluster')) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }