Вывод последних комментариев Tickets

Здравствуйте.

Помогите, пож-та с вопросом.
На главной странице сайта хочу вывести последние комментарии с сайта.

Для этой цели создал сниппет: [[!SelectComments]]
Содержимое сниппета:
<?php
$results = $modx->query("
SELECT c.resource, c.comment_last, LEFT(a.raw, 21) FROM 
	modx_tickets_comments a,
	(SELECT b.resource, b.comment_last FROM modx_tickets_threads b
	 where b.comment_last > 0) c
where a.id = c.comment_last
ORDER BY a.createdon DESC 
LIMIT 0 , 7
");
while ($r = $results->fetch(PDO::FETCH_ASSOC)) {
        print_r($r);
}

Снипет возвращает массив:
Array ( [resource] => 158 [comment_last] => 33 [raw] => Мой текст комментария )

Как из полученного массива оптимально получить ленту комментариев в виде краткого текста комментария со ссылкой на сам коммент? Ссылка формата: my-site.ru/my-resurse.html#comment-33

Возможно есть более оптимальное решение для данной задачи?
Maxim
27 декабря 2015, 00:16
modx.pro
3
3 524
+1

Комментарии: 14

Максим Кузнецов
27 декабря 2015, 05:49
0
1. Для чего вам дублировать логику работы уже встроенного сниппета Тикетсов — getComments?
Просто создаете свой сниппет, в котором заполняете требуемый набор параметров:

widget.getComments:
<?php
	$params = array();

	//Настроить по вкусу
	$params['limit'] = '4';
	$params['fastMode'] = '0';
	$params['includeContent'] = '0';
	$params['tpl'] = 'шаблон';

	return $modx->runSnippet('getComments', $params);

Далее создаете виджет типа «сниппет» и указываете в содержимом название свежесозданного сниппета (widget.getComments), после чего подключаете данный виджет к панели.

2. Вам нужно перенести ваш вопрос из раздела «компоненты MODX» в раздел «Вопросы».
    Maxim
    27 декабря 2015, 23:00
    0
    Я изначально пробовал вывести последние комментарии кодом:

    [[!getComments?
    	&parents=`0`
    	&limit=`2` 
    	&tpl=`tpl.Tickets.comment.latest` 
    	&action=`comments` 
    	&includeContent=`1`
    ]]

    Результат тот же, что и посредством вашего кода.
    А именно: выводится не последний комментарий, а заголовок темы (статьи) с последним комментарием.

    Поэтому я и хотел использовать приложенный выше SQL, к-ый получает из базы непосредственно сам текст комментария.

    Получается, стандартными средствами Tickets текст последнего комментария не вывести?
    Роман Садоян
    28 декабря 2015, 00:01
    +1
    Что-то вы намудрили, так нельзя что ли? docs.modx.pro/components/tickets/snippets/ticketlatest
    [[!TicketLatest? &limit=`5` &fastMode=`1` &action=`comments` &tpl=`tpl.Tickets.comment.latest`]]
      Maxim
      28 декабря 2015, 00:16
      0
      В том-то и проблема, что этот вариант не работает в том контексте, как нужно.
      Ваш пример, как и примеры выше, выводит заголовки статей, в к-ых есть последний комент. Мне же нужно непосредственно тексты этих самых последних комментов.

      Содержимое моего шаблона tpl.Tickets.comment.latest (может в нем дело):
      <div class="tickets-latest-row[[+guest]]">
      	<span class="user"><i class="glyphicon glyphicon-user"></i> [[+fullname]]</span> <span class="date">[[+date_ago]]</span>
      	
      	<span class="ticket">
      		<a href="[[~[[+ticket.id]]]]#comment-[[+id]]">[[+ticket.pagetitle]]</a>
      	</span>
      	<nobr><i class="glyphicon glyphicon-comment"></i> <span class="comments">[[+comments]]</span></nobr>
      </div>
      <!--tickets_guest  ticket-comment-guest-->
        Maxim
        28 декабря 2015, 00:29
        0
        блок
        [[+comments]]

        выводит число комментариев в теме, но не сам текст коммента.
        А вот как получить вывод нужного текста коммента — не смог найти. Поэтому и соорудил эту конструкцию из sql.
          Роман Садоян
          28 декабря 2015, 00:34
          0
          А параметр &includeContent у сниппета ни о чем Вам не говорит?
          [[!TicketLatest? &limit=`5` &includeContent=`1` &fastMode=`1` &action=`comments` &tpl=`tpl.Tickets.comment.latest`]]
            Maxim
            28 декабря 2015, 00:43
            0
            Пробовал его менять. Что с 1, что с 0, показывает всегда одно и тоже: [[+comments]] выводит число комментариев, а не сам текст коммента.
            Кэш чистил.
              Роман Садоян
              28 декабря 2015, 16:40
              0
              &showLog=`1`
              добавь и результат тут покажи, предполагаю что нужно использовать [[+content]]
                Maxim
                03 января 2016, 23:01
                0
                0.0005090: Query parameters are prepared.
                0.0000210: xPDO query object created
                0.0001130: innerJoined TicketThread as Thread
                0.0000980: innerJoined Ticket as Ticket
                0.0001059: leftJoined TicketsSection as Section
                0.0000989: leftJoined modUser as User
                0.0000920: leftJoined modUserProfile as Profile
                0.0000021: Grouped by `Ticket`.`id`
                0.0000870: Added selection of TicketComment: SQL_CALC_FOUND_ROWS `id`, `thread`, `parent`, `text`, `name`, `email`, `ip`, `rating`, `rating_plus`, `rating_minus`, `createdon`, `createdby`, `editedon`, `editedby`, `published`, `deleted`, `deletedon`, `deletedby`, `properties`
                0.0000360: Added selection of Ticket: `id` AS `ticket.id`, `type` AS `ticket.type`, `contentType` AS `ticket.contentType`, `pagetitle` AS `ticket.pagetitle`, `longtitle` AS `ticket.longtitle`, `description` AS `ticket.description`, `alias` AS `ticket.alias`, `link_attributes` AS `ticket.link_attributes`, `published` AS `ticket.published`, `pub_date` AS `ticket.pub_date`, `unpub_date` AS `ticket.unpub_date`, `parent` AS `ticket.parent`, `isfolder` AS `ticket.isfolder`, `introtext` AS `ticket.introtext`, `content` AS `ticket.content`, `richtext` AS `ticket.richtext`, `template` AS `ticket.template`, `menuindex` AS `ticket.menuindex`, `searchable` AS `ticket.searchable`, `cacheable` AS `ticket.cacheable`, `createdby` AS `ticket.createdby`, `createdon` AS `ticket.createdon`, `editedby` AS `ticket.editedby`, `editedon` AS `ticket.editedon`, `deleted` AS `ticket.deleted`, `deletedon` AS `ticket.deletedon`, `deletedby` AS `ticket.deletedby`, `publishedon` AS `ticket.publishedon`, `publishedby` AS `ticket.publishedby`, `menutitle` AS `ticket.menutitle`, `donthit` AS `ticket.donthit`, `privateweb` AS `ticket.privateweb`, `privatemgr` AS `ticket.privatemgr`, `content_dispo` AS `ticket.content_dispo`, `hidemenu` AS `ticket.hidemenu`, `class_key` AS `ticket.class_key`, `context_key` AS `ticket.context_key`, `content_type` AS `ticket.content_type`, `uri` AS `ticket.uri`, `uri_override` AS `ticket.uri_override`, `hide_children_in_tree` AS `ticket.hide_children_in_tree`, `show_in_tree` AS `ticket.show_in_tree`, `properties` AS `ticket.properties`
                0.0000379: Added selection of TicketsSection: `id` AS `section.id`, `type` AS `section.type`, `contentType` AS `section.contentType`, `pagetitle` AS `section.pagetitle`, `longtitle` AS `section.longtitle`, `description` AS `section.description`, `alias` AS `section.alias`, `link_attributes` AS `section.link_attributes`, `published` AS `section.published`, `pub_date` AS `section.pub_date`, `unpub_date` AS `section.unpub_date`, `parent` AS `section.parent`, `isfolder` AS `section.isfolder`, `introtext` AS `section.introtext`, `richtext` AS `section.richtext`, `template` AS `section.template`, `menuindex` AS `section.menuindex`, `searchable` AS `section.searchable`, `cacheable` AS `section.cacheable`, `createdby` AS `section.createdby`, `createdon` AS `section.createdon`, `editedby` AS `section.editedby`, `editedon` AS `section.editedon`, `deleted` AS `section.deleted`, `deletedon` AS `section.deletedon`, `deletedby` AS `section.deletedby`, `publishedon` AS `section.publishedon`, `publishedby` AS `section.publishedby`, `menutitle` AS `section.menutitle`, `donthit` AS `section.donthit`, `privateweb` AS `section.privateweb`, `privatemgr` AS `section.privatemgr`, `content_dispo` AS `section.content_dispo`, `hidemenu` AS `section.hidemenu`, `class_key` AS `section.class_key`, `context_key` AS `section.context_key`, `content_type` AS `section.content_type`, `uri` AS `section.uri`, `uri_override` AS `section.uri_override`, `hide_children_in_tree` AS `section.hide_children_in_tree`, `show_in_tree` AS `section.show_in_tree`, `properties` AS `section.properties`
                0.0000141: Added selection of modUser: `username`
                0.0000291: Added selection of modUserProfile: `internalKey`, `fullname`, `email`, `phone`, `mobilephone`, `blocked`, `blockeduntil`, `blockedafter`, `logincount`, `lastlogin`, `thislogin`, `failedlogincount`, `sessionid`, `dob`, `gender`, `address`, `country`, `city`, `state`, `zip`, `fax`, `photo`, `comment`, `website`, `extended`
                0.0001230: Added where condition: Ticket.published=1, Ticket.deleted=0, TicketComment.deleted=0
                0.0000250: Sorted by TicketComment.createdon, DESC
                0.0000031: Limited to 5, offset 0
                0.0003669: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `TicketComment`.`id`, `TicketComment`.`thread`, `TicketComment`.`parent`, `TicketComment`.`text`, `TicketComment`.`name`, `TicketComment`.`email`, `TicketComment`.`ip`, `TicketComment`.`rating`, `TicketComment`.`rating_plus`, `TicketComment`.`rating_minus`, `TicketComment`.`createdon`, `TicketComment`.`createdby`, `TicketComment`.`editedon`, `TicketComment`.`editedby`, `TicketComment`.`published`, `TicketComment`.`deleted`, `TicketComment`.`deletedon`, `TicketComment`.`deletedby`, `TicketComment`.`properties`, `Ticket`.`id` AS `ticket.id`, `Ticket`.`type` AS `ticket.type`, `Ticket`.`contentType` AS `ticket.contentType`, `Ticket`.`pagetitle` AS `ticket.pagetitle`, `Ticket`.`longtitle` AS `ticket.longtitle`, `Ticket`.`description` AS `ticket.description`, `Ticket`.`alias` AS `ticket.alias`, `Ticket`.`link_attributes` AS `ticket.link_attributes`, `Ticket`.`published` AS `ticket.published`, `Ticket`.`pub_date` AS `ticket.pub_date`, `Ticket`.`unpub_date` AS `ticket.unpub_date`, `Ticket`.`parent` AS `ticket.parent`, `Ticket`.`isfolder` AS `ticket.isfolder`, `Ticket`.`introtext` AS `ticket.introtext`, `Ticket`.`content` AS `ticket.content`, `Ticket`.`richtext` AS `ticket.richtext`, `Ticket`.`template` AS `ticket.template`, `Ticket`.`menuindex` AS `ticket.menuindex`, `Ticket`.`searchable` AS `ticket.searchable`, `Ticket`.`cacheable` AS `ticket.cacheable`, `Ticket`.`createdby` AS `ticket.createdby`, `Ticket`.`createdon` AS `ticket.createdon`, `Ticket`.`editedby` AS `ticket.editedby`, `Ticket`.`editedon` AS `ticket.editedon`, `Ticket`.`deleted` AS `ticket.deleted`, `Ticket`.`deletedon` AS `ticket.deletedon`, `Ticket`.`deletedby` AS `ticket.deletedby`, `Ticket`.`publishedon` AS `ticket.publishedon`, `Ticket`.`publishedby` AS `ticket.publishedby`, `Ticket`.`menutitle` AS `ticket.menutitle`, `Ticket`.`donthit` AS `ticket.donthit`, `Ticket`.`privateweb` AS `ticket.privateweb`, `Ticket`.`privatemgr` AS `ticket.privatemgr`, `Ticket`.`content_dispo` AS `ticket.content_dispo`, `Ticket`.`hidemenu` AS `ticket.hidemenu`, `Ticket`.`class_key` AS `ticket.class_key`, `Ticket`.`context_key` AS `ticket.context_key`, `Ticket`.`content_type` AS `ticket.content_type`, `Ticket`.`uri` AS `ticket.uri`, `Ticket`.`uri_override` AS `ticket.uri_override`, `Ticket`.`hide_children_in_tree` AS `ticket.hide_children_in_tree`, `Ticket`.`show_in_tree` AS `ticket.show_in_tree`, `Ticket`.`properties` AS `ticket.properties`, `Section`.`id` AS `section.id`, `Section`.`type` AS `section.type`, `Section`.`contentType` AS `section.contentType`, `Section`.`pagetitle` AS `section.pagetitle`, `Section`.`longtitle` AS `section.longtitle`, `Section`.`description` AS `section.description`, `Section`.`alias` AS `section.alias`, `Section`.`link_attributes` AS `section.link_attributes`, `Section`.`published` AS `section.published`, `Section`.`pub_date` AS `section.pub_date`, `Section`.`unpub_date` AS `section.unpub_date`, `Section`.`parent` AS `section.parent`, `Section`.`isfolder` AS `section.isfolder`, `Section`.`introtext` AS `section.introtext`, `Section`.`richtext` AS `section.richtext`, `Section`.`template` AS `section.template`, `Section`.`menuindex` AS `section.menuindex`, `Section`.`searchable` AS `section.searchable`, `Section`.`cacheable` AS `section.cacheable`, `Section`.`createdby` AS `section.createdby`, `Section`.`createdon` AS `section.createdon`, `Section`.`editedby` AS `section.editedby`, `Section`.`editedon` AS `section.editedon`, `Section`.`deleted` AS `section.deleted`, `Section`.`deletedon` AS `section.deletedon`, `Section`.`deletedby` AS `section.deletedby`, `Section`.`publishedon` AS `section.publishedon`, `Section`.`publishedby` AS `section.publishedby`, `Section`.`menutitle` AS `section.menutitle`, `Section`.`donthit` AS `section.donthit`, `Section`.`privateweb` AS `section.privateweb`, `Section`.`privatemgr` AS `section.privatemgr`, `Section`.`content_dispo` AS `section.content_dispo`, `Section`.`hidemenu` AS `section.hidemenu`, `Section`.`class_key` AS `section.class_key`, `Section`.`context_key` AS `section.context_key`, `Section`.`content_type` AS `section.content_type`, `Section`.`uri` AS `section.uri`, `Section`.`uri_override` AS `section.uri_override`, `Section`.`hide_children_in_tree` AS `section.hide_children_in_tree`, `Section`.`show_in_tree` AS `section.show_in_tree`, `Section`.`properties` AS `section.properties`, `User`.`username`, `Profile`.`internalKey`, `Profile`.`fullname`, `Profile`.`email`, `Profile`.`phone`, `Profile`.`mobilephone`, `Profile`.`blocked`, `Profile`.`blockeduntil`, `Profile`.`blockedafter`, `Profile`.`logincount`, `Profile`.`lastlogin`, `Profile`.`thislogin`, `Profile`.`failedlogincount`, `Profile`.`sessionid`, `Profile`.`dob`, `Profile`.`gender`, `Profile`.`address`, `Profile`.`country`, `Profile`.`city`, `Profile`.`state`, `Profile`.`zip`, `Profile`.`fax`, `Profile`.`photo`, `Profile`.`comment`, `Profile`.`website`, `Profile`.`extended` FROM `modx_tickets_comments` AS `TicketComment` JOIN `modx_tickets_threads` `Thread` ON `TicketComment`.`id` = `Thread`.`comment_last` AND `Thread`.`deleted` = 0 JOIN `modx_site_content` `Ticket` ON `Ticket`.`id` = `Thread`.`resource` LEFT JOIN `modx_site_content` `Section` ON `Section`.`id` = `Ticket`.`parent` LEFT JOIN `modx_users` `User` ON `User`.`id` = `TicketComment`.`createdby` LEFT JOIN `modx_user_attributes` `Profile` ON `Profile`.`internalKey` = `TicketComment`.`createdby` WHERE  ( `Ticket`.`published` = 1 AND `Ticket`.`deleted` = 0 AND `TicketComment`.`deleted` = 0 )  GROUP BY `Ticket`.`id` ORDER BY TicketComment.createdon DESC LIMIT 5 "
                0.0012801: SQL executed
                0.0000441: Total rows: 1
                0.0000300: Rows fetched
                0.0000608: Returning raw data
                0.0012002: Loaded chunk "tpl.Tickets.comment.text"
                0.0005870: Returning processed chunks
                0.0051179: Total time
                16 515 072: Memory usage
                  Maxim
                  03 января 2016, 23:08
                  0
                  Поясни, пожалуйста, что имелось в виду под фразой:
                  предполагаю что нужно использовать [[+content]]
                    Роман Садоян
                    03 января 2016, 23:25
                    0
                    Этот код попробуй:
                    <div class="tickets-latest-row[[+guest]]">
                    	<span class="user"><i class="glyphicon glyphicon-user"></i> [[+fullname]]</span> <span class="date">[[+date_ago]]</span>
                    	
                    	<span class="ticket">
                    		<a href="[[~[[+ticket.id]]]]#comment-[[+id]]">[[+ticket.pagetitle]]</a>
                    	</span>
                    	<nobr><i class="glyphicon glyphicon-comment"></i> <span class="comments">[[+comments]]</span></nobr>
                    <div class="content">
                    Content: [[+content]] или ticket.content:[[+ticket.content]]
                    </div>
                    </div>
                    <!--tickets_guest  ticket-comment-guest-->
                      Maxim
                      03 января 2016, 23:35
                      0
                      Применил указанный код в шаблоне.

                      Блок кода
                      <div class="content">[[+content]]</div>
                      ничего не вывел.

                      Блок кода
                      <div class="content">[[+ticket.content]]</div>
                      вывел содержимое страницы (без имеющихся на данной странице комментариев).
                        Роман Садоян
                        04 января 2016, 00:14
                        1
                        +1
                        Как оказалось нужно использовать [[+text]]
                        modx.pro/help/4100/
                          Maxim
                          04 января 2016, 15:10
                          +1
                          Роман, спасибо большое за помощь.
                          С [[+text]] всё получилось.
          Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
          14