Skip to content
Snippets Groups Projects
Select Git revision
  • 9e541393058ff4b4cde882bae907a4b9b024d4dd
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

index.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;
        }
    }