Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Index::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['indexid' => $this->indexid, 'exchangeid' => $this->exchangeid, 'ActiveFlag' => $this->ActiveFlag, 'ChangeDate' => $this->ChangeDate]);
     $query->andFilterWhere(['like', 'indname', $this->indname])->andFilterWhere(['like', 'isin', $this->isin]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function getIndeces()
 {
     return $this->hasMany(Index::className(), ['indexid' => 'indid'])->viaTable('indiceslinks', ['quoteid' => 'qid']);
 }
Exemplo n.º 3
0
 /**
  * Common function for actions create/update
  * @param Index $model
  * @param boolean $update
  * @return boolean
  */
 private function indexCreateUpdate(&$model, $update = false)
 {
     $OK = true;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (isset($_POST['IndexQuotes']) && !empty($_POST['IndexQuotes'])) {
             $transaction = Yii::$app->db->beginTransaction();
             // first delete all linked quotes in table indeces links, then recreate them
             if ($update) {
                 $OK = $OK && Yii::$app->db->createCommand()->delete('indiceslinks', ['indid' => $model->indexid])->execute();
             }
             $OK = $OK && $model->save();
             foreach ($_POST['IndexQuotes'] as $qid) {
                 $command = Yii::$app->db->createCommand()->insert('indiceslinks', ['indid' => $model->indexid, 'quoteid' => $qid]);
                 $OK = $OK && $command->execute();
             }
             if ($OK) {
                 $transaction->commit();
                 return true;
             } else {
                 $transaction->rollBack();
                 $model->addError('index', 'Some problems during transaction occured');
             }
         } else {
             $model->addError('quotes', 'The quotes list must be at least 1 item long');
         }
     }
     return false;
 }