Scalr\Model\Entity\Server::findWithProperties PHP Метод

findWithProperties() публичный статический Метод

Searches servers by criteria and selecting and initiating their Properties
public static findWithProperties ( array $criteria = null, array $group = null, array $order = null, integer $limit = null, integer $offset = null, boolean $countRecords = null ) : ArrayCollection | Server[]
$criteria array optional The search criteria.
$group array optional The group by looks like [property1, ...], by default groups by `serverId`
$order array optional The results order looks like [property1 => true|false, ... ]
$limit integer optional The records limit
$offset integer optional The offset
$countRecords boolean optional True to calculate total number of the records without limit
Результат Scalr\Model\Collections\ArrayCollection | Server[] Returns collection of the entities.
    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;
    }