protected function applyLimits($assign_course_trainer)
 {
     $username = $this->getUser()->username;
     $user_info = iHRIS_PageFormLecturer::fetch_user_info($username);
     $inst_id = $user_info["training_institution"];
     $dep_id = $user_info["department"];
     $where_lecturer = array("operator" => "FIELD_LIMIT", "field" => "training_institution", "style" => "equals", "data" => array("value" => $inst_id));
     $lecturer_field = $assign_course_trainer->getField("lecturer");
     $lecturer_field->setOption(array("meta", "limits", "default", "lecturer"), $where_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_institution", "style" => "equals", "data" => array("value" => $inst_id))));
     $assigned_courses_array = I2CE_FormStorage::listFields("assign_course_trainer", array("training"), false, $where_assigned);
     foreach ($assigned_courses_array as $assigned_course) {
         $courses = explode(",", $assigned_course["training"]);
         foreach ($courses as $course) {
             list($form, $assigned_courses[]) = array_pad(explode("|", $course, 2), 2, "");
         }
     }
     $trng_prgrms = iHRIS_PageFormEnrollcourse::get_department_programs();
     $where_courses = array("operator" => "FIELD_LIMIT", "field" => "training_program", "style" => "in", "data" => array("value" => $trng_prgrms));
     $course_field = $assign_course_trainer->getField("training");
     $course_field->setOption(array("meta", "limits", "default", "training"), $where_courses);
     $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 = $assign_course_trainer->getField("academic_year");
     $ac_field->setOption(array("meta", "limits", "default", "academic_year"), $where);
 }
 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########################
 }
 static function get_department_programs()
 {
     $ff = I2CE_FormFactory::instance();
     $pageObj = new I2CE_Page();
     $username = $pageObj->getUser()->username;
     $user_info = iHRIS_PageFormLecturer::fetch_user_info($username);
     $dep_id = $user_info["department"];
     $all_trng_prgrms = self::get_institution_programs();
     foreach ($all_trng_prgrms as $prgrms) {
         $progObj = $ff->createContainer($prgrms);
         $progObj->populate();
         if ($progObj->getField("department")->getDBValue() == $dep_id) {
             $trng_prgrms[] = $prgrms;
         }
     }
     return $trng_prgrms;
 }