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

getSettingCriteria() публичный Метод

Gets filter criteria by the setting
public getSettingCriteria ( string $name, string $value = null, array $criteria = null ) : array
$name string Setting name
$value string optional Setting value
$criteria array optional Criteria, if already exists
Результат array Returns extended criteria
    public function getSettingCriteria($name, $value = null, array $criteria = null)
    {
        $serverProperty = new ServerProperty();
        $alias = "sp_" . trim($this->db()->qstr($name), "'");
        $join = "\n            JOIN {$serverProperty->table($alias)} ON {$this->columnServerId()} = {$serverProperty->columnServerId($alias)}\n                AND {$serverProperty->columnName($alias)} = {$serverProperty->qstr('name', $name)}";
        if (isset($criteria[AbstractEntity::STMT_FROM])) {
            $criteria[AbstractEntity::STMT_FROM] .= " {$join}";
        } else {
            $criteria[AbstractEntity::STMT_FROM] = " {$join}";
        }
        if (isset($value)) {
            $where = "{$serverProperty->columnValue($alias)} = {$serverProperty->qstr('value', $value)}";
            if (isset($criteria[AbstractEntity::STMT_WHERE])) {
                $criteria[AbstractEntity::STMT_WHERE] .= " AND ({$where})";
            } else {
                $criteria[AbstractEntity::STMT_WHERE] = $where;
            }
        }
        return $criteria;
    }

Usage Example

Пример #1
0
 protected function _launchedBy($from, $to, $action)
 {
     switch ($action) {
         case static::ACT_CONVERT_TO_OBJECT:
             /* @var $from Server */
             $to->launchedBy = ['id' => $from->properties[Server::LAUNCHED_BY_ID]];
             break;
         case static::ACT_CONVERT_TO_ENTITY:
             /* @var $to Server */
             $launchedBy = ApiController::getBareId($from, 'launchedBy');
             if (!isset($launchedBy)) {
                 throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed launchedBy.id property");
             }
             $to->properties[Server::LAUNCHED_BY_ID] = $launchedBy;
             break;
         case static::ACT_GET_FILTER_CRITERIA:
             $entity = new Server();
             return $entity->getSettingCriteria(Server::LAUNCHED_BY_ID, ApiController::getBareId($from, 'launchedBy'));
     }
 }