public function run()
 {
     $uid = Yii::app()->user->id;
     if (!$uid || !$this->commentableType || !$this->itemId) {
         return;
     }
     $this->notifySubs = NotifySubscription::findOrCreate($this->commentableType, $this->itemId, $uid);
     $this->render('notifyItemSubscription');
 }
 /**
  * @return NotifySubscription
  */
 public static function findOrCreate($commentableType, $itemId, $userId)
 {
     if ($ns = NotifySubscription::model()->findByAttributes(array('item_id' => $itemId, 'commentable_type' => $commentableType, 'user_id' => $userId))) {
         return $ns;
     }
     $ns = new self();
     $ns->commentable_type = $commentableType;
     $ns->item_id = $itemId;
     $ns->user_id = $userId;
     return $ns;
 }
Exemple #3
0
 /**
  * подписка/отписка на материал
  */
 public function actionItemSubscribe()
 {
     $postNS = @$_POST['NotifySubscription'];
     $active = @$postNS['active'];
     $ns = NotifySubscription::findOrCreate(@$postNS['commentable_type'], @$postNS['item_id'], Yii::app()->user->id);
     if (!$ns->validate()) {
         print_r($ns->getErrors());
         return;
     }
     if ($active) {
         $ns->save();
         Yii::app()->user->setFlash('user-notify', YCommentsModule::t('Subscription performed'));
     } else {
         if (!$ns->isNewRecord) {
             $ns->delete();
             Yii::app()->user->setFlash('user-notify', YCommentsModule::t('Subscription canceled'));
         }
     }
     $this->widget('ycomments.widgets.NotifyItemSubscriptionWidget', array('commentableType' => $ns->commentable_type, 'itemId' => $ns->item_id));
 }
}
?>
	<?php 
echo CHtml::openTag('label', array('for' => 'nr-' . $wid));
echo $form->checkBox($this->notifyUser, 'notify_reply', array('id' => 'nr-' . $wid, 'onclick' => $ajax));
echo $this->notifyUser->getAttributeLabel('notify_reply');
echo CHtml::closeTag('label');
// 	echo $form->checkBoxRow($this->notifyUser, 'notify_reply', array(
//         'id' => 'nr-'.$wid,
//         'onclick' => $ajax
//     ));
?>
	<br><br>
	
	<?php 
NotifySubscription::$commentableType = $this->commentableType;
// respect dynamic relation
$itemCount = $this->subProvider->getTotalItemCount();
?>
	<?php 
if ($itemCount) {
    ?>
		<h3><?php 
    echo YCommentsModule::t('Item subscriptions');
    ?>
</h3>
		<?php 
    $this->widget('zii.widgets.CListView', array('id' => 'subs-items-' . $this->commentableType, 'dataProvider' => $this->subProvider, 'itemView' => '_notifySubItem', 'emptyText' => YCommentsModule::t('no subscriptions'), 'template' => "<table> {items}\n </table> {pager}\n{summary}"));
    ?>
	<?php 
}