Beispiel #1
0
 /**
  * items in the form
  */
 public function definition()
 {
     global $CURMAN, $CFG;
     parent::definition();
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('text', 'name', get_string('userset_name', 'local_elisprogram'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->addHelpButton('name', 'userset_name', 'local_elisprogram');
     $mform->addElement('textarea', 'display', get_string('userset_description', 'local_elisprogram'), array('cols' => 40, 'rows' => 2));
     $mform->setType('display', PARAM_CLEAN);
     $mform->addHelpButton('display', 'userset_description', 'local_elisprogram');
     $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : '';
     //obtain the non-child clusters that we could become the child of, with availability
     //determined based on the edit capability
     $contexts = usersetpage::get_contexts('local/elisprogram:userset_edit');
     $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts);
     //parent dropdown
     $mform->addElement('select', 'parent', get_string('userset_parent', 'local_elisprogram'), $non_child_clusters);
     $mform->addHelpButton('parent', 'userset_parent', 'local_elisprogram');
     // allow plugins to add their own fields
     $mform->addElement('header', 'userassociationfieldset', get_string('userset_userassociation', 'local_elisprogram'));
     $plugins = get_plugin_list(userset::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         require_once elis::plugin_file(userset::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
         call_user_func('cluster_' . $plugin . '_edit_form', $this, $mform, $current_cluster_id);
     }
     // custom fields
     $this->add_custom_fields('cluster', 'local/elisprogram:userset_edit', 'local/elisprogram:userset_view', 'cluster');
     $this->add_action_buttons();
 }
 /**
  * items in the form
  */
 public function definition()
 {
     global $CURMAN, $CFG;
     parent::definition();
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->addElement('text', 'name', get_string('cluster_name', 'block_curr_admin') . ':');
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->setHelpButton('name', array('clusterform/name', get_string('cluster_name', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('textarea', 'display', get_string('cluster_description', 'block_curr_admin') . ':', array('cols' => 40, 'rows' => 2));
     $mform->setHelpButton('display', array('clusterform/display', get_string('cluster_description', 'block_curr_admin'), 'block_curr_admin'));
     $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : '';
     //obtain the non-child clusters that we could become the child of, with availability
     //determined based on the edit capability
     $contexts = clusterpage::get_contexts('block/curr_admin:cluster:edit');
     $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts);
     //parent dropdown
     $mform->addElement('select', 'parent', get_string('cluster_parent', 'block_curr_admin') . ':', $non_child_clusters);
     $mform->setHelpButton('parent', array('clusterform/parent', get_string('cluster_parent', 'block_curr_admin'), 'block_curr_admin'));
     // allow plugins to add their own fields
     $plugins = get_list_of_plugins('curriculum/cluster');
     $mform->addElement('header', 'userassociationfieldset', get_string('userassociation', 'block_curr_admin'));
     foreach ($plugins as $plugin) {
         require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php';
         call_user_func('cluster_' . $plugin . '_edit_form', $this);
     }
     // custom fields
     $fields = field::get_for_context_level('cluster');
     $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('cluster', '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();
 }
 /**
  * Tests contexts in userset data object.
  *
  * Covers:
  * local/elisprogram/lib/data/userset.class.php:334
  * local/elisprogram/lib/data/userset.class.php:453
  * local/elisprogram/lib/data/userset.class.php:561
  * local/elisprogram/lib/data/userset.class.php:595
  * local/elisprogram/lib/data/userset.class.php:616
  * local/elisprogram/lib/data/userset.class.php:721
  * local/elisprogram/lib/data/userset.class.php:755
  * local/elisprogram/lib/data/userset.class.php:847
  * local/elisprogram/lib/data/userset.class.php:901
  */
 public function test_usersetcontexts()
 {
     global $USER, $DB;
     require_once elispm::file('plugins/usetclassify/usersetclassification.class.php');
     require_once elispm::file('plugins/usetclassify/lib.php');
     $this->setup_users();
     $this->setup_usersets();
     // TEST local/elisprogram/lib/data/userset.class.php:334.
     $res = userset::get_allowed_clusters(1);
     // TEST local/elisprogram/lib/data/userset.class.php:453.
     $ussfilter = new usersubset_filter('id', new field_filter('id', 1));
     $res = $ussfilter->get_sql();
     // TEST
     // local/elisprogram/lib/data/userset.class.php:561
     // local/elisprogram/lib/data/userset.class.php:595
     // local/elisprogram/lib/data/userset.class.php:616
     // local/elisprogram/lib/data/userset.class.php:721
     // local/elisprogram/lib/data/userset.class.php:755.
     $field = new field(array('shortname' => USERSET_CLASSIFICATION_FIELD));
     $field->load();
     $userset = $this->create_userset($field);
     // Get a role to assign.
     $rolesctx = $DB->get_records('role_context_levels', array('contextlevel' => CONTEXT_ELIS_USERSET));
     foreach ($rolesctx as $i => $rolectx) {
         $roleid = $rolectx->roleid;
     }
     // Add userset_view capability to our role.
     $usersetcontext = \local_elisprogram\context\userset::instance($userset->id);
     $rc = new stdClass();
     $rc->contextid = $usersetcontext->id;
     $rc->roleid = $roleid;
     $rc->capability = 'local/elisprogram:userset_view';
     $rc->permission = 1;
     $rc->timemodified = time();
     $rc->modifierid = 0;
     $DB->insert_record('role_capabilities', $rc);
     $rc = new stdClass();
     $rc->contextid = $usersetcontext->id;
     $rc->roleid = $roleid;
     $rc->capability = 'local/elisprogram:userset_enrol_userset_user';
     $rc->permission = 1;
     $rc->timemodified = time();
     $rc->modifierid = 0;
     $DB->insert_record('role_capabilities', $rc);
     // Assign role.
     $user = new user(103);
     $muser = $user->get_moodleuser();
     $raid = role_assign($roleid, $muser->id, $usersetcontext->id);
     $this->setUser(100);
     // Assign other user to userset.
     $clst = new clusterassignment();
     $clst->clusterid = $userset->id;
     $clst->userid = 104;
     $clst->plugin = 'manual';
     $clst->save();
     // Get cluster listing.
     $capability = 'local/elisprogram:userset_view';
     $contexts = get_contexts_by_capability_for_user('cluster', $capability, 100);
     $extrafilters = array('contexts' => $contexts, 'classification' => 'test field data');
     $res = cluster_get_listing('name', 'ASC', 0, 0, '', '', $extrafilters, 104);
     $res = cluster_count_records('', '', $extrafilters);
     // TEST local/elisprogram/lib/data/userset.class.php:847.
     cluster_get_non_child_clusters(1);
     // TEST local/elisprogram/lib/data/userset.class.php:901.
     cluster_get_possible_sub_clusters(1);
     $this->setUser(null);
 }