public function search($params) { $query = Mailbox::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'sender' => $this->sender, 'receiver' => $this->receiver, 'readed' => $this->readed, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
<h5 class="description-header"><?php echo $model->fullname; ?> </h5> <p class="text-center"> <?php echo $model->profile->label; ?> </p> </div> </div> <!-- messages semiwidget --> <div class="col-md-12 semiwidget-grey"> <?php $messages = \hscstudio\mailbox\models\Mailbox::getRecent(Yii::$app->user->id, $model->id); ?> <h4 class="heading-custom-one padding-bottom-sm color-blue text-center color-orange fonts-md margin-bottom-lg">Recent Messages</h4> <div class="panel-white"> <?php //var_dump($messages); die(); if (count($messages) == 0) { ?> <p class="color-red padset-left"><a href="#">No Messages</a></p> <?php } else { ?> <?php foreach ($messages as $message) { ?> <p class="color-grey padset-left"><?php
public function actionGetMailbox() { $session = Yii::$app->session; $stream = false; $objMailboxs = Mailbox::find()->where(['receiver' => Yii::$app->user->id, 'readed' => 0, 'status' => 1])->orderBy('updated_at DESC')->one(); if ($objMailboxs) { if ($session->has('message_time')) { if ($session->get('message_time') == $objMailboxs->updated_at) { // TETAP $stream = 1; } else { // BERUBAH $stream = 1; } } else { $session->set('message_time', $objMailboxs->updated_at); // BERUBAH $stream = 1; } } else { // BERUBAH $stream = 1; } header('Content-Type: text/event-stream'); if ($stream) { header('Cache-Control: no-cache'); echo "retry: 10000\n"; // Optional. We tell the browser to retry after 10 seconds $countMailbox = 0; $objMailboxs = Mailbox::find()->where(['receiver' => Yii::$app->user->id, 'readed' => 0, 'status' => 1])->orderBy('updated_at DESC')->all(); $listMailbox = ""; if ($objMailboxs) { $subjects = []; $photos = []; $i = 1; foreach ($objMailboxs as $message) { $ds = DIRECTORY_SEPARATOR; $global_path = Yii::getAlias("@common") . $ds . 'files' . $ds; $path = $global_path . $ds . 'users' . $ds; if (file_exists($path . $message->sender . '.jpg')) { $photos[] = Url::to(['site/download', 'file' => 'users/' . $message->sender . '.jpg', 'preview' => true]); } else { $photos[] = $AdminLTEAsset->baseUrl . '/img/user2-160x160.jpg'; } $subjects[] = "" . $message->subject . ""; $urls[] = Url::to(['message/view', 'id' => $message->id]); $times[] = $message->updated_at; $i++; } $subjects = '' . implode('|', $subjects) . ''; $urls = '' . implode('|', $urls) . ''; $times = '' . implode('|', $times) . ''; $photos = '' . implode('|', $photos) . ''; $countMailbox = $i - 1; } echo "data: {\"subjects\": \"" . $subjects . "\",\"times\": \"" . $times . "\",\"photos\": \"" . $photos . "\",\"urls\": \"" . $urls . "\",\"count\": \"" . $countMailbox . "\"}\n\n"; flush(); } }