<?php class xpectaProfileGetProcessor extends modObjectGetListProcessor{ public $classKey = 'modUser'; public function getData() { $c = $this->modx->newQuery($this->classKey); $c->where(array('id' => $this->getProperty('id'))); $c->select(array( "{$this->classKey}.*", )); $data = array(); if($c->prepare() && $c->stmt->execute()){ $data = $c->stmt->fetchAll(PDO::FETCH_ASSOC); } return $data; } } return 'xpectaProfileGetProcessor';
$c->leftJoin('xpectaAd', 'xpectaAd'); $c->select(array( "xpectaAd.id as ad_id", 'xpectaAd.title as ad_title', //... )); return $c;
public function getData() { $data = array(); $limit = intval($this->getProperty('limit')); $start = intval($this->getProperty('start')); /* query for chunks */ $c = $this->modx->newQuery($this->classKey); $c = $this->prepareQueryBeforeCount($c); $data['total'] = $this->modx->getCount($this->classKey,$c); $c = $this->prepareQueryAfterCount($c); $sortClassKey = $this->getSortClassKey(); $sortKey = $this->modx->getSelectColumns($sortClassKey, $this->getProperty('sortAlias',$sortClassKey),'',array($this->getProperty('sort'))); if (empty($sortKey)) $sortKey = $this->getProperty('sort'); $c->sortby($sortKey,$this->getProperty('dir')); if ($limit > 0) { $c->limit($limit,$start); } $data['results'] = $this->modx->getCollection($this->classKey,$c); return $data; }
public function prepareQueryBeforeCount(xPDOQuery $c) { $c = parent::prepareQueryBeforeCount($c); // Добавляешь условия к запросу return $c; }
class ....{ public function initialize(){ $this->setDefaultProperties(array( 'hot' => false, // Флаг, что делать только выборку новинок )); return parent::initialize(); } public function prepareQueryBeforeCount(xPDOQuery $c) { $c = parent::prepareQueryBeforeCount($c); // Если указано, что нужны только новинки if($this->getProperty('hot')){ // Добавляем условие только новинок } return $c; } }
Просто в этом процессоре мне количество и не нужно — пользователь один
Еще надо будет посмотреть, можно ли после Join'ов ограничивать количество и сортировать присоединенные записи…
require_once dirname(dirname(__FILE__)).'/getdatanew.class.php'; class modWebCatalogProductsHot1GetdataProcessor2 extends modWebCatalogProductsGetdataProcessor1{ public function initialize(){ $this->setDefaultProperties(array( 'hot1' => true, // Получать скидки "sort" => "{$this->classKey}.publishedon", "dir" => "ASC", )); return parent::initialize(); } } return 'modWebCatalogProductsHot1GetdataProcessor2';
require_once dirname(dirname(dirname(__FILE__))).'/resources/getdata.class.php'; class modWebCatalogProductsGetdataProcessor1 extends modWebResourcesGetdataProcessor{ public function initialize(){ $this->setDefaultProperties(array( 'hot1' => false, // Получать скидки )); $this->setProperties(array( "base_currency_id" => (int)$this->modx->getOption("shopmodx.default_currency"), // ID базовой валюты магазина )); return parent::initialize(); } public function prepareQueryBeforeCount(xPDOQuery $z) { $z = parent::prepareQueryBeforeCount($z); $alias = $z->getAlias(); $z->innerJoin('ShopmodxProduct', 'Product'); if($this->getProperty('hot1')){ $z->innerJoin('modTemplateVarResource', 'hot1', "hot1.contentid = {$alias}.id AND hot1.tmplvarid = 15 AND hot1.value='1'"); } // Поиск товаров в категории и подкатегориях if($category_id = $this->getProperty('category_id')){ $categories = array(); $this->getCategories($category_id, $categories); $Z->where(array( "parent:IN" => $categories, )); }
if($this->getProperty('hot')){ $c->innerJoin('modTemplateVarResource', 'hot', "hot.contentid = {$alias}.id AND hot.tmplvarid = 8 AND hot.value='1'"); } elseif($this->getProperty('hot1')){ $c->innerJoin('modTemplateVarResource', 'hot1', "hot1.contentid = {$alias}.id AND hot1.tmplvarid = 15 AND hot1.value='1'"); }
По аналогии с новинками хочу вывести на главную еще и скидки.
if($this->getProperty('hot1')){ $z->innerJoin('modTemplateVarResource', 'hot1', "hot1.contentid = {$alias}.id AND hot1.tmplvarid = 15 AND hot1.value='1'"); }