Новости Joomla

0 Пользователей и 1 Гость просматривают эту тему.
  • 7 Ответов
  • 2495 Просмотров
*

bombapiter

  • Захожу иногда
  • 71
  • 0 / 0
Всем доброго времени суток.

В моём компоненте  сортировка вывода материалов настроена по имени
Код
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'a.*'
                )
        );

        $query->from('`#__machine` AS a')
->order('a.title');

Делаю вывод материалов для RSS.
Но в RSS сортировку материалов надо сделать по дате создания
Должно быть так:
Код
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'a.*'
                )
        );

        $query->from('`#__machine` AS a')
->order('a.created');

Код должен быть таким:

Код
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'a.*'
                )
        );
        
       if (ЧЕГО_ТО_ТАМ) {
        $query->from('`#__machine` AS a')
->order('a.created');
      } else {
        $query->from('`#__machine` AS a')
->order('a.title');
      }


Что должно быть в "ЧЕГО_ТО_ТАМ"?
*

prometheus

  • Захожу иногда
  • 84
  • 7 / 0
Что-то вроде этого
Код
$ordering = $this->getState('list.ordering');
if ($ordering == 'something') {
        $query->from('`#__machine` AS a')
->order('a.created');
      } else {
        $query->from('`#__machine` AS a')
->order('a.title');
      }
*

bombapiter

  • Захожу иногда
  • 71
  • 0 / 0
Что-то вроде этого
Код
$ordering = $this->getState('list.ordering');
if ($ordering == 'something') {
        $query->from('`#__machine` AS a')
->order('a.created');
      } else {
        $query->from('`#__machine` AS a')
->order('a.title');
      }

А где определяется something ?
*

prometheus

  • Захожу иногда
  • 84
  • 7 / 0
view.feed.php
Код
$model = $this->getModel();
$model->setState('list.ordering', 'something');
*

bombapiter

  • Захожу иногда
  • 71
  • 0 / 0
Спасибо за помощь, но не работает...........

/models/machine.php
Код
<?php

/**
 * @version     1.2.5
 * @package     com_digiseller
 * @copyright   © 2013. Все права защищены.
 * @license     GNU General Public License версии 2 или более поздней; Смотрите LICENSE.txt
 * @author      rra01 <rra_01@mail.ru> - http://all-games-online.ru
 */
defined('_JEXEC') or die;

jimport('joomla.application.component.modellist');

/**
 * Methods supporting a list of Digiseller records.
 */
class MachModelItems extends JModelList {

    /**
     * Constructor.
     *
     * @param    array    An optional associative array of configuration settings.
     * @see        JController
     * @since    1.6
     */
    public function __construct($config = array()) {
        parent::__construct($config);
    }

    /**
     * Method to auto-populate the model state.
     *
     * Note. Calling getState in this method will result in recursion.
     *
     * @since 1.6
     */
    protected function populateState($ordering = null, $direction = null) {

        // Initialise variables.
        $app = JFactory::getApplication();

        // List state information
        $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
        $this->setState('list.limit', $limit);

        $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
        $this->setState('list.start', $limitstart);


if(empty($ordering)) {
$ordering = 'a.ordering';
}


        // List state information.
        parent::populateState($ordering, $direction);
    }

    /**
     * Build an SQL query to load the list data.
     *
     * @return JDatabaseQuery
     * @since 1.6
     */
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'a.*'
                )
        );

$ordering = $this->getState('list.ordering');
if ($ordering == 'a.created') {
        $query->from('`#__machine` AS a')
->order('a.created DESC');
           } else {
        $query->from('`#__machine` AS a')
->order('a.title');
}



        
    // Join over the users for the checked out user.
    $query->select('uc.name AS editor');
    $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
    
// Join over the created by field 'created_by'
$query->select('created_by.name AS created_by');
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
// Join over the category 'catid'
$query->select('catid.title AS catid_title');
$query->join('LEFT', '#__categories AS catid ON catid.id = a.catid');
        

        // Filter by search in title
        $search = $this->getState('filter.search');
        if (!empty($search)) {
            if (stripos($search, 'id:') === 0) {
                $query->where('a.id = ' . (int) substr($search, 3));
            } else {
                $search = $db->Quote('%' . $db->escape($search, true). '%');
                 $query->where('( a.name_goods LIKE '.$search.' )');
              
            }
        }

        

//Filtering catid
$filter_catid = $this->state->get("filter.catid");
if ($filter_catid) {
$query->where("a.catid = '".$filter_catid."'");
}

        return $query;
    }

    public function getItems() {
        return parent::getItems();
    }

}


viev.feed.php
Код
<?php
/**
 * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * HTML View class for the Content component
 *
 * @package Joomla.Site
 * @subpackage com_content
 * @since 1.5
 */
 



 
class DigisellerViewGoods extends JViewLegacy
{
protected $items;
protected $pagination;
protected $state;
    protected $params;



/**
* Display the view
*/
public function display($tpl = null)
{

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$feedEmail = $app->getCfg('feed_email', 'author');
$siteEmail = $app->getCfg('mailfrom');
        
        $state = $this->get('State');
        $items = $this->get('Items');
        $pagination = $this->get('Pagination');
        $params       = $app->getParams('com_digiseller');


JRequest::setVar('limit', $app->getCfg('feed_limit'));

if ($feedEmail != "none")
{
$doc->editorEmail = $siteEmail;
}


$model = $this->getModel();
$model->setState('list.ordering', 'a.created');

*

prometheus

  • Захожу иногда
  • 84
  • 7 / 0
У тебя  идет сперва
Код
$items		= $this->get('Items');
а потом
Код
$model->setState('list.ordering', 'a.created');
сам осмысли свой код приведи его к общему виду, потому что я писал не готовое решение а намек.
*

bombapiter

  • Захожу иногда
  • 71
  • 0 / 0
У тебя  идет сперва
Код
$items		= $this->get('Items');
а потом
Код
$model->setState('list.ordering', 'a.created');
сам осмысли свой код приведи его к общему виду, потому что я писал не готовое решение а намек.

Да, согласен, надо давать намёк, правильное направление для решения задачи, а не готовое решение.................
Спасибо.
*

bombapiter

  • Захожу иногда
  • 71
  • 0 / 0
Так как решил доделать компонент, подниму тему...  

Если в файле machines.php в этом участке :
Код
		if ($ordering == 'a.created') {
        $query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created');

->order('a.created');  заменить на ->order('a.created DESC'); от фид в RSS 2.0 отдается пустым. Atom 1.0  - нормальный, но режет картинки.

Вопрос: почему?

Ниже исходники.



Файл 0:/public_html/components/com_machine/models/machines.php
Код
<?php


defined('_JEXEC') or die;

jimport('joomla.application.component.modellist');

/**
 * Methods supporting a list of Machine records.
 */
class MachineModelGoods extends JModelList {


    public function __construct($config = array()) {
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'a.id',
'ordering', 'a.ordering',
'state', 'a.state',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'created_by', 'a.created_by',
'created', 'a.created',
'name_goods', 'a.name_goods',
'id_group', 'a.id_group',
'id_goods', 'a.id_goods',
'catid', 'a.catid',
'featured', 'a.featured',
'hits', 'a.hits'
);
}
        parent::__construct($config);
    }

    /**
     * Method to auto-populate the model state.
     *
     * Note. Calling getState in this method will result in recursion.
     *
     * @since 1.6
     */
    protected function populateState($ordering = null, $direction = null) {

        // Initialise variables.
        $app = JFactory::getApplication();

        // List state information
        $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
        $this->setState('list.limit', $limit);

        $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
        $this->setState('list.start', $limitstart);

        // Load the filter state.
        $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
        $this->setState('filter.search', $search);

//Filtering catid
$this->setState('filter.catid', $app->getUserStateFromRequest($this->context.'.filter.catid', 'filter_catid', '', 'string'));


        $ordering = $this->setState('list.ordering', 'a.created');


if(empty($ordering)) {
$ordering = 'a.ordering';
}



        // List state information.
        parent::populateState($ordering, $direction);
    }

    /**
     * Build an SQL query to load the list data.
     *
     * @return JDatabaseQuery
     * @since 1.6
     */
    protected function getListQuery() {
        // Create a new query object.
// $ordering = $this->getState('list.ordering');

        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
                $this->getState(
                        'list.select', 'a.*'
                )
        );



$ordering = $this->getState('list.ordering');



if ($ordering == 'a.created') {
        $query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created');
           }else {
        $query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created DESC')
->order('a.featured DESC');
}





        
    // Join over the users for the checked out user.
    $query->select('uc.name AS editor');
    $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
    
// Join over the created by field 'created_by'
$query->select('created_by.name AS created_by');
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
// Join over the category 'catid'
$query->select('catid.title AS catid_title');
$query->join('LEFT', '#__categories AS catid ON catid.id = a.catid');
        

        // Filter by search in title
        $search = $this->getState('filter.search');
        if (!empty($search)) {
            if (stripos($search, 'id:') === 0) {
                $query->where('a.id = ' . (int) substr($search, 3));
            } else {
                $search = $db->Quote('%' . $db->escape($search, true). '%');
                 $query->where('( a.name_goods LIKE '.$search.' )');
              
            }
        }

        

//Filtering catid
$filter_catid = $this->state->get("filter.catid");
if ($filter_catid) {
$query->where("a.catid = '".$filter_catid."'");
}

        return $query;
    }

    public function getItems() {
        return parent::getItems();
    }

}


Файл 0:/public_html/components/com_machine/views/machines/view.feed.php
Код
<?php


defined('_JEXEC') or die;




jimport( 'joomla.application.component.view');

 
class MachineViewGoods extends JViewLegacy
{
/*
protected $items;
protected $pagination;
protected $state;
    protected $params;


*/

public function _GetAnswer($address, $xml){
 $ch = curl_init($address);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_POST,1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
 $result=curl_exec($ch);
 return $result;
}

/**
* Display the view
*/
public function display($tpl = null)
{


$model = $this->getModel();
$model->setState('list.ordering', 'a.created');

$app = JFactory::getApplication();
$doc = &JFactory::getDocument();
$feedEmail = $app->getCfg('feed_email', 'author');
$siteEmail = $app->getCfg('mailfrom');
        
        $state = $this->get('State');
        $items = $this->get('Items');
        $pagination = $this->get('Pagination');
        $params       = $app->getParams('com_machine');



JRequest::setVar('limit', $app->getCfg('feed_limit'));

if ($feedEmail != "none")
{
$doc->editorEmail = $siteEmail;
}

        



foreach ($items as $item)
{



// strip HTML from feed item title
$title = $this->escape($item->name_goods);
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');

// url link to article
$link = JRoute::_('index.php?option=com_machine&view=good&id=' . (int)$item->id);


// strip HTML from feed item description text
$description = $item->info_description;
//$author = $item->created_by_alias ? $item->created_by_alias : $item->author;
//$author = $item->author;
$date = ($item->created ? date('r', strtotime($item->created)) : '');

// load individual item creator class
$feeditem = new JFeedItem();
$feeditem->title = $title;
$feeditem->link = $link;
$feeditem->description = '<img src="'.$item->info_img .'"><br><b>'.$orgprice. ' '.JText::_('COM_MACHINE_RUBLEY').'</b> <br>'.$description;
$feeditem->date = $date;
//$feeditem->category = $category->title;
//$feeditem->author = $author;


// We don't have the author email so we have to use site in both cases.
if ($feedEmail == 'site')
{
$feeditem->authorEmail = $siteEmail;
}
elseif($feedEmail === 'author')
{
$feeditem->authorEmail = $item->author_email;
}

// loads item info into RSS array
$doc->addItem($feeditem);
}
        
      //  $this->_prepareDocument();
       // parent::display($tpl);
}

}
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться
 

Компонент для создания тестов Ari Quiz

Автор alex_noize

Ответов: 0
Просмотров: 1229
Последний ответ 25.02.2016, 20:31:51
от alex_noize
Как проверить существует ли ID материала?

Автор sorrrrry

Ответов: 7
Просмотров: 2273
Последний ответ 15.10.2014, 16:52:58
от SmokerMan
[Решено] Доступ к параметру материала из шаблона

Автор olf

Ответов: 5
Просмотров: 1344
Последний ответ 10.07.2014, 18:32:21
от b2z
Вставка поля в форму добавления материала

Автор __noob__

Ответов: 86
Просмотров: 5314
Последний ответ 17.06.2014, 15:07:19
от __noob__
Компонент com_content. Сохранение материала

Автор Sphinx

Ответов: 62
Просмотров: 7367
Последний ответ 26.11.2013, 13:05:19
от Aleks.Denezh