protected function getMessages() {
		$result = array();
		$with = array(
			'queues' => array(
				'together'=>true,
				'on'=>'queues.is_delivered=:is_delivered',
				'with'=>'defaultMessage',
				'params'=>array(':is_delivered'=>false),
			),
			'channel'=>array('together'=>true),
		);
		$subscriptions = NfySubscriptions::model()->with($with)->findAll('t.user_id=:user_id', array(':user_id'=>Yii::app()->user->getId()));

	//VarDumper::dump($subscriptions); die();

		foreach($subscriptions as $subscription) foreach($subscription->queues as $queue) {
			$queue->delivered_on = date('Y-m-d H:i:s');
			$queue->is_delivered = true;
			if ($queue->save()) {
				$notification = array(
					'title'=>$subscription->channel->name,
					'body'=>$queue->message !== null ? $queue->message : $queue->defaultMessage->message,
				);
				if ($this->getModule()->soundUrl!==null) {
					$notification['sound'] = $this->createAbsoluteUrl($this->getModule()->soundUrl);
				}
				$result[] = $notification;
			}
		}
		return $result;
	}
Beispiel #2
0
	/**
	 * Unsubscribes user from this channel.
	 * @param integer $user_id
	 * @return boolean
	 */
	public function unsubscribe($user_id) {
		$subscriptions = NfySubscriptions::model()->findAllByAttributes(array('channel_id'=>$this->id,'user_id'=>$user_id));
		foreach($subscriptions as $subscription) {
			$subscription->delete();
		}
		return true;
	}