static function getCompanyOption($companyname) { $debugoption = new DebugOption(); $cc = new ConstraintChain(); $cc->add(new Constraint('username', 'is', 'NULL')); $cc->add(new Constraint('company_id', '=', EGS_COMPANY_ID)); $debugoption->loadBy($cc); return $debugoption; }
private function setDebugOptions() { $debugoption = DebugOption::getDebugOption(); $definedoptions = $debugoption->getOptions(); $debugoptions = $debugoption->getEnumOptions('options'); foreach ($definedoptions as $option) { $this->debugoptions[$option] = $debugoptions[$option]; } }
public function edit() { $id = $this->_data['username']; $this->_uses[$this->modeltype]->load($id); $user = $this->_uses[$this->modeltype]; $this->view->set('current', $user->roles->getAssoc()); $companies = new UsercompanyaccessCollection(DataObjectFactory::Factory('Usercompanyaccess')); $sh = new SearchHandler($companies, FALSE, FALSE); $sh->addConstraint(new Constraint('username', '=', $id)); $sh->setFields(array('id', 'usercompanyid')); $companies->load($sh); $this->view->set('selected_companies', $companies->getAssoc()); $this->view->set('username', $id); $this->view->set('edit', TRUE); $this->_new(); $this->setTemplateName('new'); $debug = DebugOption::getUserOption($id); $this->view->set('debug_id', $debug->id); $this->view->set('selected_options', $debug->getOptions()); }
public function save() { if (!$this->CheckParams($this->modeltype)) { sendBack(); } $this->loadData(); $systemcompany = $this->_uses[$this->modeltype]; $db = DB::Instance(); $db->StartTrans(); $errors = array(); $flash = Flash::Instance(); $data = $this->_data[$this->modeltype]; if (!isset($data['id']) || empty($data['id'])) { $company = DataObject::Factory($data, $errors, 'Company'); if (count($errors) > 0 || !$company->save()) { $errors[] = 'Failed to create Company'; $db->FailTrans(); } else { $data['company_id'] = $company->id; } } if (isset($data['debug_options']) && isset($data['id'])) { $debug = DebugOption::getCompanyOption($data['id']); if (isset($data['debug_enabled'])) { $data['DebugOption']['company_id'] = $data['id']; $data['DebugOption']['options'] = $debug->setOptions($data['debug_options']); } else { if ($debug->isLoaded()) { $debug->delete(); } unset($data['DebugOption']); } } else { unset($data['DebugOption']); } if (isset($data['delete_logo'])) { if ($this->delete_logo($systemcompany->logo_file_id, $errors)) { $data['logo_file_id'] = NULL; } else { $errors[] = 'Error deleting Logo image'; } } if (!empty($_FILES['file']['name'])) { // Need to upload file before checking $file = File::Factory($_FILES['file'], $errors, DataObjectFactory::Factory('File')); if ($file->save()) { if (!is_null($systemcompany->logo_file_id)) { $old_file = DataObjectFactory::Factory('File'); if (!$this->delete_logo($systemcompany->logo_file_id, $errors)) { $errors[] = 'Error replacing Logo image'; } } $data['logo_file_id'] = $file->id; } else { $errors[] = 'Error loading Logo image'; } } if (count($errors) == 0) { if (!parent::save($this->modeltype, $data, $errors)) { $errors[] = 'Failed to save System Company'; $db->FailTrans(); } } if (count($errors) == 0) { $result = $this->saved_model->setPermissions($this->_data['Permission'], $errors); if ($result === FALSE) { $errors[] = 'Failed to save System Company Permissions'; $db->FailTrans(); } } $db->CompleteTrans(); if (count($errors) > 0) { $flash->addErrors($errors); if (isset($data['id'])) { $this->_data['id'] = $data['id']; } $this->refresh(); } else { sendTo($this->name, 'index', $this->_modules); } }