コード例 #1
0
 static function cluster_assigned_handler($eventdata)
 {
     global $CURMAN, $CFG;
     // assign user to the curricula associated with the cluster
     /**
      * @todo we may need to change this if associating a user with a
      * curriculum does anything more complicated
      */
     require_once CURMAN_DIRLOCATION . '/lib/user.class.php';
     require_once CURMAN_DIRLOCATION . '/lib/clustercurriculum.class.php';
     require_once CURMAN_DIRLOCATION . '/lib/curriculumstudent.class.php';
     require_once CURMAN_DIRLOCATION . '/lib/usertrack.class.php';
     $db = $CURMAN->db;
     $timenow = time();
     $sql = 'INSERT INTO ' . $db->prefix_table(CURASSTABLE) . ' ' . '(userid, curriculumid, timecreated, timemodified) ' . 'SELECT DISTINCT u.id, clucur.curriculumid, ' . $timenow . ', ' . $timenow . ' ' . 'FROM ' . $db->prefix_table(CLSTUSERTABLE) . ' clu ' . 'INNER JOIN ' . $db->prefix_table(USRTABLE) . ' u ON u.id = clu.userid ' . 'INNER JOIN ' . $db->prefix_table(CLSTCURTABLE) . ' clucur ON clucur.clusterid = clu.clusterid ' . 'LEFT OUTER JOIN ' . $db->prefix_table(CURASSTABLE) . ' ca ON ca.userid = u.id AND ca.curriculumid = clucur.curriculumid ' . 'WHERE clu.clusterid = \'' . $eventdata->clusterid . '\' AND u.id = \'' . $eventdata->userid . '\' AND ca.curriculumid IS NULL ' . 'AND clucur.autoenrol = 1';
     $db->execute_sql($sql, false);
     // enrol user in associated tracks if autoenrol flag is set
     if ($eventdata->autoenrol) {
         $tracks = clustertrack::get_tracks($eventdata->clusterid);
         if ($tracks) {
             foreach ($tracks as $track) {
                 //make sure the cluster-track association is set up for autoenrol
                 if (record_exists(CLSTTRKTABLE, 'clusterid', $eventdata->clusterid, 'trackid', $track->trackid, 'autoenrol', 1)) {
                     usertrack::enrol($eventdata->userid, $track->trackid);
                 }
             }
         }
     }
     return true;
 }
コード例 #2
0
 function action_default()
 {
     $id = $this->required_param('id', PARAM_INT);
     $sort = $this->optional_param('sort', 'name', PARAM_CLEAN);
     $dir = $this->optional_param('dir', 'ASC', PARAM_CLEAN);
     $columns = array('idnumber' => get_string('track_idnumber', 'block_curr_admin'), 'name' => get_string('track_name', 'block_curr_admin'), 'description' => get_string('track_description', 'block_curr_admin'), 'autoenrol' => get_string('auto_enrol', 'block_curr_admin'), 'buttons' => '');
     $items = clustertrack::get_tracks($id, $sort, $dir);
     $formatters = $this->create_link_formatters(array('idnumber', 'name'), 'trackpage', 'trackid');
     $this->print_list_view($items, $columns, $formatters, 'tracks');
     // find the tracks that the user can associate with this cluster
     $contexts = trackpage::get_contexts('block/curr_admin:associate');
     $tracks = track_get_listing('name', 'ASC', 0, 0, '', '', 0, 0, $contexts);
     if (empty($tracks)) {
         $num_tracks = track_count_records();
         if (!empty($num_tracks)) {
             // some tracks exist, but don't have associate capability on
             // any of them
             echo '<div align="center"><br />';
             print_string('no_associate_caps_track', 'block_curr_admin');
             echo '</div>';
         } else {
             // no tracks at all
             echo '<div align="center"><br />';
             print_string('all_items_assigned', 'block_curr_admin');
             echo '</div>';
         }
     } else {
         $this->print_dropdown($tracks, $items, 'clusterid', 'trackid');
     }
 }
コード例 #3
0
 /**
  * @dataProvider sortautoenroldescprovider
  */
 public function testsortautoenroldesc($data)
 {
     $this->load_csv_data();
     $dataset = clustertrack::get_tracks(1, 'autoenrol', 'DESC');
     $this->assertEquals(array_values($data), array_values($dataset));
 }