/** * Description... * * @return void **/ public function delete() { if (count($this->_mapper->getUsers()->filter('company_id=?', $this->id())) > 0) { throw new RM_Validator_Exception(M('Base')->error('has_clients')); } parent::delete(); }
/** * Description... * * @return void **/ public function save() { if (!$this->_existsInDb() || $this->_propInitial('company_id') && $this->_propInitial('company_id') != $this->company_id) { if (!isNull($company = $this->_mapper->loadCompanyById($this->_propInitial('company_id')))) { $company->getCompanyGroup()->removeUserFromGroup($this); } if (!isNull($company) && !isNull($company->getCompanyGroup())) { if (!isNull($company = $this->company(TRUE)) && !isNull($company->getCompanyGroup())) { $company->getCompanyGroup()->addUserToGroup($this); } } } parent::save(); }
public function runAs($userId, $call, array $args = array()) { $origUser = $this->_loggedUser; $exception = NULL; if ($this->_runAs) { throw new RM_Base_Exception_BadUsage("Nested runAs() is prohibited!"); } $this->_runAs = 1; $this->_loggedUser = $userId == 0 ? $this->_mapper->getAnonymousUser() : $this->_mapper->loadUserById($userId); // change user context try { $result = call_user_func_array($call, $args); } catch (Exception $e) { $exception = $e; } $this->_loggedUser = $origUser; // restore user context $this->_runAs = 0; if ($exception) { throw $exception; } return $result; }
/** * Description... * * @return void **/ public function clientListQuery() { return M('Db')->createQuery($this->_mapper->table('client') . ' cl')->join('cl', 'left join ' . $this->_mapper->table('company') . ' com on com.id=cl.company_id')->what('cl.*, com.name as company'); }