Example #1
0
 /**
  * Renders teamwork message
  *
  * @param teamwork_message $message to display
  * @return string html code
  */
 protected function render_teamwork_message(teamwork_message $message)
 {
     $text = $message->get_message();
     $url = $message->get_action_url();
     $label = $message->get_action_label();
     if (empty($text) and empty($label)) {
         return '';
     }
     switch ($message->get_type()) {
         case teamwork_message::TYPE_OK:
             $sty = 'ok';
             break;
         case teamwork_message::TYPE_ERROR:
             $sty = 'error';
             break;
         default:
             $sty = 'info';
     }
     $o = html_writer::tag('span', $message->get_message());
     if (!is_null($url) and !is_null($label)) {
         $o .= $this->output->single_button($url, $label, 'get');
     }
     return $this->output->container($o, array('message', $sty));
 }
Example #2
0
 /**
  * Returns the HTML code to print the user interface
  */
 public function ui()
 {
     global $PAGE;
     $output = $PAGE->get_renderer('mod_teamwork');
     $m = optional_param('m', null, PARAM_INT);
     // status message code
     $message = new teamwork_message();
     if ($m == self::MSG_SUCCESS) {
         $message->set_text(get_string('randomallocationdone', 'teamworkallocation_random'));
         $message->set_type(teamwork_message::TYPE_OK);
     }
     $out = $output->container_start('random-allocator');
     $out .= $output->render($message);
     // the nasty hack follows to bypass the sad fact that moodle quickforms do not allow to actually
     // return the HTML content, just to display it
     ob_start();
     $this->mform->display();
     $out .= ob_get_contents();
     ob_end_clean();
     // if there are some not-grouped participant in a group mode, warn the user
     $gmode = groups_get_activity_groupmode($this->teamwork->cm, $this->teamwork->course);
     if (VISIBLEGROUPS == $gmode or SEPARATEGROUPS == $gmode) {
         $users = $this->teamwork->get_potential_authors() + $this->teamwork->get_potential_reviewers();
         $users = $this->teamwork->get_grouped($users);
         if (isset($users[0])) {
             $nogroupusers = $users[0];
             foreach ($users as $groupid => $groupusers) {
                 if ($groupid == 0) {
                     continue;
                 }
                 foreach ($groupusers as $groupuserid => $groupuser) {
                     unset($nogroupusers[$groupuserid]);
                 }
             }
             if (!empty($nogroupusers)) {
                 $list = array();
                 foreach ($nogroupusers as $nogroupuser) {
                     $list[] = fullname($nogroupuser);
                 }
                 $a = implode(', ', $list);
                 $out .= $output->box(get_string('nogroupusers', 'teamworkallocation_random', $a), 'generalbox warning nogroupusers');
             }
         }
     }
     // TODO $out .= $output->heading(get_string('stats', 'teamworkallocation_random'));
     $out .= $output->container_end();
     return $out;
 }
Example #3
0
 /**
  * Prints user interface - current allocation and a form to edit it
  */
 public function ui()
 {
     global $PAGE, $DB;
     $output = $PAGE->get_renderer('teamworkallocation_manual');
     $page = optional_param('page', 0, PARAM_INT);
     $perpage = get_user_preferences('teamworkallocation_manual_perpage', 10);
     $groupid = groups_get_activity_group($this->teamwork->cm, true);
     $hlauthorid = -1;
     // highlight this author
     $hlreviewerid = -1;
     // highlight this reviewer
     $message = new teamwork_message();
     $m = optional_param('m', '', PARAM_ALPHANUMEXT);
     // message code
     if ($m) {
         $m = explode('-', $m);
         switch ($m[0]) {
             case self::MSG_ADDED:
                 $hlauthorid = $m[1];
                 $hlreviewerid = $m[2];
                 $message = new teamwork_message(get_string('allocationadded', 'teamworkallocation_manual'), teamwork_message::TYPE_OK);
                 break;
             case self::MSG_EXISTS:
                 $hlauthorid = $m[1];
                 $hlreviewerid = $m[2];
                 $message = new teamwork_message(get_string('allocationexists', 'teamworkallocation_manual'), teamwork_message::TYPE_INFO);
                 break;
             case self::MSG_NOSUBMISSION:
                 $hlauthorid = $m[1];
                 $message = new teamwork_message(get_string('nosubmissionfound', 'teamwork'), teamwork_message::TYPE_ERROR);
                 break;
             case self::MSG_CONFIRM_DEL:
                 $hlauthorid = $m[2];
                 $hlreviewerid = $m[3];
                 if ($m[4] == 0) {
                     $message = new teamwork_message(get_string('areyousuretodeallocate', 'teamworkallocation_manual'), teamwork_message::TYPE_INFO);
                 } else {
                     $message = new teamwork_message(get_string('areyousuretodeallocategraded', 'teamworkallocation_manual'), teamwork_message::TYPE_ERROR);
                 }
                 $url = new moodle_url($PAGE->url, array('mode' => 'del', 'what' => $m[1], 'confirm' => 1, 'sesskey' => sesskey()));
                 $label = get_string('iamsure', 'teamwork');
                 $message->set_action($url, $label);
                 break;
             case self::MSG_DELETED:
                 $hlauthorid = $m[1];
                 $hlreviewerid = $m[2];
                 $message = new teamwork_message(get_string('assessmentdeleted', 'teamwork'), teamwork_message::TYPE_OK);
                 break;
             case self::MSG_DELETE_ERROR:
                 $hlauthorid = $m[1];
                 $hlreviewerid = $m[2];
                 $message = new teamwork_message(get_string('assessmentnotdeleted', 'teamwork'), teamwork_message::TYPE_ERROR);
                 break;
         }
     }
     // fetch the list of ids of all teamwork participants
     $numofparticipants = $this->teamwork->count_participants(false, $groupid);
     $participants = $this->teamwork->get_participants(false, $groupid, $perpage * $page, $perpage);
     if ($hlauthorid > 0 and $hlreviewerid > 0) {
         // display just those two users
         $participants = array_intersect_key($participants, array($hlauthorid => null, $hlreviewerid => null));
         $button = $output->single_button($PAGE->url, get_string('showallparticipants', 'teamworkallocation_manual'), 'get');
     } else {
         $button = '';
     }
     // this will hold the information needed to display user names and pictures
     $userinfo = $participants;
     // load the participants' submissions
     $submissions = $this->teamwork->get_submissions(array_keys($participants));
     $allnames = get_all_user_name_fields();
     foreach ($submissions as $submission) {
         if (!isset($userinfo[$submission->authorid])) {
             $userinfo[$submission->authorid] = new stdclass();
             $userinfo[$submission->authorid]->id = $submission->authorid;
             $userinfo[$submission->authorid]->picture = $submission->authorpicture;
             $userinfo[$submission->authorid]->imagealt = $submission->authorimagealt;
             $userinfo[$submission->authorid]->email = $submission->authoremail;
             foreach ($allnames as $addname) {
                 $temp = 'author' . $addname;
                 $userinfo[$submission->authorid]->{$addname} = $submission->{$temp};
             }
         }
     }
     // get current reviewers
     $reviewers = array();
     if ($submissions) {
         list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED);
         $picturefields = user_picture::fields('r', array(), 'reviewerid');
         $sql = "SELECT a.id AS assessmentid, a.submissionid, {$picturefields},\n                           s.id AS submissionid, s.authorid\n                      FROM {teamwork_assessments} a\n                      JOIN {user} r ON (a.reviewerid = r.id)\n                      JOIN {teamwork_submissions} s ON (a.submissionid = s.id)\n                     WHERE a.submissionid {$submissionids}";
         $reviewers = $DB->get_records_sql($sql, $params);
         foreach ($reviewers as $reviewer) {
             if (!isset($userinfo[$reviewer->reviewerid])) {
                 $userinfo[$reviewer->reviewerid] = new stdclass();
                 $userinfo[$reviewer->reviewerid]->id = $reviewer->reviewerid;
                 $userinfo[$reviewer->reviewerid]->picture = $reviewer->picture;
                 $userinfo[$reviewer->reviewerid]->imagealt = $reviewer->imagealt;
                 $userinfo[$reviewer->reviewerid]->email = $reviewer->email;
                 foreach ($allnames as $addname) {
                     $userinfo[$reviewer->reviewerid]->{$addname} = $reviewer->{$addname};
                 }
             }
         }
     }
     // get current reviewees
     $reviewees = array();
     if ($participants) {
         list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED);
         $namefields = get_all_user_name_fields(true, 'e');
         $params['teamworkid'] = $this->teamwork->id;
         $sql = "SELECT a.id AS assessmentid, a.submissionid,\n                           u.id AS reviewerid,\n                           s.id AS submissionid,\n                           e.id AS revieweeid, e.lastname, e.firstname, {$namefields}, e.picture, e.imagealt, e.email\n                      FROM {user} u\n                      JOIN {teamwork_assessments} a ON (a.reviewerid = u.id)\n                      JOIN {teamwork_submissions} s ON (a.submissionid = s.id)\n                      JOIN {user} e ON (s.authorid = e.id)\n                     WHERE u.id {$participantids} AND s.teamworkid = :teamworkid AND s.example = 0";
         $reviewees = $DB->get_records_sql($sql, $params);
         foreach ($reviewees as $reviewee) {
             if (!isset($userinfo[$reviewee->revieweeid])) {
                 $userinfo[$reviewee->revieweeid] = new stdclass();
                 $userinfo[$reviewee->revieweeid]->id = $reviewee->revieweeid;
                 $userinfo[$reviewee->revieweeid]->firstname = $reviewee->firstname;
                 $userinfo[$reviewee->revieweeid]->lastname = $reviewee->lastname;
                 $userinfo[$reviewee->revieweeid]->picture = $reviewee->picture;
                 $userinfo[$reviewee->revieweeid]->imagealt = $reviewee->imagealt;
                 $userinfo[$reviewee->revieweeid]->email = $reviewee->email;
                 foreach ($allnames as $addname) {
                     $userinfo[$reviewee->revieweeid]->{$addname} = $reviewee->{$addname};
                 }
             }
         }
     }
     // the information about the allocations
     $allocations = array();
     foreach ($participants as $participant) {
         $allocations[$participant->id] = new stdClass();
         $allocations[$participant->id]->userid = $participant->id;
         $allocations[$participant->id]->submissionid = null;
         $allocations[$participant->id]->reviewedby = array();
         $allocations[$participant->id]->reviewerof = array();
     }
     unset($participants);
     foreach ($submissions as $submission) {
         $allocations[$submission->authorid]->submissionid = $submission->id;
         $allocations[$submission->authorid]->submissiontitle = $submission->title;
         $allocations[$submission->authorid]->submissiongrade = $submission->grade;
     }
     unset($submissions);
     foreach ($reviewers as $reviewer) {
         $allocations[$reviewer->authorid]->reviewedby[$reviewer->reviewerid] = $reviewer->assessmentid;
     }
     unset($reviewers);
     foreach ($reviewees as $reviewee) {
         $allocations[$reviewee->reviewerid]->reviewerof[$reviewee->revieweeid] = $reviewee->assessmentid;
     }
     unset($reviewees);
     // prepare data to be rendered
     $data = new teamworkallocation_manual_allocations();
     $data->teamwork = $this->teamwork;
     $data->allocations = $allocations;
     $data->userinfo = $userinfo;
     $data->authors = $this->teamwork->get_potential_authors();
     $data->reviewers = $this->teamwork->get_potential_reviewers();
     $data->hlauthorid = $hlauthorid;
     $data->hlreviewerid = $hlreviewerid;
     $data->selfassessment = $this->teamwork->useselfassessment;
     // prepare the group selector
     $groupselector = $output->container(groups_print_activity_menu($this->teamwork->cm, $PAGE->url, true), 'groupwidget');
     // prepare paging bar
     $pagingbar = new paging_bar($numofparticipants, $page, $perpage, $PAGE->url, 'page');
     $pagingbarout = $output->render($pagingbar);
     $perpageselector = $output->perpage_selector($perpage);
     return $groupselector . $pagingbarout . $output->render($message) . $output->render($data) . $button . $pagingbarout . $perpageselector;
 }