/** * Get total personal messages * */ public function getTotalMessages() { // Count the messages in the participants table return PersonalMessageParticipant::model()->count('user_id=:id', array(':id' => Yii::app()->user->id)); }
/** * view help topic action */ public function actionView() { // Check Access checkAccessThrowException('op_personalmessages_view'); if (isset($_GET['id']) && ($model = PersonalMessageTopic::model()->with(array('author', 'participants', 'replies'))->findByPk($_GET['id']))) { // Make sure we are a participant if ($model->author_id != Yii::app()->user->id) { $participantExists = PersonalMessageParticipant::model()->exists('topic_id=:topic AND user_id=:user', array(':user' => Yii::app()->user->id, ':topic' => $model->id)); if (!$participantExists) { ferror(at('Sorry, You are not allowed to view this personal message as you are not a participant.')); alog(at("Tried Accessing a Personal Message '{name}' When he is not a participant.", array('{name}' => $model->title))); $this->redirect(getReferrer('personalmessages/index')); } } alog(at("Viewed Personal Message '{name}'.", array('{name}' => $model->title))); // Add Breadcrumb $this->addBreadCrumb(at('Viewing Personal Message')); $this->title[] = at('Viewing Personal Message "{name}"', array('{name}' => $model->title)); $reply = new PersonalMessageReply(); if (isset($_POST['PersonalMessageReply'])) { checkAccessThrowException('op_personalmessages_reply'); $reply->attributes = $_POST['PersonalMessageReply']; $reply->topic_id = $model->id; if ($reply->save()) { fok(at('Reply Sent.')); alog(at("Replied To Personal Message '{name}'.", array('{name}' => $model->title))); $this->redirect(getReferrer('personalmessages/index')); } } // Delete all the notifications we have for this topic PersonalMessageNotification::model()->deleteAll('user_id=:user AND topic_id=:topic', array(':user' => Yii::app()->user->id, ':topic' => $model->id)); // Display form $this->render('view', array('model' => $model, 'reply' => $reply)); } else { ferror(at('Could not find that ID.')); $this->redirect(array('personalmessages/index')); } }