* @package Core
*/
class PHPWS_List {
var $_module = NULL;
var $_controller = NULL;
var $_class = NULL;
var $_table = NULL;
var $_ids = NULL;
var $_dbColumns = array();
var $_listColumns = array();
var $_name = NULL;
var $_template = NULL;
var $_op = NULL;
var $_paging = array();
var $_where = NULL;
var $_order = NULL;
var $_overrideOrder = array();
var $_pager = NULL;
var $_anchor = FALSE;
var $_idColumn = "id";
var $_extraListTags = array();
var $_extraRowTags = array();
function getList() {
if(!isset($this->_module)) {
echo "Module not set.
";
//return PHPWS_Error(PHPWS_LIST_MODULE_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_controller)) {
$this->_controller = $this->_module;
}
if(!isset($this->_class)) {
echo "Class not set.
";
//return PHPWS_Error(PHPWS_LIST_CLASS_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_table)) {
echo "Table not set.
";
//return PHPWS_Error(PHPWS_LIST_TABLE_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_dbColumns)) {
echo "Database Columns not set.
";
//return PHPWS_Error(PHPWS_LIST_COLUMNS_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_listColumns)) {
echo "List Columns not set.
";
//return PHPWS_Error(PHPWS_LIST_COLUMNS_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_name)) {
echo "Name not set.
";
//return PHPWS_Error(PHPWS_LIST_NAME_NOT_SET, "core", "PHPWS_List::getList()");
}
if(!isset($this->_template)) {
$this->_template = $this->_name;
}
if(!isset($this->_op)) {
echo "Op not set.
";
//return PHPWS_Error(PHPWS_LIST_OP_NOT_SET, "core", "PHPWS_List::getList()");
}
$theme = $_SESSION['OBJ_layout']->current_theme;
$themeRowTpl = "themes/$theme/templates/$this->_module/$this->_template/row.tpl";
$moduleRowTpl = PHPWS_SOURCE_DIR."mod/$this->_module/templates/$this->_template/row.tpl";
$themeListTpl = "themes/$theme/templates/$this->_module/$this->_template/list.tpl";
$moduleListTpl = PHPWS_SOURCE_DIR."mod/$this->_module/templates/$this->_template/list.tpl";
if(file_exists($themeRowTpl)) $rowTpl = $themeRowTpl;
else $rowTpl = $moduleRowTpl;
if(file_exists($themeListTpl)) $listTpl = $themeListTpl;
else $listTpl = $moduleListTpl;
if(isset($_REQUEST['list']) && ($this->_name == $_REQUEST['list'])) $this->catchOrder();
if(isset($this->_paging) && is_array($this->_paging) && (sizeof($this->_paging) > 0)) {
if(!isset($this->_pager)) {
$this->_pager = new PHPWS_Pager;
}
$this->_pager->setLinkBack("./index.php?module=$this->_controller&$this->_op&list=$this->_name");
$this->_pager->setLimits($this->_paging['limits']);
$this->_pager->makeArray(TRUE);
if($this->_anchor) $this->_pager->setAnchor("#$this->_name");
$this->_pager->limit = $this->_paging['limit'];
if(is_array($this->_ids)) {
$this->_pager->setData($this->_orderIds($this->_ids));
} else {
$this->_pager->setData($this->_getIds());
}
if(isset($_REQUEST['list']) && ($this->_name == $_REQUEST['list'])) $this->_pager->pageData();
else $this->_pager->pageData(FALSE);
$items = $this->getItems($this->_pager->getData());
$totalItems = $this->_pager->getNumRows();
} else {
$this->_pager = NULL;
if(is_array($this->_ids)) {
$items = $this->getItems($this->_ids);
} else {
$items = $this->getItems();
}
$totalItems = sizeof($items);
}
/* Begin building main list tags array for processTemplate() */
$listTags = array();
if($this->_anchor) $listTags["ANCHOR"] = "_name\" name=\"$this->_name\">";
foreach($this->_dbColumns as $column) {
$capscolumn = strtoupper($column);
$key = "{$capscolumn}_ORDER_LINK";
$listTags[$key] = NULL;
if($totalItems > 0) {
$anchor = NULL;
if($this->_anchor) $anchor = "#$this->_name";
if(isset($this->_overrideOrder[$column][0])) $overRide = $this->_overrideOrder[$column][0];
else $overRide = "default";
switch($overRide) {
case 0:
$listTags[$key] .= "_controller&$this->_op&list=$this->_name&column=$column&order=1$anchor\">";
$listTags[$key] .= "";
break;
case 1:
$listTags[$key] .= "_controller&$this->_op&list=$this->_name&column=$column&order=2$anchor\">";
$listTags[$key] .= "";
break;
case 2:
$listTags[$key] .= "_controller&$this->_op&list=$this->_name&column=$column&order=0$anchor\">";
$listTags[$key] .= "";
break;
default:
$listTags[$key] .= "_controller&$this->_op&list=$this->_name&column=$column&order=1$anchor\">";
$listTags[$key] .= "";
}
}
}
/* Build each item's row */
$listTags['LIST_ITEMS'] = array();
if($totalItems > 0) {
foreach($items as $item) {
$object = NULL;
if(class_exists($this->_class)) {
$object = new $this->_class($item);
$classMethods = get_class_methods($this->_class);
} else {
//return PHPWS_Error(PHPWS_LIST_CLASS_NOT_EXISTS, "core", "PHPWS_List::getList()");
echo "Class does not exist.";
}
PHPWS_WizardBag::toggle($row_class, PHPWS_LIST_TOGGLE_CLASS);
/* Build row tags array for processTemplate() */
$rowTags = array();
$rowTags["ROW_CLASS"] = $row_class;
foreach($this->_listColumns as $column) {
$capscolumn = strtoupper($column);
$method = "getList{$column}";
if(is_object($object) && preg_grep('/^' . preg_quote($method, '/') . '$/i', $classMethods)) {
$rowTags[$capscolumn] = $object->{$method}();
} else {
$rowTags[$capscolumn] = "Get method not found.";
}
}
$rowTags = array_merge($rowTags, $this->_extraRowTags);
/* Process this item and concatenate onto the current list of items */
$listTags["LIST_ITEMS"][] = PHPWS_Template::processTemplate($rowTags, "core", $rowTpl, FALSE);
}
$listTags["LIST_ITEMS"] = implode("\n", $listTags["LIST_ITEMS"]);
if(isset($this->_pager) && is_object($this->_pager)) {
$listTags['NAV_BACKWARD'] = $this->_pager->getBackLink($this->_paging['back']);
$listTags['NAV_FORWARD'] = $this->_pager->getForwardLink($this->_paging['forward']);
if($this->_paging['section']) {
$listTags['NAV_SECTIONS'] = $this->_pager->getSectionLinks();
}
$listTags['NAV_LIMITS'] = $this->_pager->getLimitLinks();
$listTags['NAV_INFO'] = $this->_pager->getSectionInfo();
} else {
$listTags['TOTAL'] = $totalItems;
}
$listTags = array_merge($listTags, $this->_extraListTags);
$content = PHPWS_Template::processTemplate($listTags, "core", $listTpl, FALSE);
} else {
$columns = sizeof($this->_listColumns);
$listTags["LIST_ITEMS"] = "