Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param bool $unimproved
  *
  * @return ActiveDataProvider
  */
 public function search($params = [], $unimproved = false)
 {
     $query = Release::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params, '');
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'mod_id' => $this->mod_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['<', 'publish_at', $this->publish_at]);
     $query->andFilterWhere(['like', 'version', $this->version]);
     $query->andFilterWhere(['like', 'file_name', $this->version]);
     if ($unimproved) {
         $models = $dataProvider->getModels();
         $keys = $dataProvider->getKeys();
         $unimproved = $this->mod->getUnimprovedReleases($models);
         foreach ($unimproved as $release) {
             array_unshift($models, $release);
             $keys[] = key($models);
         }
         $dataProvider->setModels($models);
         $dataProvider->setKeys($keys);
     }
     return $dataProvider;
 }
Example #2
0
 public function getIds($categoryId, $field)
 {
     if ($field == "categories") {
         //        $this->findAll(array('category_id'=>$categoryId));
         $query = $this->find()->where(['=', 'category_id', $categoryId]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'brand_id']);
         return $provider->getKeys();
     } else {
         return [];
     }
 }
 public function testActiveQuery()
 {
     $provider = new ActiveDataProvider(['query' => Customer::find()->orderBy('id ASC')]);
     $models = $provider->getModels();
     $this->assertEquals(10, count($models));
     $this->assertTrue($models[0] instanceof Customer);
     $keys = $provider->getKeys();
     $this->assertTrue($keys[0] instanceof \MongoId);
     $provider = new ActiveDataProvider(['query' => Customer::find(), 'pagination' => ['pageSize' => 5]]);
     $models = $provider->getModels();
     $this->assertEquals(5, count($models));
 }
 public function testActiveQuery()
 {
     $provider = new ActiveDataProvider(['query' => ArticleIndex::find()->orderBy('id ASC')]);
     $models = $provider->getModels();
     $this->assertEquals(2, count($models));
     $this->assertTrue($models[0] instanceof ArticleIndex);
     $this->assertTrue($models[1] instanceof ArticleIndex);
     $this->assertEquals([1, 2], $provider->getKeys());
     $provider = new ActiveDataProvider(['query' => ArticleIndex::find(), 'pagination' => ['pageSize' => 1]]);
     $models = $provider->getModels();
     $this->assertEquals(1, count($models));
 }
Example #5
0
 public function getIds($Id, $field)
 {
     if ($field == "devices") {
         $query = $this->find()->where(['=', 'device_id', $Id]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'product_id']);
         return $provider->getKeys();
     }
     if ($field == "products") {
         $query = $this->find()->where(['=', 'product_id', $Id]);
         $provider = new ActiveDataProvider(['query' => $query, 'key' => 'device_id']);
         return $provider->getKeys();
     } else {
         return [];
     }
 }
Example #6
0
 /**
  * @param $headers
  * @throws \yii\base\ExitException
  */
 public function ajax($headers)
 {
     $id_parent = $headers['adm-nestable-id-parent'];
     $items = Yii::$app->getRequest()->post('nestable_items');
     $json['r'] = 0;
     if ($this->tableAlias === null) {
         $query = $this->grid->dataProvider->query;
         if (is_array($query->from)) {
             foreach ($query->from as $k => $table) {
                 if (is_integer($k)) {
                     $this->tableAlias = $table . '.';
                 } else {
                     $this->tableAlias = $k . '.';
                 }
                 break;
             }
         } else {
             if ($query->from) {
                 $this->tableAlias = $query->from . '.';
             }
         }
     } else {
         if ($this->tableAlias = false) {
             $this->tableAlias = '';
         } else {
             $this->tableAlias .= '.';
         }
     }
     if ($id_parent) {
         if ($this->parentCol) {
             $query = $this->getQuery()->where([$this->parentCol => $id_parent]);
             $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => [$this->weightCol => $this->orderBy]]]);
             $models = $dataProvider->getModels();
             $keys = $dataProvider->getKeys();
             $json['r'] = 1;
             $json['items'] = $this->renderItems($models, $keys);
         }
     } elseif (!empty($items)) {
         $weight = [];
         $this->step($weight, $items);
         $json = ['r' => 1, 'weight' => $weight];
     }
     // only need the content enclosed within this widget
     $response = Yii::$app->getResponse();
     $response->clearOutputBuffers();
     $response->setStatusCode(200);
     $response->format = Response::FORMAT_JSON;
     $response->data = $json;
     $response->send();
     Yii::$app->end();
 }
 public function testQuery()
 {
     $query = new Query();
     $provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order')->orderBy('id')]);
     $orders = $provider->getModels();
     $this->assertEquals(3, count($orders));
     $this->assertTrue(is_array($orders[0]));
     $this->assertEquals([0, 1, 2], $provider->getKeys());
     $query = new Query();
     $provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order'), 'pagination' => ['pageSize' => 2]]);
     $orders = $provider->getModels();
     $this->assertEquals(2, count($orders));
 }