Skip to content
Snippets Groups Projects
Select Git revision
  • db208469891dba550193c55542e7b8ce6ce8631f
  • 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

mysql.lib.php

Blame
  • CourseCode.php 3.24 KiB
    <?php
    
    class CourseCode extends Nmc_Db_Table_Row
    {
        /**
         * Gets the next course code
         *
         * @return CourseCode
         */
        public function getNextAlphabetically()
        {
            $db = $this->_table->getAdapter();
    
            $order = 'subject, course_number, course_letter';
    
            $where = array();
            $where[] = $db->quoteInto('subject = ?', $this->subject);
            $where[] = $db->quoteInto('course_number = ?', $this->courseNumber);
            $where[] = $db->quoteInto('course_letter > ?', $this->courseLetter);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            $where = array();
            $where[] = $db->quoteInto('subject = ?', $this->subject);
            $where[] = $db->quoteInto('course_number > ?', $this->courseNumber);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            $where = array();
            $where[] = $db->quoteInto('subject > ?', $this->subject);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            return null;
    
        }
    
        /**
         * Returns the previous course code
         *
         * @return CourseCode
         */
        public function getPreviousAlphabetically()
        {
            $db = $this->_table->getAdapter();
    
            $order = 'subject DESC, course_number DESC, course_letter DESC';
    
            $where = array();
            $where[] = $db->quoteInto('subject = ?', $this->subject);
            $where[] = $db->quoteInto('course_number = ?', $this->courseNumber);
            $where[] = $db->quoteInto('course_letter < ?', $this->courseLetter);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            $where = array();
            $where[] = $db->quoteInto('subject = ?', $this->subject);
            $where[] = $db->quoteInto('course_number < ?', $this->courseNumber);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            $where = array();
            $where[] = $db->quoteInto('subject < ?', $this->subject);
            $where = implode(' AND ', $where);
    
            $row = $this->_table->fetchRow($where, $order);
            if($row->id) {
                return $row;
            }
    
            return null;
        }
    
        public function _save()
        {
            if(!$this->integratedStudies) {
                $this->integratedStudies = 'no';
            }
            if(!$this->courseLetter) {
                $this->courseLetter = '';
            }
            return parent::_save();
        }
    
        public function _get($name)
        {
            switch($name) {
                case 'courseNumber':
                    $courseNumber = parent::_get('courseNumber');
                    if(Zend_Filter::isInt($courseNumber) && $courseNumber > 0) {
                        return str_pad($courseNumber, 3, '0', STR_PAD_LEFT);
                    } else {
                        return $courseNumber;
                    }
                    break;
                default:
                    return parent::_get($name);
            }
        }
    }