Пример #1
0
 public function getAccessTypes()
 {
     if ($this->accessTypes == null && !property_exists($this, "flagAccessTypes")) {
         $this->flagAccessTypes = true;
         //echo '#'.(++$this->dt).'sspd';
         $this->accessTypes = [];
         $this->load->model('entities/easol/Easol_ReportAccess');
         $accessType = new Easol_ReportAccess();
         $this->accessTypes = $accessType->findAllBySql("SELECT EASOL.RoleType.* FROM EASOL.ReportAccess, EASOL.RoleType WHERE EASOL.RoleType.RoleTypeId=EASOL.ReportAccess.RoleTypeId AND EASOL.ReportAccess.ReportId=? ORDER BY RoleTypeName ASC", [$this->ReportId]);
     }
     return $this->accessTypes;
 }
Пример #2
0
 /**
  * @param null | int $id
  * @throws Exception
  */
 public function edit($id = null)
 {
     if ($id == null) {
         throw new \Exception("Invalid report Id");
     }
     $this->load->model('entities/easol/Easol_Report');
     $model = new Easol_Report();
     $model = $model->hydrate($model->findOne($id));
     // die(print_r($model));
     //die(print_r($this->input->post('access[access]')));
     if ($this->input->post('report') && $model->populateForm($this->input->post('report'))) {
         if ($this->form_validation->run() != FALSE) {
             if ($model->save()) {
                 $this->load->model('entities/easol/Easol_ReportAccess');
                 /*
                                 foreach($this->input->post('access[access]') as $access){
                                     $displayAccess = new Easol_ReportAccess();
                                     $displayAccess->ReportId = $model->ReportId;
                                     $displayAccess->RoleTypeId = $access;
                                     $displayAccess->save();
                                 }
                 */
                 $aRoles = [];
                 foreach ($model->getAccessTypes() as $role) {
                     if (!in_array($role->RoleTypeId, $this->input->post('access[access]'))) {
                         $this->db->delete('EASOL.ReportAccess', array('ReportId' => $model->ReportId, 'RoleTypeId' => $role->RoleTypeId));
                     }
                     $aRoles[] = $role->RoleTypeId;
                 }
                 foreach ($this->input->post('access[access]') as $access) {
                     if (in_array($access, $aRoles)) {
                         continue;
                     }
                     $displayAccess = new Easol_ReportAccess();
                     $displayAccess->ReportId = $model->ReportId;
                     $displayAccess->RoleTypeId = $access;
                     $displayAccess->save();
                 }
                 $this->session->set_flashdata('message', 'Report Updated Successfully : ' . $model->ReportName);
                 $this->session->set_flashdata('type', 'success');
                 return redirect(site_url("reports/edit/" . $model->ReportId));
             }
         }
     }
     // $report->ReportName = "Report";
     /* echo $report->ReportName."sdd";
        echo $report->ReportName."sdd"; */
     //$report->save();
     $this->render("edit", ['model' => $model]);
 }