Example #1
0
 function getList(&$params)
 {
     $model = modZbannersHelper::getModel();
     // Model Variables
     $vars['cid'] = (int) $params->get('cid');
     $vars['catid'] = (int) $params->get('catid');
     $vars['limit'] = (int) $params->get('count', 1);
     $vars['ordering'] = $params->get('ordering');
     $bannersList = $model->getList($vars);
     if ($params->get('tag_search')) {
         $user =& JFactory::getUser();
         //           $banners = $this->getBanners($user->id, $bannersList);
         #####################3
         $db =& JFactory::getDBO();
         $session = JFactory::getSession();
         $zonal_actual = $session->get('zonales_zonal_name', null);
         $tags = HighLevelApi::getAncestors($user->id, $zonal_actual);
         // suma uno a todos los elementos del array
         // para que hasta los que no tengan valor se tengan en cuenta
         foreach ($tags as $key => $t) {
             $auxA = $key == $zonal_actual ? 1 : 0;
             $tags[$key] = $t + 1 + $auxA;
         }
         $pieces = array_keys($tags);
         $query = 'select cp.content_id as banner_id, cpv.name as tag from #__custom_properties cp, #__custom_properties_fields cpf, #__custom_properties_values cpv where cp.field_id=cpf.id and cp.value_id=cpv.id and cp.ref_table="banner" and cpf.name="root_zonales" and cpv.name in (\'' . implode("','", $pieces) . '\')';
         $db->setQuery($query);
         $dbBanners = $db->loadObjectList();
         // mapeo los banners obtenidos con la relevancia correspondiente
         $bannersW = array();
         foreach ($dbBanners as $bannerTag) {
             $currentTag = $bannerTag->tag;
             foreach ($tags as $tag => $relevance) {
                 if ($tag == $currentTag) {
                     $auxB = isset($bannersW[$bannerTag->banner_id]) ? $bannersW[$bannerTag->banner_id] : 0;
                     $bannersW[$bannerTag->banner_id] = $auxB + $relevance;
                 }
             }
         }
         // solo me interensan los banners que deben ser mostrados
         //        $bannersM = array();
         //        foreach ($bannersList as $banner) {
         //            foreach ($bannersW as $bannerId => $relevanceB) {
         //                if ($bannerId == $banner->bid) {
         //                    $bannersM[$bannerId] = $relevanceB;
         //                }
         //            }
         //        }
         $bannersM = $bannersW;
         // ordeno los banners por relevancia
         $bannersSorted = arsort($bannersM, SORT_NUMERIC);
         /*
          *  ##################
          */
         // normalizo las relevancias
         //        $total = array_sum($tags);
         //        $contributions = array();
         //        foreach ($tags as $name => $value) {
         //            $contributions[$name] = ($value * modZbannersHelper::MAXTOTAL) / $total;
         //        }
         //
         //
         //        $random = rand(0, modZbannersHelper::MAXTOTAL);
         //
         //        $max = max($tags);
         //
         //        // obtengo las posiciones donde cambian los valores
         //        $positions = array();
         //        $positions[] = 0;
         //        $count = count($contributions);
         //        for ($j = 1; $j < $count;$j++){
         //            if ($contributions[$j] != $contributions[$j - 1]){
         //                $positions[] = $j;
         //            }
         //        }
         //
         //        $countP = count($positions);
         //        for ($i = 1;$i < $countP;$i++){
         //            $pos = $positions[$i];
         //            $posPrevius = $positions[$i - 1];
         //            if ($random >= $contributions[$posPrevius] && $random < $contributions[$pos]){
         //                $showMe = $posPrevius;
         //            }
         //        }
         /*
          *  ###################
          */
         // elimino la relevancia. ya no es necesaria
         $bannersIdsRaw = array_keys($bannersM);
         $totalBanners = count($bannersIdsRaw);
         // si tengo mas banners que los solicitados
         if ($totalBanners > $vars['limit']) {
             // elimino los menos relevantes que sobren
             $bannersIds = array_slice($bannersIdsRaw, 0, $vars['limit']);
         } else {
             // si no
             $bannersIds = $bannersIdsRaw;
             // si faltan banners
             if ($totalBanners < $vars['limit']) {
                 // busco en la base de datos banners que no tengan zona asociada
                 // solo la cantidad que faltan
                 $totalBannersNeeded = $vars['limit'] - $totalBanners;
                 $selectNonZone = "SELECT bn.bid FROM #__banner bn where bn.bid not in\n                            (SELECT b.bid FROM #__custom_properties j,\n                                                #__banner b,\n                                                #__custom_properties_fields f\n                                          where j.ref_table='banner'\n                                                and j.content_id=b.bid\n                                                and f.name='root_zonales'\n                                                 and f.id=j.field_id\n                                                ) limit {$totalBannersNeeded}";
                 $db->setQuery($selectNonZone);
                 $noZoneBanners = $db->loadObjectList();
                 if ($bannersSorted) {
                     foreach ($noZoneBanners as $currentBanner) {
                         // los agrego al final porque no son relevantes
                         $bannersIds[] = $currentBanner->bid;
                     }
                 }
             }
         }
         if (count($bannersIds) <= 0) {
             return;
         }
         $case = '';
         foreach ($bannersIds as $pos => $id) {
             $case .= "when {$id} then {$pos} ";
         }
         $catId = $vars['catid'];
         $cId = $vars['cid'];
         $select = "select b.bid, b.impmade, b.imptotal, b.custombannercode, b.name,\n        b.imageurl, b.clickurl, b.params, case b.bid\n            {$case} end as orden from #__banner b  where b.bid in (" . implode(',', $bannersIds) . ") and b.catid={$catId} and b.cid={$cId} and b.showBanner=1 order by orden DESC";
         $db->setQuery($select);
         $banners = $db->loadObjectList();
         ##########################
         //			$document		=& JFactory::getDocument();
         //			$keywords		=  $document->getMetaData( 'keywords' );
         //
         //
         //
         //			$vars['tag_search'] = array($zonal_actual);
     } else {
         $banners = $bannersList;
     }
     $model->impress($banners);
     return $banners;
 }
<?php

/**
* @version	$Id: mod_banners.php 10381 2008-06-01 03:35:53Z pasamio $
* @package	Zonales
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license	GNU/GPL, see LICENSE.php
*
* Zonales is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// Include the syndicate functions only once
require_once dirname(__FILE__) . DS . 'helper.php';
$headerText = trim($params->get('header_text'));
$footerText = trim($params->get('footer_text'));
$list = modZbannersHelper::getList($params);
require JModuleHelper::getLayoutPath('mod_zbanners');
Example #3
0
    ?>
	<div class="bannerheader"><?php 
    echo $headerText;
    ?>
</div>
<?php 
}
$totalElements = count($list);
for ($i = $totalElements - 1; $i >= 0; $i--) {
    $item = $list[$i];
    ?>
<div class="banneritem<?php 
    echo $params->get('moduleclass_sfx');
    ?>
"><?php 
    echo modZbannersHelper::renderBanner($params, $item);
    ?>
<div class="clr"></div>
	</div>
<?php 
}
?>

<?php 
if ($footerText) {
    ?>
	<div class="bannerfooter<?php 
    echo $params->get('moduleclass_sfx');
    ?>
">
		 <?php