First pass at converting files to use autoloading! Take care if you have an old yioop system you are upgrading, a=chris
First pass at converting files to use autoloading! Take care if you have an old yioop system you are upgrading, a=chris
<?php
/**
* SeekQuarry/Yioop --
* Open Source Pure PHP Search Engine, Crawler, and Indexer
*
* Copyright (C) 2009 - 2015 Chris Pollett chris@pollett.org
*
* LICENSE:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* END LICENSE
*
* @author Pushkar Umaranikar
* @license http://www.gnu.org/licenses/ GPL3
* @link http://www.seekquarry.com/
* @copyright 2009 - 2015
* @filesource
*/
if (!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
/** Loads the base class */
require_once BASE_DIR."/models/model.php";
/**
* This class is used to handle
* database statements related to Advertisement Metadata
*
* @author Pushkar Umaranikar
* @package seek_quarry\model
*/
class AdMetaDataModel extends Model
{
/**
* Associations of the form
* name of field for web forms => database column names/abbreviations
* In this case, things will in general map to the USERS table in the
* Yioop data base
* var array
*/
var $search_table_column_map = array("id"=>"AD_ID",
"clicks" => "CLICKS", "impressions" => "IMPRESSIONS",);
/**
* These fields if present in $search_array (used by @see getRows() ),
* but with value "-1", will be skipped as part of the where clause
* but will be used for order by clause
* @var array
*/
var $any_fields = array("status");
/**
* {@inheritDoc}
*
* @param mixed $args any additional arguments which should be used to
* determine these tables (in this case none)
*/
function selectCallback($args = NULL)
{
return "AD_ID, CLICKS, IMPRESSIONS";
}
/**
* {@inheritDoc}
*
* @param mixed $args any additional arguments which should be used to
* determine these tables (in this case none)
*/
function fromCallback($args = NULL)
{
return "ADVERTISEMENT_METADATA";
}
/**
* {@inheritDoc}
*
* @param mixed $args any additional arguments which should be used to
* determine these tables (in this case none)
*/
function whereCallback($args = NULL)
{
return "";
}
/**
* Checks if advertisement metadata present or not
*
* @param integer $ad_id represents advertisement id
* @return boolean value representing metedata present or not
*/
function isAdvMetadataPresent($ad_id)
{
$db = $this->db;
$sql = "SELECT AD_ID FROM ADVERTISEMENT_METADATA WHERE AD_ID = ?";
$result = $db->execute($sql,array($ad_id));
if ($result) {
if ($mix = $db->fetchArray($result)) {
return true;
} else {
return false;
}
}
}
/**
* Records number of impressions for an advertisement
*
* @param string $ad_id of an advertisement
* @param boolean $is_new Checks if advertisement is newly created or not
*/
function addImpression($ad_id,$is_new)
{
$db = $this->db;
$clicks = 0;
$impressions = 1;
if ($is_new) {
$sql = "INSERT INTO ADVERTISEMENT_METADATA
(AD_ID,CLICKS,IMPRESSIONS) VALUES (?, ?, ?)";
$result = $db->execute($sql,array(
$ad_id,$clicks,$impressions));
} else {
$sql= "UPDATE ADVERTISEMENT_METADATA SET
IMPRESSIONS= IMPRESSIONS +1 WHERE AD_ID = ?";
$result = $db->execute($sql,array($ad_id));
}
}
/**
* Records the number of clicks for an advertisement
*
* @param integer $ad_id advertisement id
*/
function addClick($ad_id)
{
$db = $this->db;
$sql = "UPDATE ADVERTISEMENT_METADATA SET CLICKS = CLICKS + 1 WHERE
AD_ID = ?";
$result = $db->execute($sql,array($ad_id));
}
}
?>