示例#1
0
 /**
  * Assign the user to the program.
  * @param array $elements An array of elements to perform the action on.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $pgmid = required_param('id', PARAM_INT);
     // Permissions.
     if (curriculumpage::can_enrol_into_curriculum($pgmid) !== true) {
         return array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram'));
     }
     foreach ($elements as $userid => $label) {
         if ($this->can_assign($pgmid, $userid) === true) {
             $stucur = new curriculumstudent(array('userid' => $userid, 'curriculumid' => $pgmid));
             $stucur->save();
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
示例#2
0
 function print_tabs()
 {
     $id = $this->required_param('id', PARAM_INT);
     $page = $this->get_tab_page();
     $params = array('id' => $id);
     $rows = array();
     $row = array();
     // main row of tabs
     foreach ($page->tabs as $tab) {
         $tab = $page->add_defaults_to_tab($tab);
         if ($tab['showtab'] === true) {
             $target = new $tab['page'](array_merge($tab['params'], $params));
             if (!$target->can_do()) {
                 //insufficient permissions according to tab's page, so don't add it
                 continue;
             }
             $row[] = new tabobject($tab['tab_id'], $target->url, $tab['name']);
         }
     }
     if (!empty($row)) {
         $rows[] = $row;
     }
     // assigned/unassigned tabs
     //$assignedpage = clone($this->get_basepage());
     //unset($assignedpage->params['_assign']);
     $assignedpage = $this->get_new_page(array('id' => $id, '_assign' => 'unassign'));
     // TBD: arbitrary != 'assign' ???
     //$unassignedpage = clone($assignedpage);
     //$unassignedpage->params['_assign'] = 'assign';
     $unassignedpage = $this->get_new_page(array('id' => $id, '_assign' => 'assign'));
     list($assigned_string, $unassigned_string) = $this->get_assigned_strings();
     $iscurstupage = get_class($this) == 'curriculumstudentpage';
     if (!$iscurstupage && $this->can_do_default() || $iscurstupage && curriculumpage::can_enrol_into_curriculum($id)) {
         $row = array(new tabobject('assigned', $assignedpage->url, $assigned_string), new tabobject('unassigned', $unassignedpage->url, $unassigned_string));
     } else {
         $row = array(new tabobject('assigned', $assignedpage->url, $assigned_string));
     }
     $rows[] = $row;
     print_tabs($rows, $this->is_assigning() ? 'unassigned' : 'assigned', array(), array(get_class($this)));
 }
示例#3
0
 /**
  * Transforms each result.
  * @param array $row An array for a single result.
  * @return array The transformed result.
  */
 protected function results_row_transform(array $row)
 {
     $row = parent::results_row_transform($row);
     // Whether the user can unassign from the program at all.
     static $canunassignany = null;
     // Whether the user can unassin any user from the program.
     static $canunassignall = null;
     // If not already set, determine whether the user can do any unassigning.
     if ($canunassignany === null) {
         $canunassignany = curriculumpage::can_enrol_into_curriculum($this->programid);
     }
     // If not already set, determine whether the user can unassign anyone - but only if $canunassignany is true.
     if ($canunassignany === true && $canunassignall === null) {
         $cpage = new curriculumpage();
         if ($cpage->_has_capability('local/elisprogram:program_enrol', $this->programid)) {
             $canunassignall = true;
         }
     }
     // Set the 'canunassign' parameter for use in javascript.
     if ($canunassignall === true) {
         $row['canunassign'] = '1';
     } else {
         if ($canunassignany === true) {
             $row['canunassign'] = curriculumstudent::can_manage_assoc($row['element_id'], $this->programid) === true ? '1' : '0';
         } else {
             $row['canunassign'] = '0';
         }
     }
     return $row;
 }
 function definition()
 {
     $mform =& $this->_form;
     $id = required_param('id', PARAM_INT);
     if (curriculumpage::can_enrol_into_curriculum($id)) {
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
         $mform->addElement('hidden', '_assign', 'unassign');
         $mform->setType('_assign', PARAM_TEXT);
         $mform->addElement('hidden', 's', 'curstu');
         $mform->setType('s', PARAM_TEXT);
         $mform->addElement('hidden', '_selection');
         $mform->setType('_selection', PARAM_TEXT);
         $this->add_action_buttons(false, $this->get_submit_button_name());
     }
 }
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a curriculum
  *
  * @param    int      $userid  The id of the user being associated to the curricula
  * @param    int      $curid   The id of the curricula we are associating the user to
  *
  * @return   boolean           True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $curid)
 {
     global $USER;
     if (!curriculumpage::can_enrol_into_curriculum($curid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if (curriculumpage::_has_capability('block/curr_admin:curriculum:enrol', $curid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:curriculum:enrol_cluster_user', $USER->id);
     $allowed_clusters = array();
     //get the clusters and check the context against them
     $clusters = clustercurriculum::get_clusters($curid);
     $allowed_clusters = $context->get_allowed_instances($clusters, 'cluster', 'id');
     //query to get users associated to at least one enabling cluster
     $cluster_select = '';
     if (empty($allowed_clusters)) {
         $cluster_select = '0=1';
     } else {
         $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')';
     }
     $select = "userid = {$userid} AND {$cluster_select}";
     //user just needs to be in one of the possible clusters
     if (record_exists_select(CLSTUSERTABLE, $select)) {
         return true;
     }
     return false;
 }
示例#6
0
 /**
  * Determines whether the current user is allowed to create, edit, and delete associations
  * between a user and a curriculum
  *
  * @param    int      $userid  The id of the user being associated to the curricula
  * @param    int      $curid   The id of the curricula we are associating the user to
  *
  * @return   boolean           True if the current user has the required permissions, otherwise false
  */
 public static function can_manage_assoc($userid, $curid)
 {
     global $USER, $DB;
     // TODO: Ugly, this needs to be overhauled
     $cpage = new curriculumpage();
     if (!curriculumpage::can_enrol_into_curriculum($curid)) {
         //the users who satisfty this condition are a superset of those who can manage associations
         return false;
     } else {
         if ($cpage->_has_capability('local/elisprogram:program_enrol', $curid)) {
             //current user has the direct capability
             return true;
         }
     }
     //get the context for the "indirect" capability
     $context = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:program_enrol_userset_user', $USER->id);
     $allowedclusters = array();
     // Get the clusters and check the context against them.
     $clusters = clustercurriculum::get_clusters($curid);
     $allowedclusters = $context->get_allowed_instances($clusters, 'cluster', 'clusterid');
     // Query to get users associated to at least one enabling cluster.
     $clusterselect = '';
     if (empty($allowedclusters)) {
         $clusterselect = '0=1';
     } else {
         $clusterselect = 'clusterid IN (' . implode(',', $allowedclusters) . ')';
     }
     $select = "userid = {$userid} AND {$clusterselect}";
     //user just needs to be in one of the possible clusters
     if ($DB->record_exists_select(clusterassignment::TABLE, $select)) {
         return true;
     }
     return false;
 }
 /**
  * Determine whether the current user can enrol students into the class.
  * @return bool Whether the user can enrol users into the class or not.
  */
 public function can_do_add()
 {
     $id = $this->required_param('id');
     return curriculumpage::can_enrol_into_curriculum($id);
 }
 function can_do_default()
 {
     $id = $this->required_param('id', PARAM_INT);
     if ($this->is_assigning()) {
         return curriculumpage::can_enrol_into_curriculum($id);
     } else {
         return curriculumpage::_has_capability('block/curr_admin:curriculum:view', $id);
     }
 }