Выборка за текущий год, месяц.

Добрый день. Подскажите, пожалуйста, есть ли возможность средствами PdoTools ограничить выборку материалов за последний год, за месяц, неделю?
Проблема в следующем: на сайте есть рубрика «Самое читаемое», и pdoResources выбирает по всем материалам с 2012 года. Как бы ограничить диапазон?
Любовь
29 мая 2014, 12:17
modx.pro
3
2 720
0

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

Василий Наумкин
29 мая 2014, 16:19
2
+3
&where=`{"createdon:>":"2014-01-01 00:00:00"}`
    Любовь
    30 мая 2014, 12:56
    0
    Спасибо! Так работает. Но с сортировкой &sortby=`HitsPage` (сортировка по количеству просмотров) уже нет — ищет по всем материалам.
      Алексей Ерохин
      30 мая 2014, 14:58
      0
      Если HitsPage — это дополнительное поле в ms_products, то сортировать надо так
      &sortby=`Data.HitsPage`
        Любовь
        30 мая 2014, 15:12
        0
        Нет, это обычные ресурсы MODx
          Алексей Ерохин
          30 мая 2014, 15:15
          0
          TV?
          [[!msProducts?
          	&includeTVs=`action,discount`
          	&sortby=`TVaction.value`
          	&where=`{"TVdiscount":"1"}`
          ]]
            Любовь
            30 мая 2014, 15:39
            0
            Да, это TV.
            [[!pdoResources? &parents=`19,12,7976,8108,8209,8311,15594` &includeTVs=`HitsPage, comment,expert_photo` &limit=`5` &depth=`0` &tpl=`tmp` &where=`{"createdon:>":"2014-05-28 00:00:00"}` &sortby=`HitsPage` &hideContainers=`1`]]
            Когда вызываю без &sortby=`HitsPage`, то материалы выводятся как раз до 28.05.2014 и сортируются по дате, а с &sortby=`HitsPage` ищет по всем материалам и выводит по количеству просмотров.
    Любовь
    30 мая 2014, 13:08
    0
    Стандартными средствами значит не получится?
      Василий Наумкин
      30 мая 2014, 17:13
      0
      Должно работать. Включай showLog=`1` и смотри, какой выходит SQL запрос и почему сортировка по ТВ отменяет фильтрацию.
        Любовь
        30 мая 2014, 17:25
        0
        Разобраться бы…
        SQL запрос проверила, выводит как на сайте. А как понять с фильтрацией что не так? Поможешь?
        0.0001462: pdoTools loaded
        0.0000360: xPDO query object created
        0.0000670: Added TVs filters
        0.0005841: Included list of tvs: comment, expert_photo, HitsPage
        0.0004621: leftJoined modTemplateVarResource as TVcomment
        0.0003810: leftJoined modTemplateVarResource as TVexpert_photo
        0.0003750: leftJoined modTemplateVarResource as TVhitspage
        0.0007579: Added selection of modResource: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`
        0.0000200: Added selection of modTemplateVarResource: IFNULL(`value`, '0') AS `tv.comment`
        0.0000160: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `tv.expert_photo`
        0.0000160: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `tv.HitsPage`
        0.0000908: Replaced TV conditions
        0.0000730: Processed additional conditions
        0.0007062: Added where condition: createdon:>=2014-05-28 00:00:00, 0=`TVhitspage`.`value` > '10', modResource.parent:IN(19,12,7976,8108,8209,8311,15594), modResource.published=1, modResource.deleted=0, modResource.isfolder=0
        0.0000858: Replaced TV conditions
        0.0002980: Sorted by modResource.publishedon, DESC
        0.0000081: Limited to 5, offset 0
        0.0007181: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, IFNULL(`TVcomment`.`value`, '0') AS `tv.comment`, IFNULL(`TVexpert_photo`.`value`, '') AS `tv.expert_photo`, IFNULL(`TVhitspage`.`value`, '') AS `tv.HitsPage` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVcomment` ON `TVcomment`.`contentid` = `modResource`.`id` AND `TVcomment`.`tmplvarid` = 15 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVexpert_photo` ON `TVexpert_photo`.`contentid` = `modResource`.`id` AND `TVexpert_photo`.`tmplvarid` = 7 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVhitspage` ON `TVhitspage`.`contentid` = `modResource`.`id` AND `TVhitspage`.`tmplvarid` = 8 WHERE  ( `modResource`.`createdon` > '2014-05-28 00:00:00' AND `TVhitspage`.`value` > '10' AND `modResource`.`parent` IN (19,12,7976,8108,8209,8311,15594) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 AND `modResource`.`isfolder` = 0 )  ORDER BY modResource.publishedon DESC LIMIT 5 "
        0.0627708: SQL executed
        0.0002000: Total rows: 536
        0.0001361: Rows fetched
        0.0064921: Prepared and processed TVs
        0.0020850: Loaded chunk "tmp"
        0.0193532: Returning processed chunks
        0.0939331: Total time
        19 660 800: Memory usage
          Василий Наумкин
          30 мая 2014, 18:52
          0
          Ну вот у тебя выходит условие
          WHERE  ( `modResource`.`createdon` > '2014-05-28 00:00:00' AND `TVhitspage`.`value` > '10' AND `modResource`.`parent` IN (19,12,7976,8108,8209,8311,15594) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 AND `modResource`.`isfolder` = 0 )

          А вот сортировка по дате публикации
          ORDER BY modResource.publishedon DESC

          Скрипт говорит, что под условия подходят 536 ресурса и выводит 5 из них. Ошибок нет, что не так?
            Любовь
            30 мая 2014, 22:43
            0
            Ошибок нет, но работает не так как мне надо)
            Из этого промежутка времени по найденным материалам нужно еще отсортировать их по HitsPage от бОльшего к меньшему.
            ORDER BY modResource.publishedon DESC
            эта сортировка регулируется с помощью &sortby?

            Переписала так:
            [[!pdoResources? &parents=`19,12,7976,8108,8209,8311,15594` &includeTVs=`HitsPage, comment,expert_photo` &limit=`5` &depth=`0` &tpl=`tmp` &where=`{"createdon:>":"2014-05-28 00:00:00"}` &sortbyTV=`HitsPage`  &sortdirTV=`DESC` &hideContainers=`1` &showLog=`1`]]
            Добавила &sortbyTV=`HitsPage` &sortdirTV=`DESC` и выборка опять по всем материалам, а не за последние 2 дня.
              Василий Наумкин
              31 мая 2014, 06:25
              0
              У pdoResources нет параметров sortbyTV и sortdirTV, они ему не нужны.

              Указывай
              &sortby=`HitsPage`
              &sortdir=`DESC`
              и смотри в лог, для проверки.
                Любовь
                31 мая 2014, 08:30
                0
                Это был первоначальный вариант.
                  Виталий Киреев
                  31 мая 2014, 08:36
                  0
                  Лог с этим вариантом или нет? По вашему логу сортировка по умолчанию.
                    Василий Наумкин
                    31 мая 2014, 08:37
                    0
                    В SQL видно, что ТВ присоединяется как TVhitspage, значит сортировка будет работать вот так:
                    &sortby=`TVhitspage.value`

                    По идее, и сокращенный вариант должен работать, но тут видно проблема в заглавных буквах.
                      Любовь
                      31 мая 2014, 09:49
                      0
                      Переименовала в hitspage, вызываю так:
                      [[!pdoResources? &parents=`19,12,7976,8108,8209,8311,15594` &includeTVs=`hitspage, comment,expert_photo` &limit=`5` &depth=`0` &tpl=`tmp` &where=`{"createdon:>":"2014-05-28 00:00:00"}` &sortby=`TVhitspage.value`  &sortdir=`DESC` &hideContainers=`1` &showLog=`1`]]
                      Условие получается такое:
                      Added where condition: <b>createdon:>=2014-05-28 00:00:00, modResource.parent:IN(19,12,7976,8108,8209,8311,15594), modResource.published=1, modResource.deleted=0, modResource.isfolder=0
                      А запрос такой:
                      SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, IFNULL(`TVcomment`.`value`, '0') AS `tv.comment`, IFNULL(`TVexpert_photo`.`value`, '') AS `tv.expert_photo`, IFNULL(`TVhitspage`.`value`, '') AS `tv.hitspage` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVcomment` ON `TVcomment`.`contentid` = `modResource`.`id` AND `TVcomment`.`tmplvarid` = 15 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVexpert_photo` ON `TVexpert_photo`.`contentid` = `modResource`.`id` AND `TVexpert_photo`.`tmplvarid` = 7 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVhitspage` ON `TVhitspage`.`contentid` = `modResource`.`id` AND `TVhitspage`.`tmplvarid` = 8 WHERE  ( `modResource`.`createdon` > '2014-05-28 00:00:00' AND `modResource`.`parent` IN (19,12,7976,8108,8209,8311,15594) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 AND `modResource`.`isfolder` = 0 )  ORDER BY CAST(TVhitspage.value AS DECIMAL(13,3)) DESC LIMIT 5
                      Но опять ищет по всем материалам.
                        Василий Наумкин
                        31 мая 2014, 10:19
                        0
                        Ну и куда пропал из условия WHERE
                        AND `TVhitspage`.`value` > '10'
                        ?

                        Наверное, должно быть так:
                        &where=`{"createdon:>":"2014-05-28 00:00:00","hitspage:>":10}`

                        Или так:
                        &where=`{"createdon:>":"2014-05-28 00:00:00","TVhitspage.value:>":10}`
                          Любовь
                          01 июня 2014, 15:58
                          0
                          [[!pdoResources?
                          &parents=`19,12,7976,8108,8209,8311,15594`
                          &includeTVs=`hitspage, comment, expert_photo`
                          &limit=`5`
                          &depth=`0`
                          &tpl=`tmp`
                          &where=`{«createdon:>»:«2014-05-28 00:00:00»,«TVhitspage.value:>»:10500}`
                          &sortby=`hitspage`
                          &sortdir=`DESC`
                          &hideContainers=`1`
                          &showLog=`1`]]

                          SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, IFNULL(`TVcomment`.`value`, '0') AS `tv.comment`, IFNULL(`TVexpert_photo`.`value`, '') AS `tv.expert_photo`, IFNULL(`TVhitspage`.`value`, '') AS `tv.hitspage` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVcomment` ON `TVcomment`.`contentid` = `modResource`.`id` AND `TVcomment`.`tmplvarid` = 15 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVexpert_photo` ON `TVexpert_photo`.`contentid` = `modResource`.`id` AND `TVexpert_photo`.`tmplvarid` = 7 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVhitspage` ON `TVhitspage`.`contentid` = `modResource`.`id` AND `TVhitspage`.`tmplvarid` = 8 WHERE  ( `modResource`.`createdon` > '2014-05-28 00:00:00' AND `TVhitspage`.`value` > '10500' AND `modResource`.`parent` IN (19,12,7976,8108,8209,8311,15594) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 AND `modResource`.`isfolder` = 0 )  ORDER BY CAST(`TVhitspage`.`value` AS DECIMAL(13,3)) DESC LIMIT 5
                          Все равно выводит все материалы, даже с условием
                          AND `TVhitspage`.`value` > '10500'
                          хотя таких материалов нет. Получается это условие не срабатывает.
                          Любовь
                          02 июня 2014, 22:22
                          0
                          [[!pdoResources? 
                                       &parents=`19,12,7976,8108,8209,8311,15594` 
                                       &includeTVs=`hitspage, comment, expert_photo` 
                                       &limit=`5` 
                                       &depth=`0` 
                                       &tpl=`tmp` 
                                       &where=`{"publishedon:>":"2014-05-28 00:00:00"}` 
                                       &sortby=`hitspage`  
                                       &sortdir=`DESC` 
                                       &hideContainers=`1` 
                                       &showLog=`1`]]
                          Так же по идее должно работать? Выбираются материалы до 28.05 и сортируются по количеству просмотров. Или я что-то упускаю?
                          Алексей Ерохин
                          03 июня 2014, 01:55
                          1
                          +2
                          Поля publishedon, createdon, editedon, deletedon хранятся в базе в виде int(20). Вам нужно Вашу дату перевести в unix timestamp. Например, 1401235200 для 2014-05-28 00:00:00 в GMT.
                          Либо использовать &where без json:
                          &where=`modResource.publishedon > UNIX_TIMESTAMP('2014-05-28 00:00:00')`
                          Любовь
                          03 июня 2014, 09:26
                          0
                          Так работает) Огромное спасибо!
                Виталий Киреев
                31 мая 2014, 06:30
                0
                &sortby=`tv.HitsPage`&sortdir=`DESC`
                по идее
                  Любовь
                  31 мая 2014, 08:31
                  0
                  А так ошибка sql запроса.
        Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
        23