<?php
/**
* @version	$Id: l-visit_eh.php 15696 2013-02-19 11:30:53Z 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
	 * @return void
	 * @access protected
	 */
	protected function OnDeleteVisits(kEvent $event)
	{
		$key_field = $event->MasterEvent->Prefix == 'u' ? 'PortalUserId' : 'ResourceId';
		$table_name = $this->getUnitConfig()->getTableName();

		$object = $event->MasterEvent->getObject();
		/* @var $object kDBItem */

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