Пример #1
0
 public function __construct(View &$view)
 {
     $view->set('sideBarTemplateName', 'elements/sidebar.tpl');
     $report = new HasReport();
     $reports = $report->getByPermission();
     if (!empty($reports)) {
         $sidebar_reports = array();
         foreach ($reports as $report_id => $report) {
             $sidebar_reports[$report] = array('tag' => $report, 'link' => array('module' => 'reporting', 'controller' => 'reports', 'action' => 'run', 'id' => $report_id));
         }
         $this->addList('reports', $sidebar_reports);
     }
 }
Пример #2
0
 public function save_report_roles()
 {
     if (!$this->checkParams('Report')) {
         $this->dataError();
         sendBack();
     }
     $flash = Flash::Instance();
     $errors = array();
     if (empty($this->_data['HasReport']['role_id'])) {
         $errors[] = 'No roles selected';
     } elseif (!empty($this->_data['Report']['id'])) {
         $data['report_id'] = $this->_data['Report']['id'];
         $db = DB::Instance();
         $db->StartTrans();
         $new_roles = implode(',', $this->_data['HasReport']['role_id']);
         // Delete any existing report-roles that are not in the selection
         $hasreports = new HasReportCollection(new HasReport());
         $sh = new SearchHandler($hasreports, false);
         $sh->addConstraint(new Constraint('report_id', '=', $data['report_id']));
         $sh->addConstraint(new Constraint('role_id', 'not in', '(' . $new_roles . ')'));
         if ($hasreports->delete($sh) === false) {
             $errors[] = 'Error deleting existing roles';
         } else {
             //echo 'Check for existing report-role<pre>'.print_r($this->_data['HasReport']['role_id'], true).'</pre><br>';
             foreach ($this->_data['HasReport']['role_id'] as $role_id) {
                 // Check for existing report-role
                 $hasreport = new HasReport();
                 $hasreport->loadBy(array('report_id', 'role_id', 'permissions_id'), array($data['report_id'], $role_id, ''));
                 if (!$hasreport->isLoaded()) {
                     // no existing permission for this report-role so insert it
                     $data['role_id'] = $role_id;
                     $hasreport = DataObject::Factory($data, $errors, 'HasReport');
                     if (!$hasreport || !$hasreport->save()) {
                         $errors[] = $db->ErrorMsg();
                         $errors[] = 'Error saving report roles';
                         $db->FailTrans();
                         break;
                     }
                 }
             }
         }
         //echo 'Errors<pre>'.print_r($errors, true).'</pre><br>';
         //exit;
         $db->completeTrans();
     }
     if (count($errors) === 0) {
         sendTo($this->name, 'view', $this->_modules, array('id' => $this->_data[$this->modeltype]['id']));
     } else {
         $flash->addErrors($errors);
         $this->refresh();
     }
 }