<?php

/*------------------------------------------------------------------------
# JBusinessDirectory
# author CMSJunkie
# copyright Copyright (C) 2012 cmsjunkie.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.cmsjunkie.com
# Technical Support:  Forum - http://www.cmsjunkie.com/forum/j-businessdirectory/?p=1
-------------------------------------------------------------------------*/

defined('_JEXEC') or die('Restricted access');

class JTableEventVideos extends JTable {
	public $id				= null;
	public $eventId		= null;

	/**
	 * Constructor
	 *
	 * @param object Database connector object
	 */
	public function __construct(&$db) {
		parent::__construct('#__jbusinessdirectory_event_videos', 'id', $db);
	}

	public function setKey($k) {
		$this->_tbl_key = $k;
	}


	/**
	 * Delete all videos of the event with id = $eventId
	 *
	 * @param $eventId int Id of the event which videos will be deleted
	 * @return mixed
	 */
	public function deleteAllForEvent($eventId) {
		$db =JFactory::getDBO();
		$sql = "delete from #__jbusinessdirectory_event_videos where eventId=".$eventId;
		$db->setQuery($sql);
		return $db->execute();
	}

	/**
	 * Get all videos of the event with id = $eventId
	 *
	 * @param $eventId int The id of event which videos are required
	 * @return object[] All videos of event
	 */
	public function getEventVideos($eventId) {
		$db =JFactory::getDBO();
		$sql = "select * from #__jbusinessdirectory_event_videos where eventId=". $eventId ." ORDER BY id" ;
		$db->setQuery($sql);
		return $db->loadObjectList();
	}
}
