Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function prepareResult(array $rows, ConnectionInterface $connection = null)
 {
     return parent::prepareResult($this->fillUpSnippets($rows), $connection);
 }
Exemplo n.º 2
0
 protected function load()
 {
     //@TODO cache
     if (!($dataItems = (new Query())->from($this->itemsTable)->orderBy(['order_index' => SORT_DESC])->indexBy('name')->all($this->connection))) {
         throw new RBACException('Items is empty.');
     }
     static::$items = $dataItems;
     $alias = Query::alias($this->rolesTable, $this->rolesTable);
     //@TODO cache
     if (!($dataRolesItems = (new Query())->select(SelectBuilder::selects([['roles' => ['name', 'type', 'description', 'data']], ['access_items' => ['name', 'type', 'description', 'data'], 'items']]))->from($this->rolesItemsTable)->innerJoin($this->itemsTable, "{$this->rolesItemsTable}.item = {$this->itemsTable}.name")->innerJoin($this->rolesTable, "{$this->rolesItemsTable}.role = {$alias}.name")->andWhere(["{$alias}.[[type]]" => RBACInterface::TYPE_ROLE])->orderBy(["{$alias}.[[order_index]]" => SORT_DESC])->asSubattributes()->all($this->connection))) {
         return;
     }
     $result = [];
     foreach ($dataRolesItems as $value) {
         if (isset($result[$value['name']])) {
             $result[$value['name']]['items'] = array_merge($result[$value['name']]['items'], (array) $value['items']['name']);
             continue;
         }
         $value['items'] = [$value['items']['name']];
         $result[$value['name']] = $value;
     }
     static::$items = ArrayHelper::toType(ArrayHelper::filterRecursive($result + static::$items, function ($value, $key) {
         return !in_array($key, ['name'], true);
     }));
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 protected function queryScalar($selectExpression, ConnectionInterface $connection = null)
 {
     if ($this->sql === null) {
         return parent::queryScalar($selectExpression, $connection);
     }
     /* @var $modelClass ActiveRecord */
     $modelClass = $this->modelClass;
     if ($connection === null) {
         $connection = $modelClass::getConnection();
     }
     return (new Query())->select([$selectExpression])->from(['c' => "({$this->sql})"])->params($this->params)->createCommand($connection)->queryScalar();
 }