/**
  * Creates a new Announcement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Announcement();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', 'New announcement created successfully!');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Announcement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Announcement();
     if ($model->load(Yii::$app->request->post())) {
         $model->setAttributes(array('user_fk' => Yii::$app->user->identity->user_id));
     }
     if ($model->save()) {
         return $this->redirect(['view', 'id' => $model->announcement_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Announcement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('announcementCreate')) {
         $model = new Announcement();
         $model->datetime = date("Y-m-d H:i:s");
         $model->Administrator_id = Yii::$app->user->id;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             AnnouncementHasParticipant::registerAllUsersToAnnouncement($model->getPrimaryKey());
             return $this->redirect(['view', 'id' => $model->id, 'Administrator_id' => $model->Administrator_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
 public function actionWriteAnnouncement($data)
 {
     if (Yii::$app->request->isAjax && !Yii::$app->user->isGuest) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $object = json_decode($data);
         $content = Html::encode($object->msg);
         if (!empty(trim($object->msg))) {
             $announcement = new Announcement();
             $announcement->content = $content;
             $announcement->save();
             if ($announcement->save()) {
                 return array('announcementSave' => true);
             }
         }
     }
 }
 /**
  * Saves the Announcement
  *
  * @param Announcement $announcement
  * @return bool
  */
 public function save(Announcement $announcement)
 {
     return $announcement->save();
 }