-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
69 lines (57 loc) · 2.11 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @license GNU/GPL v2
* @copyright Copyright (c) Lyquix. All rights reserved.
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
class modLyquixBannersHelper {
// returns the item id/s of banner/s
static function getItems(&$params) {
// Load libraries
require_once("components/com_flexicontent/classes/flexicontent.helper.php");
require_once("components/com_flexicontent/helpers/permission.php");
// Initialize
global $mainframe;
$mainframe = JFactory::getApplication();
$db = JFactory::getDBO();
$user = JFactory::getUser();
// get null date and now
$nullDate = $db->getNullDate();
$date = JFactory::getDate();
// build query
$query = "SELECT DISTINCT c.id FROM #__content AS c, #__flexicontent_cats_item_relations as fcir, #__flexicontent_items_ext as fie WHERE c.id = fcir.itemid AND c.id = fie.item_id AND c.state = 1 AND c.publish_up < UTC_TIMESTAMP() AND (c.publish_down = '0000-00-00 00:00:00' OR c.publish_down > UTC_TIMESTAMP())";
// category
if($params->get('catid')) {
$query .= " AND fcir.catid = ".$params->get('catid');
}
// type
if($params->get('typeid')) {
$query .= " AND fie.type_id = ".$params->get('typeid');
}
// language scope
if($params->get('lang_scope',1)) {
$lang = flexicontent_html::getUserCurrentLang();
$query .= " AND (fie.language = '*' OR fie.language LIKE '".$lang."%')";
}
// remove unauthorized items
$gid = !FLEXI_J16GE ? (int)$user->get('aid') : max($user->getAuthorisedViewLevels());
if(FLEXI_ACCESS && class_exists('FAccess')) {
$readperms = FAccess::checkUserElementsAccess($user->gmid, 'read');
if (isset($readperms['item']) && count($readperms['item']) ) {
$query .= " AND (c.access <= ".$gid." OR c.id IN (".implode(",", $readperms['item'])."))";
}
else {
$query .= " AND c.access <= ".$gid;
}
}
else {
$query .= " AND c.access <= ".$gid;
}
// add ordering
$query .= " ORDER BY ".$params->get('ordering', 'fcir.ordering');
// Execute query
$db->setQuery($query, 0);
$items = $db->loadColumn();
return array_slice($items, 0, $params->get('count',5), true);
}
}