XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
read.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
31 {
41  function &getAll($criteria = null, $fields = null, $asObject = true, $id_as_key = true)
42  {
43  if (is_array($fields) && count($fields) > 0) {
44  if (!in_array($this->handler->keyName, $fields)) {
45  $fields[] = $this->handler->keyName;
46  }
47  $select = "`" . implode("`, `", $fields) . "`";
48  } else {
49  $select = "*";
50  }
51  $limit = null;
52  $start = null;
53  $sql = "SELECT {$select} FROM `{$this->handler->table}`";
54  if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
55  $sql .= " " . $criteria->renderWhere();
56  if ($groupby = $criteria->getGroupby()) {
57  $sql .= $groupby;
58  }
59  if ($sort = $criteria->getSort()) {
60  $sql .= " ORDER BY {$sort} " . $criteria->getOrder();
61  $orderSet = true;
62  }
63  $limit = $criteria->getLimit();
64  $start = $criteria->getStart();
65  }
66  if (empty($orderSet)) {
67  //$sql .= " ORDER BY `{$this->handler->keyName}` DESC";
68  }
69  $result = $this->handler->db->query($sql, $limit, $start);
70  $ret = array();
71  if ($asObject) {
72  while ($myrow = $this->handler->db->fetchArray($result)) {
73  $object =& $this->handler->create(false);
74  $object->assignVars($myrow);
75  if ($id_as_key) {
76  $ret[$myrow[$this->handler->keyName]] = $object;
77  } else {
78  $ret[] = $object;
79  }
80  unset($object);
81  }
82  } else {
83  $object =& $this->handler->create(false);
84  while ($myrow = $this->handler->db->fetchArray($result)) {
85  $object->assignVars($myrow);
86  if ($id_as_key) {
87  $ret[$myrow[$this->handler->keyName]] = $object->getValues(array_keys($myrow));
88  } else {
89  $ret[] = $object->getValues(array_keys($myrow));
90  }
91  }
92  unset($object);
93  }
94  return $ret;
95  }
96 
107  function &getObjects($criteria = null, $id_as_key = false, $as_object = true)
108  {
109  $objects = $this->getAll($criteria, null, $as_object, $id_as_key);
110  return $objects;
111  }
112 
121  function getList($criteria = null, $limit = 0, $start = 0)
122  {
123  $ret = array();
124  if ($criteria == null) {
125  $criteria = new CriteriaCompo();
126  }
127 
128  $sql = "SELECT `{$this->handler->keyName}`";
129  if (!empty($this->handler->identifierName)) {
130  $sql .= ", `{$this->handler->identifierName}`";
131  }
132  $sql .= " FROM `{$this->handler->table}`";
133  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
134  $sql .= ' ' . $criteria->renderWhere();
135  if ($sort = $criteria->getSort()) {
136  $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
137  }
138  $limit = $criteria->getLimit();
139  $start = $criteria->getStart();
140  }
141  $result = $this->handler->db->query($sql, $limit, $start);
142  if (!$result) {
143  return $ret;
144  }
145 
147  while ($myrow = $this->handler->db->fetchArray($result)) {
148  // identifiers should be textboxes, so sanitize them like that
149  $ret[$myrow[$this->handler->keyName]] = empty($this->handler->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->handler->identifierName]);
150  }
151  return $ret;
152  }
153 
160  function &getIds($criteria = null)
161  {
162  $ret = array();
163  $sql = "SELECT `{$this->handler->keyName}` FROM `{$this->handler->table}`";
164  $limit = $start = null;
165  if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
166  $sql .= ' ' . $criteria->renderWhere();
167  $limit = $criteria->getLimit();
168  $start = $criteria->getStart();
169  }
170  if (!$result = $this->handler->db->query($sql, $limit, $start)) {
171  return $ret;
172  }
173  while ($myrow = $this->handler->db->fetchArray($result)) {
174  $ret[] = $myrow[$this->handler->keyName];
175  }
176  return $ret;
177  }
178 
191  function &getByLimit($limit = 0, $start = 0, $criteria = null, $fields = null, $asObject = true)
192  {
193  $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated, please use getAll instead.');
194  if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
195  $criteria->setLimit($limit);
196  $criteria->setStart($start);
197  } else if (!empty($limit)) {
198  $criteria = new CriteriaCompo();
199  $criteria->setLimit($limit);
200  $criteria->setStart($start);
201  }
202  $ret = $this->handler->getAll($criteria, $fields, $asObject);
203  return $ret;
204  }
205 
214  function convertResultSet($result, $id_as_key = false, $as_object = true)
215  {
216  $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated.');
217  $ret = array();
218  while ($myrow = $this->handler->db->fetchArray($result)) {
219  $obj =& $this->handler->create(false);
220  $obj->assignVars($myrow);
221  if (!$id_as_key) {
222  if ($as_object) {
223  $ret[] =& $obj;
224  } else {
225  $row = array();
226  $vars = $obj->getVars();
227  foreach (array_keys($vars) as $i) {
228  $row[$i] = $obj->getVar($i);
229  }
230  $ret[] = $row;
231  }
232  } else {
233  if ($as_object) {
234  $ret[$myrow[$this->handler->keyName]] =& $obj;
235  } else {
236  $row = array();
237  $vars = $obj->getVars();
238  foreach (array_keys($vars) as $i) {
239  $row[$i] = $obj->getVar($i);
240  }
241  $ret[$myrow[$this->handler->keyName]] = $row;
242  }
243  }
244  unset($obj);
245  }
246 
247  return $ret;
248  }
249 }
250 
251 ?>