| Current Path : /var/www/iplanru/data/www/iplan.5018.vps.agava.net/modules/mod_anrek/ |
| Current File : /var/www/iplanru/data/www/iplan.5018.vps.agava.net/modules/mod_anrek/helper.php |
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
* Class Module Helper
* @author kirdinyuri
*/
class modAnrekHelper
{
public static function getText($zoo_type,$zoo_count,$zoo_Itemid,$zoo_template)
{
$lang=JFactory::getLanguage();
$lang=$lang->getTag();
$lang = substr($lang,0,2);
if ($lang<>'ru'){$langtourl="&lang={$lang}";}
$sql_lang='';
if ($lang<>"ru")
{
$sql_lang=" and instr(elements,'\"0\": \"est\"')<>0 ";
}
if ($zoo_template=="0")
{
$sql="SELECT id, name, DATE_FORMAT(created,\"%d.%m.%y\") as crdate, elements
FROM jos_zoo_item
where type=\"{$zoo_type}\" and state=1 {$sql_lang}
order by created desc
limit {$zoo_count}";
$db= &JFactory::getDBO();
$count='';
$db->setQuery($sql, 0, $count);
$rows = $db->loadObjectList();
if (count($rows)<>0)
{
foreach ($rows as $row)
{
$ret[]="<div id=\"zoo-anons\">
<span>{$row->crdate}</span>
<span>
<a id=\"zoo-anons-link1\" href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">{$row->name}</a>
</span>
</div>";
}
}
}
if ($zoo_template=="1")
{
$sql="SELECT id, name, DATE_FORMAT(created,\"%d.%m.%y\") as crdate, elements
FROM jos_zoo_item
where type=\"{$zoo_type}\" and state=1 {$sql_lang}
order by created desc
limit {$zoo_count}";
$db= &JFactory::getDBO();
$count='';
$db->setQuery($sql, 0, $count);
$rows = $db->loadObjectList();
if (count($rows)<>0)
{
foreach ($rows as $row)
{
$a=json_decode($row->elements,true);
$imgpath=$a['57172c66-27cb-442d-a964-19f64f744a3b']['file'];
$ret[]="<div id=\"zoo-anons2\">
<table>
<tr>
<td>
<div id=\"zoo-anons-image\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">
<img src=\"{$imgpath}\" />
</a>
</div>
</td>
<td valign=\"top\">
<div id=\"zoo-anons-text\">
<span id=\"zoo-anons-date\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">
{$row->crdate}</span><br>
</a>
<span>
<a id=\"zoo-anons-link1\" href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">{$row->name}</a>
</span>
</div>
</td>
</tr>
</table>
</div>
";
}
}
}
if ($zoo_template=="2")
{
$ret[]='<div class="newstyle">';
if ($lang=="ru") $ret[]="<div id=\"zagolovok2\">Анонсы готовых бизнес-планов<br> и маркетинговых исследований за 2014 г.</div>";
if ($lang=="en") $ret[]="<div id=\"zagolovok2\">Announcements of ready business plans<br> and marketing research for 2014</div>";
$sql="SELECT id, name, DATE_FORMAT(created,\"%d.%m.%y\") as crdate, elements
FROM jos_zoo_item
where type=\"{$zoo_type}\" and state=1 AND YEAR(`created`) = YEAR(NOW()) {$sql_lang}
order by created desc
limit {$zoo_count}";
$db= &JFactory::getDBO();
$count='';
$db->setQuery($sql, 0, $count);
$rows = $db->loadObjectList();
if (count($rows)<>0)
{
foreach ($rows as $row)
{
$a=json_decode($row->elements,true);
$imgpath=$a['57172c66-27cb-442d-a964-19f64f744a3b']['file'];
$ret[]="<div id=\"zoo-anons2\">
<table>
<tr>
<td>
<div id=\"zoo-anons-image\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">
<img src=\"{$imgpath}\" />
</a>
</div>
</td>
<td valign=\"top\">
<div id=\"zoo-anons-text\">
<span id=\"zoo-anons-date\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">
{$row->crdate}</span><br>
</a>
<span id=\"zagolovok4\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">{$row->name}</a>
</span>
</div>
</td>
</tr>
</table>
</div>
";
}
}
if ($lang=="ru") $ret[]="<div id=\"zagolovok2\">Анонсы готовых бизнес-планов<br> и маркетинговых исследований за 2010-2013 гг.</div>";
if ($lang=="en") $ret[]="<div id=\"zagolovok2\">Announcements of ready business plans<br> and marketing research for 2010-2013</div>";
$sql="SELECT id, name, DATE_FORMAT(created,\"%d.%m.%y\") as crdate
FROM jos_zoo_item
where type=\"{$zoo_type}\" and state=1 AND YEAR(`created`) <> YEAR(NOW()) {$sql_lang}
order by created desc
limit {$zoo_count}";
$db= &JFactory::getDBO();
$count='';
$db->setQuery($sql, 0, $count);
$rows = $db->loadObjectList();
if (count($rows)<>0)
{
foreach ($rows as $row)
{
$ret[]="<div id=\"zoo-anons\">
<span>{$row->crdate}</span><br>
<span id=\"zagolovok4\">
<a href=\"".JRoute::_("/index.php?option=com_zoo&view=item&item_id={$row->id}&Itemid={$zoo_Itemid}{$langtourl}")."\">{$row->name}</a>
</span>
</div>";
}
}
$ret[]='</div>';
}
return implode("\r\n",$ret);
}
static function getData( $params )
{
$db = JFactory::getDbo();
$m=array();
$matid=0;
$option='';
$view='';
$Itemid=0;
//проверка текущего урл
$burl = $_SERVER['REQUEST_URI'];
$turl = $_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');
if ($turl=="/bp.php" and $cat==0 and $matid==0){$cat='21';}
if ($turl=="/mi.php" and $cat==0 and $matid==0){$cat='121';}
if (($turl=="/bp.php" or $turl=="/mi.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 -1 YEAR)
order by RAND()
limit 4")->loadObjectList();
foreach($list as $row)
{
$m[]=$row->id;
}
}
if (($turl=="/bp.php" or $turl=="/mi.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']<>'')
{
$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 id 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<>"Маркетинговые исследования" )
{
$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
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()
limit 4")->loadObjectList();
foreach($list as $row)
{
$m[]=$row->id;
}
}
if (count($m)==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
{$wh1}{$wh2}
order by RAND()
limit 4")->loadObjectList();
foreach($list as $row)
{
$m[]=$row->id;
}
}
if (count($m)==0)
{
$list = $db->setQuery(" SELECT i.id as id
FROM #__zoo_category_item ci, #__zoo_item i
where i.type=\"product\"
and i.created>DATE_ADD(now(), INTERVAL -1 YEAR)
and ci.item_id=i.id
and i.state=1
{$wh1}{$wh2}
order by RAND()
limit 4")->loadObjectList();
foreach($list as $row)
{
$m[]=$row->id;
}
}
//formiruem raboty
if (count($m)<>0)
{
foreach($m as $item)
{
$list = $db->setQuery('SELECT c.params val FROM #__zoo_category_item ci, #__zoo_category c
where ci.category_id=c.id and ci.item_id='.$item)->loadObjectList();
$f='';
foreach($list as $row)
{
if ($f=='')
{
$a=json_decode($row->val,true);
if ($a['metadata.title']=="Бизнес-планы") {$f='108';}
if ($a['metadata.title']=="Маркетинговые исследования") {$f='109';}
}
}
$list = $db->setQuery('SELECT *, DATE_FORMAT(created,"%m.%d.%y") as created2 FROM #__zoo_item where state=1 and id='.$item)->loadAssoc();
$a=json_decode($list['elements'],true);
$n[]='
<div class="rec_item">
<a href="'.JRoute::_('index.php?option=com_zoo&item_id='.$item.'&Itemid='.$f.'&view=item').'" >
<img src="'.JRoute::_($a['57172c66-27cb-442d-a964-19f64f744a3b']['file']).'" />
<div class="rec_date">'.$list['created2'].'</div>
<div class="rec_name">'.$list['name'].'</div>
</a>
</div>
';
}
}
return implode("",$n);
}
}