/** * Creates a new BlockTime model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new BlockTime(); if ($model->load(Yii::$app->request->post()) && $model->save()) { //each time a block Time is created , it fetches all the registration tokens of all the users with the course and sends them a push notification $UsersHasCourse = UserHasCourse::findAll(["course_id" => $model->course_id]); foreach ($UsersHasCourse as $user_one) { $User = InvokerUser::findOne(['id' => $user_one['user_id']]); $gcmClient = new GcmClient('YOUR_API_KEY'); $message = new Message($gcmClient); $message->addRegistrationId($User->reg_token); $message->setData(['title' => 'New Block Time', 'message' => ['starttime' => $model->starttime, 'endtime' => $model->endtime]]); try { $response = $message->send(); // The send() method returns a Response object print_r($response); //exit(1); } catch (Exception $exception) { echo 'uh-oh: ' . $exception->getMessage(); //exit(1); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = InvokerUser::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(['id' => $this->id, 'access_time' => $this->access_time]); $query->andFilterWhere(['like', 'mobile_id', $this->mobile_id])->andFilterWhere(['like', 'phone_number', $this->phone_number])->andFilterWhere(['like', 'reg_token', $this->reg_token]); return $dataProvider; }
/** * Finds the InvokerUser model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return InvokerUser the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = InvokerUser::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }