/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MessageRecord::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, 'user_id' => $this->user_id, 'event_id' => $this->event_id, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'number', $this->number]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $this->refreshProfile();
         $current = $this->getLocationCurrent();
         $event = $this->getEvent();
         $radius = MessageRecord::RADIUS_UNDER_MILD;
         if ($event->urgent == Event::URGENT_URGENT) {
             $radius = MessageRecord::RADIUS_UNDER_URGENT;
         } elseif ($event->urgent == Event::URGENT_EMERGENCY) {
             $radius = MessageRecord::RADIUS_UNDER_EMERGENCY;
         }
         $numbers = Yii::$app->telecoms->getNumbers($current->latitude, $current->longitude, $radius);
         $newNumbers = MessageRecord::getNewNumbers($event->id, $numbers);
         if (!$newNumbers) {
             throw new Exception("No new numbers found");
         }
         Yii::$app->telecoms->sendMessage($newNumbers, $this);
         MessageRecord::createRecords($event->id, $newNumbers);
         $transaction->commit();
         return true;
     } catch (\yii\db\Exception $e) {
         $this->addError('title', 'fail to create record in database');
     } catch (\yii\base\Exception $e) {
         $this->addError('title', $e->getMessage());
     }
     $transaction->rollBack();
     return false;
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMessageRecords()
 {
     return $this->hasMany(\common\models\message\MessageRecord::className(), ['event_id' => 'id']);
 }
 /**
  * Finds the MessageRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MessageRecord the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MessageRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }