<?php
/**
* @version	$Id: l-visit_eh.php 12738 2009-10-20 19:36:22Z alex $
* @package	In-Link
* @copyright	Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license      GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/

defined('FULL_PATH') or die('restricted access!');

class LinkVisitEventHandler extends kDBEventHandler {

	/**
	 * Deletes visits when user/link got deleted
	 *
	 * @param kEvent $event
	 */
	function OnDeleteVisits(&$event)
	{
		$key_field = $event->MasterEvent->Prefix == 'u' ? 'PortalUserId' : 'ResourceId';
		$table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');

		$object =& $event->MasterEvent->getObject();

		$sql = 'DELETE FROM '.$table_name.'
				WHERE '.$key_field.' = '.$object->GetDBField($key_field);
		$this->Conn->Query($sql);
	}
}