20 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
45 function validateLinks()
47 if (empty($this->handler->table_link) || empty($this->handler->field_link)) {
48 trigger_error(
"The linked table is not set yet.", E_USER_WARNING);
51 if (empty($this->handler->field_object)) {
52 $this->handler->field_object = $this->handler->field_link;
67 function &getByLink(
$criteria = null,
$fields = null, $asObject =
true, $field_link = null, $field_object = null)
69 if (!empty($field_link)) {
70 $this->handler->field_link = $field_link;
72 if (!empty($field_object)) {
73 $this->handler->field_object = $field_object;
75 if (!$this->validateLinks()) {
80 if (!in_array(
"o." . $this->handler->keyName,
$fields)) {
81 $fields[] =
"o." . $this->handler->keyName;
83 $select = implode(
",",
$fields);
90 $sql =
" SELECT {$select}"
91 .
" FROM {$this->handler->table} AS o"
92 .
" LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
102 if (empty($orderSet)) {
103 $sql .=
" ORDER BY o.{$this->handler->keyName} DESC";
108 while ($myrow = $this->handler->db->fetchArray(
$result)) {
109 $object =& $this->handler->create(
false);
110 $object->assignVars($myrow);
111 $ret[$myrow[$this->handler->keyName]] = $object;
115 $object =& $this->handler->create(
false);
116 while ($myrow = $this->handler->db->fetchArray(
$result)) {
117 $object->assignVars($myrow);
118 $ret[$myrow[$this->handler->keyName]] = $object->getValues(array_keys($myrow));
133 if (!$this->validateLinks()) {
137 $sql =
" SELECT COUNT(DISTINCT {$this->handler->keyName}) AS count"
138 .
" FROM {$this->handler->table} AS o"
139 .
" LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
146 $myrow = $this->handler->db->fetchArray(
$result);
147 return intval($myrow[
"count"]);
158 if (!$this->validateLinks()) {
161 $sql =
" SELECT l.{$this->handler->keyName_link}, COUNT(*)"
162 .
" FROM {$this->handler->table} AS o"
163 .
" LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
167 $sql .=
" GROUP BY l.{$this->handler->keyName_link}";
172 while (list ($id, $count) = $this->handler->db->fetchRow(
$result)) {
187 if (!$this->validateLinks()) {
191 foreach ($data as $key => $val) {
192 $set[] =
"o.{$key}=" . $this->handler->db->quoteString($val);
194 $sql =
" UPDATE {$this->handler->table} AS o"
195 .
" SET " . implode(
", ", $set)
196 .
" LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
200 return $this->handler->db->query(
$sql);
211 if (!$this->validateLinks()) {
214 $sql =
"DELETE FROM {$this->handler->table} AS o "
215 .
" LEFT JOIN {$this->handler->table_link} AS l ON o.{$this->handler->field_object} = l.{$this->handler->field_link}";
219 return $this->handler->db->query(
$sql);