Example #1
0
 /**
  * Creates a new Point model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionAddpoints($rule_id, $count = 1)
 {
     $maxpos = Point::find(['rule_id' => $rule_id])->max('position');
     for ($i = 0; $i < $count; $i++) {
         $model = new Point();
         $model->rule_id = intval($rule_id);
         $model->position = $maxpos + $i + 1;
         $model->points = 0;
         $model->save();
     }
     return $this->redirect(['view', 'id' => $rule_id]);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Point::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'rule_id' => $this->rule_id, 'position' => $this->position, 'points' => $this->points]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPoints()
 {
     return $this->hasMany(Point::className(), ['rule_id' => 'id']);
 }
Example #4
0
 public function actionUpdates()
 {
     $errors = '';
     $rule_id = null;
     $models = Point::find()->where(['id' => array_keys($_POST['Point'])])->indexBy('id')->all();
     if (Point::loadMultiple($models, Yii::$app->request->post()) && Point::validateMultiple($models)) {
         $count = 0;
         foreach ($models as $model) {
             // populate and save records for each model
             if (count($model->errors) > 0) {
                 $errors .= print_r($model->errors, true);
             }
             if (!$rule_id) {
                 $rule_id = $model->rule_id;
             }
             if ($model->save()) {
                 $count++;
             }
         }
         Yii::$app->session->setFlash('success', Yii::t('igolf', "Processed {0} records successfully.", $count));
         return $this->redirect(['rule/view', 'id' => $rule_id]);
         // redirect to your next desired page
     } else {
         Yii::$app->session->setFlash('error', Yii::t('igolf', "Could not processed your request. Errors: ", $errors));
         return $this->redirect(['rule/view', 'id' => $rule_id]);
         // redirect to your next desired page
     }
 }