protected function applyLimits($resAppObj)
 {
     $username = $this->getUser()->username;
     $user_info = iHRIS_PageFormLecturer::fetch_user_info($username);
     $inst_id = $user_info["training_institution"];
     $academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     ####################Limiting the display of training courses####################
     //get list of training that are having end of semester assessment
     $trng_prgrms = iHRIS_PageFormEnrollcourse::get_department_programs();
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_course_exam_type", "style" => "equals", "data" => array("training_course_exam_type|final")), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $trng_prgrms))));
     $trainings = I2CE_FormStorage::search("training", false, $where);
     foreach ($trainings as $training) {
         $training_courses[] = "training|" . $training;
     }
     //get list of courses assigned to lecturers
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $inst_id))));
     $trainer_assigned_courses = I2CE_FormStorage::listFields("assign_course_trainer", array("training"), false, $where);
     $assigned_courses = array();
     if (is_array($trainer_assigned_courses)) {
         foreach ($trainer_assigned_courses as $crs) {
             $assigned_courses[] = $crs["training"];
         }
     }
     //get list of courses for which results have been uploaded
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "in", "data" => array("value" => $training_courses))));
     $results = I2CE_FormStorage::listFields("students_results_grade", array("training"), false, $where);
     unset($training_courses);
     if (count($results) > 0) {
         foreach ($results as $id => $result) {
             //avoid displaying courses with results,but from other institutions
             if (!in_array($result["training"], $assigned_courses)) {
                 continue;
             }
             $course = explode("|", $result["training"]);
             $training_courses[] = $course[1];
         }
     }
     //end of getting list of courses for which results have been uploaded
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "in", "data" => array("value" => $training_courses));
     $course_field = $resAppObj->getField("training");
     $course_field->setOption(array("meta", "limits", "default", "training"), $where);
     #######################End of limiting the display of training courses###########################
     ####################Limiting the display of training institution######################
     $train_inst_id = explode("|", $inst_id);
     $train_inst_id = $train_inst_id[1];
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $train_inst_id));
     $inst_field = $resAppObj->getField("training_institution");
     $inst_field->setOption(array("meta", "limits", "default", "training_institution"), $where);
     ####################End Limiting the display of training institution######################
     ###################Limiting the display of academic year###############################
     $ac_yr = explode("|", $academic_year_id);
     $ac_yr = $ac_yr[1];
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $ac_yr));
     $acyr_field = $resAppObj->getField("academic_year");
     $acyr_field->setOption(array("meta", "limits", "default", "academic_year"), $where);
     ###################End of Limiting the display of acdemic year########################
 }
 /**
  * Create and load data for the objects used for this form.
  */
 protected function loadObjects()
 {
     $this->ff = I2CE_FormFactory::instance();
     //check to ensure that the current academic year is available
     iHRIS_AcademicYear::ensureAcademicYear();
     $selected_courses = $this->post("course");
     $person_id = $this->post("person_id");
     $curr_semester = $this->post("curr_semester");
     $student_registration = STS_PageFormPerson::load_current_registration($person_id);
     if (count($selected_courses) == 0) {
         $this->userMessage("No courses Selected!!!");
         $this->setRedirect("view?id=" . $this->person_id);
     }
     foreach ($selected_courses as $course) {
         $courseObj = $this->factory->createContainer($course);
         $courseObj->populate();
         $total_credits = $total_credits + $courseObj->getField("course_credits")->getDBValue();
     }
     $selected_courses = implode(",", $selected_courses);
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $person_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $curr_semester)), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $student_registration["id"]))));
     $enrolled_courses = I2CE_FormStorage::search("enroll_course", false, $where);
     if (count($enrolled_courses) > 0) {
         foreach ($enrolled_courses as $enrollment) {
             $course_enrollment_form = "enroll_course|" . $enrollment;
         }
     } else {
         $course_enrollment_form = "enroll_course";
     }
     if (!($enrollcourseObj = $this->ff->createContainer($course_enrollment_form)) instanceof I2CE_Form) {
         I2CE::raiseError("Invalid Object");
         return false;
     }
     $trainingCourseField = $enrollcourseObj->getField("training");
     $trainingCourseField->setFromPost($selected_courses);
     $date_enrolled = date("Y-m-d");
     $enrollcourseObj->getField("date_enrolled")->setFromDB($date_enrolled);
     $semesterField = $enrollcourseObj->getField("semester");
     $semesterField->setFromPost($curr_semester);
     $enrollcourseObj->getField("total_credits")->setValue($total_credits);
     $enrollcourseObj->getField("registration")->setFromDB($student_registration["id"]);
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     if (!($academicYearField = $enrollcourseObj->getField("academic_year")) instanceof I2CE_FormField_MAP) {
         return;
     }
     $academicYearField->setFromDB($academic_year_id);
     $parentObj = $this->ff->createContainer($person_id);
     if ($parentObj instanceof I2CE_Form) {
         $parentObj->populate();
     }
     $this->setObject($enrollcourseObj, I2CE_PageForm::EDIT_PRIMARY);
     $this->setObject($parentObj, I2CE_PageForm::EDIT_PARENT);
     parent::save();
     $this->userMessage("Courses Enrolled Successfully");
     $this->setRedirect("view?id=" . $person_id);
     return true;
 }
예제 #3
0
 /**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.
  */
 protected function loadObjects()
 {
     $role = $this->getUser()->role;
     if ($role != "registrar") {
         $this->userMessage("Only Registrar Can Add Students");
         $this->setRedirect("home");
     }
     //check to ensure that the current academic year is available
     iHRIS_AcademicYear::ensureAcademicYear();
     $username = $this->getUser()->username;
     $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
     $factory = I2CE_FormFactory::instance();
     if ($this->isPost()) {
         $person = $factory->createContainer("person");
         $person->load($this->post);
         $regObj = $factory->createContainer("registration");
         $regObj->load($this->post);
         $regObj->getField("training_institution")->setFromDB($inst_id);
         $regObj->getField("registration_status")->setFromDB("registration_status|ongoing");
         $program = $regObj->getField("training_program")->getDBValue();
         $st_reg_num = self::generateRegistrationNumber($program, $inst_id);
         $regObj->getField("registration_number")->setFromPost($st_reg_num);
     } else {
         if ($this->get_exists('id')) {
             $id = $this->get('id');
             if (strpos($id, '|') === false) {
                 I2CE::raiseError("Depcreated use of id variable");
                 $id = 'person|' . $id;
             }
         } else {
             $id = 'person|0';
         }
         $person = $factory->createContainer($id);
         if ($this->get_exists('id')) {
             $person->populateChildren("registration");
             foreach ($person->getChildren("registration") as $regObj) {
             }
         } else {
             $regObj = $this->factory->createContainer("registration|0");
         }
         if (!$person instanceof iHRIS_Person) {
             I2CE::raiseError("Could not create valid person form from id:{$id}");
             return;
         }
         $person->populate();
         $person->load($this->request());
     }
     $this->applyLimits($inst_id, $person, $regObj);
     $this->template->setForm($regObj);
     $this->template->setForm($person);
 }
 protected function showCourses()
 {
     if (!($listNode = $this->template->getElementByID("existing_course_list")) instanceof DOMNode) {
         return;
     }
     if ($this->getUser()->role == "registrar" || $this->getUser()->role == "lecturer" || $this->getUser()->role == "hod" || $this->getUser()->role == "principal" || $this->getUser()->role == "deputy_principal") {
         ######getting id of the currently logged in lecturer######
         $username = $this->getUser()->username;
         $where = array("operator" => "FIELD_LIMIT", "field" => "identification_number", "style" => "equals", "data" => array("value" => $username));
         $lecturer = I2CE_FormStorage::search("lecturer", false, $where);
         foreach ($lecturer as $id) {
             $lecturer_id = "lecturer|" . $id;
         }
         ######Getting the current academic year######
         $academic_year = iHRIS_AcademicYear::currentAcademicYear();
         $where = array("operator" => "FIELD_LIMIT", "field" => "name", "style" => "equals", "data" => array("value" => $academic_year));
         $academic_year_id = I2CE_FormStorage::Search("academic_year", false, $where);
         $academic_year_id = "academic_year|" . $academic_year_id[0];
         ######Getting a list of courses assigned to this lecturer######
         $where_assign_course = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "lecturer", "style" => "equals", "data" => array("value" => $lecturer_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id))));
         $assigned_courses = I2CE_FormStorage::listFields("assign_course_trainer", array("training"), false, $where_assign_course);
     } else {
         $this->userMessage("Login as a training provider to add results");
         $this->redirect("manage?action=provider");
         return false;
     }
     ######Displaying courses assigned to this lecturer######
     if (count($assigned_courses) == 0) {
         $this->userMessage("No courses assigned to you,contact the Registrar for further assistance");
         $this->redirect("manage?action=provider");
         return false;
     }
     foreach ($assigned_courses as $id => $course) {
         $course_id = explode("|", $course["training"]);
         $course_id = $course_id[1];
         $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $course_id));
         $training_courses = I2CE_FormStorage::ListFields("training", array("name", "code"), false, $where);
         foreach ($training_courses as $id => $training_course) {
             $course_name = $training_course["name"];
             $course_code = $training_course["code"];
             $course = $course_code . "-" . $course_name;
             $id = "training|" . $id;
             $aNode = $this->template->createElement("a", array(href => "add_results?id=" . $id), $course);
             $liNode = $this->template->createElement("li");
             $this->template->appendNode($aNode, $liNode);
             $this->template->appendNode($liNode, $listNode);
         }
     }
 }
 protected function action()
 {
     if (!$this->hasPermission("task(can_add_students_results)" or $this->getUser()->role == "admin")) {
         $this->setRedirect("noaccess");
     }
     $this->ff = I2CE_FormFactory::instance();
     $this->user = new I2CE_User();
     //check to ensure that the current academic year is available
     iHRIS_AcademicYear::ensureAcademicYear();
     $this->current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($this->current_academic_year);
     $this->academic_year_id = "academic_year|" . $academic_year_id;
     $this->course_id = $this->request("course_id");
     if (!($courseObj = $this->ff->createContainer($this->course_id)) instanceof iHRIS_Training || !($examTypesField = $courseObj->getField('training_course_exam_type')) instanceof I2CE_FormField_MAP_MULT) {
         I2CE::raiseError("Invalid training course: " . $this->course_id);
         return false;
     }
     $courseObj->populate();
     $reg_numbers = $this->post("reg_num");
     ######start processing results of each student######
     foreach ($reg_numbers as $this->reg_num) {
         $this->getParentId($this->reg_num);
         $all_results = false;
         $this->update = false;
         ######process each course assessment for this student######
         $exam_types = explode(",", $examTypesField->getDBValue());
         foreach ($exam_types as $exam_type) {
             if ($this->post_exists($this->reg_num . "_results")) {
                 $this->students_results_grade_form = "students_results_grade|" . $this->post($this->reg_num . "_results");
                 break;
             } else {
                 $this->students_results_grade_form = "students_results_grade";
             }
         }
         foreach ($exam_types as $exam_type) {
             ######Skip processing existing assessment results######
             $mark = $this->check_assessment_mark($exam_type);
             if ($this->post($exam_type . "/" . $this->reg_num) != "" and $mark < 0) {
                 $this->results[$exam_type] = $this->post($exam_type . "/" . $this->reg_num);
             }
         }
         if (count($this->results) > 0) {
             $this->saveResults($exam_types);
         }
         unset($this->results);
         ######End of processing each course assessment for this student######
     }
     ######End of processing results of each student######
 }
 protected function getElectiveCourses($curr_semester)
 {
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $current_academic_year_id = "academic_year|" . $academic_year_id;
     $semester = self::getSemesterName($curr_semester);
     $trng_prgrms = self::get_institution_programs();
     unset($trng_prgrms[$this->program]);
     for ($semester = $semester; $semester > 0; $semester = $semester - 2) {
         $semester_id = "semester|" . self::getSemesterId($semester);
         $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $semester_id)), 1 => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $trng_prgrms)))));
         $courses = I2CE_FormStorage::listFields("training", array("id"), false, $where);
         foreach ($courses as $id => $course_array) {
             $training_course = "training|" . $id;
             if ($this->is_rescheduled($training_course, $current_academic_year_id, $curr_semester)) {
                 continue;
             }
             //check if a student took and passed this course then skip displaying it
             $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "equals", "data" => array("value" => $training_course)), 1 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $this->person_id)), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $this->student_registration["id"]))));
             $results = I2CE_FormStorage::ListFields("students_results_grade", array("total_marks", "status"), false, $where);
             $status = "display";
             foreach ($results as $result) {
                 if ($result["status"] == "status|pass") {
                     $status = "pass";
                     break;
                 }
             }
             if ($status == "display") {
                 $this->elective_courses[$id] = $training_course;
             }
         }
         //get elective courses that have been rescheduled to this semester
         $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $current_academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $semester)), 2 => array("operator" => "NOT", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "equals", "data" => array("value" => $this->program)))), 3 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $this->training_institution))));
         $courses = I2CE_FormStorage::listFields("reschedule_course", array("training"), false, $where);
         foreach ($courses as $course) {
             $trn_id = explode("|", $course["training"]);
             $id = $trn_id[1];
             $this->elective_courses[$id] = $course["training"];
         }
     }
 }
 protected function is_approved($results_academic_year, $course)
 {
     $academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     if ($results_academic_year != $academic_year_id) {
         return true;
     }
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "like", "data" => array("value" => "%" . $course . "%")), 2 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $this->student_registration["training_institution"]))));
     $is_approved = I2CE_FormStorage::search("results_approval", false, $where);
     if (count($is_approved) > 0) {
         return true;
     }
     return false;
 }
 protected function action()
 {
     if (!$this->hasPermission("task(can_add_students_results)" or $this->getUser()->role == "admin")) {
         $this->setRedirect("noaccess");
         return;
     }
     $this->ff = I2CE_FormFactory::instance();
     //update academic year
     iHRIS_AcademicYear::ensureAcademicYear();
     //retrive the academic year
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     $this->course_id = $this->request("id");
     $where_course_id = array("operator" => "AND", "operand" => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'training', 'style' => 'like', 'data' => array('value' => "%" . $this->course_id . "%")), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'academic_year', 'style' => 'equals', 'data' => array('value' => $academic_year_id))));
     $parents = I2CE_FormStorage::listFields("enroll_course", array("parent", "training", "academic_year"), false, $where_course_id);
     if (!($listNode = $this->template->getElementByID("students_list")) instanceof DOMNode) {
         return;
     }
     if (!($hidden_data = $this->template->getElementByID("hidden_data")) instanceof DOMNode) {
         return;
     }
     if (count($parents) == 0) {
         $this->userMessage("No students enrolled for this course!!!");
         $this->setRedirect("add_results_select_course");
     }
     $input = $this->template->createElement("input", array("type" => "hidden", "name" => "course_id", "value" => $this->course_id));
     $this->template->appendNode($input, $listNode);
     $table = $this->template->createElement("table", array("class" => "multiFormTable", "width" => "100%", "border" => "0", "cellpadding" => "0", "cellspacing" => "0"));
     $tr = $this->template->createElement("tr");
     $th = $this->template->createElement("th", array("width" => "60%"), "Student Name");
     $this->template->appendNode($th, $tr);
     $th = $this->template->createElement("th", "", "Registration Number");
     $this->template->appendNode($th, $tr);
     $this->appendExamTypesHeaders($tr);
     $this->template->appendNode($tr, $table);
     //retrieving the max mark for each assessment
     foreach ($this->exam_types as $exam_type) {
         list($form, $id) = array_pad(explode("|", $exam_type, 2), 2, '');
         list($form, $course_id) = array_pad(explode("|", $this->course_id, 2), 2, '');
         $max_mark = I2CE_FormStorage::lookupField("training", $course_id, array($id), false);
         $max_mark = $max_mark[$id];
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => $id, "id" => $id, "value" => $max_mark));
         $this->template->appendNode($input, $listNode);
     }
     //fecth lecturer institution to make sure can see students for his/her institution
     $username = $this->getUser()->username;
     $inst_id = iHRIS_PageFormLecturer::fetch_institution($username);
     foreach ($parents as $enroll_id => $parent) {
         $reg_details = STS_PageFormPerson::load_current_registration($person_id);
         ###drop students which are on different institution###
         if ($inst_id != $reg_details["training_institution"]) {
             continue;
         }
         $trainings = explode(",", $parent["training"]);
         $tr = $this->template->createElement("tr");
         $person_id = $parent["parent"];
         $reg_num = $this->getRegistrationNumber($person_id);
         $input = $this->template->createElement("input", array("type" => "hidden", "name" => "reg_num[" . $reg_num . "]", "value" => $reg_num));
         $this->template->appendNode($input, $tr);
         list($form, $id) = array_pad(explode("|", $person_id, 2), 2, '');
         $field_data = I2CE_FormStorage::lookupField("person", $id, array('firstname', 'surname'), false);
         if (is_array($field_data) && array_key_exists('surname', $field_data) && array_key_exists('firstname', $field_data)) {
             $fullname = $field_data['firstname'] . ' ' . $field_data['surname'];
             $aNode = $this->template->createElement("a", array("href" => "view?id=" . $person_id), $fullname);
             $td = $this->template->createElement("td");
             $this->template->appendNode($aNode, $td);
             $this->template->appendNode($td, $tr);
             $td = $this->template->createElement("td", array("id" => $reg_num, "align" => "center"));
             $this->template->addTextNode($reg_num, $reg_num, $td);
             $this->template->appendNode($td, $tr);
             $this->appendExamTypesInput($tr, $reg_num, $person_id, $this->course_id, $parent["academic_year"], $enroll_id);
         }
         $this->template->appendNode($tr, $table);
     }
     $tr = $this->template->createElement("tr");
     $td = $this->template->createElement("td", array("colspan" => "10", "align" => "right"));
     $input = $this->template->createElement("input", array("type" => "submit", "value" => "Save", "onclick" => "return verify()"));
     $this->template->appendNode($input, $td);
     $this->template->appendNode($td, $tr);
     $this->template->appendNode($tr, $table);
     $this->template->appendNode($table, $listNode);
 }
 protected function save()
 {
     $username = $this->getUser()->username;
     $training_institution = iHRIS_PageFormLecturer::fetch_institution($username);
     $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
     $assign_course_trainer->load($this->post);
     $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
     $lecturer = $assign_course_trainer->getField("lecturer")->getDBValue();
     $training_courses = $assign_course_trainer->getField("training")->getDBValue();
     $academic_year = $assign_course_trainer->getField("academic_year")->getDBValue();
     $training_courses = explode(",", $training_courses);
     $lecturers = explode(",", $lecturer);
     foreach ($lecturers as $lecturer) {
         foreach ($training_courses as $training_course) {
             //check if this course has been assigned for this lecturer
             $academic_year = iHRIS_AcademicYear::currentAcademicYear();
             $academic_year_id = iHRIS_AcademicYear::academicYearId($academic_year);
             $academic_year_id = "academic_year|" . $academic_year_id;
             $where_assigned = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "academic_year", "style" => "equals", "data" => array("value" => $academic_year_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training", "style" => "equals", "data" => array("value" => $training_course)), 2 => array("operator" => "FIELD_LIMIT", "field" => "lecturer", "style" => "equals", "data" => array("value" => $lecturer)), 3 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution))));
             $is_assigned = I2CE_FormStorage::search("assign_course_trainer", false, $where_assigned);
             if (count($is_assigned) > 0) {
                 continue;
             }
             $assign_course_trainer = $this->factory->createContainer("assign_course_trainer");
             $assign_course_trainer->getField("lecturer")->setFromDB($lecturer);
             $assign_course_trainer->getField("academic_year")->setFromDB($academic_year_id);
             $assign_course_trainer->getField("training")->setFromDB($training_course);
             $assign_course_trainer->getField("training_institution")->setFromDB($training_institution);
             /***alert HOD***/
             //get lecturer department
             $lectObj = $this->factory->createContainer($lecturer);
             $lectObj->populate();
             $lect_dep_id = $lectObj->getField("department")->getDBValue();
             //get course department
             $trainObj = $this->factory->createContainer($training_course);
             $trainObj->populate();
             $program = $trainObj->getField("training_program")->getDBValue();
             $progObj = $this->factory->createContainer($program);
             $progObj->populate();
             $course_dep_id = $progObj->getField("department")->getDBValue();
             $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $training_institution)), 1 => array("operator" => "OR", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $lect_dep_id)), 1 => array("operator" => "FIELD_LIMIT", "field" => "department", "style" => "equals", "data" => array("value" => $course_dep_id)))), 2 => array("operator" => "FIELD_LIMIT", "field" => "role", "style" => "equals", "data" => array("value" => "role|hod"))));
             $hods = I2CE_FormStorage::listFields("lecturer", array("identification_number"), false, $where);
             $module_factory = I2CE_ModuleFactory::instance();
             $code = $trainObj->getField("code")->getDBValue();
             $course_name = $trainObj->getField("name")->getDBValue();
             $lect_fname = $lectObj->getField("first_name")->getDBValue();
             $lect_sname = $lectObj->getField("surname")->getDBValue();
             $lect_oname = $lectObj->getField("other_name")->getDBValue();
             $lect_name = $lect_fname . " " . $lect_oname . " " . $lect_sname;
             $lect_name = trim($lect_name);
             foreach ($hods as $hod) {
                 if ($module_factory->isEnabled("UserAlerts")) {
                     $alerts = $module_factory->getClass("UserAlerts");
                     $alerts->sendUserAlert($hod["identification_number"], 'notice', $code . "-" . $course_name . " Has Been Assigned To " . $lect_name, 'CustomReports/show/lecturer_assigned_courses', 'Vew Course Assignment Report');
                 } else {
                     I2CE::raiseError("Tried to send user alert, but the module isn't enabled.");
                 }
             }
             /***End of alerting HOD***/
             $assign_course_trainer->save($this->user);
         }
     }
     $this->userMessage("Course(s) Assigned To Trainer!!!");
     $this->setRedirect("assign_course_trainer");
 }
 protected function applyLimits($primary, $inst_id, $role)
 {
     $all_trng_prgrms = iHRIS_PageFormEnrollcourse::get_institution_programs();
     $dep_training_prgrms = iHRIS_PageFormEnrollcourse::get_department_programs();
     $semesters = array("semester|1", "semester|3", "semester|5");
     if ($role == "registrar") {
         $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "in", "data" => array("value" => $semesters)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $all_trng_prgrms))));
     } else {
         if ($role == "hod") {
             $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "in", "data" => array("value" => $semesters)), 1 => array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $dep_training_prgrms))));
         }
     }
     $training = $primary->getField("training");
     $training->setOption(array("meta", "limits", "default", "training"), $where);
     iHRIS_AcademicYear::ensureAcademicYear();
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $academic_year_id));
     $ac_yr = $primary->getField("academic_year");
     $ac_yr->setOption(array("meta", "limits", "default", "academic_year"), $where);
 }
 /**
  * Save the objects to the database.
  * 
  * Save the default object being edited and return to the view page.
  * @global array
  */
 protected function save()
 {
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $academic_year_id = "academic_year|" . $academic_year_id;
     $dropSemObj = $this->factory->createContainer("drop_semester");
     $dropSemObj->load($this->post);
     $dropSemObj->getField("registration")->setFromDB($this->student_registration["id"]);
     //drop results for this semester and all enrolled courses.
     $where = array("operator" => "AND", "operand" => array(0 => array("operator" => "FIELD_LIMIT", "field" => "parent", "style" => "equals", "data" => array("value" => $this->getPrimary()->getParent())), 1 => array("operator" => "FIELD_LIMIT", "field" => "semester", "style" => "equals", "data" => array("value" => $this->student_registration["semester"])), 2 => array("operator" => "FIELD_LIMIT", "field" => "registration", "style" => "equals", "data" => array("value" => $this->student_registration["id"]))));
     $enrolled_courses = I2CE_FormStorage::search("enroll_course", false, $where);
     foreach ($enrolled_courses as $enroll_id) {
         $where = array("operator" => "FIELD_LIMIT", "field" => "enroll_course", "style" => "equals", "data" => array("value" => "enroll_course|" . $enroll_id));
         $results = I2CE_FormStorage::search("students_results_grade", false, $where);
         foreach ($results as $id) {
             $resObj = $this->factory->createContainer("students_results_grade|" . $id);
             $resObj->populateChildren("students_results");
             foreach ($resObj->getChildren("students_results") as $stResObj) {
                 $stResObj->populate();
                 $stResObj->delete();
             }
             $resObj->populate();
             $resObj->delete();
         }
         $enrObj = $this->factory->createContainer("enroll_course|" . $enroll_id);
         $enrObj->populate();
         $enrObj->delete();
     }
     $dropSemObj->save($this->user);
     $dropSemObj->cleanup();
     if ($saved !== false) {
         $message = "Student Dropped From Current Semester.";
     } else {
         $message = "Failed To Drop A Student From This Semester.";
     }
     $this->userMessage($message);
     $this->setRedirect("view?id=" . $this->getPrimary()->getParent());
     return $saved;
 }
 public static function getMethods()
 {
     return array('iHRIS_PageView->action_overall_GPA' => 'action_overall_GPA');
     iHRIS_AcademicYear::ensureAcademicYear();
 }
 protected function applyLimits($primary)
 {
     $current_academic_year = iHRIS_AcademicYear::currentAcademicYear();
     $academic_year_id = iHRIS_AcademicYear::academicYearId($current_academic_year);
     $where = array("operator" => "FIELD_LIMIT", "field" => "id", "style" => "equals", "data" => array("value" => $academic_year_id));
     $ac_field = $primary->getField("academic_year");
     $ac_field->setOption(array("meta", "limits", "default", "academic_year"), $where);
 }