Your IP : 216.73.216.89


Current Path : /home/azimutno/www/demo/plugins/nextendslidergenerator/k2/items/
Upload File :
Current File : /home/azimutno/www/demo/plugins/nextendslidergenerator/k2/items/generator.php

<?php
/*
# author Roland Soos
# copyright Copyright (C) Nextendweb.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-3.0.txt GNU/GPL
*/
defined('_JEXEC') or die('Restricted access'); ?><?php

nextendimport('nextend.smartslider.generator_abstract');

class NextendGeneratorK2_Items extends NextendGeneratorAbstract {

    var $extraFields;

    function NextendGeneratorK2_Items($data) {
        parent::__construct($data);
        $this->extraFields = array();
        $this->_variables = array(
            'id' => 'ID of the item',
            'title' => 'Title of the item',
            'url' => 'Url of the item',
            'alias' => 'Alias of the item',
            'introtext' => 'Intro of the item',
            'fulltext' => 'Text of the item',
            'catid' => 'Id of the item\'s category',
            'cat_title' => 'Title of the item\'s category',
            'categoryurl' => 'Url to the item\'s category',
            'created_by' => 'Id of the item\'s creator',
            'created_by_alias' => 'Name of the article\'s creator',
            'image' => 'Image for the item',
            'image_caption' => 'Image caption for the item',
            'image_credits' => 'Image credits for the item',
            'hits' => 'Hits of the item'
        );

        $this->loadExtraFields();
        if (count($this->extraFields) > 0) {
            foreach ($this->extraFields AS $v) {
                $this->_variables['extra' . $v['id'] . '_' . preg_replace("/\W|_/", "", $v['group_name'] . '_' . $v['name'])] = 'Extra field ' . $v['name'] . ' of the item';
            }
        }
    }

    function loadExtraFields() {
        static $extraFields = null;
        if ($extraFields === null) {
            $db = NextendDatabase::getInstance();

            $query = 'SELECT ';
            $query .= 'groups.name AS group_name, ';
            $query .= 'field.name AS name, ';
            $query .= 'field.id ';

            $query .= 'FROM #__k2_extra_fields_groups AS groups ';

            $query .= 'LEFT JOIN #__k2_extra_fields AS field ON field.group = groups.id ';

            $query .= 'WHERE field.published = 1 ';

            $db->setQuery($query);
            $this->extraFields = $db->loadAssocList('id');
        }
    }

    function getData($number) {

        nextendimport('nextend.database.database');
        $db = NextendDatabase::getInstance();

        $data = array();

        $category = array_map('intval', explode('||', $this->_data->get('k2itemssourcecategory', '')));

        $query = 'SELECT ';
        $query .= 'con.id, ';
        $query .= 'con.title, ';
        $query .= 'con.alias, ';
        $query .= 'con.introtext, ';
        $query .= 'con.fulltext, ';
        $query .= 'con.catid, ';
        $query .= 'cat.name AS cat_title, ';
        $query .= 'cat.alias AS cat_alias, ';
        $query .= 'con.created_by, ';
        $query .= 'usr.name AS created_by_alias, ';
        $query .= 'con.hits, ';
        $query .= 'con.image_caption, ';
        $query .= 'con.image_credits, ';
        $query .= 'con.extra_fields ';

        $query .= 'FROM #__k2_items AS con ';

        $query .= 'LEFT JOIN #__users AS usr ON usr.id = con.created_by ';

        $query .= 'LEFT JOIN #__k2_categories AS cat ON cat.id = con.catid ';


        $query .= 'WHERE con.catid IN (' . implode(',', $category) . ') ';
        $sourceuserid = intval($this->_data->get('k2itemssourceuserid', ''));
        if ($sourceuserid) {
            $query .= 'AND con.created_by = ' . $sourceuserid . ' ';
        }
        if ($this->_data->get('k2itemssourcepublished', 1)) {
            $jnow = JFactory::getDate();
            $now = version_compare(JVERSION,'1.6.0','<') ? $jnow->toMySQL() : $jnow->toSql();
            $query .= "AND con.published = 1 AND (con.publish_up = '0000-00-00 00:00:00' OR con.publish_up < '".$now."') AND (con.publish_down = '0000-00-00 00:00:00' OR con.publish_down > '".$now."') ";
        }
        $query .= 'AND con.trash = 0 ';

        if ($this->_data->get('k2itemssourcefeatured', 0)) {
            $query .= 'AND con.featured = 1 ';
        }
        $language = $this->_data->get('k2itemssourcelanguage', '*');
        if ($language) {
            $query .= 'AND con.language = ' . $db->quote($language) . ' ';
        }

        $order = NextendParse::parse($this->_data->get('k2itemsorder1', 'con.title|*|asc'));
        if ($order[0]) {
            $query .= 'ORDER BY ' . $order[0] . ' ' . $order[1] . ' ';
            $order = NextendParse::parse($this->_data->get('k2itemsorder2', 'con.title|*|asc'));
            if ($order[0]) {
                $query .= ', ' . $order[0] . ' ' . $order[1] . ' ';
            }
        }


        $query .= 'LIMIT 0, ' . $number . ' ';

        $db->setQuery($query);
        $result = $db->loadAssocList();

        $this->loadExtraFields();

        for ($i = 0; $i < count($result); $i++) {
            $result[$i]['url'] = JRoute::_('index.php?option=com_k2&view=item&id=' . $result[$i]['id'] . ':' . $result[$i]['alias']);
            $result[$i]['categoryurl'] = JRoute::_('index.php?option=com_k2&view=itemlist&task=category&id=' . $result[$i]['catid'] . ':' . $result[$i]['cat_alias']);

            $result[$i]['image'] = "media/k2/items/cache/" . md5("Image" . $result[$i]['id']) . "_XL.jpg";

            $extraFields = json_decode($result[$i]['extra_fields'], true);
            if (is_array($extraFields) && count($extraFields) > 0) {
                foreach ($extraFields AS $field) {
                    $result[$i]['extra' . $field['id'] . '_' . preg_replace("/\W|_/", "", $this->extraFields[$field['id']]['group_name'] . '_' . $this->extraFields[$field['id']]['name'])] = $field['value'];
                }
            }
        }
        return $result;
    }
}