Beispiel #1
0
 /**
  * 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());
         }
     }
 }
Beispiel #2
0
 /**
  * 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());
             }
         }
     }
 }
Beispiel #3
0
 /**
  * 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;
 }