/** * Clicks the URL, incrementing the counter */ function click() { $id = $this->getState('banner.id'); // update click count $query = new JQuery(); $query->update('#__banners'); $query->set('clicks = (clicks + 1)'); $query->where('id = ' . (int) $id); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } // track clicks $item =& $this->getItem(); $trackClicks = $item->track_clicks; if ($trackClicks < 0 && $item->cid) { $trackClicks = $item->client_track_clicks; } if ($trackClicks < 0) { $config =& JComponentHelper::getParams('com_banners'); $trackClicks = $config->get('track_clicks'); } if ($trackClicks > 0) { $trackDate = JFactory::getDate()->toFormat('%Y-%m-%d'); $query = new JQuery(); $query->select('`count`'); $query->from('#__banner_tracks'); $query->where('track_type=2'); $query->where('banner_id=' . (int) $id); $query->where('track_date=' . $this->_db->Quote($trackDate)); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } $count = $this->_db->loadResult(); $query = new JQuery(); if ($count) { // update count $query->update('#__banner_tracks'); $query->set('`count` = (`count` + 1)'); $query->where('track_type=2'); $query->where('banner_id=' . (int) $id); $query->where('track_date=' . $this->_db->Quote($trackDate)); } else { // insert new count $query->insert('#__banner_tracks'); $query->set('`count` = 1'); $query->set('track_type=2'); $query->set('banner_id=' . (int) $id); $query->set('track_date=' . $this->_db->Quote($trackDate)); } $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } } }
/** * Makes impressions on a list of banners */ function impress() { $trackDate = JFactory::getDate()->toFormat('%Y-%m-%d'); $items =& $this->getItems(); foreach ($items as $item) { // Increment impression made $id = $item->id; $query = new JQuery(); $query->update('#__banners'); $query->set('impmade = (impmade + 1)'); $query->where('id=' . (int) $id); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } // track impressions $trackImpressions = $item->track_impressions; if ($trackImpressions < 0 && $item->cid) { $trackImpressions = $item->client_track_impressions; } if ($trackImpressions < 0) { $config =& JComponentHelper::getParams('com_banners'); $trackImpressions = $config->get('track_impressions'); } if ($trackImpressions > 0) { // is track already created ? $query = new JQuery(); $query->select('`count`'); $query->from('#__banner_tracks'); $query->where('track_type=1'); $query->where('banner_id=' . (int) $id); $query->where('track_date=' . $this->_db->Quote($trackDate)); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } $count = $this->_db->loadResult(); $query = new JQuery(); if ($count) { // update count $query->update('#__banner_tracks'); $query->set('`count` = (`count` + 1)'); $query->where('track_type=1'); $query->where('banner_id=' . (int) $id); $query->where('track_date=' . $this->_db->Quote($trackDate)); } else { // insert new count $query->insert('#__banner_tracks'); $query->set('`count` = 1'); $query->set('track_type=1'); $query->set('banner_id=' . (int) $id); $query->set('track_date=' . $this->_db->Quote($trackDate)); } $this->_db->setQuery((string) $query); if (!$this->_db->query()) { JError::raiseError(500, $this->_db->getErrorMsg()); } } } }
public static function updateReset() { $user = JFactory::getUser(); $db = JFactory::getDBO(); $query = new JQuery(); $query->select('*'); $query->from("#__banners"); $query->where("NOW()>=`reset`"); $query->where("`reset`!='0000-00-00 00:00:00' AND `reset`!=NULL"); $query->where("(`checked_out`=0 OR `checked_out`=" . $db->Quote($user->id) . ")"); $db->setQuery((string) $query); $rows = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); return false; } JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_banners/tables'); foreach ($rows as $row) { $purchase_type = $row->purchase_type; if ($purchase_type < 0 && $row->cid) { $client = JTable::getInstance('Client', 'BannersTable'); $client->load($row->cid); $purchase_type = $client->purchase_type; } if ($purchase_type < 0) { $params = JComponentHelper::getParams('com_banners'); $purchase_type = $params->get('purchase_type'); } switch ($purchase_type) { case 1: $reset = '0000-00-00 00:00:00'; break; case 2: $reset = JFactory::getDate('+1 year ' . date('Y-m-d', strtotime('now')))->toMySQL(); break; case 3: $reset = JFactory::getDate('+1 month ' . date('Y-m-d', strtotime('now')))->toMySQL(); break; case 4: $reset = JFactory::getDate('+7 day ' . date('Y-m-d', strtotime('now')))->toMySQL(); break; case 5: $reset = JFactory::getDate('+1 day ' . date('Y-m-d', strtotime('now')))->toMySQL(); break; } // Update the row ordering field. $query = new JQuery(); $query->update('`#__banners`'); $query->set('`reset` = ' . $db->quote($reset)); $query->set('`impmade` = ' . $db->quote(0)); $query->set('`clicks` = ' . $db->quote(0)); $query->where('`id` = ' . $db->quote($row->id)); $db->setQuery((string) $query); $db->query(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); return false; } } return true; }
/** * Method to save the form data. * * @param array The form data. * @return boolean True on success. */ public function save($data) { // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('module.id'); $isNew = true; // Include the content modules for the onSave events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError(JText::sprintf('JTable_Error_Bind_failed', $table->getError())); return false; } // Prepare the row for saving $this->_prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onBeforeSaveContent event. $result = $dispatcher->trigger('onBeforeContentSave', array(&$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // // Process the menu link mappings. // $assignment = isset($data['assignment']) ? $data['assignment'] : 0; // Delete old module to menu item associations // $this->_db->setQuery( // 'DELETE FROM #__modules_menu'. // ' WHERE moduleid = '.(int) $table->id // ); $query = new JQuery(); $query->delete(); $query->from('#__modules_menu'); $query->where('moduleid=' . (int) $table->id); $this->_db->setQuery((string) $query); $this->_db->query(); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } // If the assignment is numeric, then something is selected (otherwise it's none). if (is_numeric($assignment)) { // Variable is numeric, but could be a string. $assignment = (int) $assignment; // Check needed to stop a module being assigned to `All` // and other menu items resulting in a module being displayed twice. if ($assignment === 0) { // assign new module to `all` menu item associations // $this->_db->setQuery( // 'INSERT INTO #__modules_menu'. // ' SET moduleid = '.(int) $table->id.', menuid = 0' // ); $query = new JQuery(); $query->insert('#__modules_menu'); $query->set('moduleid=' . (int) $table->id); $query->set('menuid=0'); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } else { if (!empty($data['assigned'])) { // Get the sign of the number. $sign = $assignment < 0 ? -1 : +1; // Preprocess the assigned array. $tuples = array(); foreach ($data['assigned'] as &$pk) { $tuples[] = '(' . (int) $table->id . ',' . (int) $pk * $sign . ')'; } $this->_db->setQuery('INSERT INTO #__modules_menu (moduleid, menuid) VALUES ' . implode(',', $tuples)); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } // Clean the cache. $cache = JFactory::getCache('com_modules'); $cache->clean(); // Trigger the onAfterContentSave event. $dispatcher->trigger('onAfterContentSave', array(&$table, $isNew)); $this->setState('module.id', $table->id); return true; }