Skip to content
Snippets Groups Projects
Select Git revision
  • 24465aaec2254a59f895fd7fb35deba6049b7c6e
  • master default
  • disable-new-requests
  • fix-bulletin-view-missing-notes-error
  • add-missing-queue-managers
  • projects-task-53
  • projects-task-51
  • projects-task-43
  • projects-task-24
  • projects-task-31
  • projects-task-32
  • projects-task-8
  • project-setup-docs
  • projects-task-28
  • projects-task-27
  • projects-task-9
  • projects-task-7
  • mass-update-course-codes-in-sections
  • wdn-four
  • learning-outcomes
  • additional-bulletin-pages
  • svn-redesign
  • svn-popups
  • svn-trunk
  • svn-performance
  • svn-tim
26 results

CourseEsDesignations.php

Blame
  • CourseEsDesignations.php 3.65 KiB
    <?php
    
    class CourseEsDesignations extends Nmc_Db_Table
    {
        protected $_primary = 'courseEsDesignationId';
        protected $_rowClass = 'CourseEsDesignation';
    
        /**
         * The one true instance
         *
         * @var CourseEsDesignations
         */
        static protected $_instance;
    
        /**
         * Return the one true instance
         *
         * @return CourseEsDesignations
         */
        static public function getInstance($config = array())
        {
            if (!self::$_instance) {
                self::$_instance = new CourseEsDesignations($config);
            }
            return self::$_instance;
        }
    
        /**
         * Returns boolean indicating whether or not the course is ES for the
         * specified college, or any college if none is given.
         *
         * @param CourseCode $course
         * @param College $college
         * @return bool
         */
        public function isCourseCodeEssentialStudies(CourseCode $course, College $college = null)
        {
            $db = $this->getAdapter();
    
            $where = array();
            $where[] = $db->quoteInto('courseCode = ?', $course->getPrimaryKey());
            if ($college) {
                $where[] = $db->quoteInto('college = ?', $college->getPrimaryKey());
            }
            $where = implode(' AND ', $where);
    
            $result = $this->fetchAll($where);
            if ($result->count() > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public function getEssentialStudiesAreas(CourseCode $course, College $college = null)
        {
            $db = $this->getAdapter();
            $where   = array();
            $where[] = $db->quoteInto('courseCode = ?', $course->getPrimaryKey());
            if ($college) {
                $where[] = $db->quoteInto('college = ?', $college->getPrimaryKey());
            }
            $where = implode(' AND ', $where);
    
            $results = $this->fetchAll($where);
            $areas = $this->getEmptyEssentialStudiesArray($college);
    
            foreach ($results as $row) {
                if ($college) {
                    $areas[$row->area] = true;
                } else {
                    $areas[$row->college->name][$row->area] = true;
                }
            }
    
            return $areas;
        }
    
        public function setEssentialStudiesAreas(CourseCode $course, College $college, $areas)
        {
            $db = $this->getAdapter();
    
            foreach ($areas as $areaName => $areaValue) {
                $where   = array();
                $where[] = $db->quoteInto('courseCode = ?', $course->getPrimaryKey());
                $where[] = $db->quoteInto('college = ?',    $college->getPrimaryKey());
                $where[] = $db->quoteInto('area = ?',    $areaName);
                $where   = implode(' AND ', $where);
                $row = $this->fetchRow($where);
                if ($row && $areaValue == 'no') {
                    $row->delete();
                } else if (!$row && $areaValue == 'yes') {
                    $row = $this->fetchNew();
                    $row->courseCode = $course->getPrimaryKey();
                    $row->college = $college;
                    $row->area = $areaName;
                    $row->save();
                }
            }
        }
    
        public function getEmptyEssentialStudiesArray(College $college = null)
        {
            $areaCodes = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
            $colleges = Colleges::getInstance()->fetchAll();
    
            $areas = array();
            if ($college) {
                foreach ($areaCodes as $areaCode) {
                    $areas[$areaCode] = false;
                }
            } else {
                foreach ($colleges as $collegeRow) {
                    $areas[$collegeRow->name] = array();
                    foreach ($areaCodes as $areaCode) {
                        $areas[$collegeRow->name][$areaCode] = false;
                    }
                }
            }
    
            return $areas;
        }
    }