public function addAction()
 {
     //$this->view->page_title = "Add Course";
     $authorization = Zend_Auth::getInstance();
     $identity = $authorization->getIdentity();
     if ($identity->user_type == "admin") {
         $form = new Application_Form_Materialtype();
         $id = $this->getRequest()->getParam('id');
         if ($id) {
             $model = new Application_Model_Materialtype();
             $type_data = $model->getTypeById($id);
             $form->populate($type_data[0]);
             if ($this->getRequest()->isPost()) {
                 if ($form->isValid($_POST)) {
                     $model = new Application_Model_Materialtype();
                     $model->editType($form->getValues(), $id);
                     var_dump($form->getValues());
                     $this->redirect("/materialtype/add");
                 }
             }
         } else {
             if ($this->getRequest()->isPost()) {
                 if ($form->isValid($_POST)) {
                     $model = new Application_Model_Materialtype();
                     $this->view->success = $model->addType($form->getValues());
                     $form->reset();
                 }
             }
         }
         $this->view->form = $form;
         $model = new Application_Model_Materialtype();
         $types = $model->listTypes();
         //$page=$this->_getParam('page',1);
         //$paginator = Zend_Paginator::factory($courses);
         // $paginator->setItemCountPerPage(10);
         //$paginator->setCurrentPageNumber($page);
         $this->view->types = $types;
         //$this->view->action = "add";
     } else {
         $this->redirect("materialtype/index");
     }
 }
Beispiel #2
0
 public function editAction()
 {
     $authorization = Zend_Auth::getInstance();
     $identity = $authorization->getIdentity();
     if ($identity->user_type == "admin") {
         $form = new Application_Form_Materials();
         $model = new Application_Model_Materials();
         $id = $this->getRequest()->getParam('id');
         $material_data = $model->getMaterialById($id);
         $course_model = new Application_Model_Courses();
         $courses = $course_model->listCourses();
         for ($i = 0; $i < count($courses); $i++) {
             $options[$courses[$i]['id']] = $courses[$i]['name'];
         }
         $form->getElement('cid')->setMultiOptions($options);
         $options = NULL;
         $type_model = new Application_Model_Materialtype();
         $types = $type_model->listTypes();
         for ($i = 0; $i < count($types); $i++) {
             $options[$types[$i]['id']] = $types[$i]['type_name'];
         }
         $form->getElement('tid')->setMultiOptions($options);
         $form->populate($material_data[0]);
         if ($this->getRequest()->isPost()) {
             if ($form->isValid($this->getRequest()->getParams())) {
                 $model = new Application_Model_Materials();
                 $model->editMaterial($form->getValues(), $id);
                 $this->redirect("/materials/list");
             }
         }
         $this->view->form = $form;
         $this->render("add");
     } else {
         $this->view->notAllwed = "The page not allowed for normal user.";
         $this->_redirect("/materials/list");
     }
 }