forked from pimcore/pimcore
/
Resource.php
77 lines (66 loc) · 2.8 KB
/
Resource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Pimcore
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.pimcore.org/license
*
* @category Pimcore
* @package Object
* @copyright Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
* @license http://www.pimcore.org/license New BSD License
*/
class Object_List_Resource extends Pimcore_Model_List_Resource_Abstract {
/**
* Loads a list of objects for the specicifies parameters, returns an array of Object_Abstract elements
*
* @return array
*/
public function load() {
$objects = array();
$objectsData = $this->db->fetchAll("SELECT o_id,o_type FROM objects" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
foreach ($objectsData as $objectData) {
if($object = Object_Abstract::getById($objectData["o_id"])) {
$objects[] = $object;
}
}
$this->model->setObjects($objects);
return $objects;
}
public function getCount() {
if (count($this->model->getObjects()) > 0) {
return count($this->model->getObjects());
}
$amount = $this->db->fetchAll("SELECT COUNT(*) as amount FROM objects" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
return $amount["amount"];
}
public function getTotalCount() {
$amount = $this->db->fetchRow("SELECT COUNT(*) as amount FROM objects" . $this->getCondition() . $this->getGroupBy(), $this->model->getConditionVariables());
return $amount["amount"];
}
/**
* Loads a list of document ids for the specicifies parameters, returns an array of ids
*
* @return array
*/
public function loadIdList() {
$objectIds = $this->db->fetchCol("SELECT o_id FROM objects" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
return $objectIds;
}
protected function getCondition() {
if ($cond = $this->model->getCondition()) {
if (Object_Abstract::doHideUnpublished() && !$this->model->getUnpublished()) {
return " WHERE (" . $cond . ") AND o_published = 1";
}
return " WHERE " . $cond . " ";
}
else if (Object_Abstract::doHideUnpublished() && !$this->model->getUnpublished()) {
return " WHERE o_published = 1";
}
return "";
}
}