| Current Path : /var/www/iplanru/data/www/www.i-plan.ru/modules/mod_recomend/ |
| Current File : /var/www/iplanru/data/www/www.i-plan.ru/modules/mod_recomend/helper.php |
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
* Class Module Helper
* @author kirdinyuri
*/
class modRecomendHelper
{
/**
* getData method
* @param $params
* @return array
*/
static function getData( $params )
{
$db = JFactory::getDbo();
$m=array();
$matid=0;
$option='';
$view='';
$Itemid=0;
//проверка текущего урл
$burl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$turl = isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : '';
$jinput = JFactory::getApplication()->input;
$matid=$jinput->get( 'item_id', 0, 'INT' );
$option=$jinput->get( 'option', '');
$view=$jinput->get( 'view', '');
$Itemid=$jinput->get( 'Itemid', 0,'INT' );
$cat=$jinput->get( 'category_id', 0,'INT');
$lang=$jinput->get( 'lang', "ru");
if ($turl=="/bp.php" and $cat==0 and $matid==0){$cat='2376';}
if ($turl=="/mi.php" and $cat==0 and $matid==0){$cat='2376';}
if ($turl=="/catalog.php" and $cat==0 and $matid==0){$cat='2376';}
//фиксированнный набор С этим исследованием покупают
/*$fix=false;
if (($turl=="/bp.php" or $turl=="/mi.php" or $turl=="/catalog.php") and $matid<>0)
{
$list = $db->setQuery('SELECT elements FROM #__zoo_item where state=1 and id='.$matid)->loadAssoc();
$a=json_decode($list['elements'],true);
if (count($a['89a94924-6bec-43db-953f-71e1be6570ed']['item'])<>0)
{
foreach($a['89a94924-6bec-43db-953f-71e1be6570ed']['item'] as $item)
{
$m[]=$item;
$fix=true;
}
}
if (count($a['51bccd62-4a17-4a7d-b988-9167f4b59c6e']['item'])<>0)
{
foreach($a['51bccd62-4a17-4a7d-b988-9167f4b59c6e']['item'] as $item)
{
$m[]=$item;
$fix=true;
}
}
}*/
//category
if (($turl=="/bp.php" or $turl=="/mi.php" or $turl=="/catalog.php") and $cat<>0 and $matid==0)
{
$list = $db->setQuery(" SELECT i.id as id
FROM #__zoo_category_item ci, #__zoo_item i
where i.type=\"product\"
and ci.category_id={$cat}
and ci.item_id=i.id
and i.state=1
and created>DATE_ADD(now(), INTERVAL -7 YEAR)
order by RAND()
limit 4")->loadObjectList();
foreach($list as $row)$m[]=$row->id;
}
//works
$tekcat='';
if (($turl=="/bp.php" or $turl=="/mi.php" or $turl=="/catalog.php") and $matid<>0)
{
$tekcat = $db->setQuery("SELECT category_id cat
FROM #__zoo_category_item
where item_id={$matid}
and category_id<>0
and category_id>=2376")->loadAssoc();
if ($tekcat)
{
$list = $db->setQuery(" SELECT i.id as id
FROM #__zoo_category_item ci, #__zoo_item i
where i.type=\"product\"
and ci.category_id={$tekcat[cat]}
and ci.item_id=i.id
and i.id<>{$matid}
and i.state=1
and created>DATE_ADD(now(), INTERVAL -7 YEAR)
order by created desc
limit 5")->loadObjectList();
foreach($list as $row)$m[]=$row->id;
}
}
//сбор по родительской отрасли рекурсивно
if (count($m)<5 and $tekcat)
{
$parent=$db->setQuery(" SELECT parent FROM #__zoo_category WHERE id=".$tekcat[cat])->loadAssoc();
$parent=$parent['parent'];
$sql_cat=' and (ci.category_id='.$parent;
$cc = modRecomendHelper::getCat($parent);
foreach($cc as $i)
{
$sql_cat.=' or ci.category_id='.$i;
}
$sql_cat.=')';
$item2 = $db->setQuery(" SELECT distinct i.id
FROM jos_zoo_item i, jos_zoo_category_item ci
WHERE i.id=ci.item_id and i.state=1 and type=\"product\" {$sql_cat}
order by created desc
limit 5")->loadAssocList();
if ($item2)
{
foreach($item2 as $elem)
{
$m[]=$elem['id'];
}
}
}
/*if (($turl=="/bp.php" or $turl=="/mi.php" or $turl=="/catalog.php") and $matid<>0)
{
$list = $db->setQuery('SELECT elements FROM #__zoo_item where state=1 and id='.$matid)->loadAssoc();
$a=json_decode($list['elements'],true);
//fin model
if ($a['6e6bfd81-74f2-434c-8306-b80e2287bf44']['item']['0']<>'' and
$a['5eea65b2-7504-4863-bae7-7fb95490e156']['option']['0']<>'rabota-s-fm' and
( ($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']<>'est' and $lang=="ru") or
($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']=='est' and $lang=="en"))
)
{
$m[]=$a['6e6bfd81-74f2-434c-8306-b80e2287bf44']['item']['0'];
}
//samaya svejaya
if (count($a['7b18a4ef-f209-4c68-a854-03c04184955d']['item'])<>0)
{
$sql='SELECT id FROM #__zoo_item where type="product" and state=1 and (';
foreach ( $a['7b18a4ef-f209-4c68-a854-03c04184955d']['item'] as $item)
{
$sqlid[]='id='.$item;
}
$sql.=implode(" or ", $sqlid);
$sql.=') order by created desc';
$list = $db->setQuery($sql)->loadAssoc();
$m[]=$list['id'];
unset($sql,$sqlid);
}
//4 work
$br='';
$list = $db->setQuery("SELECT c.name as name, c.id as id
FROM #__zoo_category_item ci, #__zoo_category c
where ci.category_id=c.id and ci.item_id={$matid}")->loadObjectList();
foreach($list as $row)
{
if ($br=='')
{
if ($row->name<>"Все маркетинговые исследования" &&
$row->name<>"Все бизнес-планы" &&
$row->name<>"Бизнес-планы" &&
$row->name<>"Маркетинговые исследования" &&
$row->name<>"All marketing researches" &&
$row->name<>"All business plans" &&
$row->name<>"Business plans" &&
$row->name<>"Marketing researches" )
{
$br=$row->id;
}
}
}
if (isset($m[0])){$wh1=" and i.id<>".$m[0];}
if (isset($m[1])){$wh2=" and i.id<>".$m[1];}
$list = $db->setQuery(" SELECT i.id as id, i.elements as elements
FROM #__zoo_category_item ci, #__zoo_item i
where i.type=\"product\"
and ci.category_id={$br}
and ci.item_id=i.id
and i.state=1
and created>DATE_ADD(now(), INTERVAL -1 YEAR)
and i.id<>{$matid}
{$wh1}{$wh2}
order by RAND()")->loadObjectList();
foreach($list as $row)
{
$a=json_decode($row->elements,true);
if (($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']<>'est' and $lang=="ru") or
($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']=='est' and $lang=="en"))
{$mr[]=$row->id;}
}
if (count($mr)>0){$m[]=$mr[0];}
if (count($mr)>1){$m[]=$mr[1];}
if (count($mr)>2){$m[]=$mr[2];}
if (count($mr)>3){$m[]=$mr[3];}
unset($mr);
}
*/
/*if (count($m)<4)
{
$list = $db->setQuery(" SELECT i.id as id, i.elements as elements
FROM #__zoo_category_item ci, #__zoo_item i
where i.type=\"product\"
and ci.category_id={$cat}
and ci.item_id=i.id
and i.state=1
{$wh1}{$wh2}
order by RAND()")->loadObjectList();
foreach($list as $row)
{
$a=json_decode($row->elements,true);
if (($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']<>'est' and $lang=="ru") or
($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']=='est' and $lang=="en"))
{$mr[]=$row->id;}
}
if (count($mr)>0){$m[]=$mr[0];}
if (count($mr)>1){$m[]=$mr[1];}
if (count($mr)>2){$m[]=$mr[2];}
if (count($mr)>3){$m[]=$mr[3];}
unset($mr);
}*/
/*if (count($m)<4)
{
$list = $db->setQuery(" SELECT i.id as id, i.elements as elements
FROM #__zoo_item i
where i.type=\"product\"
and i.created>DATE_ADD(now(), INTERVAL -1 YEAR)
and i.state=1
{$wh1}{$wh2}
order by RAND()")->loadObjectList();
foreach($list as $row)
{
$a=json_decode($row->elements,true);
if (($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']<>'est' and $lang=="ru") or
($a['43191a2a-0fb3-4578-b7e0-dbf5e584873d']['option']['0']=='est' and $lang=="en"))
{$mr[]=$row->id;}
}
if (count($mr)>0){$m[]=$mr[0];}
if (count($mr)>1){$m[]=$mr[1];}
if (count($mr)>2){$m[]=$mr[2];}
if (count($mr)>3){$m[]=$mr[3];}
unset($mr);
}*/
jimport('imagecache.imagecache');
$ImageCache = new ImageCache();
//formiruem raboty
$n=array();
if (count($m)<>0)
{
if (count($m)>0){$t[]=$m[0];}
if (count($m)>1){$t[]=$m[1];}
if (count($m)>2){$t[]=$m[2];}
if (count($m)>3){$t[]=$m[3];}
if (count($m)>4){$t[]=$m[4];}
foreach($t as $item)
{
$list = $db->setQuery('SELECT *, DATE_FORMAT(created,"%d.%m.%y") as created2 FROM #__zoo_item where state=1 and type="product" and id='.$item)->loadAssoc();
$a=json_decode($list['elements'],true);
$imagepath=$ImageCache->ImageCacheJPG($a['57172c66-27cb-442d-a964-19f64f744a3b']['file'],'mod_recomend',61,86,70);
$sm_name=$a['c3b4b9f6-9d61-42f4-a5f1-889be3cf412d']['0']['value'];
if ($sm_name)
{$name=$sm_name;}
else
{$name=$list['name'];}
$n[]='
<div class="rec_item">
<a href="'.JRoute::_('index.php?option=com_zoo&item_id='.$item.'&Itemid=117&view=item').'" >
<div class="rec_img"><img src="'.JRoute::_($imagepath).'" /></div>
<div class="rec_date">'.$list['created2'].'</div>
<div class="rec_name">'.$name.'</div>
</a>
</div>';
}
}
return implode("",$n);
}
static function getCat( $cat)
{
$m=array();
$db = JFactory::getDbo();
$list = $db->setQuery(" SELECT id,name
FROM #__zoo_category
where
parent=\"{$cat}\"
and published=1
order by ordering")->loadAssocList();
if (count($list)<>0)
{
foreach($list as $row)
{
$m[]=$row['id'] ;
$m = array_merge($m, modRecomendHelper::getCat($row['id'] ));
}
}
return $m;
}
}