/** * Creates a 2 dimensional array of items from the current table. * * This function creates an sql statement based on variables currently set in * this object. The statement is then executed on the current table and it's * result is returned as the list of current items. * * @param boolean $filterGroups Flag whether or not to filter items that are not * associated with a users group * @return mixed A 2-dimentional array of items or FALSE on failure. * @access public * @see getList() */ function getItems($ids = NULL, $filterGroups = FALSE, $everything = FALSE) { if (isset($this->_table)) { $table = $this->_table; } else { $table = $this->_tables[$this->listName]; } /* Make sure the table name is set before continuing */ if (isset($table)) { if (is_array($this->_listColumns[$this->listName])) { if ($everything) { $sql = 'SELECT *'; } else { $sql = 'SELECT id, '; foreach ($this->_listColumns[$this->listName] as $listColumn => $listLabel) { if ($listColumn != 'id') { $sql .= $listColumn . ', '; } } $sql = substr($sql, 0, strlen($sql) - 2); } $sql .= ' FROM ' . $table; } else { $error = new PHPWS_Error('core', 'PHPWS_Manager:getItems()', 'Format error in config file.', 'exit', 1); $error->message(NULL); } } else { $error = new PHPWS_Error('core', 'PHPWS_Manager:getItems()', 'Table not set!', 'exit', 1); $error->message(NULL); } $whereFlag = FALSE; $sort = $this->getSort(); if (isset($sort)) { $sql .= $sort; $whereFlag = TRUE; } if (is_array($ids) && sizeof($ids) > 0) { if ($whereFlag) { $sql .= ' AND ('; } else { $sql .= ' WHERE ('; } foreach ($ids as $id) { $sql .= " id='{$id}' OR "; } $sql = substr($sql, 0, strlen($sql) - 4) . ')'; } $order = $this->getOrder(); if (isset($order)) { $sql .= $order; } /* Set associative mode for db and execute query */ $result = PHPWS_DB::getAll($sql); if ($filterGroups) { $size = sizeof($result); for ($i = 0; $i < $size; $i++) { $groups = unserialize($result[$i]['groups']); if (is_array($groups)) { foreach ($groups as $value) { if (!$_SESSION['OBJ_user']->userInGroup($value)) { unset($result[$i]); } } } } $result = PHPWS_Array::reIndex($result); } /* Return result of query */ return $result; }