function simple_template_for_batches($facetofaceid,$session_cancel=0){ global $DB,$CFG,$USER,$SITE; $sentby_name=fullname($DB->get_record('user',array('id'=>$USER->id))); $sentby_id=$USER->id; $facetoface=$DB->get_record_sql("SELECT * FROM {facetoface} where id=$facetofaceid"); if($session_cancel==0 || $session_cancel==2){ $facetofacesessions=$DB->get_records_sql("SELECT * FROM {facetoface_sessions} fss JOIN {facetoface_sessions_dates} as fsd ON fsd.sessionid=fss.id where facetoface=$facetoface->id"); } //print_object($facetofacesessions); $facetoface_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} where f2fid=$facetoface->id"); $facetoface_course=$DB->get_record_sql("SELECT * FROM {local_batch_courses} where batchid=$facetoface->id"); if((!empty($facetoface)) && (!empty($facetoface_users))){ $mail=new stdClass(); switch($facetoface->active){ case 1: if($session_cancel==0){ $mailsubject=get_string('subject_active', 'facetoface'); }elseif($session_cancel==2){ $mailsubject=get_string('subject_active_session_cancel', 'facetoface'); } $mail->batch_status=get_string('batch_active', 'facetoface'); break; case 8: $mailsubject=get_string('subject_complete', 'facetoface'); $mail->batch_status=get_string('batch_complete', 'facetoface'); break; case 2: $mailsubject=get_string('subject_cancel', 'facetoface'); $mail->batch_status=get_string('batch_cancel', 'facetoface'); break; case 0: $batch_cousre=$DB->get_record('course',array('id'=>$facetoface_course->courseid)); $tataaia = new stdclass(); $tataaia->picture3 = $CFG->wwwroot.'/mod/facetoface/pix/Picture3.png'; $tataaia->picture2 = $CFG->wwwroot.'/mod/facetoface/pix/Picture2.png'; $tataaia->programname = $batch_cousre->fullname; $tataaia->date = date("d M, Y ",$facetoface->startdate); $tataaia->time = date("g:i a",$facetoface->startdate);; $tataaia->venue = 'Thane Training Room'; $tataaia->summary =strip_tags($batch_cousre->summary); $tataaia->summary2 = 'Request you to please discuss with your supervisor, plan your work and make sure that you attend this program'; $tataaia->senderfullname = 'Jagadeep M.P'; $tataaia->designation = 'Manager-Training & Development'; $tataaia->mobileno = '9000 469 5151'; $mailsubject="Batch Start Invitation"; $mail->batch_status=get_string('batch_active', 'facetoface'); } $mail->batch_name=$facetoface->name; $mail->batch_startdate=date("d M, Y ",$facetoface->startdate); $mail->batch_enddate=date("d M, Y ",$facetoface->enddate); $tariner_name=$DB->get_record('user',array('id'=>$facetoface->trainerid)); $mail->tariner_name=fullname($tariner_name); if($facetoface_course){ if($facetoface_course->courseid!=0){ $batch_cousre=$DB->get_field('course','fullname',array('id'=>$facetoface_course->courseid)); $mail->batch_course=$batch_cousre; }else{ $mail->batch_course="-----"; } if($facetoface_course->testid!=0){ $quiz=$DB->get_record('quiz',array('id'=>$facetoface_course->testid)); $mail->test_name=$quiz->name; $course_completion_check=$DB->record_exists_sql("SELECT * FROM {course_completion_criteria} cc, {course} c Where c.id=$facetoface_course->courseid and c.id=cc.course and c.enablecompletion=1 AND cc.module IS NOT NULL AND cc.moduleinstance in (SELECT id FROM {course_modules} where course=$facetoface_course->courseid and instance=$facetoface_course->testid)"); if($course_completion_check==1){ $mail->test_status=get_string('test_completed', 'facetoface'); }else{ $mail->test_status=get_string('test_not_completed', 'facetoface'); } }else{ $mail->test_name="-----"; $mail->test_status="-----"; } } if($facetofacesessions && ($session_cancel==0 || $session_cancel==2)){ $session_mail='<h2 style="text-align:center;font-weight:bold;">SESSION DETAILS</h2>'; $session_mail.='<table style="border:1px solid #333;">'; $i=1; foreach($facetofacesessions as $sessiondate){ //print_object($sessiondate); $sessiondates=new stdClass(); $timenow = time(); if (!empty($html)) { $html= html_writer::empty_tag('br'); } $sessionobj = facetoface_format_session_times($sessiondate->timestart, $sessiondate->timefinish, $sessiondate->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $html .= $sessionobj->startdate . ', '; } else { $html .= $sessionobj->startdate . ' - ' . $sessionobj->enddate . ', '; } $html .= $sessionobj->starttime . ' - ' . $sessionobj->endtime . ' ' . $sessionobj->timezone; $duration=round(($sessiondate->duration/60),2); $session_mail.='<tr>'; $session_mail.='<td style="border:1px solid #333;">Session '.$i.' '.'Timings : </td>'; $session_mail.='<td style="border:1px solid #333;"><b>'.$html.'</b></td>'; $session_mail.='<td style="border:1px solid #333;">Duration : </td>'; $session_mail.='<td style="border:1px solid #333;"><b>'.$duration.' Hours </b></td>'; if ($sessiondate->roomid) { $room = $DB->get_record('facetoface_room', array('id' => $sessiondate->roomid)); $sessionroom = $room->name." ". $room->building." ".$room->address; }else{ $sessionroom = "----"; } $sessiondates->datetimeknown=$sessiondate->datetimeknown; $sessiondates->sessiondates=facetoface_get_session_dates($sessiondate->id); //print_object($sessiondates); $session_cancel=$DB->get_record_sql("SELECT * FROM {facetoface_signups} as fsg JOIN {facetoface_signups_status} as fsst on fsst.signupid=fsg.id where fsg.sessionid=$sessiondate->id group by fsg.sessionid"); if($session_cancel->statuscode==10){ $status = get_string('sessionincancel', 'facetoface'); }else{ if ($sessiondate->datetimeknown && facetoface_has_session_started($sessiondates, $timenow) && !facetoface_is_session_in_progress($sessiondates, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); } else if ($sessiondate->datetimeknown && facetoface_has_session_started($sessiondates, $timenow)&&facetoface_is_session_in_progress($sessiondates, $timenow)) { $status = get_string('sessionover', 'facetoface'); } } $session_mail.='<td style="border:1px solid #333;">Room : </td>'; $session_mail.='<td style="border:1px solid #333;"><b>'.$sessionroom.'</b></td>'; $session_mail.='<td style="border:1px solid #333;">Status : </td>'; $session_mail.='<td style="border:1px solid #333;"><b>'.$status.'</b></td>'; $session_mail.='</tr>'; $i++; } $session_mail.='</table>'; $mail->sessions_details=$session_mail; }else{ $mail->sessions_details=""; } $userenrolments=array(); foreach($facetoface_users as $facetoface_user){ $user=$DB->get_record('user',array('id'=>$facetoface_user->userid)); if($facetoface_course){ $userenrolments[]=$DB->get_record_sql("SELECT * FROM {user_enrolments} where userid=$facetoface_user->userid and enrolid in (SELECT id FROM {enrol} where courseid=$facetoface_course->courseid and enrol='manual')"); } } $emai_users=email_send_users_list($userenrolments,$facetoface_course->courseid,$facetoface->trainerid); $to_emailid=$emai_users[0]; $to_userid=$emai_users[1]; //print_object($emai_users); $from = $DB->get_record('user',array('id'=>2)); $messagetext='Batch'; if($facetoface->active==0){ $messagetext_fr=get_string('first_time_notify', 'facetoface',$tataaia); $messagehtml=text_to_html($messagetext_fr); }else{ $messagetext_fr=get_string('batch_mail', 'facetoface',$mail); $messagehtml=text_to_html($messagetext_fr); } if((!empty($to_emailid))&&(!empty($to_userid))){ $sucess=email_logs_insert_table($to_emailid,$to_userid,$from->email,$from->id,$mailsubject,$messagehtml,$sentby_id,$sentby_name,$facetoface_course->courseid,$facetofaceid); return $sucess; } } }
/** * Called when viewing course page. * * @param cm_info $coursemodule */ function facetoface_cm_info_view(cm_info $coursemodule) { global $USER, $DB; if (!($facetoface = $DB->get_record('facetoface', array('id' => $coursemodule->instance)))) { return null; } $coursemodule->set_name($facetoface->name); $contextmodule = context_module::instance($coursemodule->id); if (!has_capability('mod/facetoface:view', $contextmodule)) { return null; // Not allowed to view this activity. } $contextcourse = context_course::instance($coursemodule->course); // Can view attendees. $viewattendees = has_capability('mod/facetoface:viewattendees', $contextcourse); // Can see "view all sessions" link even if activity is hidden/currently unavailable. $iseditor = has_any_capability(array('mod/facetoface:viewattendees', 'mod/facetoface:editsessions', 'mod/facetoface:addattendees', 'mod/facetoface:addattendees', 'mod/facetoface:takeattendance'), $contextcourse); $table = html_writer::start_tag('table', array('class' => 'table90 inlinetable')); $timenow = time(); $strviewallsessions = get_string('viewallsessions', 'facetoface'); $sessions_url = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id)); $htmlviewallsessions = html_writer::link($sessions_url, $strviewallsessions, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strviewallsessions)); if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) { // User has signedup for the instance. if (!$facetoface->multiplesessions) { // First submission only. $submissions = array(array_shift($submissions)); } foreach ($submissions as $submission) { if ($session = facetoface_get_session($submission->sessionid)) { $allowcancellation = false; if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $status = get_string('sessionover', 'facetoface'); if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else { $status = get_string('bookingstatus', 'facetoface'); } $sessiondates = ''; if ($session->datetimeknown) { foreach ($session->sessiondates as $date) { if (!empty($sessiondates)) { $sessiondates .= html_writer::empty_tag('br'); } $sessionobj = facetoface_format_session_times($date->timestart, $date->timefinish, $date->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $sessiondates .= get_string('sessionstartdateandtime', 'facetoface', $sessionobj); } else { $sessiondates .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj); } } } else { $sessiondates = get_string('wait-listed', 'facetoface'); } $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); $options = html_writer::tag('tr', html_writer::tag('td', ' ')); // Don't include the link to cancel a session if it has already occurred. $moreinfolink = ''; $cancellink = ''; $strcancelbooking = get_string('cancelbooking', 'facetoface'); $cancel_url = new moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $session->id)); if (!facetoface_has_session_started($session, $timenow)) { $strmoreinfo = get_string('moreinfo', 'facetoface'); $signup_url = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $strmoreinfo, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $strmoreinfo)))); $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking)))); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } else { // Session is started. if ($allowcancellation) { $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking)))); } } // Get room data. $roomtext = ''; $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid)); if (!empty($roomdata)) { $roomtext = isset($roomdata->name) ? format_string($roomdata->name) .', '.html_writer::empty_tag('br') : ''; $roomtext .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : ''; $roomtext .= isset($roomdata->address) ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : ''; } // Don't include the link to view attendees if user is lacking capability. $attendeeslink = ''; if ($viewattendees) { $strseeattendees = get_string('seeattendees', 'facetoface'); $attendees_url = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id)); $attendeeslink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($attendees_url, $strseeattendees, array('class' => 'f2fsessionlinks f2fviewattendees', 'title' => $strseeattendees)))); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } $table .= html_writer::start_tag('tr') .html_writer::tag('td', $status, array('class' => 'f2fsessionnotice', 'colspan' => '2')) .html_writer::end_tag('tr') .html_writer::start_tag('tr', array('class' => 'f2fsessioninfo')) .html_writer::tag('td', $roomtext . $sessiondates . html_writer::empty_tag('br'), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .$options .$moreinfolink .$attendeeslink .$cancellink .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } // Add closing "view all sessions" row to table. $table .= html_writer::start_tag('tr') .html_writer::tag('td', $htmlviewallsessions, array('colspan' => '2')) .html_writer::end_tag('tr') .html_writer::end_tag('table'); } else if ($sessions = facetoface_get_sessions($facetoface->id)) { if ($facetoface->display > 0) { $j=1; $sessionsinprogress = array(); $futuresessions = array(); foreach ($sessions as $session) { if (!facetoface_session_has_capacity($session, $contextmodule, MDL_F2F_STATUS_WAITLISTED) && !$session->allowoverbook) { continue; } if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && !facetoface_is_session_in_progress($session, $timenow)) { // Finished session, don't display. continue; } else { $signup = get_string('signup', 'facetoface'); $signup_url = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $signup, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $signup)))); $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } $multidate = ''; $sessiondate = ''; $sessiontime = ''; if ($session->datetimeknown) { if (empty($session->sessiondates)) { $sessiondate = get_string('unknowndate', 'facetoface'); $sessiontime = get_string('unknowntime', 'facetoface'); } else { $sessionobj = facetoface_format_session_times($session->sessiondates[0]->timestart, $session->sessiondates[0]->timefinish, $session->sessiondates[0]->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $sessiondate = get_string('sessionstartdateandtime', 'facetoface', $sessionobj); } else { $sessiondate .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj); } if (count($session->sessiondates) > 1) { $multidate = html_writer::start_tag('br') . get_string('multidate', 'facetoface'); } } } else { $sessiondate = get_string('wait-listed', 'facetoface'); } $locationstring = ''; $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid)); if (!empty($roomdata)) { $locationstring = isset($roomdata->name) ? format_string($roomdata->name) .', '.html_writer::empty_tag('br') : ''; $locationstring .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : ''; $locationstring .= isset($roomdata->address) ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : ''; } $sessionobject = new stdClass(); $sessionobject->location = $locationstring; $sessionobject->date = $sessiondate; $sessionobject->multidate = $multidate; if ($session->datetimeknown && (facetoface_has_session_started($session, $timenow)) && facetoface_is_session_in_progress($session, $timenow)) { $sessionsinprogress[] = $sessionobject; } else { $sessionobject->options = $options; $sessionobject->moreinfolink = $moreinfolink; $futuresessions[] = $sessionobject; } $j++; if ($j > $facetoface->display) { break; } } if (!empty($sessionsinprogress)) { $table .= html_writer::start_tag('tr') . html_writer::tag('td', get_string('sessioninprogress', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2')) . html_writer::end_tag('tr'); foreach ($sessionsinprogress as $session) { $table .= html_writer::start_tag('tr') .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .html_writer::tag('tr', html_writer::tag('td', ' ')) .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } if (!empty($futuresessions)) { $table .= html_writer::start_tag('tr') . html_writer::tag('td', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2')) . html_writer::end_tag('tr'); foreach ($futuresessions as $session) { $table .= html_writer::start_tag('tr') .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .$session->options .$session->moreinfolink .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } $table .= html_writer::start_tag('tr') .html_writer::tag('td', ($iseditor || ($coursemodule->visible && $coursemodule->available)) ? $htmlviewallsessions : $strviewallsessions, array('colspan' => '2')) .html_writer::end_tag('tr') .html_writer::end_tag('table'); } else { // Show only name if session display is set to zero. $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive')); $coursemodule->set_content($content); return; } } else if (has_capability('mod/facetoface:viewemptyactivities', $contextmodule)) { $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive')); $coursemodule->set_content($content); return; } else { // Nothing to display to this user. $coursemodule->set_content(''); return; } $coursemodule->set_content($table); }
/** * Builds session list table given an array of sessions */ public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions) { $output = ''; $tableheader = array(); foreach ($customfields as $field) { if (!empty($field->showinsummary)) { $tableheader[] = format_string($field->name); } } $tableheader[] = get_string('date', 'facetoface'); $tableheader[] = get_string('time', 'facetoface'); $tableheader[] = get_string('room', 'facetoface'); if ($viewattendees) { $tableheader[] = get_string('capacity', 'facetoface'); } else { $tableheader[] = get_string('seatsavailable', 'facetoface'); } $tableheader[] = get_string('status', 'facetoface'); $tableheader[] = get_string('options', 'facetoface'); $timenow = time(); $table = new html_table(); $table->summary = get_string('previoussessionslist', 'facetoface'); $table->attributes['class'] = 'generaltable fullwidth'; $table->head = $tableheader; $table->data = array(); foreach ($sessions as $session) { $isbookedsession = false; $bookedsession = $session->bookedsession; $sessionstarted = false; $sessionfull = false; $sessionrow = array(); // Custom fields $customdata = $session->customfielddata; foreach ($customfields as $field) { if (empty($field->showinsummary)) { continue; } if (empty($customdata[$field->id])) { $sessionrow[] = ' '; } else { if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) { $sessionrow[] = str_replace(CUSTOMFIELD_DELIMITER, html_writer::empty_tag('br'), format_string($customdata[$field->id]->data)); } else { $sessionrow[] = format_string($customdata[$field->id]->data); } } } // Dates/times $allsessiondates = ''; $allsessiontimes = ''; if ($session->datetimeknown) { foreach ($session->sessiondates as $date) { if (!empty($allsessiondates)) { $allsessiondates .= html_writer::empty_tag('br'); $allsessiontimes .= html_writer::empty_tag('br'); } $sessionobj = facetoface_format_session_times($date->timestart, $date->timefinish, $date->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $allsessiondates .= $sessionobj->startdate; } else { $allsessiondates .= $sessionobj->startdate . ' - ' . $sessionobj->enddate; } $allsessiontimes .= $sessionobj->starttime . ' - ' . $sessionobj->endtime . ' ' . $sessionobj->timezone; } } else { $allsessiondates = get_string('wait-listed', 'facetoface'); $allsessiontimes = get_string('wait-listed', 'facetoface'); $sessionwaitlisted = true; } $sessionrow[] = $allsessiondates; $sessionrow[] = $allsessiontimes; // Room. if (isset($session->room)) { $roomhtml = ''; $roomhtml .= isset($session->room->name) ? format_string($session->room->name) . html_writer::empty_tag('br') : ''; $roomhtml .= isset($session->room->building) ? format_string($session->room->building) . html_writer::empty_tag('br') : ''; $roomhtml .= isset($session->room->address) ? format_string($session->room->address) . html_writer::empty_tag('br') : ''; $sessionrow[] = $roomhtml; } else { $sessionrow[] = ''; } // Capacity. if ($session->datetimeknown) { $signupcount = facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_BOOKED); } else { $signupcount = facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_APPROVED); } if ($viewattendees) { if ($session->datetimeknown) { $a = array('current' => $signupcount, 'maximum' => $session->capacity); $stats = get_string('capacitycurrentofmaximum', 'facetoface', $a); if ($signupcount > $session->capacity) { $stats .= get_string('capacityoverbooked', 'facetoface'); } $waitlisted = facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_APPROVED) - $signupcount; if ($waitlisted > 0) { $stats .= " (" . $waitlisted . " " . get_string('status_waitlisted', 'facetoface') . ")"; } } else { $stats = $session->capacity . " (" . $signupcount . " " . get_string('status_waitlisted', 'facetoface') . ")"; } } else { $stats = max(0, $session->capacity - $signupcount); } $sessionrow[] = $stats; // Status. $allowcancellation = false; $status = get_string('bookingopen', 'facetoface'); if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); $sessionstarted = true; // If user status is wait-listed. if ($bookedsession && $bookedsession->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $status = get_string('sessionover', 'facetoface'); $sessionstarted = true; // If user status is wait-listed. if ($bookedsession && $bookedsession->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else if ($bookedsession && $session->id == $bookedsession->sessionid) { $signupstatus = facetoface_get_status($bookedsession->statuscode); $status = get_string('status_'.$signupstatus, 'facetoface'); $isbookedsession = true; } else if ($signupcount >= $session->capacity) { $status = get_string('bookingfull', 'facetoface'); $sessionfull = true; } $sessionrow[] = $status; // Options. $options = ''; if ($editsessions) { $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id)), new pix_icon('t/edit', get_string('edit', 'facetoface')), null, array('title' => get_string('editsession', 'facetoface'))) . ' '; $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'c' => 1)), new pix_icon('t/copy', get_string('copy', 'facetoface')), null, array('title' => get_string('copysession', 'facetoface'))) . ' '; $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'd' => 1)), new pix_icon('t/delete', get_string('delete', 'facetoface')), null, array('title' => get_string('deletesession', 'facetoface'))) . ' '; $options .= html_writer::empty_tag('br'); } if ($viewattendees) { $options .= html_writer::link('attendees.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('attendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface'))); $options .= html_writer::empty_tag('br'); } if ($isbookedsession) { $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('moreinfo', 'facetoface'), array('title' => get_string('moreinfo', 'facetoface'))); $options .= html_writer::empty_tag('br'); $options .= html_writer::link('cancelsignup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); } else if (!$sessionstarted and !$bookedsession) { if (!facetoface_session_has_capacity($session, $this->context, MDL_F2F_STATUS_WAITLISTED) && !$session->allowoverbook) { $options .= get_string('none', 'facetoface'); } else { $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface')); } } if (empty($options)) { if ($sessionstarted && $allowcancellation) { $options = html_writer::link('cancelsignup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); } else { $options = get_string('none', 'facetoface'); } } $sessionrow[] = $options; $row = new html_table_row($sessionrow); // Set the CSS class for the row. if ($sessionstarted) { $row->attributes = array('class' => 'dimmed_text'); } else if ($isbookedsession) { $row->attributes = array('class' => 'highlight'); } else if ($sessionfull) { $row->attributes = array('class' => 'dimmed_text'); } // Add row to table. $table->data[] = $row; } $output .= html_writer::table($table); return $output; }
/** * Builds session list table given an array of sessions */ public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions) { global $CFG; $output = ''; $tableheader = array(); foreach ($customfields as $field) { if (!empty($field->showinsummary)) { $tableheader[] = format_string($field->name); } } $tableheader[] = get_string('date', 'facetoface'); $tableheader[] = get_string('time', 'facetoface'); if ($viewattendees) { $tableheader[] = get_string('capacity', 'facetoface'); } else { $tableheader[] = get_string('seatsavailable', 'facetoface'); } $tableheader[] = get_string('status', 'facetoface'); $tableheader[] = get_string('options', 'facetoface'); $timenow = time(); $table = new html_table(); $table->summary = get_string('previoussessionslist', 'facetoface'); $table->head = $tableheader; $table->data = array(); foreach ($sessions as $session) { $isbookedsession = false; $bookedsession = $session->bookedsession; $sessionstarted = false; $sessionfull = false; $sessionrow = array(); // Custom fields. $customdata = $session->customfielddata; foreach ($customfields as $field) { if (empty($field->showinsummary)) { continue; } if (empty($customdata[$field->id])) { $sessionrow[] = ' '; } else { if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) { $sessionrow[] = str_replace(CUSTOMFIELD_DELIMITER, html_writer::empty_tag('br'), format_string($customdata[$field->id]->data)); } else { $sessionrow[] = format_string($customdata[$field->id]->data); } } } // Dates/times. $allsessiondates = ''; $allsessiontimes = ''; if ($session->datetimeknown) { foreach ($session->sessiondates as $date) { if (!empty($allsessiondates)) { $allsessiondates .= html_writer::empty_tag('br'); } $allsessiondates .= userdate($date->timestart, get_string('strftimedate')); if (!empty($allsessiontimes)) { $allsessiontimes .= html_writer::empty_tag('br'); } $allsessiontimes .= userdate($date->timestart, get_string('strftimetime')) . ' - ' . userdate($date->timefinish, get_string('strftimetime')); } } else { $allsessiondates = get_string('wait-listed', 'facetoface'); $allsessiontimes = get_string('wait-listed', 'facetoface'); $sessionwaitlisted = true; } $sessionrow[] = $allsessiondates; $sessionrow[] = $allsessiontimes; // Capacity. $signupcount = facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_APPROVED); $stats = $session->capacity - $signupcount; if ($viewattendees) { $stats = $signupcount . ' / ' . $session->capacity; } else { $stats = max(0, $stats); } $sessionrow[] = $stats; // Status. $status = get_string('bookingopen', 'facetoface'); if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); $sessionstarted = true; } else { if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $status = get_string('sessionover', 'facetoface'); $sessionstarted = true; } else { if ($bookedsession && $session->id == $bookedsession->sessionid) { $signupstatus = facetoface_get_status($bookedsession->statuscode); $status = get_string('status_' . $signupstatus, 'facetoface'); $isbookedsession = true; } else { if ($signupcount >= $session->capacity) { $status = get_string('bookingfull', 'facetoface'); $sessionfull = true; } } } } $sessionrow[] = $status; // Options. $options = ''; if ($editsessions) { $options .= $this->output->action_icon(new moodle_url($CFG->wwwroot . '/mod/facetoface/' . 'sessions.php', array('s' => $session->id)), new pix_icon('t/edit', get_string('edit', 'facetoface')), null, array('title' => get_string('editsession', 'facetoface'))) . ' '; $options .= $this->output->action_icon(new moodle_url($CFG->wwwroot . '/mod/facetoface/' . 'sessions.php', array('s' => $session->id, 'c' => 1)), new pix_icon('t/copy', get_string('copy', 'facetoface')), null, array('title' => get_string('copysession', 'facetoface'))) . ' '; $options .= $this->output->action_icon(new moodle_url($CFG->wwwroot . '/mod/facetoface/' . 'sessions.php', array('s' => $session->id, 'd' => 1)), new pix_icon('t/delete', get_string('delete', 'facetoface')), null, array('title' => get_string('deletesession', 'facetoface'))) . ' '; $options .= html_writer::empty_tag('br'); } if ($viewattendees) { $options .= html_writer::link($CFG->wwwroot . '/mod/facetoface/' . 'attendees.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, get_string('attendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface'))) . html_writer::empty_tag('br'); } if ($isbookedsession) { $options .= html_writer::link($CFG->wwwroot . '/mod/facetoface/' . 'signup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, get_string('moreinfo', 'facetoface'), array('title' => get_string('moreinfo', 'facetoface'))) . html_writer::empty_tag('br'); $options .= html_writer::link($CFG->wwwroot . '/mod/facetoface/' . 'cancelsignup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); } else { if (!$sessionstarted and !$bookedsession) { $options .= html_writer::link($CFG->wwwroot . '/mod/facetoface/' . 'signup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, get_string('signup', 'facetoface')); } } if (empty($options)) { $options = get_string('none', 'facetoface'); } $sessionrow[] = $options; $row = new html_table_row($sessionrow); // Set the CSS class for the row. if ($sessionstarted) { $row->attributes = array('class' => 'dimmed_text'); } else { if ($isbookedsession) { $row->attributes = array('class' => 'highlight'); } else { if ($sessionfull) { $row->attributes = array('class' => 'dimmed_text'); } } } // Add row to table. $table->data[] = $row; } $output .= html_writer::table($table); return $output; }
function print_session_list($courseid, $facetoface, $location) { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $f2f_renderer = $PAGE->get_renderer('mod_facetoface'); $timenow = time(); $context = context_course::instance($courseid); $f2f_renderer->setcontext($context); $viewattendees = has_capability('mod/facetoface:viewattendees', $context); $editsessions = has_capability('mod/facetoface:editsessions', $context); $bookedsession = null; $submissions = facetoface_get_user_submissions($facetoface->id, $USER->id); if (!$facetoface->multiplesessions) { $submission = array_shift($submissions); $bookedsession = $submission; } $customfields = facetoface_get_session_customfields(); // print_object($customfields); $upcomingarray = array(); $previousarray = array(); $upcomingtbdarray = array(); if ($sessions = facetoface_get_custom_sessions($facetoface->id, $location)) { //print_object($sessions); $table = new html_table(); $table->summary = get_string('previoussessionslist', 'facetoface'); $table->attributes['class'] = 'generaltable fullwidth'; $table->head = $tableheader; $table->data = array(); foreach ($sessions as $session) { $sessionstarted = false; $sessionfull = false; $sessionwaitlisted = false; $isbookedsession = false; $sessiondata = $session; if ($facetoface->multiplesessions) { $submission = facetoface_get_user_submissions($facetoface->id, $USER->id,MDL_F2F_STATUS_REQUESTED, MDL_F2F_STATUS_FULLY_ATTENDED, $session->id); $bookedsession = array_shift($submission); } $sessiondata->bookedsession = $bookedsession; // $sessiondata->name=$session->name; if ($session->roomid) { $room = $DB->get_record('facetoface_room', array('id' => $session->roomid)); $sessiondata->room = $room; //$sessiondata->room = "Nrr"; } // Add custom fields to sessiondata $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); $sessiondata->customfielddata = $customdata; // Is session waitlisted if (!$session->datetimeknown) { $sessionwaitlisted = true; } // Check if session is started if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $sessionstarted = true; } elseif ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $sessionstarted = true; } // Put the row in the right table if ($sessionstarted) { $previousarray[] = $sessiondata; } elseif ($sessionwaitlisted) { $upcomingtbdarray[] = $sessiondata; } else { // Normal scheduled session $upcomingarray[] = $sessiondata; } } } // Upcoming sessions print_object($session); // Upcoming sessions $output=''; echo $OUTPUT->heading(get_string('upcomingsessions', 'facetoface')); if (empty($upcomingarray) && empty($upcomingtbdarray)) { print_string('noupcoming', 'facetoface'); } else { $upcomingarray = array_merge($upcomingarray, $upcomingtbdarray); $output = $f2f_renderer->print_session_list_custom_table($table,$tableheader,$session->name,$customfields, $upcomingarray, $viewattendees, $editsessions); } // $output=''; // $ff=$facetoface->id; // Previous sessions if (!empty($previousarray)) { //echo $OUTPUT->heading(get_string('previoussessions', 'facetoface')); $output =$f2f_renderer->print_session_list_custom_table($table,$tableheader,$sessionsname,$customfields, $previousarray, $viewattendees, $editsessions); } // $table = new html_table(); //echo $output; echo $out= html_writer::table($output); }
} } echo $OUTPUT->header(); $heading = get_string('signupfor', 'facetoface', $facetoface->name); $viewattendees = has_capability('mod/facetoface:viewattendees', $context); $signedup = facetoface_check_signup($facetoface->id); if ($signedup and $signedup != $session->id) { print_error('error:signedupinothersession', 'facetoface', $returnurl); } echo $OUTPUT->box_start(); echo $OUTPUT->heading($heading); $timenow = time(); if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $inprogressstr = get_string('cannotsignupsessioninprogress', 'facetoface'); $overstr = get_string('cannotsignupsessionover', 'facetoface'); $errorstring = facetoface_is_session_in_progress($session, $timenow) ? $inprogressstr : $overstr; echo html_writer::empty_tag('br') . $errorstring; echo $OUTPUT->box_end(); echo $OUTPUT->footer($course); exit; } if (!$signedup && !facetoface_session_has_capacity($session, $context) && !$session->allowoverbook) { print_error('sessionisfull', 'facetoface', $returnurl); echo $OUTPUT->box_end(); echo $OUTPUT->footer($course); exit; } echo facetoface_print_session($session, $viewattendees); if ($signedup) { if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow))) { // Cancellation link.
function print_session_list($courseid, $facetofaceid, $location) { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $f2frenderer = $PAGE->get_renderer('mod_facetoface'); $timenow = time(); $context = context_course::instance($courseid); $viewattendees = has_capability('mod/facetoface:viewattendees', $context); $editsessions = has_capability('mod/facetoface:editsessions', $context); $bookedsession = null; if ($submissions = facetoface_get_user_submissions($facetofaceid, $USER->id)) { $submission = array_shift($submissions); $bookedsession = $submission; } $customfields = facetoface_get_session_customfields(); $upcomingarray = array(); $previousarray = array(); $upcomingtbdarray = array(); if ($sessions = facetoface_get_sessions($facetofaceid, $location)) { foreach ($sessions as $session) { $sessionstarted = false; $sessionfull = false; $sessionwaitlisted = false; $isbookedsession = false; $sessiondata = $session; $sessiondata->bookedsession = $bookedsession; // Add custom fields to sessiondata. $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); $sessiondata->customfielddata = $customdata; // Is session waitlisted. if (!$session->datetimeknown) { $sessionwaitlisted = true; } // Check if session is started. $sessionstarted = facetoface_has_session_started($session, $timenow); if ($session->datetimeknown && $sessionstarted && facetoface_is_session_in_progress($session, $timenow)) { $sessionstarted = true; } else { if ($session->datetimeknown && $sessionstarted) { $sessionstarted = true; } } // Put the row in the right table. if ($sessionstarted) { $previousarray[] = $sessiondata; } else { if ($sessionwaitlisted) { $upcomingtbdarray[] = $sessiondata; } else { // Normal scheduled session. $upcomingarray[] = $sessiondata; } } } } // Upcoming sessions. echo $OUTPUT->heading(get_string('upcomingsessions', 'facetoface')); if (empty($upcomingarray) && empty($upcomingtbdarray)) { print_string('noupcoming', 'facetoface'); } else { $upcomingarray = array_merge($upcomingarray, $upcomingtbdarray); echo $f2frenderer->print_session_list_table($customfields, $upcomingarray, $viewattendees, $editsessions); } if ($editsessions) { $addsessionlink = html_writer::link(new moodle_url('sessions.php', array('f' => $facetofaceid)), get_string('addsession', 'facetoface')); echo html_writer::tag('p', $addsessionlink); } // Previous sessions. if (!empty($previousarray)) { echo $OUTPUT->heading(get_string('previoussessions', 'facetoface')); echo $f2frenderer->print_session_list_table($customfields, $previousarray, $viewattendees, $editsessions); } }
function print_session_list($courseid, $facetoface, $location,$currenttab) { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $f2f_renderer = $PAGE->get_renderer('mod_facetoface'); $timenow = time(); $context = context_course::instance($courseid); $f2f_renderer->setcontext($context); $viewattendees = has_capability('mod/facetoface:viewattendees', $context); $editsessions = has_capability('mod/facetoface:editsessions', $context); $bookedsession = null; $submissions = facetoface_get_user_submissions($facetoface->id, $USER->id); if (!$facetoface->multiplesessions) { $submission = array_shift($submissions); $bookedsession = $submission; } $customfields = facetoface_get_session_customfields(); // print_object($customfields); $upcomingarray = array(); $previousarray = array(); $upcomingtbdarray = array(); if ($sessions = facetoface_get_custom_sessions($facetoface->id, $location)) { //print_object($sessions); $tableheader = array(); $tableheader[] = get_string('session_name','facetoface'); $tableheader[] = get_string('date', 'facetoface'); $tableheader[] = get_string('time', 'facetoface'); $tableheader[] = get_string('room', 'facetoface'); $tableheader[] = get_string('capacity', 'facetoface'); $tableheader[] = get_string('status', 'facetoface'); $tableheader[] = get_string('options', 'facetoface'); $table = new html_table(); $table->summary = get_string('previoussessionslist', 'facetoface'); $table->attributes['class'] = 'generaltable fullwidth'; $table->head = $tableheader; $table->data = array(); foreach ($sessions as $session) { $sessionstarted = false; $sessionfull = false; $sessionwaitlisted = false; $isbookedsession = false; $sessiondata = $session; // $sessiondata->bookedsession = $bookedsession; // $sessiondata->name=$session->name; if ($session->roomid) { $room = $DB->get_record('facetoface_room', array('id' => $session->roomid)); $sessiondata->room = $room; } // Add custom fields to sessiondata $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); $sessiondata->customfielddata = $customdata; // Is session waitlisted if (!$session->datetimeknown) { $sessionwaitlisted = true; } // Check if session is started if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $sessionstarted = true; } elseif ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $sessionstarted = true; } // Put the row in the right table if ($sessionstarted) { $previousarray[] = $sessiondata; } elseif ($sessionwaitlisted) { $upcomingtbdarray[] = $sessiondata; } else { // Normal scheduled session $upcomingarray[] = $sessiondata; } } } // Upcoming sessions //print_object($sessions); // Upcoming sessions $output=''; echo "<h2 class='tmhead2'>".get_string('sessions','facetoface')."</h2>"; echo '<div>'; echo '<a href="'.$CFG->wwwroot.'/course/modedit.php?add=facetoface&type=&course=1§ion=1&return=0" > Add New Session </a>'; echo '</div>'; print_sessiontabs($currenttab); $output=''; if($currenttab=="upcoming") { echo $OUTPUT->heading(get_string('upcomingsessions', 'facetoface')); if (empty($upcomingarray) && empty($upcomingtbdarray)) { print_string('noupcoming', 'facetoface'); } else { $upcomingarray = array_merge($upcomingarray, $upcomingtbdarray); $output = $f2f_renderer->print_session_list_custom_table($table,$tableheader,$session->name,$customfields, $upcomingarray, $viewattendees, $editsessions); echo $out= html_writer::table($output); } } else if($currenttab=="previous") { // // $ff=$facetoface->id; // Previous sessions if (!empty($previousarray)) { echo $OUTPUT->heading(get_string('previoussessions', 'facetoface')); $output =$f2f_renderer->print_session_list_custom_table($table,$tableheader,$sessionsname,$customfields, $previousarray, $viewattendees, $editsessions); echo $out= html_writer::table($output); } } // $table = new html_table(); //echo $output; }
function test_facetoface_is_session_in_progress() { // Define test variables. $session1 = $this->sessions['sess0']; $sess0 = $this->array_to_object($session1); $sess0->sessiondates = array(0 => new stdClass()); $sess0->sessiondates[0]->timestart = time() - 100; $sess0->sessiondates[0]->timefinish = time() + 100; $session2 = $this->sessions['sess1']; $sess1 = $this->array_to_object($session2); $timenow = time(); // Test for valid case. $this->assertTrue((bool)facetoface_is_session_in_progress($sess0, $timenow), $this->msgtrue); // Test for invalid case. $this->assertFalse((bool)facetoface_is_session_in_progress($sess1, $timenow), $this->msgfalse); $this->resetAfterTest(true); }