Форум - Показ последних сообщений

#
Форум - Показ последних сообщений
Подскажите плиз, как модифицировать код вывода последних сообщений форума таким образом, чтобы в xml передавалась информация по категории, к которой принадлежит последнее сообщение...

<?php
/**
* Показ последних сообщений форума.
*
* <code>
* $oForum = Core_Entity::factory('Forum', 1);
*
* $Forum_Last_Posts_Show = new Forum_Last_Posts_Show(
*    $oForum
* );
*
* $Forum_Last_Posts_Show
*    ->xsl(
*       Core_Entity::factory('Xsl')->getByName('ПоследниеСообщенияФорума')
*    )
*    ->show();
* </code>
*
* @package HostCMS 6\Forum
* @version 6.x
* @author Hostmake LLC
* @copyright © 2005-2013 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
*/
class Forum_Last_Posts_Show extends Core_Controller
{
    /**
     * Allowed object properties
     * @var array
     */
    protected $_allowedProperties = array(
       'limit',
    );

    protected $_forumTopicPosts = NULL;

    /**
     * Constructor.
     * @param Forum_Model $oSiteuser user
     */
    public function __construct(Forum_Model $oForum)
    {
       parent::__construct($oForum->clearEntities());

       $this->limit = 3;

      $this->_forumTopicPosts = Core_Entity::factory('Forum_Topic_Post');
      $this->_forumTopicPosts
       ->queryBuilder()
       ->select('forum_topic_posts.*')
       ->join('forum_topics', 'forum_topics.id', '=', 'forum_topic_posts.forum_topic_id')
       ->join('forum_categories', 'forum_categories.id', '=', 'forum_topics.forum_category_id')
       ->join('forum_groups', 'forum_groups.id', '=', 'forum_categories.forum_group_id')
       ->where('forum_groups.forum_id', '=', $oForum->id)
       ->where('forum_groups.deleted', '=', 0)
       ->where('forum_categories.deleted', '=', 0)
       ->where('forum_topics.deleted', '=', 0)
       ->clearOrderBy()
       ->orderBy('forum_topic_posts.datetime', 'DESC')
       ->limit($this->limit);
    }

    public function forumTopicPosts()
    {
       return $this->_forumTopicPosts;
    }

    /**
     * Show built data
     * @return self
     */
    public function show()
    {
       $oForum = $this->getEntity();

       $aForum_Topic_Posts = $this->_forumTopicPosts->findAll(FALSE);
      
       foreach ($aForum_Topic_Posts as $oForum_Topic_Posts)
       {
          $this->addEntity(
             $oForum_Topic_Posts->clearEntities()
             ->showXmlSiteuser(TRUE)
          );
       }

       return parent::show();
    }
}
?>

SNN
#
Re: Форум - Показ последних сообщений
как-то так

    public function show() {
      
   $aCategories = array();
        $oForum = $this->getEntity();

        $aForum_Topic_Posts = $this->_forumTopicPosts->findAll(FALSE);
      
        foreach ($aForum_Topic_Posts as $oForum_Topic_Posts)
        {
         $aCategories[] = $oForum_Topic_Posts->forum_topic->forum_category;
         $this->addEntity(
            $oForum_Topic_Posts->clearEntities()
            ->showXmlSiteuser(TRUE)
         );
        }
      if (!empty($aCategories)) {
         $this->addEntities($aCategories);
      }

        return parent::show();
     }
HostDev.pw - модули для HostCMS, Telegram: @hostdev
#
Re: Форум - Показ последних сообщений
Благодарю за помощь!
SNN
#
Re: Форум - Показ последних сообщений
Правда не совсем получается пока, архитектура xml не совсем корректна....
Сейчас такая архитектура...

<forum id="1">
   <structure_id>36</structure_id>
   <user_id>19</user_id>
   <site_id>1</site_id>
   <name>Форум</name>
   <description>Демонстрационная конференция</description>
   <topics_on_page>10</topics_on_page>
   <posts_on_page>10</posts_on_page>
   <flood_protection_time>1</flood_protection_time>
   <allow_edit_time>14400</allow_edit_time>
   <allow_delete_time>1800</allow_delete_time>
   <url>/forums/</url>
   <forum_topic_post id="8">
      <siteuser_id>0</siteuser_id>
      <ip>85.26.165.60</ip>
      <subject>Обсуждаем последние новости</subject>
      <forum_topic_id>6</forum_topic_id>
      <deleted>0</deleted>
      <datetime>26.12.2014 17:16:21</datetime>
      <original_text>Обсуждаем последние новости</original_text>
      <text>Обсуждаем последние новости</text>
   </forum_topic_post>
   <forum_category id="8">
      <forum_group_id>4</forum_group_id>
      <name>Новости</name>
      <description></description>
      <closed>0</closed>
      <sorting>1</sorting>
      <email>sergey.nikol@gmail.com</email>
      <postmoderation>1</postmoderation>
      <visible>1</visible>
      <use_captcha>1</use_captcha>
      <user_id>20</user_id>
      <allow_guest_posting>1</allow_guest_posting>
      <count_topics>1</count_topics>
      <count_topic_posts>1</count_topic_posts>
      <new_posts>1</new_posts>
      <captcha_id>61959</captcha_id>
   </forum_category>
</forum>



А нужно чтобы forum_topic_post был внутри forum_category  .... иначе не получается категорию связать с сообщением...
SNN
#
Re: Форум - Показ последних сообщений
хм, тогда так

public function show() {  
   $aCategories = array();
   $oForum = $this->getEntity();

   $aForum_Topic_Posts = $this->_forumTopicPosts->findAll(FALSE);

   foreach ($aForum_Topic_Posts as $oForum_Topic_Posts)
   {
      $aCategories[] = $oForum_Topic_Posts->forum_topic->forum_category;
      $oForum_Topic_Posts->addEntity(
           Core::factory('Core_Xml_Entity')->name('forum_category_id')->value($oForum_Topic_Posts->forum_topic->forum_category->id)
      );
      $this->addEntity(
         $oForum_Topic_Posts->clearEntities()
            ->showXmlSiteuser(TRUE)
      );
   }
   if (!empty($aCategories)) {
      $this->addEntities($aCategories);
   }
   return parent::show();
}
HostDev.pw - модули для HostCMS, Telegram: @hostdev
#
Re: Форум - Показ последних сообщений
В xml по факту ничего не изменилось... возможно я где-то ошибся.. привожу весь код

<?php

class Forum_Last_Posts_Show extends Core_Controller
{
    /**
     * Allowed object properties
     * @var array
     */
    protected $_allowedProperties = array(
       'limit',
    );

    protected $_forumTopicPosts = NULL;

    /**
     * Constructor.
     * @param Forum_Model $oSiteuser user
     */
    public function __construct(Forum_Model $oForum)
    {
       parent::__construct($oForum->clearEntities());

       $this->limit = 2;

      $this->_forumTopicPosts = Core_Entity::factory('Forum_Topic_Post');
      $this->_forumTopicPosts
       ->queryBuilder()
       ->select('forum_topic_posts.*')
       ->join('forum_topics', 'forum_topics.id', '=', 'forum_topic_posts.forum_topic_id')
       ->join('forum_categories', 'forum_categories.id', '=', 'forum_topics.forum_category_id')
       ->join('forum_groups', 'forum_groups.id', '=', 'forum_categories.forum_group_id')
       ->where('forum_groups.forum_id', '=', $oForum->id)
       ->where('forum_groups.deleted', '=', 0)
       ->where('forum_categories.deleted', '=', 0)
       ->where('forum_topics.deleted', '=', 0)
       ->clearOrderBy()
       ->orderBy('forum_topic_posts.datetime', 'DESC')
       ->limit($this->limit);
    }

    public function forumTopicPosts()
    {
       return $this->_forumTopicPosts;
    }

    /**
     * Show built data
     * @return self
     */
         public function show() {  
         $aCategories = array();
         $oForum = $this->getEntity();

         $aForum_Topic_Posts = $this->_forumTopicPosts->findAll(FALSE);

         foreach ($aForum_Topic_Posts as $oForum_Topic_Posts)
         {
           $aCategories[] = $oForum_Topic_Posts->forum_topic->forum_category;
           $oForum_Topic_Posts->addEntity(
               Core::factory('Core_Xml_Entity')->name('forum_category_id')->value($oForum_Topic_Posts->forum_topic->forum_category->id)
           );
           $this->addEntity(
             $oForum_Topic_Posts->clearEntities()
               ->showXmlSiteuser(TRUE)
           );
         }
         if (!empty($aCategories)) {
           $this->addEntities($aCategories);
         }
         return parent::show();
      }

}
?>
SNN
#
Re: Форум - Показ последних сообщений
S.Nikol,
в ветке "forum_topic_post" должен был добавиться элемент "forum_category_id"
HostDev.pw - модули для HostCMS, Telegram: @hostdev
#
Re: Форум - Показ последних сообщений
Текущий код

<?php
/**
* Показ последних сообщений форума.
*
* <code>
* $oForum = Core_Entity::factory('Forum', 1);
*
* $Forum_Last_Posts_Show = new Forum_Last_Posts_Show(
*    $oForum
* );
*
* $Forum_Last_Posts_Show
*    ->xsl(
*       Core_Entity::factory('Xsl')->getByName('ПоследниеСообщенияФорума')
*    )
*    ->show();
* </code>
*
* @package HostCMS 6\Forum
* @version 6.x
* @author Hostmake LLC
* @copyright © 2005-2013 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
*/
class Forum_Last_Posts_Show extends Core_Controller
{
    /**
     * Allowed object properties
     * @var array
     */
    protected $_allowedProperties = array(
       'limit',
    );

    protected $_forumTopicPosts = NULL;

    /**
     * Constructor.
     * @param Forum_Model $oSiteuser user
     */
    public function __construct(Forum_Model $oForum)
    {
       parent::__construct($oForum->clearEntities());

       $this->limit = 2;

      $this->_forumTopicPosts = Core_Entity::factory('Forum_Topic_Post');
      $this->_forumTopicPosts
       ->queryBuilder()
       ->select('forum_topic_posts.*')
       ->join('forum_topics', 'forum_topics.id', '=', 'forum_topic_posts.forum_topic_id')
       ->join('forum_categories', 'forum_categories.id', '=', 'forum_topics.forum_category_id')
       ->join('forum_groups', 'forum_groups.id', '=', 'forum_categories.forum_group_id')
       ->where('forum_groups.forum_id', '=', $oForum->id)
       ->where('forum_groups.deleted', '=', 0)
       ->where('forum_categories.deleted', '=', 0)
       ->where('forum_topics.deleted', '=', 0)
       ->clearOrderBy()
       ->orderBy('forum_topic_posts.datetime', 'DESC')
       ->limit($this->limit);
    }

    public function forumTopicPosts()
    {
       return $this->_forumTopicPosts;
    }

    /**
     * Show built data
     * @return self
     */
         public function show() {  
         $aCategories = array();
         $oForum = $this->getEntity();

         $aForum_Topic_Posts = $this->_forumTopicPosts->findAll(FALSE);

         foreach ($aForum_Topic_Posts as $oForum_Topic_Posts)
         {
           $aCategories[] = $oForum_Topic_Posts->forum_topic->forum_category;
           $oForum_Topic_Posts->addEntity(
               Core::factory('Core_Xml_Entity')->name('forum_category_id')->value($oForum_Topic_Posts->forum_topic->forum_category->id)
           );
           $this->addEntity(
             $oForum_Topic_Posts->clearEntities()
               ->showXmlSiteuser(TRUE)
           );
         }
         if (!empty($aCategories)) {
           $this->addEntities($aCategories);
         }
         return parent::show();
      }

}
?>



То что получаем в результате на выдаче в XML


<forum id="1">
   <structure_id>36</structure_id>
   <user_id>19</user_id>
   <site_id>1</site_id>
   <name>Форум</name>
   <description>Демонстрационная конференция</description>
   <topics_on_page>10</topics_on_page>
   <posts_on_page>10</posts_on_page>
   <flood_protection_time>1</flood_protection_time>
   <allow_edit_time>14400</allow_edit_time>
   <allow_delete_time>1800</allow_delete_time>
   <url>/forums/</url>
   <forum_topic_post id="8">
      <siteuser_id>0</siteuser_id>
      <ip>85.26.165.60</ip>
      <subject>Обсуждаем последние новости</subject>
      <forum_topic_id>6</forum_topic_id>
      <deleted>0</deleted>
      <datetime>26.12.2014 17:16:21</datetime>
      <original_text>Обсуждаем последние новости</original_text>
      <text>Обсуждаем последние новости</text>
   </forum_topic_post>
   <forum_topic_post id="7">
      <siteuser_id>0</siteuser_id>
      <ip>85.26.165.60</ip>
      <subject>Где можно оформить получение пособий</subject>
      <forum_topic_id>5</forum_topic_id>
      <deleted>0</deleted>
      <datetime>26.12.2014 17:15:08</datetime>
      <original_text>Подскажите, где можно оформить получение пособий для многодетных семей в районе Хорешево-Мневники?</original_text>
      <text>Подскажите, где можно оформить получение пособий для многодетных семей в районе Хорешево-Мневники?</text>
   </forum_topic_post>
   <forum_category id="8">
      <forum_group_id>4</forum_group_id>
      <name>Новости</name>
      <description></description>
      <closed>0</closed>
      <sorting>1</sorting>
      <email></email>
      <postmoderation>1</postmoderation>
      <visible>1</visible>
      <use_captcha>1</use_captcha>
      <user_id>20</user_id>
      <allow_guest_posting>1</allow_guest_posting>
      <count_topics>1</count_topics>
      <count_topic_posts>1</count_topic_posts>
      <new_posts>1</new_posts>
      <captcha_id>79951</captcha_id>
   </forum_category>
   <forum_category id="9">
      <forum_group_id>4</forum_group_id>
      <name>Льготы (Обсуждение льгот, государственных услуг, законов)</name>
      <description></description>
      <closed>0</closed>
      <sorting>0</sorting>
      <email></email>
      <postmoderation>1</postmoderation>
      <visible>1</visible>
      <use_captcha>1</use_captcha>
      <user_id>20</user_id>
      <allow_guest_posting>1</allow_guest_posting>
      <count_topics>1</count_topics>
      <count_topic_posts>1</count_topic_posts>
      <new_posts>1</new_posts>
      <captcha_id>17001</captcha_id>
   </forum_category>
</forum>
Модератор
#
Re: Форум - Показ последних сообщений
Поменяйте местами блоки. Так:

           $this->addEntity(
             $oForum_Topic_Posts->clearEntities()
               ->showXmlSiteuser(TRUE)
           );

           $oForum_Topic_Posts->addEntity(               Core::factory('Core_Xml_Entity')->name('forum_category_id')->value($oForum_Topic_Posts->forum_topic->forum_category->id)
           );


Вы только что начали читать предложение, чтение которого вы уже заканчиваете.
#
Re: Форум - Показ последних сообщений
Благодарю! То что нужно)))
SNN
Авторизация