Added in class member variables, fixed warnings about undefined array values, prettied up the code to Campware coding conventions.
This commit is contained in:
parent
3be0939b41
commit
20b1098f3e
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
class uiBrowse
|
||||
{
|
||||
var $Base; // uiBase object
|
||||
var $prefix;
|
||||
var $col;
|
||||
var $criteria;
|
||||
var $reloadUrl;
|
||||
|
||||
function uiBrowse(&$uiBase)
|
||||
{
|
||||
$this->Base =& $uiBase;
|
||||
|
@ -10,19 +16,25 @@ class uiBrowse
|
|||
#$this->results =& $_SESSION[constant('UI_'.$this->prefix.'_SESSNAME')]['results'];
|
||||
$this->reloadUrl = UI_BROWSER.'?popup[]=_reload_parent&popup[]=_close';
|
||||
|
||||
if (empty($this->criteria['limit'])) $this->criteria['limit'] = UI_BROWSE_DEFAULT_LIMIT;
|
||||
if (empty($this->criteria['filetype'])) $this->criteria['filetype'] = UI_FILETYPE_ANY;
|
||||
if (empty($this->criteria['limit'])) {
|
||||
$this->criteria['limit'] = UI_BROWSE_DEFAULT_LIMIT;
|
||||
}
|
||||
if (empty($this->criteria['filetype'])) {
|
||||
$this->criteria['filetype'] = UI_FILETYPE_ANY;
|
||||
}
|
||||
|
||||
if (!is_array($this->col)) {
|
||||
## init Categorys
|
||||
$this->setDefaults();
|
||||
}
|
||||
}
|
||||
} // constructor
|
||||
|
||||
|
||||
function setReload()
|
||||
{
|
||||
$this->Base->redirUrl = $this->reloadUrl;
|
||||
}
|
||||
} // fn setReload
|
||||
|
||||
|
||||
function setDefaults($reload=FALSE)
|
||||
{
|
||||
|
@ -32,11 +44,11 @@ class uiBrowse
|
|||
$this->col[2]['value'][0] = '%%all%%';
|
||||
$this->col[3]['category'] = UI_BROWSE_DEFAULT_KEY_3;
|
||||
$this->col[3]['value'][0] = '%%all%%';
|
||||
|
||||
for ($col=1; $col<=3; $col++) {
|
||||
$this->setCategory(array('col' => $col, 'category' => $this->col[$col]['category'], 'value' => array(0 => '%%all%%')));
|
||||
|
||||
|
||||
for ($col = 1; $col <= 3; $col++) {
|
||||
$this->setCategory(array('col' => $col,
|
||||
'category' => $this->col[$col]['category'],
|
||||
'value' => array(0 => '%%all%%')));
|
||||
$this->setValue(
|
||||
array('col' => $col,
|
||||
'category' => $this->col[$col]['category'],
|
||||
|
@ -45,35 +57,43 @@ class uiBrowse
|
|||
);
|
||||
}
|
||||
|
||||
if ($reload === TRUE) $this->setReload();
|
||||
}
|
||||
if ($reload === TRUE) {
|
||||
$this->setReload();
|
||||
}
|
||||
} // fn setDefaults
|
||||
|
||||
|
||||
function getCriteria()
|
||||
{
|
||||
return $this->criteria;
|
||||
}
|
||||
} // fn getCriteria
|
||||
|
||||
|
||||
function getResult()
|
||||
{
|
||||
{
|
||||
$this->searchDB();
|
||||
return $this->results;
|
||||
}
|
||||
} // fn getResult
|
||||
|
||||
|
||||
function browseForm($id, $mask2)
|
||||
{
|
||||
{
|
||||
include dirname(__FILE__).'/formmask/metadata.inc.php';
|
||||
#$mask2['browse_columns']['category']['options'][0] = tra('Select a Value');
|
||||
foreach ($mask['pages'] as $key=>$val) {
|
||||
foreach ($mask['pages'] as $key => $val) {
|
||||
foreach ($mask['pages'][$key] as $v){
|
||||
if ($v['type']) $mask2['browse_columns']['category']['options'][$this->Base->_formElementEncode($v['element'])] = tra($v['label']);
|
||||
if (isset($v['type']) && $v['type']) {
|
||||
$tmp = $this->Base->_formElementEncode($v['element']);
|
||||
$mask2['browse_columns']['category']['options'][$tmp] = tra($v['label']);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for($n=1; $n<=3; $n++) {
|
||||
for ($n = 1; $n <= 3; $n++) {
|
||||
$form = new HTML_QuickForm('col'.$n, UI_STANDARD_FORM_METHOD, UI_HANDLER);
|
||||
$form->setConstants(array('id' => $id, 'col' => $n, 'category' => $this->Base->_formElementEncode($this->col[$n]['category'])));
|
||||
$form->setConstants(array('id' => $id,
|
||||
'col' => $n,
|
||||
'category' => $this->Base->_formElementEncode($this->col[$n]['category'])));
|
||||
$mask2['browse_columns']['value']['options'] = $this->options($this->col[$n]['values']['results']);
|
||||
$mask2['browse_columns']['value']['default'] = $this->col[$n]['form_value'];
|
||||
$this->Base->_parseArr2Form($form, $mask2['browse_columns']);
|
||||
|
@ -93,30 +113,41 @@ class uiBrowse
|
|||
$output['global']['dynform'] = $renderer->toArray();
|
||||
|
||||
return $output;
|
||||
}
|
||||
} // fn browseForm
|
||||
|
||||
|
||||
/**
|
||||
* @param array $parm
|
||||
* @return void
|
||||
*/
|
||||
function setCategory($parm)
|
||||
{
|
||||
$which = $parm['col'];
|
||||
$this->col[$which]['category'] = $this->Base->_formElementDecode($parm['category']);
|
||||
$this->col[$which]['values'] = $this->Base->gb->browseCategory($this->col[$which]['category'], $this->col[$which]['criteria'], $this->Base->sessid);
|
||||
$criteria = isset($this->col[$which]['criteria']) ? $this->col[$which]['criteria'] : null;
|
||||
$this->col[$which]['values'] = $this->Base->gb->browseCategory($this->col[$which]['category'], $criteria, $this->Base->sessid);
|
||||
|
||||
$this->Base->redirUrl = UI_BROWSER.'?act='.$this->prefix;
|
||||
|
||||
$this->clearHierarchy($which);
|
||||
#print_r($this->col);
|
||||
}
|
||||
} // fn setCategory
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param array $parm
|
||||
*/
|
||||
function setValue($parm)
|
||||
{
|
||||
$this->criteria['offset'] = 0;
|
||||
$which = $parm['col'];
|
||||
$next = $which + 1;
|
||||
$this->col[$which]['form_value'] = $parm['value'][0];
|
||||
if ($parm['value'][0] == '%%all%%') {
|
||||
if ($parm['value'][0] == '%%all%%') {
|
||||
$this->col[$next]['criteria'] = array('operator' => 'and', 'filetype' => $this->criteria['filetype']);
|
||||
} else {
|
||||
} else {
|
||||
$this->col[$next]['criteria'] = array(
|
||||
'operator' => 'and',
|
||||
'filetype' => $this->criteria['filetype'],
|
||||
|
@ -131,7 +162,9 @@ class uiBrowse
|
|||
)
|
||||
);
|
||||
}
|
||||
$this->col[$next]['values'] = $this->Base->gb->browseCategory($this->col[$next]['category'], $this->col[$next]['criteria'], $this->Base->sessid);
|
||||
$nextCriteria = isset($this->col[$next]['criteria']) ? $this->col[$next]['criteria'] : null;
|
||||
$category = isset($this->col[$next]['category']) ? $this->col[$next]['category'] : null;
|
||||
$this->col[$next]['values'] = $this->Base->gb->browseCategory($category, $nextCriteria, $this->Base->sessid);
|
||||
|
||||
#echo "cat: ".$this->col[$next]['category']."\n";
|
||||
#echo "criteria: "; print_r($this->col[$next]['criteria']);
|
||||
|
@ -142,19 +175,21 @@ class uiBrowse
|
|||
#$this->searchDB();
|
||||
$this->Base->redirUrl = UI_BROWSER.'?act='.$this->prefix;
|
||||
#$this->setReload();
|
||||
}
|
||||
} // fn setValue
|
||||
|
||||
|
||||
function options($arr)
|
||||
{
|
||||
{
|
||||
$ret['%%all%%'] = '---all---';
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $val)
|
||||
foreach ($arr as $val) {
|
||||
$ret[$val] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
} // fn options
|
||||
|
||||
|
||||
function clearHierarchy($which)
|
||||
{
|
||||
|
@ -165,18 +200,19 @@ class uiBrowse
|
|||
$this->col[$col]['values'] = NULL;
|
||||
$this->col[$col]['form_value'] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // fn clearHierarchy
|
||||
|
||||
|
||||
function setCriteria() {
|
||||
//$this->criteria['conditions'] = array();
|
||||
unset($this->criteria['conditions']);
|
||||
for($col=3; $col>=1; $col--) {
|
||||
for ($col=3; $col>=1; $col--) {
|
||||
if (is_array($this->col[$col]['criteria'])) {
|
||||
$this->criteria = array_merge ($this->col[$col]['criteria'], $this->criteria);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // fn setCriteria
|
||||
|
||||
|
||||
function searchDB()
|
||||
|
@ -184,11 +220,11 @@ class uiBrowse
|
|||
$this->results = array('page' => $this->criteria['offset']/$this->criteria['limit']);
|
||||
|
||||
$results = $this->Base->gb->localSearch($this->criteria, $this->Base->sessid);
|
||||
|
||||
|
||||
if (!is_array($results) || !count($results)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->results['cnt'] = $results['cnt'];
|
||||
foreach ($results['results'] as $rec) {
|
||||
$tmpId = $this->Base->gb->_idFromGunid($rec["gunid"]);
|
||||
|
@ -217,7 +253,7 @@ class uiBrowse
|
|||
#print_r($this->criteria);
|
||||
#print_r($this->results);
|
||||
return TRUE;
|
||||
}
|
||||
} // fn searchDB
|
||||
|
||||
|
||||
function pagination(&$results)
|
||||
|
@ -240,11 +276,18 @@ class uiBrowse
|
|||
$deltaUpper = UI_BROWSERESULTS_DELTA;
|
||||
$start = $currp;
|
||||
|
||||
if ($start+$delta-$maxp > 0) $deltaLower += $start+$delta-$maxp; ## correct lower boarder if page is near end
|
||||
if ($start+$delta-$maxp > 0) {
|
||||
// correct lower border if page is near end
|
||||
$deltaLower += $start+$delta-$maxp;
|
||||
}
|
||||
|
||||
for ($n = $start-$deltaLower; $n <= $start+$deltaUpper; $n++) {
|
||||
if ($n <= 0) $deltaUpper++; ## correct upper boarder if page is near zero
|
||||
elseif ($n <= $maxp) $this->results['pagination'][$n] = $n;
|
||||
if ($n <= 0) {
|
||||
// correct upper border if page is near zero
|
||||
$deltaUpper++;
|
||||
} elseif ($n <= $maxp) {
|
||||
$this->results['pagination'][$n] = $n;
|
||||
}
|
||||
}
|
||||
|
||||
#array_pop($this->results['pagination']);
|
||||
|
@ -253,22 +296,23 @@ class uiBrowse
|
|||
$this->results['next'] = $results['cnt'] > $this->criteria['offset'] + $this->criteria['limit'] ? TRUE : FALSE;
|
||||
$this->results['prev'] = $this->criteria['offset'] > 0 ? TRUE : FALSE;
|
||||
ksort($this->results['pagination']);
|
||||
}
|
||||
} // fn pagination
|
||||
|
||||
|
||||
function reOrder($by)
|
||||
{
|
||||
$this->criteria['offset'] = NULL;
|
||||
|
||||
if ($this->criteria['orderby'] == $by && !$this->criteria['desc'])
|
||||
if ($this->criteria['orderby'] == $by && !$this->criteria['desc']) {
|
||||
$this->criteria['desc'] = TRUE;
|
||||
else
|
||||
} else {
|
||||
$this->criteria['desc'] = FALSE;
|
||||
}
|
||||
|
||||
$this->criteria['orderby'] = $by;
|
||||
$this->setReload();
|
||||
#$this->searchDB();
|
||||
}
|
||||
} // fn reOrder
|
||||
|
||||
|
||||
function setOffset($page)
|
||||
|
@ -285,29 +329,31 @@ class uiBrowse
|
|||
}
|
||||
$this->setReload();
|
||||
#$this->searchDB();
|
||||
}
|
||||
} // fn setOffset
|
||||
|
||||
|
||||
function setLimit($limit)
|
||||
{
|
||||
{
|
||||
$this->criteria['limit'] = $limit;
|
||||
$this->setReload();
|
||||
#$this->searchDB();
|
||||
}
|
||||
} // fn setLimit
|
||||
|
||||
|
||||
function setFiletype($filetype)
|
||||
{
|
||||
$this->criteria['filetype'] = $filetype;
|
||||
{
|
||||
$this->criteria['filetype'] = $filetype;
|
||||
$this->criteria['offset'] = 0;
|
||||
|
||||
|
||||
for ($n=1; $n<=3; $n++) {
|
||||
$this->col[$n]['criteria']['filetype'] = $filetype;
|
||||
|
||||
$this->col[$n]['criteria']['filetype'] = $filetype;
|
||||
|
||||
$this->col[$n]['values'] = $this->Base->gb->browseCategory($this->col[$n]['category'], $this->col[$n]['criteria'], $this->Base->sessid);
|
||||
$this->clearHierarchy($n);
|
||||
}
|
||||
|
||||
|
||||
$this->setReload();
|
||||
#$this->searchDB();
|
||||
}
|
||||
}
|
||||
} // fn setFiletype
|
||||
} // class uiBrowse
|
||||
?>
|
Loading…
Reference in New Issue