Skip to content
Snippets Groups Projects
ViewController.php 2.59 KiB
Newer Older
<?php

class Courses_ViewController extends App_Controller_Action
{
    public function indexAction()
    {
    	$requestId = $this->getRequest()->getParam('id');
    	if ($requestId == 'session') {
    		$session = new Zend_Session_Namespace('Edit Request');
    		$request = $session->request;
    		$course = $session->course;
    		$parentCourse = $session->parentCourse;
    		if ($request->getId()) {
    			$initialRequest = false;
    		} else {
    			$initialRequest = true;
    		}
    		$preview = true;
    	} else {
            $request = Requests_RequestModel::find($requestId);
            $course = Courses_CourseModel::findLatestOfRequest($request);

	        $parentCourse = null;
	        if (in_array($request->getType(), array('ChangeCourse', 'AddACEAndChangeCourse'))) {
	            $parentCourse = Courses_CourseModel::findParentOfRequest($request);
	        }
	        $initialRequest = false;
	        $preview = false;
    	}

    	$comments = Requests_CommentsModel::findByRequest($request);
    	$user = Auth_UserModel::findCurrentUser();

    	$this->view->request = $request;
    	$this->view->course = $course;
    	$this->view->parentCourse = $parentCourse;
    	$this->view->comments = $comments;
    	$this->view->user = $user;
    	$this->view->initialRequest = $initialRequest;
    	$this->view->preview = $preview;
    	$this->view->terms = $this->_getFutureTerms();
    	$this->view->isRequestValid = $course->isValid() && $request->isValid();

        $session = new Zend_Session_Namespace(__CLASS__);
        if ($session->tabName) {
    	    $this->view->selectedCommentTab = $session->tabName;
        } else {
            $this->view->selectedCommentTab = 'commentsTab';
        }
    }

    public function setCommentTabAction()
    {
    	$tabName = $this->getRequest()->getParam('tabName');
    	$session = new Zend_Session_Namespace(__CLASS__);
    	$session->tabName = $tabName;
    	exit;
    }

    protected function _getFutureTerms()
    {
        $now = new Zend_Date();
        $month = $now->get(Zend_Date::MONTH);
        $thisYear = $now->get(Zend_Date::YEAR);
        $nextYear = $thisYear + 1;

        $terms = array();
        if ($month < 3) {
            $terms[$thisYear . '3'] = 'Summer ' . $thisYear;
        }
        if ($month < 8) {
            $terms[$nextYear . '1'] = 'Fall ' . $thisYear;
        }
        for ($year = $nextYear; $year < $thisYear + 5; $year++) {
            $terms[$year . '2'] = 'Spring ' . $year;
            $terms[$year . '3'] = 'Summer ' . $year;
            $terms[($year + 1) . '1'] = 'Fall ' . ($year + 1);
        }

        return $terms;
    }
}