diff --git a/application/controllers/JobController.php b/application/controllers/JobController.php new file mode 100644 index 00000000..0ac1ca55 --- /dev/null +++ b/application/controllers/JobController.php @@ -0,0 +1,78 @@ +indexAction(); + } + + public function editAction() + { + $this->indexAction(); + } + + public function runAction() + { + // TODO: Form, POST + $id = $this->params->get('id'); + $job = Job::load($id, $this->db()); + if ($job->run()) { + Notification::success('Job has successfully been completed'); + $this->redirectNow( + Url::fromPath( + 'director/job', + array('id' => $id) + ) + ); + } else { + Notification::success('Job run failed'); + } + } + + public function indexAction() + { + $form = $this->view->form = $this->loadForm('directorJob') + ->setSuccessUrl('director/job') + ->setDb($this->db()); + + if ($id = $this->params->get('id')) { + $this->prepareTabs($id)->activate('edit'); + $form->loadObject($id); + $this->view->title = sprintf( + $this->translate('Job %s'), + $form->getObject()->job_name + ); + } else { + $this->view->title = $this->translate('Add job'); + $this->prepareTabs()->activate('add'); + } + + $form->handleRequest(); + $this->setViewScript('object/form'); + } + + protected function prepareTabs($id = null) + { + if ($id) { + return $this->getTabs()->add('edit', array( + 'url' => 'director/job/edit', + 'urlParams' => array('id' => $id), + 'label' => $this->translate('Job'), + )); + } else { + return $this->getTabs()->add('add', array( + 'url' => 'director/job/add', + 'label' => $this->translate('Job'), + )); + } + } +}