From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/admin/Library/Scaffold.php | 272 ++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100755 h-source/admin/Library/Scaffold.php (limited to 'h-source/admin/Library/Scaffold.php') diff --git a/h-source/admin/Library/Scaffold.php b/h-source/admin/Library/Scaffold.php new file mode 100755 index 0000000..2ac3fa5 --- /dev/null +++ b/h-source/admin/Library/Scaffold.php @@ -0,0 +1,272 @@ +HTML,..) + + public $mainMenu = null; //the reference to the MenuHelper object + public $pageList = null; //the reference to the PageDivisionHelper object + public $itemList = null; //the reference to the ListHelper object + public $popupMenu = null; //the reference to the PopupHelper object + + public $form = null; //the reference to the form object + public $entries = null; //the entries of the form (string having entries separated by comma) + public $values = array(); //the values inserted in the form (taken from the table if $this->queryType === 'update' or if an error occured during the databse query, otherwise taken from the $_POST array) + + //the list of fields of the select query + public $fields = null; + + public function __construct($type,$controller,$model,$viewArgs,$params = null) { + + $this->_type = $type; + $this->_controller = $controller; + $this->model = $model; + $this->viewArgs = $viewArgs; + + $autoParams = array( + 'mainAction' => 'main', + 'modifyAction' => 'form/update', + 'associateAction' => 'associate', + 'panelController' => 'panel', + 'pageList' => true, + 'pageVariable' => 'page', + 'recordPerPage' => 10, + 'mainMenu' => 'panel,add', + 'formMenu' => 'panel,back', + 'postSubmitValue' => 'Save', + 'popup' => false, + 'popupType' => 'exclusive' + ); + + //set the $this->scaffold->params array + if (is_array($params)) { + foreach ($params as $key => $value) { + $autoParams[$key] = $value; + } + } + $this->params = $autoParams; + + } + + //ad some clauses to the select query + //whereArray = array ($table_field => $value) + public function appendWhereQueryClause($whereArray) + { + $this->model->appendWhereQueryClause($whereArray); + } + + //set clauses to the select query + //whereArray = array ($table_field => $value) + public function setWhereQueryClause($whereArray) + { + $this->model->setWhereQueryClause($whereArray); + } + + //initialize the main scaffold (ListHelper) + //$recordList: field of the table to show, $primaryKey: the key of the table + public function loadMain($recordList,$primaryKey,$theme = 'edit,del') + { + $this->_primaryKey = $primaryKey; + + $recordListArray = explode(',',$recordList); + foreach ($recordListArray as $record) { + $this->itemList->addItem("simpleText",";$record;"); + } + + $themeArray = explode(',',$theme); + + foreach ($themeArray as $el) + { + switch ($el) + { + case 'moveup': + $this->itemList->addItem('moveupForm',$this->_controller.'/'.$this->params['mainAction'],$primaryKey); + break; + case 'movedown': + $this->itemList->addItem('movedownForm',$this->_controller.'/'.$this->params['mainAction'],$primaryKey); + break; + case 'link': + $this->itemList->addItem('associateForm',$this->_controller.'/'.$this->params['associateAction'],$primaryKey); + break; + case 'edit': + $this->itemList->addItem('editForm',$this->_controller.'/'.$this->params['modifyAction'],$primaryKey); + break; + case 'del': + $this->itemList->addItem('delForm',$this->_controller.'/'.$this->params['mainAction'],$primaryKey); + break; + } + } + + } + + //initialize the form + //$queryType = insert/update + //$action: the action of the form (controller/action/queryString) + public function loadForm($queryType,$action) + { + $this->queryType = $queryType; + $submitName = $this->model->getSubmitName($queryType); + $value = $this->params['postSubmitValue']; + $viewStatus = Url::createUrl(array_values($this->viewArgs)); + $this->model->setForm($action.$viewStatus,array($submitName => $value),'POST'); + $this->form = $this->model->form; + } + + //function to obtain the values to use in the form + //$func = function to validate the values + //$id = the id of the record (used if $_POST[$this->m[$this->model]->identifierName] is not present) + public function getFormValues($func = 'sanitizeHtml',$id = null,$defaultValues = array(),$functionsIfFromDb = array()) + { + if ($this->_type === 'form') + { + $this->values = $this->model->getFormValues($this->queryType,$func,$id,$defaultValues,$functionsIfFromDb); + } + } + + //set the head of the table + //$columnsName: name of the columns. It has to be a comma-separated list of strings + public function setHead($columnsName) + { + $this->itemList->setHead($columnsName); + } + + //method to set the type of the entries of the form + //$entries: string containing the list of the entries where each entry is separated by comma: entry1,entry2,entry3 + //$entryType: associative array that describes the entries of the form. The key is the entry name while the value is the entry type (textarea,inputText,etc) + public function setFormEntries($entries = 'model',$entryType = array(),$optionsArray = array()) + { + if ($this->_type === 'form') + { + if ($entries === 'model') + { + $this->entries = $this->model->fields; + if ($this->queryType === 'update') + { + $this->entries .= ','. $this->model->identifierName; + } + } + else + { + $this->entries = null; + } + $entriesArray = explode(',',$this->entries); + if (isset($this->form)) + { + foreach ($entriesArray as $entry) + { + $type = isset($entryType[$entry]) ? $entryType[$entry] : 'InputText'; + $options = isset($optionsArray[$entry]) ? $optionsArray[$entry] : null; + $this->form->setEntry($entry,$type,$options); + } + if ($this->queryType === 'update') + { + $this->form->setEntry($this->model->identifierName,'Hidden'); + } + } + else + { + throw new Exception('form object has not been initialized. Call the scaffold->loadForm method before'); + } + } + } + + //add an item to the list of items + public function addItem($type, $action = '', $field = '', $name = '') { + if ($this->_type === 'main') { + $this->itemList->addItem($type, $action, $field, $name); + } + } + + //update the table + public function update($methodsList = '',$id = null) { + $this->model->updateTable($methodsList,$id); + } + + //method to create the HTML of the scaffold + //$values: the values to insert in the from entries + public function render($values = null,$subset = null) + { + + if ($this->_type === 'main') + { + + $recordNumber = $this->model->rowNumber(); + + if (isset($this->viewArgs[$this->params['pageVariable']])) + { + $page = $this->viewArgs[$this->params['pageVariable']]; + } + else + { + $this->params['pageList'] = false; + } + + $recordPerPage = $this->params['recordPerPage']; + + if ($this->params['pageList'] === true) + { + $this->model->limit = $this->pageList->getLimit($page,$recordNumber,$recordPerPage); + $this->html['pageList'] = $this->pageList->render((int)($page-2),5); + $position = array($page,$this->pageList->getNumbOfPages()); + } + else + { + $this->model->limit = null; + $this->html['pageList'] = null; + $position = array(1,1); + } + + $values = $this->model->getTable($this->fields); + + $primaryKey = $this->_primaryKey; + + //pass the variable position + $this->itemList->position = $position; + $this->html['main'] = $this->itemList->render($values); + + $this->html['menu'] = $this->mainMenu->render($this->params['mainMenu']); + + $popupHtml = null; + if ($this->params['popup'] === true) + { + $this->html['popup'] = $this->popupMenu->render(); + $popupHtml = "
\n".$this->html['popup']."\n
\n"; + } + + $this->html['all'] = "\n".$this->model->notice."\n $popupHtml \n
\n".$this->html['main']."\n
\n"."
\n
\n".$this->html['pageList']."
\n
\n\n"; + + } + else if ($this->_type === 'form') + { + + $subset = (!isset($subset)) ? $this->entries : $subset; + $values = (!isset($values)) ? $this->values : $values; + $this->html['menu'] = $this->mainMenu->render($this->params['formMenu']); + $this->html['main'] = $this->form->render($values,$subset); + $this->html['all'] = "\n".$this->model->notice."\n
\n".$this->html['main']."
\n"; + + } + + return $this->html['all']; + + } + +} \ No newline at end of file -- cgit v1.2.3