Example #1
0
 public function index()
 {
     error_reporting(E_ALL & ~E_WARNING & ~E_STRICT);
     $this->load->helper('url');
     //$uid = $_SESSION['UserID'];
     /*if (!isset($_SESSION['UserID']))
       {
           redirect('login');
       }*/
     $user = new User_model();
     if (!$user->loadPropertiesFromPrimaryKey($_SESSION['UserID'])) {
         redirect('Login/logout');
     }
     if ($user->isStudent()) {
         $this->uid = $user->getUserID();
     } else {
         if ($user->isAdvisor()) {
             if ($this->uri->segment(3)) {
                 $this->uid = $this->uri->segment(3);
             } else {
                 if ($_SESSION['StudCWID']) {
                     $this->uid = $_SESSION['StudCWID'];
                 } else {
                     redirect('Login');
                 }
             }
         } else {
             redirect('Login');
         }
     }
     $_SESSION['StudCWID'] = $this->uid;
     // $uid = 10210078;
     //$year = 2015;
     $prev_form = $this->loadAdvisingForm($this->uid);
     /*if (isset($_SESSION['StudentFormUID']))
       {
           $prev_form = $this->loadAdvisingForm($_SESSION['StudentFormUID']);
       }
       else
       {
           $prev_form = $this->loadAdvisingForm($_SESSION['UserID']);
       }*/
     //Get course list for student
     //First, get all courses for current quarter, set now to 'NAME_SPRING'
     $quarter = academic_quarter_model::NAME_SPRING;
     $aqm = academic_quarter_model::getLatestAcademicQuarter();
     //$aqm = new academic_quarter_model();
     //$aqm->loadPropertiesFromNameAndYear($quarter, $year);
     $qid = $aqm->getAcademicQuarterID();
     $course_sections = $aqm->getAllCourseSections();
     //Next, load the current user and get his courses taken
     $usermod = new user_model();
     $usermod->loadPropertiesFromPrimaryKey($this->uid);
     $courseids = array();
     //Get all of the course IDs for courses in the student's curricula
     $curricula = $usermod->getCurriculums();
     foreach ($curricula as $curriculum) {
         $slots = $curriculum->getCurriculumCourseSlots();
         foreach ($slots as $slot) {
             $validIDs = $slot->getValidCourseIDs();
             foreach ($validIDs as $cor) {
                 if (!in_array($cor, $courseids)) {
                     array_push($courseids, $cor);
                 }
             }
         }
     }
     //Now, remove each course section that does not fit into the student's curricula
     foreach ($course_sections as $key => $value) {
         if (!in_array($value->getCourse()->getCourseID(), $courseids)) {
             unset($course_sections[$key]);
         }
     }
     //Then, we can remove courses whose prerequisites are not met
     $courseIDs_passed = array();
     foreach ($course_sections as $key => $value) {
         $prereqs = $value->getCourse()->getPrerequisiteCourses();
         if (count($prereqs) != 0) {
             $sig_required = true;
             foreach ($prereqs as $prereq) {
                 if (array_search($prereq->getCourseID(), $courseIDs_passed) == true) {
                     $sig_required = false;
                     break;
                 }
             }
             if ($sig_required) {
                 unset($course_sections[$key]);
             }
         }
     }
     $courses_taken = $usermod->getAllCoursesTaken();
     if (!empty($courses_taken)) {
         //Populate an array of course IDs for which the course was passed by the student
         foreach ($courses_taken as $key => $value) {
             if (!empty($value)) {
                 if (!empty($value[0]->getCourse()->getAllCurriculumCourseSlots())) {
                     $min_grade = $value[0]->getCourse()->getAllCurriculumCourseSlots()[0]->getMinimumGrade();
                     switch ($min_grade) {
                         case 4:
                             $min_grade = 'A';
                             break;
                         case 3:
                             $min_grade = 'B';
                             break;
                         case 2:
                             $min_grade = 'C';
                             break;
                         case 1:
                             $min_grade = 'D';
                             break;
                         default:
                             $min_grade = 'ZZZZZZ';
                             break;
                     }
                     if ($usermod->getGradeForCourseSection($value[0]) <= $min_grade) {
                         array_push($courseIDs_passed, $value[0]->getCourse()->getCourseID());
                     }
                 }
             }
         }
     }
     foreach ($course_sections as $key => $value) {
         if (in_array($value->getCourse()->getCourseID(), $courseIDs_passed)) {
             unset($course_sections[$key]);
         }
     }
     //Now, we should have a complete list of course sections that are eligible
     //as well as available
     $working_list = $this->get_list($course_sections);
     $course_sections = $aqm->getAllCourseSections();
     $full_list = $this->get_list($course_sections);
     //Container holding course sections for courses already passed
     //$courseSections_passed = array();
     //At this point, the available course sections will be whittled down
     //based on what courses have already been taken.  First, the classes
     //already completed will be extracted
     /*foreach($course_sections as $key => $value)
       {
           //We've already gotten an array of passed courses.  Now we must remove
           //all sections whose course ID matches a passed one
           if (in_array($value->getCourse()->getCourseID(), $courseIDs_passed))
           {
               array_push($courseSections_passed, $value);
               unset($course_sections[$key]);
           }
       }*/
     //Now, what we need is classes that can be taken.  To that end, we will
     //pull all of the course sections for a quarter and unset and move those
     //classes whose prerequisites are not met to a signature_required array
     //First, the array which will hold all course sections where signatures
     //are required (prerequisites not met) must be declared
     //$signature_required = array();
     //Now, parse through and selectively move sig_required courses
     /*foreach($course_sections as $key => $value)
       {
           $prereqs = $value->getCourse()->getPrerequisiteCourses();
       
           if (count($prereqs) != 0)
           {
               $sig_required = true;
               foreach($prereqs as $prereq)
               {
                   if (array_search($prereq->getCourseID(), $courseIDs_passed) == true)
                   {
                       $sig_required = false;
                       break;
                   }
               }
               if ($sig_required)
               {
                   array_push($signature_required, $value);
                   unset($course_sections[$key]);
               }
           }
       }*/
     //Now, we have a three lists of course sections.  One, $courseSections_passed,
     //contains all course sections for courses offered this quarter that the
     //student has passed in the past
     //The second, $signature_required, contains all course sections for which the
     //prerequisites are not met.  For the student to take these courses,
     //a signature will have to be procured
     //The third and final array, $course_sections, contains only those sections for
     //courses that don't fall into the previous two categories.  Essentially, they
     //would be higher priority courses than the others.
     //At this point, we need to sort each array by subject, then by number,
     //then by section.
     //$working_list = $this->get_list($signature_required, $courseSections_passed, $course_sections);
     //$name_arr = array('Recommended', 'Passed', 'Signature');
     //$index = 0;
     /*foreach ($working_list as $cat)
       {
           $name = $name_arr[$index];
           $index = $index + 1;
           foreach($cat as $subj)
           {
               foreach($subj as $course)
               {
                   foreach($course as $sec)
                   {
                       echo $name . "\n" . $sec->getCourse()->getCourseName() .
                               "\n" . $sec->getCourse()->getCourseNumber() .
                               "\n" . $sec->getSectionName() . "\n";
                   }
               }
           }
       }*/
     /*foreach ($working_list as $cat)
       {
           echo $cat->getName() . "\n" . $cat->getSubjects()[0]->getName() . "\n" .
                   $cat->getSubjects()[0]->getCourses()[0]->getName() . "\n" .
                   $cat->getSubjects()[0]->getCourses()[0]->getSections()[0]->getSectionName() . "\n";
       }*/
     /*foreach($working_list['Recommended']->getSubjects() as $subj)
       {
           foreach ($subj->getCourses() as $crs)
           {
               foreach($crs->getSections() as $sec)
               {
                   echo $subj->getName() . "\n" . $crs->getName() . "\n" . $sec->getSectionName() . "\n";
               }
           }
       }*/
     $data = array('recommended' => $working_list, 'all_courses' => $full_list, 'quarter_id' => $qid, 'cwid' => $usermod->getUserID(), 'student_name' => $usermod->getName(), 'form' => $prev_form, 'user' => $user);
     $this->load->view('advising_view', $data);
 }