public function saveJosOrtherWork(JosOrtherWork $jos_orther_work)
 {
     $data = array('content' => $jos_orther_work->getContent(), 'user_id' => $jos_orther_work->getUserId(), 'year_id' => $jos_orther_work->getYearId(), 'time_from' => $jos_orther_work->getTimeFrom(), 'time_to' => $jos_orther_work->getTimeTo(), 'note' => $jos_orther_work->getNote());
     $value_id = (int) $jos_orther_work->getValueId();
     if ($value_id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getOrtherWorkByArrayConditionAndArrayColumns(array('value_id' => $value_id), array('user_id'))) {
             $this->tableGateway->update($data, array('value_id' => $value_id));
         } else {
             return false;
         }
     }
     return true;
 }
 public function editOrtherWorkAction()
 {
     // điểm truy cập csdl
     $jos_users_table = $this->getServiceLocator()->get('Permission\\Model\\JosUsersTable');
     $jos_year_table = $this->getServiceLocator()->get('NamHoc\\Model\\JosYearTable');
     $jos_orther_work_table = $this->getServiceLocator()->get('Application\\Model\\JosOrtherWorkTable');
     $id_giang_vien = $this->params('id');
     $read = $this->getServiceLocator()->get('AuthService')->getStorage()->read();
     if (isset($read['username']) and $read['username']) {
         // kiểm tra user đang đăng nhập
         $user = $jos_users_table->getGiangVienByArrayConditionAndArrayColumns(array('username' => $read['username']));
         // kiểm tra user có quyền editAllProfile không
         $white_lists = $read['white_list'];
         $edit_all_profile = 0;
         foreach ($white_lists as $key => $white_list) {
             if ($white_list['action'] == 'editAllProfile') {
                 $edit_all_profile = 1;
             }
         }
         if ($user and isset($user[0]['id']) and $id_giang_vien == $user[0]['id']) {
             // nếu đã đăng nhập
             $edit_all_profile = 1;
         }
         // có quyền
         if ($edit_all_profile == 1) {
             $request = $this->getRequest();
             if ($request->isPost()) {
                 $post = $request->getPost();
                 $edit_orther_work_form = new EditOrtherWorkForm();
                 $edit_orther_work_form->setData($post);
                 if ($edit_orther_work_form->isValid()) {
                     // lấy year_id default
                     $year = $jos_year_table->getYearByArrayConditionAndArrayColumn(array('is_active' => 1));
                     if (!$year or !isset($year[0]['year_id'])) {
                         die('Lỗi, Không xác định được năm cần sửa');
                     }
                     $year_id = $year[0]['year_id'];
                     // Kiểm tra nếu science_research đã tồn tại thì không add, ko tồn tại thì add
                     $orther_work_exist = $jos_orther_work_table->getOrtherWorkByArrayConditionAndArrayColumns(array('user_id' => $id_giang_vien, 'year_id' => $year_id, 'content' => $post['content']), array());
                     if (!$orther_work_exist or $orther_work_exist and $orther_work_exist[0]['value_id'] == $post['value_id']) {
                         $orther_work_new = new JosOrtherWork();
                         $orther_work_new->exchangeArray($post);
                         $orther_work_new->setUserId($id_giang_vien);
                         $orther_work_new->setYearId($year_id);
                         $time_from = date('Y-m-d', strtotime($post['time_from']));
                         $orther_work_new->setTimeFrom($time_from);
                         $time_to = date('Y-m-d', strtotime($post['time_to']));
                         $orther_work_new->setTimeTo($time_to);
                         $jos_orther_work_table->saveJosOrtherWork($orther_work_new);
                         $this->flashMessenger()->addSuccessMessage('Chúc mừng cập nhật thành công!');
                         return $this->redirect()->toRoute('application/crud', array('action' => 'index', 'id' => $id_giang_vien));
                     }
                 }
             }
         }
     }
     if (isset($id_giang_vien)) {
         $this->flashMessenger()->addErrorMessage('Bạn không có quyền truy cập. Vui lòng kiểm tra lại!');
         return $this->redirect()->toRoute('application/crud', array('action' => 'index', 'id' => $id_giang_vien));
     }
     $this->flashMessenger()->addErrorMessage('Bạn không có quyền truy cập. Vui lòng kiểm tra lại!');
     return $this->redirect()->toRoute('application/crud', array('action' => 'index'));
 }