Created
February 3, 2017 11:36
-
-
Save CB9TOIIIA/00cb077b9868202a7301816f3d7a9c00 to your computer and use it in GitHub Desktop.
Хак getByCategory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getByCategory($application_id, $category_id, $published = false, $user = null, $orderby = "", $offset = 0, $limit = 0, $ignore_order_priority = false) { | |
// get database | |
$db = $this->database; | |
// get dates | |
$date = $this->app->date->create(); | |
$now = $db->Quote($date->toSQL()); | |
$null = $db->Quote($db->getNullDate()); | |
// get item ordering | |
list($join, $order) = $this->_getItemOrder($orderby, $ignore_order_priority); | |
$query = "SELECT a.id" | |
." FROM ".$this->name." AS a" | |
." LEFT JOIN ".ZOO_TABLE_CATEGORY_ITEM." AS b ON a.id = b.item_id" | |
.($join ? $join : "") | |
." WHERE a.application_id = ".(int) $application_id | |
." AND a.".$this->app->user->getDBAccessString($user) | |
.($published == true ? " AND a.state = 1" | |
." AND (a.publish_up = ".$null." OR a.publish_up <= ".$now.")" | |
." AND (a.publish_down = ".$null." OR a.publish_down >= ".$now.")": "") | |
." AND b.category_id ".(is_array($category_id) ? " IN (".implode(",", $category_id).")" : " = ".(int) $category_id) | |
." GROUP BY a.id" | |
.($order ? " ORDER BY " . $order : "") | |
.($limit ? " LIMIT ".(int) $offset.",".(int) $limit : ""); | |
$list = $this->app->database->queryAssocList($query); | |
$itemOrig = array_reduce($list, function($acc, $item){ | |
$acc[] = $item['id']; | |
return $acc; | |
}, []); | |
$list = JBModelItem::model()->getZooItemsByIds($itemOrig); | |
$list = $this->app->jbarray->sortByArray($list, $itemOrig); | |
return $list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment