/**
  * 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]);
     }
 }