Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/person/story/notification.php
<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Engine™
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.anahitapolis.com
 */

class AnModelPersonStoryNotification extends AnModelStoryAbstract 
{	
	static public function describe($notification)
	{
		parent::describe($notification);
		
		$notification->getProperty('owner')->setModel('lib.anahita.model.person');
		$notification->getProperty('owner')->setInverseRelationship();
		$notification->filter()->where('story.story_type','=','notification');
		
		
		
	}
	
	/**
	 * Get the email object of this notification 
	 * @return KObject
	 */
	public function getEmail()
	{		
		$email_template = $this->application->getStoryTemplate('email', $this->template->getName());
		if ( !$email_template ) return null;
		$email			= new KObject();
		$email->subject = $email_template->parseSubject($this);
		$email->body	= $email_template->parseBody($this);
		return $email;
	}
	
	protected function _registerHooks()
	{
		$this->registerFunctionAfter('insert', 'mailNotification');	
	}
	
	/**
	 * Mail notification
	 * 
	 * @return void
	 */
	public function mailNotification()
	{
		$setting_key = 'notification_'.$this->template->getName();
		
		if ( !$this->owner->email || strlen($this->owner->email) == 0 )
			return;
			
		$ret = $this->application->getActorSettingValue($this->owner, $setting_key, true) && $this->getEmail();
		
		if ( !$ret ) return;
		
		$mail		  = KFactory::tmp('lib.anahita.util.mailer');
		
		$body 		  = (string) KFactory::tmp('lib.anahita.uikit.email.notification')
							->setNotification($this); 
									
		$mail->Subject = $this->getEmail()->subject;

		$mail->setBody($body);
		
		$mail->addRecipient(array($this->owner->email));
	
		$mail->Send();
		
		return $mail;		
	}
}
Return current item: Anahita Social Engine