Author: N.V.
Inheritance: extends Scalr\Model\Entity\Setting
Example #1
0
 /**
  * Gets cloud credentials for listed clouds
  *
  * @param   string[]    $clouds             optional Clouds list
  * @param   array       $credentialsFilter  optional Criteria to filter by CloudCredentials properties
  * @param   array       $propertiesFilter   optional Criteria to filter by CloudCredentialsProperties
  *
  * @return  EntityIterator|CloudCredentials[]
  */
 public function cloudCredentialsList(array $clouds = null, array $credentialsFilter = [], array $propertiesFilter = [])
 {
     if (!is_array($clouds)) {
         $clouds = (array) $clouds;
     }
     $cloudCredentials = new CloudCredentials();
     $cloudCredProps = new CloudCredentialsProperty();
     $criteria = $credentialsFilter;
     $from[] = empty($criteria[AbstractEntity::STMT_FROM]) ? " {$cloudCredentials->table()} " : $criteria[AbstractEntity::STMT_FROM];
     $where = empty($criteria[AbstractEntity::STMT_WHERE]) ? [] : [$criteria[AbstractEntity::STMT_WHERE]];
     $criteria[] = ['accountId' => $this->id];
     if (!empty($clouds)) {
         $clouds = implode(", ", array_map(function ($cloud) use($cloudCredentials) {
             return $cloudCredentials->qstr('cloud', $cloud);
         }, $clouds));
         $where[] = "{$cloudCredentials->columnCloud()} IN ({$clouds})";
     }
     if (!empty($propertiesFilter)) {
         foreach ($propertiesFilter as $property => $propCriteria) {
             $alias = "ccp_" . trim($cloudCredentials->db()->qstr($property), "'");
             $from[] = "\n                    LEFT JOIN {$cloudCredProps->table($alias)} ON\n                        {$cloudCredentials->columnId()} = {$cloudCredProps->columnCloudCredentialsId($alias)} AND\n                        {$cloudCredProps->columnName($alias)} = {$cloudCredProps->qstr('name', $property)}\n                ";
             $built = $cloudCredProps->_buildQuery($propCriteria, 'AND', $alias);
             if (!empty($built['where'])) {
                 $where[] = $built['where'];
             }
         }
     }
     $criteria[AbstractEntity::STMT_FROM] = implode("\n", $from);
     if (!empty($where)) {
         $criteria[AbstractEntity::STMT_WHERE] = "(" . implode(") AND (", $where) . ")";
     }
     return CloudCredentials::find($criteria);
 }
Example #2
0
 /**
  * Gets filter criteria by the setting
  *
  * @param   string  $name                Setting name
  * @param   string  $value      optional Setting value
  * @param   array   $criteria   optional Criteria, if already exists
  *
  * @return  array   Returns extended criteria
  */
 public function getSettingCriteria($name, $value = null, array $criteria = null)
 {
     $cloudCredentialsProperty = new CloudCredentialsProperty();
     $alias = "ccp_" . trim($this->db()->qstr($name), "'");
     $join = "\n            JOIN {$cloudCredentialsProperty->table($alias)} ON {$this->columnId()} = {$cloudCredentialsProperty->columnCloudCredentialsId($alias)}\n                AND {$cloudCredentialsProperty->columnName($alias)} = {$cloudCredentialsProperty->qstr('name', $name)}";
     if (isset($criteria[AbstractEntity::STMT_FROM])) {
         $criteria[AbstractEntity::STMT_FROM] .= " {$join}";
     } else {
         $criteria[AbstractEntity::STMT_FROM] = " {$join}";
     }
     if (isset($value)) {
         $where = "{$cloudCredentialsProperty->columnValue($alias)} = {$cloudCredentialsProperty->qstr('value', $value)}";
         if (isset($criteria[AbstractEntity::STMT_WHERE])) {
             $criteria[AbstractEntity::STMT_WHERE] .= " AND ({$where})";
         } else {
             $criteria[AbstractEntity::STMT_WHERE] = $where;
         }
     }
     return $criteria;
 }
Example #3
0
 /**
  * Gets cloud credentials for listed clouds
  *
  * @param   string[]    $clouds             optional Clouds list
  * @param   array       $credentialsFilter  optional Criteria to filter by CloudCredentials properties
  * @param   array       $propertiesFilter   optional Criteria to filter by CloudCredentialsProperties
  * @param   bool        $cacheResult        optional Cache result
  *
  * @return Entity\CloudCredentials[]
  */
 public function cloudCredentialsList(array $clouds = null, array $credentialsFilter = [], array $propertiesFilter = [], $cacheResult = true)
 {
     if (!is_array($clouds)) {
         $clouds = (array) $clouds;
     }
     $cloudCredentials = new Entity\CloudCredentials();
     $envCloudCredentials = new Entity\EnvironmentCloudCredentials();
     $cloudCredProps = new Entity\CloudCredentialsProperty();
     $criteria = array_merge($credentialsFilter, [\Scalr\Model\AbstractEntity::STMT_FROM => $cloudCredentials->table(), \Scalr\Model\AbstractEntity::STMT_WHERE => '']);
     if (!empty($clouds)) {
         $criteria[\Scalr\Model\AbstractEntity::STMT_FROM] .= "\n                JOIN {$envCloudCredentials->table('cecc')} ON\n                    {$cloudCredentials->columnId()} = {$envCloudCredentials->columnCloudCredentialsId('cecc')} AND\n                    {$cloudCredentials->columnCloud()} = {$envCloudCredentials->columnCloud('cecc')}\n            ";
         $clouds = implode(", ", array_map(function ($cloud) use($envCloudCredentials) {
             return $envCloudCredentials->qstr('cloud', $cloud);
         }, $clouds));
         $criteria[\Scalr\Model\AbstractEntity::STMT_WHERE] = "\n                {$envCloudCredentials->columnEnvId('cecc')} = {$envCloudCredentials->qstr('envId', $this->id)} AND\n                {$envCloudCredentials->columnCloud('cecc')} IN ({$clouds})\n            ";
     }
     if (!empty($propertiesFilter)) {
         foreach ($propertiesFilter as $property => $propCriteria) {
             $criteria[\Scalr\Model\AbstractEntity::STMT_FROM] .= "\n                    LEFT JOIN {$cloudCredProps->table('ccp')} ON\n                        {$cloudCredentials->columnId()} = {$cloudCredProps->columnCloudCredentialsId('ccp')} AND\n                        {$cloudCredProps->columnName('ccp')} = {$cloudCredProps->qstr('name', $property)}\n                ";
             $conjunction = empty($criteria[\Scalr\Model\AbstractEntity::STMT_WHERE]) ? "" : "AND";
             $criteria[\Scalr\Model\AbstractEntity::STMT_WHERE] .= "\n                    {$conjunction} {$cloudCredProps->_buildQuery($propCriteria, 'AND', 'ccp')}\n                ";
         }
     }
     /* @var $cloudsCredentials Entity\CloudCredentials[] */
     $cloudsCredentials = Entity\CloudCredentials::find($criteria);
     $result = [];
     $cont = \Scalr::getContainer();
     foreach ($cloudsCredentials as $cloudCredentials) {
         $result[$cloudCredentials->cloud] = $cloudCredentials;
         if ($cacheResult) {
             $cloudCredentials->bindEnvironment($this->id);
             $cloudCredentials->cache($cont);
         }
     }
     return $result;
 }
Example #4
0
 /**
  * Gets cloud credentials for listed clouds
  *
  * @param   string[]    $clouds             optional Clouds list
  * @param   array       $credentialsFilter  optional Criteria to filter by CloudCredentials properties
  * @param   array       $propertiesFilter   optional Criteria to filter by CloudCredentialsProperties
  * @param   bool        $cacheResult        optional Cache result
  *
  * @return Entity\CloudCredentials[]
  */
 public function cloudCredentialsList(array $clouds = null, array $credentialsFilter = [], array $propertiesFilter = [], $cacheResult = true)
 {
     if (!is_array($clouds)) {
         $clouds = (array) $clouds;
     }
     $cloudCredentials = new Entity\CloudCredentials();
     $cloudCredProps = new Entity\CloudCredentialsProperty();
     $envCloudCredentials = new Entity\EnvironmentCloudCredentials();
     $criteria = $credentialsFilter;
     $from[] = empty($criteria[AbstractEntity::STMT_FROM]) ? " {$cloudCredentials->table()} " : $criteria[AbstractEntity::STMT_FROM];
     $where = empty($criteria[AbstractEntity::STMT_WHERE]) ? [] : [$criteria[AbstractEntity::STMT_WHERE]];
     $from[] = "\n            JOIN {$envCloudCredentials->table('cecc')} ON\n                {$cloudCredentials->columnId()} = {$envCloudCredentials->columnCloudCredentialsId('cecc')} AND\n                {$cloudCredentials->columnCloud()} = {$envCloudCredentials->columnCloud('cecc')}\n        ";
     $where[] = "{$envCloudCredentials->columnEnvId('cecc')} = {$envCloudCredentials->qstr('envId', $this->id)}";
     if (!empty($clouds)) {
         $clouds = implode(", ", array_map(function ($cloud) use($cloudCredentials) {
             return $cloudCredentials->qstr('cloud', $cloud);
         }, $clouds));
         $where[] = "{$cloudCredentials->columnCloud()} IN ({$clouds})";
     }
     if (!empty($propertiesFilter)) {
         foreach ($propertiesFilter as $property => $propCriteria) {
             $alias = "ccp_" . trim($cloudCredentials->db()->qstr($property), "'");
             $from[] = "\n                    LEFT JOIN {$cloudCredProps->table($alias)} ON\n                        {$cloudCredentials->columnId()} = {$cloudCredProps->columnCloudCredentialsId($alias)} AND\n                        {$cloudCredProps->columnName($alias)} = {$cloudCredProps->qstr('name', $property)}\n                ";
             $built = $cloudCredProps->_buildQuery($propCriteria, 'AND', $alias);
             if (!empty($built['where'])) {
                 $where[] = $built['where'];
             }
         }
     }
     $criteria[AbstractEntity::STMT_FROM] = implode("\n", $from);
     if (!empty($where)) {
         $criteria[AbstractEntity::STMT_WHERE] = "(" . implode(") AND (", $where) . ")";
     }
     /* @var $cloudsCredentials Entity\CloudCredentials[] */
     $cloudsCredentials = Entity\CloudCredentials::find($criteria);
     $result = [];
     foreach ($cloudsCredentials as $cloudCredentials) {
         $result[$cloudCredentials->cloud] = $cloudCredentials;
         if ($cacheResult) {
             $cloudCredentials->bindEnvironment($this->id);
             $cloudCredentials->cache();
         }
     }
     return $result;
 }