Esempio n. 1
0
 public function _defaultAclRole($from, $to, $action)
 {
     switch ($action) {
         case static::ACT_CONVERT_TO_OBJECT:
             /* @var $from TeamEnvs */
             $to->defaultAclRole = ['id' => $from->getTeam()->accountRoleId];
             break;
         case static::ACT_CONVERT_TO_ENTITY:
             /* @var $to TeamEnvs */
             // now its only Team property
             throw new ApiNotImplementedErrorException('Adjustment the default ACL Role for the Environment has not been implemented yet.');
         case static::ACT_GET_FILTER_CRITERIA:
             $aclRoleId = ApiController::getBareId($from, 'defaultAclRole');
             $team = new Team();
             $envTeam = new TeamEnvs();
             return [AbstractEntity::STMT_FROM => "\n                        JOIN {$team->table('t')} ON {$team->columnId('t')} = {$envTeam->columnTeamId()}\n                            AND {$team->columnAccountRoleId('t')} = " . $team->qstr('accountRoleId', $aclRoleId) . "\n                    "];
     }
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
File: Farm.php Progetto: scalr/scalr
 /**
  * Searches farms by criteria and selecting and initiating their Teams
  *
  * @param    array        $criteria     optional The search criteria.
  * @param    array        $group        optional The group by looks like [property1, ...], by default groups by `id`
  * @param    array        $order        optional The results order looks like [property1 => true|false, ... ]
  * @param    int          $limit        optional The records limit
  * @param    int          $offset       optional The offset
  * @param    bool         $countRecords optional True to calculate total number of the records without limit
  *
  * @return   ArrayCollection|Farm[] Returns collection of the entities.
  *
  * @throws \Scalr\Exception\ModelException
  */
 public static function findWithTeams(array $criteria = null, array $group = null, array $order = null, $limit = null, $offset = null, $countRecords = null)
 {
     $farm = new Farm();
     /* @var $farms Farm[] */
     $farms = [];
     if (!isset($group)) {
         $group = ['id'];
     }
     $collection = $farm->result(AbstractEntity::RESULT_ENTITY_COLLECTION)->find($criteria, $group, $order, $limit, $offset, $countRecords);
     /* @var $farm Farm */
     foreach ($collection as $farm) {
         $farms[$farm->id] = $farm;
     }
     $team = new Team();
     $farmTeam = new FarmTeam();
     $stmt = "\n            SELECT {$team->fields()}, {$farmTeam->fields('ft', true)}\n            FROM {$team->table()}\n            JOIN {$farmTeam->table('ft')} ON {$farmTeam->columnTeamId('ft')} = {$team->columnId()}\n              AND {$farmTeam->columnFarmId('ft')} IN ('" . implode("', '", array_keys($farms)) . "')\n        ";
     foreach ($team->db()->Execute($stmt) as $row) {
         $team = new Team();
         $team->load($row);
         $farmTeam->load($row, 'ft');
         $farms[$farmTeam->farmId]->_teams[$team->id] = $team;
     }
     return $collection;
 }