/**
  * Creates a new Journal model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Journal();
     $model->date = Yii::$app->formatter->asDate('today', 'long');
     $model->user_id = Yii::$app->user->id;
     //var_dump($model->shared_with); die();
     if ($model->load(Yii::$app->request->post())) {
         $model->shared_with = implode(',', $model->shared_with);
         if ($model->save()) {
             Yii::$app->notification->notify($model->entry, $model, $model->user, Yii::$app->controller->id, $model->shared_with);
             Yii::$app->session->setFlash('success', 'Journal successfully posted.');
             return $this->redirect(['index']);
         }
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('_form', ['model' => $model]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
 /**
  * Synchronizes new samples from another source.
  * In this case synchronizes with production server. Check configuration in config/params.php
  *
  * This is esay version of one table replication, for advanced synchronization check database
  * replication manuals for your DB.
  */
 public function actionSync()
 {
     /**
      * Find max id and load all new records in current journal
      */
     $lastModel = Journal::find()->orderBy(['id' => SORT_DESC])->one();
     $syncData = file_get_contents(Yii::$app->params['journalSyncUrl'] . $lastModel->id);
     if (!empty($syncData)) {
         $syncData = json_decode($syncData, true);
         foreach ($syncData as $row) {
             $newModel = new Journal();
             $newModel->load(['Journal' => $row]);
             $newModel->save();
         }
     }
     return $this->redirect(['index']);
 }