Beispiel #1
0
 public function listAction()
 {
     $authorization = Zend_Auth::getInstance();
     $identity = $authorization->getIdentity();
     if ($identity) {
         $model = new Application_Model_Materials();
         $materials = $model->listMaterials();
         $course_model = new Application_Model_Courses();
         for ($i = 0; $i < count($materials); $i++) {
             $courses[$i] = $course_model->getCourseById($materials[$i]['cid'])[0]['name'];
         }
         $type_model = new Application_Model_Materialtype();
         for ($i = 0; $i < count($materials); $i++) {
             $types[$i] = $type_model->getTypeById($materials[$i]['tid'])[0]['type_name'];
         }
         //$page=$this->_getParam('page',1);
         //$paginator = Zend_Paginator::factory($courses);
         // $paginator->setItemCountPerPage(10);
         //$paginator->setCurrentPageNumber($page);
         $this->view->materials = $materials;
         $this->view->courses = $courses;
         $this->view->types = $types;
         $this->view->identity = $identity;
     } else {
         $this->_redirect("/users/login");
     }
 }
 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");
     }
 }