all() public method

Executes query and returns all results as an array.
public all ( Connection $db = null ) : array | ActiveRecord[]
$db Connection the DB connection used to create the DB command. If null, the DB connection returned by [[modelClass]] will be used.
return array | ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned.
コード例 #1
0
ファイル: UserListBox.php プロジェクト: VasileGabriel/humhub
 /**
  * @inheritdoc
  */
 public function run()
 {
     $countQuery = clone $this->query;
     $pagination = new \yii\data\Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->pageSize]);
     $this->query->offset($pagination->offset)->limit($pagination->limit);
     return $this->render("userListBox", ['title' => $this->title, 'users' => $this->query->all(), 'pagination' => $pagination]);
 }
コード例 #2
0
ファイル: ArrayModelField.php プロジェクト: bariew/yii2-tools
 /**
  * @inheritdoc
  */
 public function run()
 {
     $result = [];
     $class = $this->relation->modelClass;
     $form = $this->form;
     $template = '<div class="template">' . $this->render($this->viewName, ['model' => new $class(), 'form' => $this->form, 'index' => 'myindex']) . '</div>';
     $items = $this->items ?: $this->relation->all();
     foreach ($items as $index => $model) {
         $result[] = $this->render($this->viewName, compact('index', 'model', 'form'));
     }
     $result[] = Html::a(\Yii::t('app', ' Add'), '#', ['class' => 'btn btn-success glyphicon glyphicon-plus', 'template' => $template, 'onclick' => '
             $(this).before($(this).attr("template").replace(/myindex/g, "new-"+Date.now())); return false;']);
     return implode('', $result);
 }
コード例 #3
0
ファイル: PackagingPostQuery.php プロジェクト: sea129/kbay
 /**
  * 拿到属于用户的所有,返回数组
  * @param  [type] $userID [description]
  * @param  [type] $db     [description]
  * @return [type]         [description]
  */
 public function allOfUser($userID, $db = null)
 {
     $this->where(['user_id' => $userID]);
     $this->orderBy('price ASC');
     $this->asArray();
     return parent::all($db);
 }
コード例 #4
0
ファイル: Exporter.php プロジェクト: arogachev/yii2-excel
 protected function fillModels()
 {
     $models = $this->dataProvider ? $this->dataProvider->getModels() : $this->query->all();
     foreach ($models as $model) {
         $this->_models[] = new Model(['instance' => $model, 'standardModel' => $this->_standardModels[0]]);
     }
 }
コード例 #5
0
ファイル: ListingImagesQuery.php プロジェクト: sea129/kbay
 public function allOfProduct($productID, $db = null)
 {
     $this->where(['product_id' => $productID]);
     $this->indexBy('ebay_account_id');
     $this->asArray();
     return parent::all($db);
 }
コード例 #6
0
 /**
  * @inheritdoc
  * @return Comment[]|array
  */
 public function all($db = null)
 {
     $result = parent::all($db);
     if (!$this->loadComments) {
         return $result;
     }
     return $this->buildCommentsHierarchy($result);
 }
コード例 #7
0
 public function allOfEbay($ebayID, $db = null)
 {
     //$this->select(['*','COUNT(*)']);
     $this->where(['ebay_account_id' => $ebayID]);
     $this->orderBy('updated_at DESC');
     //最新的在第一个
     //$this->asArray();
     return parent::all($db);
 }
コード例 #8
0
 /**
  * @inheritdoc
  */
 public function all($db = null)
 {
     $rows = parent::all($db);
     if (count($rows) > 0 && $this->isMappableQuery()) {
         /** @var ActiveRecord|ActiveRecordTrait $className */
         $className = $this->modelClass;
         $className::addRowsToMap($rows);
     }
     return $rows;
 }
コード例 #9
0
ファイル: Stream.php プロジェクト: alefernie/intranet
 public function run()
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $this->init();
     $wallEntries = $this->activeQuery->all();
     $output = "";
     $generatedWallEntryIds = array();
     $lastEntryId = "";
     foreach ($wallEntries as $wallEntry) {
         $underlyingObject = $wallEntry->content->getPolymorphicRelation();
         if ($underlyingObject === null) {
             throw new Exception('Could not get contents underlying object!');
         }
         $underlyingObject->populateRelation('content', $wallEntry->content);
         $output .= $this->controller->renderAjax('@humhub/modules/content/views/layouts/wallEntry', ['entry' => $wallEntry, 'user' => $underlyingObject->content->user, 'mode' => $this->mode, 'object' => $underlyingObject, 'content' => $underlyingObject->getWallOut()], true);
         $generatedWallEntryIds[] = $wallEntry->id;
         $lastEntryId = $wallEntry->id;
     }
     return ['output' => $output, 'lastEntryId' => $lastEntryId, 'counter' => count($wallEntries), 'entryIds' => $generatedWallEntryIds];
 }
コード例 #10
0
 /**
  * This method loads and maps models optionally with additional data-attributes for dropdown-lists. You can use it
  * like this:
  *
  * <code>
  *     <?php
  *         $rateData = DropdownHelper::fetchItemsWithData(Rate::find()->orderTitle(), 'id', 'title', ['currency','per_hour','per_km']);
  *     ?>
  *     <?= $form->field($model, 'rate_id')->dropDownList($rateData['items'], ['prompt'=>Yii::t('app', 'Choose one...'), 'options'=>$rateData['itemOptions']]) ?>
  * </code>
  *
  * @param \yii\db\ActiveQuery $query the prepared query to fetch the data for
  * @param string $from the attribute to map from (usually the id of the model)
  * @param string $to the attribute to map to (usually something like `name`). Note that this can also be a closure
  * with the signature `function ($model)` returning a string
  * @param string[] $dataAttributes list of model attributes which will be loaded as additional `data-XXX` fields
  * for the dropdown-options
  * @return array an array with the keys `items` and `itemOptions`. The first contains the items for the dropdown
  * and second their additional data-options if specified
  */
 public static function fetchItemsWithData($query, $from, $to, $dataAttributes = [])
 {
     /* @var $models \yii\db\ActiveRecord[] */
     //prepare returned vars
     $items = [];
     $itemOptions = [];
     //load data
     $models = $query->all();
     //iterate
     foreach ($models as $model) {
         //item
         $valFrom = $model->{$from};
         $valTo = $to instanceof \Closure ? call_user_func($to, $model) : $model->{$to};
         $items[$valFrom] = $valTo;
         //check if there are item options or continue
         if (empty($dataAttributes)) {
             continue;
         }
         //fetch item options
         $itemOptions[$valFrom] = [];
         foreach ($dataAttributes as $dataAttr) {
             if (!isset($itemOptions[$valFrom]['data'])) {
                 $itemOptions[$valFrom]['data'] = [];
             }
             //prepare
             $parts = explode('.', $dataAttr);
             $identifier = implode('-', $parts);
             //fetch value
             $valOrObj = $model;
             foreach ($parts as $part) {
                 $valOrObj = $valOrObj->{$part};
             }
             //set options
             $itemOptions[$valFrom]['data'][$identifier] = $valOrObj instanceof Object || is_array($valOrObj) ? Json::encode($valOrObj) : $valOrObj;
         }
     }
     //return
     return ['items' => $items, 'itemOptions' => $itemOptions];
 }
コード例 #11
0
ファイル: EntityQuery.php プロジェクト: tsyrya/mybriop
 public function formattedAll($format, $params, $db = null)
 {
     if (is_string($params)) {
         $params = ['valueColumn' => $params];
     }
     $keyColumn = ArrayHelper::getValue($params, 'keyColumn', 'id');
     $valueColumn = ArrayHelper::getValue($params, 'valueColumn');
     if (!$valueColumn) {
         throw new InvalidConfigException("'valueColumn' must be set if format was choosen.");
     }
     $rows = parent::all($db);
     if ($format === self::DROP_DOWN) {
         return ArrayHelper::map($rows, $keyColumn, $valueColumn);
     }
     if ($format === self::DEP_DROP_AJAX) {
         $output = [];
         foreach ($rows as $row) {
             $output[] = ['id' => $row[$keyColumn], 'name' => $row[$valueColumn]];
         }
         return ['output' => $output, 'selected' => ArrayHelper::getValue($params, 'selected')];
     }
     throw new InvalidConfigException('Invalid format was choosen');
 }
コード例 #12
0
 /**
  * @inheritdoc
  * @return Progressjobdetail[]|array
  */
 public function all($db = null)
 {
     return parent::all($db);
 }
コード例 #13
0
ファイル: Stream.php プロジェクト: VasileGabriel/humhub
 public function getWallEntries()
 {
     return $this->activeQuery->all();
 }
コード例 #14
0
 /**
  * @inheritdoc
  * @return \app\models\activeRecords\Log[]|array
  */
 public function all($db = null)
 {
     $this->orderBy('log_time DESC');
     return parent::all($db);
 }
コード例 #15
0
ファイル: EbayAccountQuery.php プロジェクト: sea129/kbay
 public function allOfCurrentUser($db = null)
 {
     $this->where(['user_id' => Yii::$app->user->id]);
     return parent::all($db);
 }
コード例 #16
0
ファイル: Searcher.php プロジェクト: pbabilas/bcode
 /**
  * @return array|\yii\db\ActiveRecord[]
  */
 public function findAll()
 {
     $this->query->limit($this->limit);
     return $this->query->all();
 }