/** * @inheritdoc */ public function run() { $model = Yii::createObject(['class' => Message::className(), 'author_id' => $this->userId, 'recipient_id' => $this->contactId]); $options = ArrayHelper::merge($this->options, ['id' => $this->id, 'data' => ['pjax' => $this->pjaxId, 'fancy' => $this->fancySelector]]); $formOptions = ArrayHelper::merge(['id' => "{$this->id}-form", 'action' => Yii::$app->urlManager->createUrl($this->route), 'enableClientValidation' => true, 'enableAjaxValidation' => false, 'validateOnSubmit' => true], $this->formOptions); if ($this->fancySelector) { echo \newerton\fancybox\FancyBox::widget(['target' => $this->fancySelector, 'config' => array_merge(['href' => '#' . $this->id, 'autoDimensions' => false, 'autoSize' => false, 'width' => 500, 'height' => 200, 'type' => 'inline'], $this->fancyOptions)]); Html::addCssStyle($options, 'display:none'); } return $this->render($this->tpl, ['id' => $this->id, 'model' => $model, 'options' => $options, 'formOptions' => $formOptions]); }
/** * Returns vount unreaded messages for user * @return int */ public function actionCount() { return Message::find()->byRecipient()->unread()->count(); }
/** * Returns messages table name * @return string */ public function getMsgTableName() { return Message::tableName(); }
/** * Returns data provider for messages * @return object|ActiveDataProvider * @throws \yii\base\InvalidConfigException */ public function getDataProvider() { if (is_null($this->_dataProvider)) { $query = Message::find()->byContact($this->contactId, $this->userId)->with(['author', 'recipient']); if (is_callable($this->queryModifier)) { $func = $this->queryModifier; $func($query); } $this->_dataProvider = Yii::createObject(ArrayHelper::merge(['class' => ActiveDataProvider::className(), 'query' => $query], $this->dataProviderOptions)); $this->_dataProvider->sort->defaultOrder = $this->defaultOrder; $this->_dataProvider->pagination->pageSize = $this->pageSize; } return $this->_dataProvider; }
/** * Relation with last message * @return \yii\db\ActiveQuery */ public function getLastMessage() { return $this->hasOne(Message::className(), ['id' => 'last_message_id']); }