public static function findWithProperties(array $criteria = null, array $group = null, array $order = null, $limit = null, $offset = null, $countRecords = null)
{
$server = new Server();
/* @var $servers Server[] */
$servers = [];
if (!isset($group)) {
$group = ['serverId'];
}
$collection = $server->result(AbstractEntity::RESULT_ENTITY_COLLECTION)->find($criteria, $group, $order, $limit, $offset, $countRecords);
foreach ($collection as $server) {
/* @var $server Server */
$servers[$server->serverId] = $server;
}
if (count($servers) > 0) {
$propertiesCollection = ServerProperty::find([['serverId' => ['$in' => array_keys($servers)]], ['$or' => [['name' => Scalr_Role_Behavior::SERVER_BASE_HOSTNAME], ['name' => self::LAUNCH_REASON], ['name' => self::LAUNCHED_BY_ID]]]]);
/* @var $serverProperties ServerProperty[] */
$serverProperties = [];
foreach ($propertiesCollection as $property) {
/* @var $property ServerProperty */
$serverProperties[$property->serverId][$property->name] = $property;
}
foreach ($servers as $serverId => $server) {
if (isset($serverProperties[$serverId][Scalr_Role_Behavior::SERVER_BASE_HOSTNAME])) {
$servers[$serverId]->properties[Scalr_Role_Behavior::SERVER_BASE_HOSTNAME] = $serverProperties[$serverId][Scalr_Role_Behavior::SERVER_BASE_HOSTNAME]->value;
} else {
$servers[$serverId]->properties[Scalr_Role_Behavior::SERVER_BASE_HOSTNAME] = null;
}
if (isset($serverProperties[$serverId][self::LAUNCH_REASON])) {
$servers[$serverId]->properties[self::LAUNCH_REASON] = $serverProperties[$serverId][self::LAUNCH_REASON]->value;
} else {
$servers[$serverId]->properties[self::LAUNCH_REASON] = null;
}
if (isset($serverProperties[$serverId][self::LAUNCHED_BY_ID])) {
$servers[$serverId]->properties[self::LAUNCHED_BY_ID] = $serverProperties[$serverId][self::LAUNCHED_BY_ID]->value;
} else {
$servers[$serverId]->properties[self::LAUNCHED_BY_ID] = null;
}
}
}
return $collection;
}