Пример #1
0
 public function actionRead($id)
 {
     $model = Message::findOne(['id' => $id]);
     $model['status'] = 1;
     $model->save();
     return $this->render('read', ['model' => $model]);
 }
Пример #2
0
 public function actionIndexWithDescriptions()
 {
     if (isset($_POST['Room'])) {
         $roomsInput = $_POST['Room'];
         foreach ($roomsInput as $item) {
             $sourceMessage = \common\models\SourceMessage::findOne(['message' => $item['description']]);
             // If null, I need to create source message
             if ($sourceMessage == null) {
                 $sourceMessage = new \common\models\SourceMessage();
             }
             $sourceMessage->category = 'app';
             $sourceMessage->message = $item['description']['en'];
             $sourceMessage->save();
             $otherLanguages = ['zh-cn'];
             foreach ($otherLanguages as $otherLang) {
                 $message = \common\models\Message::findOne(['id' => $sourceMessage->id, 'language' => $otherLang]);
                 if ($message == null) {
                     $message = new \common\models\Message();
                 }
                 $message->id = $sourceMessage->id;
                 $message->language = $otherLang;
                 $message->translation = $item['description'][$otherLang];
                 $message->save();
             }
             // Room to update
             $roomToUpdate = \frontend\models\BaseRoom::findOne($item['id']);
             $roomToUpdate->description = $item['description']['en'];
             $roomToUpdate->save();
         }
     }
     $rooms = BaseRoom::find()->all();
     return $this->render('indexWithDescriptions', ['rooms' => $rooms]);
 }
Пример #3
0
 /**
  * Finds the Message model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Message the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Message::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #4
0
 public static function getMessageBySensor($sensorId, $value)
 {
     if ($sensorId > 0) {
         $message = Message::findOne(['sensor_id' => $sensorId, 'active' => self::STATUS_ACTIVE]);
         if ($value == 1) {
             return $message['message_1'];
         }
         if ($value == 0) {
             return $message['message_0'];
         }
     }
     return 'null';
 }
Пример #5
0
 /**
  * Updates an existing SourceMessage model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $lang = Lang::find()->all();
     foreach ($lang as $i) {
         $model_content[$i->code] = Message::findOne(['id' => $id, 'language' => $i->code]);
     }
     if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->save()) {
         foreach ($model_content as $key => $content) {
             $content->save(false);
         }
         return $this->redirect(['/message']);
     } else {
         return $this->render('update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Пример #6
0
 /**
  * 删除消息,根据用户id,消息id从message表中标记特定用户已经删除的消息
  * @param $messageId
  * @param $userId
  * @return bool
  */
 public static function deleteMessageByUserId($messageId, $userId)
 {
     //读取数据库中deleted字段值
     $message = Message::findOne(['id' => $messageId]);
     $deleted = $message->deleted;
     //如果deleted字段不等于null
     if ($deleted == 0) {
         $deleted = $userId;
     } else {
         $deletedArr = explode(',', $deleted);
         //如果已删除字段在deleted字段中,则跳过
         if (in_array($userId, $deletedArr)) {
             return true;
         } else {
             $deleted .= ',' . $userId;
         }
     }
     //更新message中的deleted字段
     $message->deleted = (string) $deleted;
     return $message->save();
 }
 /**
  * @param $id
  * @return Message
  */
 protected function loadDialog($id)
 {
     return Message::findOne(['from' => $id]);
 }
Пример #8
0
 /**
  * Gets translation in requested language
  * @param  string $language Language the translation must be in
  * @return string|null      Returns either string eiher null when no
  *                                  translations found for this message
  */
 public function getTranslation($language, $onlyMessage = true)
 {
     $model = Message::findOne(['id' => $this->id, 'language' => $language]);
     return empty($model) || !$onlyMessage ? $model : $model->translation;
 }