public function _costCenter($from, $to, $action) { switch ($action) { case static::ACT_CONVERT_TO_OBJECT: /* @var $from Environment */ $to->costCenter = $from->getProperty(EnvironmentProperty::SETTING_CC_ID); break; case static::ACT_CONVERT_TO_ENTITY: /* @var $to Environment */ $ccId = ApiController::getBareId($from, 'costCenter'); if (empty($ccId)) { throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Missed property costCenter"); } $this->controller->getCostCenter($ccId); $to->setProperty(EnvironmentProperty::SETTING_CC_ID, $ccId); break; case static::ACT_GET_FILTER_CRITERIA: $env = new Environment(); $envProperty = new EnvironmentProperty(); return [AbstractEntity::STMT_FROM => "\n JOIN {$envProperty->table('cep')} ON {$env->columnId()} = {$envProperty->columnEnvId('cep')}\n AND {$envProperty->columnName('cep')} = " . $envProperty->qstr('name', EnvironmentProperty::SETTING_CC_ID) . "\n ", AbstractEntity::STMT_WHERE => "{$envProperty->columnValue('cep')} = " . $envProperty->qstr('value', $from->costCenter)]; } }
/** * Gets default search criteria according current account * * @return array Returns array of the search criteria */ private function getDefaultCriteria() { $criteria = [['accountId' => $this->getUser()->getAccountId()]]; $user = $this->getUser(); if (!$user->canManageAcl()) { $env = new Account\Environment(); $teamEnv = new Account\TeamEnvs(); $team = new Account\Team(); $teamUser = new Account\TeamUser(); $criteria = array_merge($criteria, [AbstractEntity::STMT_DISTINCT => true, AbstractEntity::STMT_FROM => " {$env->table()}\n JOIN {$teamEnv->table('te')} ON {$teamEnv->columnEnvId('te')} = {$env->columnId()}\n JOIN {$team->table('at')} ON {$team->columnId('at')} = {$teamEnv->columnTeamId('te')}\n JOIN {$teamUser->table('tu')} ON {$teamUser->columnTeamId('tu')} = {$team->columnId('at')}\n ", AbstractEntity::STMT_WHERE => "{$teamUser->columnUserId('tu')} = " . $teamUser->qstr('userId', $user->id) . " AND {$team->columnAccountId('at')} = " . $team->qstr('accountId', $user->getAccountId())]); } return $criteria; }