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