コード例 #1
0
 public function addAction()
 {
     // tạo form add
     $add_form = new AddYearForm();
     $return_array['add_form'] = $add_form;
     // kiểm tra post dữ liệu
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         $add_form->setData($post);
         if ($add_form->isValid()) {
             // tạo điểm truy cập csdl bảng jos_year
             $jos_year_table = $this->getServiceLocator()->get('NamHoc\\Model\\jos_year_table');
             $check_year = $jos_year_table->getYearByArrayConditionAndArrayColumn(array('year_id' => $post['year_id']), array('is_active'));
             if ($check_year) {
                 $this->flashMessenger()->addErrorMessage('Lỗi, Năm học đã tồn tại. Vui lòng kiểm tra lại!');
                 return $this->redirect()->toRoute('nam_hoc/crud', array('action' => 'index'));
             }
             // tạo năm học mới
             $new_year = new JosYear();
             $new_year->setYearId($post['year_id']);
             $new_year->setIsActive(0);
             // lưu lại
             $jos_year_table->saveYear($new_year);
             //cập nhật thành công
             $this->flashMessenger()->addSuccessMessage('Chúc mừng, tạo năm học mới thành công!');
             return $this->redirect()->toRoute('nam_hoc/crud', array('action' => 'index'));
         }
     }
     // lỗi thực thi không thành công
     $this->flashMessenger()->addErrorMessage('Lỗi, Thực thi không thành công. Vui lòng kiểm tra lại!');
     return $this->redirect()->toRoute('nam_hoc/crud', array('action' => 'index'));
 }
コード例 #2
0
 public function saveYear(JosYear $jos_year)
 {
     $data = array('is_active' => $jos_year->getIsActive(), 'year_id' => $jos_year->getYearId());
     $year_id = (int) $jos_year->getYearId();
     if ($this->getYearByArrayConditionAndArrayColumn(array('year_id' => $year_id), array('year_id'))) {
         $this->tableGateway->update($data, array('year_id' => $year_id));
     } else {
         $this->tableGateway->insert($data);
     }
 }