/** * Gets Images which are associated with the Role * * @param array $criteria optional The search criteria on the Image result set. * @param array $group optional The group parameter * @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 \Scalr\Model\Collections\EntityIterator Returns Images which are associated with the role */ public function getImages(array $criteria = null, array $group = null, array $order = null, $limit = null, $offset = null, $countRecords = null) { $image = new Image(); $roleImage = new RoleImage(); $criteria = $criteria ?: []; $criteria[static::STMT_FROM] = $image->table() . "\n JOIN " . $roleImage->table() . " ON {$roleImage->columnImageId} = {$image->columnId}\n AND {$roleImage->columnPlatform} = {$image->columnPlatform}\n AND {$roleImage->columnCloudLocation} = {$image->columnCloudLocation}"; $criteria[static::STMT_WHERE] = "{$roleImage->columnRoleId} = " . intval($this->id); $criteria[] = ['$or' => [['accountId' => null], ['$and' => [['accountId' => $this->accountId], ['$or' => [['envId' => null], ['envId' => $this->envId]]]]]]]; return $image->find($criteria, $group, $order, $limit, $offset, $countRecords); }
/** * Gets the Image Entity * * @return Image|null Returns the Image that corresponds to the Server */ public function getImage() { if (empty($this->_image) && !empty($this->roleId) && !empty($this->platform)) { $i = new Image(); $ri = new RoleImage(); $rec = $this->db()->GetRow("\n SELECT {$i->fields()}\n FROM {$i->table()}\n LEFT JOIN {$ri->table()} ON {$i->columnPlatform} = {$ri->columnPlatform}\n AND {$i->columnCloudLocation} = {$ri->columnCloudLocation}\n AND {$i->columnId} = {$ri->columnImageId}\n WHERE {$ri->columnRoleId} = ?\n AND {$ri->columnPlatform} = ?\n AND {$ri->columnCloudLocation} = ?\n AND ({$i->columnAccountId} IS NULL OR {$i->columnAccountId} = ?\n AND ({$i->columnEnvId} IS NULL OR {$i->columnEnvId} = ?)\n )\n ", [$this->roleId, $this->platform, in_array($this->platform, [SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::AZURE]) ? '' : $this->cloudLocation, $this->getFarm()->accountId, $this->getFarm()->envId]); if ($rec) { $this->_image = $i; $this->_image->load($rec); } } return $this->_image; }