Select Git revision
NewController.php
NewController.php 4.40 KiB
<?php
class Bulletin_NewController extends Creq_Controller_Action
{
public function indexAction()
{
//disable new requests
$this->_helper->getHelper('FlashMessenger')->addMessage(
"If you would like to submit a change please contact your college catalog editor or Nicolette Brenton at 402-472-4030 or brenton@unl.edu."
);
$this->view->messages = $this->_helper->getHelper('FlashMessenger')->getMessages();
$colleges = array();
$collegeMajors = Bulletin_UtilityModel::getMajors();
foreach ($collegeMajors as $college => $majors) {
$colleges[$college] = $college;
asort($collegeMajors[$college]);
$collegeMajors[$college] = array('_college' => 'College Information') + $collegeMajors[$college];
}
$this->view->colleges = $colleges;
$this->view->collegeMajors = $collegeMajors;
}
public function createAction()
{
$this->redirect('/bulletin/new');
$in = $this->getAllParams();
if ($in['college'] == '_null') {
$in['college'] = NULL;
}
if ($in['major'] == '_college') {
$in['major'] = NULL;
}
if (!$in['college']) {
$this->_helper->getHelper('FlashMessenger')->addMessage('You must select a bulletin section to edit.');
$this->redirect('/bulletin/new');
}
$activeRequests = Bulletin_SectionModel::findActiveRequestByCollegeAndMajorId($in['college'], $in['major']);
foreach ($activeRequests as $activeRequest) {
$href = $this->view->baseUrl('/requests/view/index/id/' . $activeRequest->getId());
$this->_helper->getHelper('FlashMessenger')->addMessage(
"There is already an <a href=\"$href\">active request</a> for that college/major"
);
$this->redirect('/bulletin/new');
}
$allRequests = Bulletin_SectionModel::findAllRequestsByCollegeAndMajorId($in['college'], $in['major']);
foreach ($allRequests as $request) {
$pullRequestNumber = $request->getPullRequestNumber();
// Make sure we have a number and not NULL
if (is_int($pullRequestNumber) && intval($pullRequestNumber) > 0){
$merged = Bulletin_RepositoryModel::getInstance()->pullRequestHasBeenMerged(intval($pullRequestNumber));
if ($merged == false) {
$this->_helper->getHelper('FlashMessenger')->addMessage(
"There is a pending request for that college/major. Please wait until the request is finalized before creating a new request.<br/>Merge Request: $pullRequestNumber"
);
$this->redirect('/bulletin/new');
}
}
}
$request = Requests_RequestModel::fetchNew();
$request->setType('BulletinEdit');
$request->setModule('bulletin');
$user = Auth_UserModel::findCurrentUser();
$request->setOwner($user);
$request->setJustification('Updating bulletin section.');
$section = Bulletin_SectionModel::fetchNew();
$section->setCollege($in['college']);
if ($in['major']) {
$section->setMajorId($in['major']);
}
$front = Zend_Controller_Front::getInstance();
$options = $front->getParam('bootstrap')->getOptions();
$month = $options['bulletin']['setting']['switchOverMonth'];
$currentYear = Zend_Date::now()->get(Zend_Date::YEAR);
if (Zend_Date::now()->get(Zend_Date::MONTH) >= $month) {
$currentYear++;
}
$section->setYear($currentYear);
Bulletin_RepositoryModel::getInstance()->pull();
$filePath = Bulletin_RepositoryModel::getInstance()->getFilePathForSection($section);
if (!$filePath) {
$this->_helper->getHelper('FlashMessenger')->addMessage('Unable to find an existing file for that college/major.');
$this->redirect('/bulletin/new');
}
$id = bin2hex(openssl_random_pseudo_bytes('16'));
$session = new Zend_Session_Namespace('Edit Request ' . $id);
$session->section = $section;
$session->request = $request;
$session->fileContents = Bulletin_RepositoryModel::getInstance()->getFileContents('data/' . $filePath);
unset($session->currentSavedRequestId);
$this->redirect('/bulletin/edit/index/id/' . $id);
}
}