/** * Pull ads from the database */ function getQueryInfo() { $dbr = PRDatabase::getDb(); // First we must construct the filter before we pull ads // When the filter comes in it is space delimited, so break that... $likeArray = preg_split('/\\s/', $this->filter); // ...and then insert all the wildcards betwean search terms if (empty($likeArray)) { $likeArray = $dbr->anyString(); } else { $anyStringToken = $dbr->anyString(); $tempArray = array($anyStringToken); foreach ($likeArray as $likePart) { $tempArray[] = $likePart; $tempArray[] = $anyStringToken; } $likeArray = $tempArray; } // Get the current campaign and filter on that as well if required $campaign = $this->mRequest->getVal('campaign'); $campaignId = AdCampaign::getCampaignId($campaign); if ($campaignId) { // Return all the ads not already assigned to the current campaign return array('tables' => array('adlinks' => 'pr_adlinks', 'ads' => 'pr_ads'), 'fields' => array('ads.ad_name', 'ads.ad_id'), 'conds' => array('adlinks.ad_id IS NULL', 'ad_name' . $dbr->buildLike($likeArray)), 'join_conds' => array('adlinks' => array('LEFT JOIN', "adlinks.ad_id = ads.ad_id " . "AND adlinks.cmp_id = {$campaignId}"))); } else { // Return all the ads in the database return array('tables' => array('ads' => 'pr_ads'), 'fields' => array('ads.ad_name', 'ads.ad_id'), 'conds' => array('ads.ad_name' . $dbr->buildLike($likeArray))); } }
/** * @param IContextSource $hostTitle * @param string $formSection * @param array $prependPrototypes * @param array $appendPrototypes * @param string $adFilter * @param bool $editable */ function __construct($hostTitle, $formSection = null, $prependPrototypes = array(), $appendPrototypes = array(), $adFilter = '', $editable = false) { $this->editable = $editable; $this->filter = $adFilter; parent::__construct(); $this->prependPrototypes = $prependPrototypes; $this->appendPrototypes = $appendPrototypes; $this->formSection = $formSection; $this->viewPage = $hostTitle; // Override paging defaults list($this->mLimit, $this->mOffset) = $this->mRequest->getLimitOffset(20, ''); $this->mLimitsShown = array(20, 50, 100); // Get the database object $this->mDb = PRDatabase::getDb(); }
/** * Set the database query to retrieve all the ads in the database * * @return array of query settings */ function getQueryInfo() { $dbr = PRDatabase::getDb(); // When the filter comes in it is space delimited, so break that... $likeArray = preg_split('/\\s/', $this->filter); // ...and then insert all the wildcards betwean search terms if (empty($likeArray)) { $likeArray = $dbr->anyString(); } else { $anyStringToken = $dbr->anyString(); $tempArray = array($anyStringToken); foreach ($likeArray as $likePart) { $tempArray[] = $likePart; $tempArray[] = $anyStringToken; } $likeArray = $tempArray; } return array('tables' => array('ads' => 'pr_ads'), 'fields' => array('ads.ad_name', 'ads.ad_id'), 'conds' => array('ads.ad_name' . $dbr->buildLike($likeArray))); }
/** * Check to see if an ad actually exists in the database * * @return bool * @throws AdDataException If it's a silly query */ public function exists() { $db = PRDatabase::getDb(); if ($this->name !== null) { $selector = array('ad_name' => $this->name); } elseif ($this->id !== null) { $selector = array('ad_id' => $this->id); } else { throw new AdDataException('Cannot determine ad existence without name or ID.'); } $row = $db->selectRow('pr_ads', 'ad_name', $selector); if ($row) { return true; } else { return false; } }
/** * Updates the weight of a ad in a campaign. * * @param $campaignName String Name of the campaign to update * @param $adId Int ID of the ad in the campaign * @param $weight Int New ad weight */ static function updateWeight($campaignName, $adId, $weight) { $dbw = PRDatabase::getDb(); $campaignId = AdCampaign::getCampaignId($campaignName); $dbw->update('pr_adlinks', array('adl_weight' => $weight), array('ad_id' => $adId, 'cmp_id' => $campaignId)); }
/** * Create form for managing ads assigned to a campaign */ function assignedAdsForm($campaign) { $dbr = PRDatabase::getDb(); $res = $dbr->select(array('campaigns' => 'pr_campaigns', 'adlinks' => 'pr_adlinks', 'ads' => 'pr_ads'), array('ads.ad_id', 'ads.ad_name', 'adlinks.adl_weight'), array('campaigns.cmp_name' => $campaign, 'campaigns.cmp_id = adlinks.cmp_id', 'adlinks.ad_id = ads.ad_id'), __METHOD__, array('ORDER BY' => 'campaigns.cmp_id')); // No ads found if ($dbr->numRows($res) < 1) { return ''; } if ($this->editable) { $readonly = array(); } else { $readonly = array('disabled' => 'disabled'); } $weights = array(); $ads = array(); foreach ($res as $row) { $ads[] = $row; $weights[] = $row->adl_weight; } $isBalanced = count(array_unique($weights)) === 1; // Build Assigned ads HTML $htmlOut = Html::hidden('change', 'weight'); $htmlOut .= Xml::fieldset($this->msg('promoter-assigned-ads')->text()); // Equal weight ads $htmlOut .= Xml::openElement('tr'); $htmlOut .= Xml::tags('td', array(), Xml::label($this->msg('promoter-balanced')->text(), 'balanced')); $htmlOut .= Xml::tags('td', array(), Xml::check('balanced', $isBalanced, array_replace($readonly, array('value' => $campaign, 'id' => 'balanced')))); $htmlOut .= Xml::closeElement('tr'); $htmlOut .= Xml::openElement('table', array('cellpadding' => 9, 'width' => '100%')); if ($this->editable) { $htmlOut .= Xml::element('th', array('align' => 'left', 'width' => '5%'), $this->msg("promoter-remove")->text()); } $htmlOut .= Xml::element('th', array('align' => 'left', 'width' => '5%', 'class' => 'pr-weight'), $this->msg('promoter-weight')->text()); /* $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), $this->msg( 'promoter-bucket' )->text() ); */ $htmlOut .= Xml::element('th', array('align' => 'left', 'width' => '70%'), $this->msg('promoter-ads')->text()); // Table rows foreach ($ads as $row) { $htmlOut .= Xml::openElement('tr'); if ($this->editable) { // Remove $htmlOut .= Xml::tags('td', array('valign' => 'top'), Xml::check('removeAds[]', false, array('value' => $row->ad_name))); } // Weight $htmlOut .= Xml::tags('td', array('valign' => 'top', 'class' => 'pr-weight'), $this->weightDropDown("weight[{$row->ad_id}]", $row->adl_weight)); // Ad $ad = Ad::fromName($row->ad_name); $htmlOut .= Xml::tags('td', array('valign' => 'top'), $ad->linkToPreview()); $htmlOut .= Xml::closeElement('tr'); } $htmlOut .= Xml::closeElement('table'); $htmlOut .= Xml::closeElement('fieldset'); return $htmlOut; }