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;
}