-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
SampleCodeGen/app/controllers/admin/PeopleController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
<?php | ||
/* | ||
* ======================================================================= | ||
* FILE NAME: people.router.php | ||
* DATE CREATED: 25-10-2017 | ||
* FOR TABLE: people | ||
* AUTHOR: Hezecom Technology Solutions LTD. | ||
* CONTACT: http://hezecom.com <info@hezecom.com> | ||
* ======================================================================= | ||
*/ | ||
namespace App\Controller; | ||
|
||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
|
||
use App\Model\HTSPrivilegedUser; | ||
use App\Model\People; | ||
|
||
class PeopleController extends AdminBaseController | ||
{ | ||
private function routeURL($path) | ||
{ | ||
return $this->htsUrl.'/admin/people/'.$path; | ||
} | ||
|
||
private function model() | ||
{ | ||
return new People(); | ||
} | ||
|
||
/*View Controller*/ | ||
public function View(Request $request, Response $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-view'); | ||
/*Table header*/ | ||
$primary_key = 'id';/*this will be hidden*/ | ||
$actionButton = '<span class="right">'.$this->lang['HTS_ACTIONS'].'</span>'; | ||
$fieldLabel = array($primary_key, $this->lang['PEOP_NAME'],$this->lang['PEOP_GENDER'],$this->lang['PEOP_DATE_REGISTERED'],$this->lang['PEOP_PICTURE'],$actionButton); | ||
|
||
/*send data to template*/ | ||
$htsvars = [ | ||
'page' => [ | ||
'title' => 'People- ' . H_TITLE, | ||
'ptitle' => 'People', | ||
'viewproURL' => $this->routeURL('viewpro'), | ||
'lastColumn' => count($fieldLabel)-1, | ||
'addURL' => $this->routeURL('add'), | ||
'exportURL' => $this->routeURL('export'), | ||
'detailsURL' => 'details', | ||
'deleteURL' => $this->routeURL('delete'), | ||
], | ||
'fieldLabels' => $fieldLabel | ||
]; | ||
return $this->view->render($response, 'admin/views/people/View.html', $htsvars); | ||
} | ||
|
||
|
||
/*Datatable Procesing*/ | ||
public function ViewPro($request, $response, $args) | ||
{ | ||
/*table data to display*/ | ||
$primary_key='id'; | ||
$columns = array($primary_key, 'name','gender','date_registered','picture'); | ||
/*get root link*/ | ||
$result= $this->model()->SelectTableData($columns,'update'); | ||
echo json_encode($result); | ||
} | ||
|
||
|
||
/*export*/ | ||
public function Export() | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-export'); | ||
$printer=get('p'); | ||
$result =$this->model()->SelectAll(10000); | ||
include($this->htsPath.'templates/admin/views/people/Export.phtml'); | ||
if($printer=='csv') { | ||
\App\Lib\HDB::hus()->ExportTable('people'); | ||
}elseif($printer=='json') { | ||
Json_Export($result, 'people'); | ||
} | ||
} | ||
|
||
|
||
/*Details*/ | ||
public function Details($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-details'); | ||
$htsvars = [ | ||
'page' => [ | ||
'title' => 'People Detail'. H_TITLE, | ||
'addURL' => $this->routeURL('add'), | ||
'viewURL' => $this->routeURL('view'), | ||
'updateURL' => $this->routeURL('update/'.$args['id']), | ||
'deleteURL' => $this->routeURL('delete') | ||
], | ||
'row' => $this->model()->SelectOne($args['id']), | ||
'lists' => $this->model()->SelectAll(10), | ||
|
||
]; | ||
return $this->view->render($response, 'admin/views/people/Details.html', $htsvars); | ||
} | ||
|
||
|
||
/*add*/ | ||
public function Add($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-add'); | ||
$htsvars = [ | ||
'page' => [ | ||
'title' => 'Add People - '.H_TITLE, | ||
'proURL' => $this->routeURL('addpro'), | ||
'viewURL' => $this->routeURL('view'), | ||
] | ||
]; | ||
return $this->view->render($response, 'admin/views/people/Add.html', $htsvars); | ||
} | ||
|
||
/*Add Process*/ | ||
public function AddPro($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-add'); | ||
if($_POST){ | ||
/*form validation*/ | ||
if (post('name')==''){ | ||
field_error($this->lang['PEOP_NAME']); | ||
} | ||
elseif (post('gender')==''){ | ||
field_error($this->lang['PEOP_GENDER']); | ||
} | ||
elseif (post('date_registered')==''){ | ||
field_error($this->lang['PEOP_DATE_REGISTERED']); | ||
} | ||
elseif (post('others')==''){ | ||
field_error($this->lang['PEOP_OTHERS']); | ||
} | ||
else{ | ||
$this->model()->Insert(post('name'),post('gender'),post('date_registered'),post('others')); | ||
json_success($this->lang['LANG_ADD_SUCCESS']); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
/*update*/ | ||
public function Update($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-update'); | ||
$htsvars = [ | ||
'page' => [ | ||
'title' => 'Update People - '.H_TITLE, | ||
'proURL' => $this->routeURL('addpro'), | ||
'addURL' => $this->routeURL('add'), | ||
'viewURL' => $this->routeURL('view'), | ||
'deleteURL' => $this->routeURL('delete'), | ||
'updateproURL' => $this->routeURL('updatepro'), | ||
|
||
], | ||
'row' => $this->model()->SelectOne($args['id']), | ||
|
||
]; | ||
return $this->view->render($response, 'admin/views/people/Update.html', $htsvars); | ||
} | ||
|
||
/*Update Process*/ | ||
public function UpdatePro($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-update'); | ||
if($_POST){ | ||
/*form validation*/ | ||
if (post('id')==''){ | ||
field_error($this->lang['PEOP_OTHERS']); | ||
} | ||
elseif (post('name')==''){ | ||
field_error($this->lang['PEOP_NAME']); | ||
} | ||
elseif (post('gender')==''){ | ||
field_error($this->lang['PEOP_GENDER']); | ||
} | ||
elseif (post('date_registered')==''){ | ||
field_error($this->lang['PEOP_DATE_REGISTERED']); | ||
} | ||
elseif (post('others')==''){ | ||
field_error($this->lang['PEOP_OTHERS']); | ||
} | ||
else{ | ||
$this->model()->Update(post('name'),post('gender'),post('date_registered'),post('others'),post('id')); | ||
json_success($this->lang['LANG_UPDATE_SUCCESS']); | ||
} | ||
} | ||
} | ||
|
||
/*Delete*/ | ||
public function Delete($request, $response, $args) | ||
{ | ||
HTSPrivilegedUser::HTSuser()->HTSPrivilege('people-delete'); | ||
$dfile = $this->model()->SelectOne(get('id')); | ||
delete_files(UPLOAD_PATH.$dfile->picture); | ||
delete_files(THUMB_PATH.$dfile->picture); | ||
$rows = $this->model()->Delete(get('id')); | ||
return $response->withStatus(302)->withHeader('Location', $this->routeURL('view')); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
$container['App\Controller\PeopleController'] = function ($c) { | ||
return new App\Controller\PeopleController($c); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"HTS_SYSTEM_LANGUAGE" : "======Generated language file======", | ||
|
||
"HTS_PEOPLE" : "People", | ||
"PEOP_ID" : "Id", | ||
"PEOP_NAME" : "Name", | ||
"PEOP_GENDER" : "Gender", | ||
"PEOP_DATE_REGISTERED" : "Date registered", | ||
"PEOP_PICTURE" : "Picture", | ||
"PEOP_OTHERS" : "Others" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
/** | ||
* ========================================================= | ||
* CLASSNAME: people | ||
* DATE CREATED: 25-10-2017 | ||
* FOR TABLE: people | ||
* AUTHOR: Hezecom Technology Solutions LTD. | ||
* CONTACT: http://hezecom.com <info@hezecom.com> | ||
* ========================================================= | ||
*/ | ||
|
||
namespace App\Model; | ||
use App\Lib\HDB; | ||
|
||
class People{ | ||
|
||
private $hts; | ||
private $table = 'people'; | ||
|
||
function __construct() | ||
{ | ||
$this->hts = HDB::hus(); | ||
} | ||
|
||
/** | ||
* SELECT FOR DATATABLE | ||
* @param $columns = list of table fields to display | ||
* @param $editlink = link to edit page | ||
* @return array | ||
*/ | ||
public function SelectTableData($columns, $editlink) | ||
{ | ||
$fieldsvars = implode(', ', $columns); | ||
$sqldata = "SELECT $fieldsvars FROM $this->table"; | ||
$sqlcount = "SELECT COUNT(*) AS ntotal FROM $this->table"; | ||
return $this->hts->HTSdataTable($sqldata,$sqlcount,$columns,$editlink,"people"); | ||
} | ||
|
||
/* | ||
* SELECT MULTIPLE RECORD WITH LIMIT | ||
* @param $limit | ||
* @return array|bool|mixed | ||
*/ | ||
public function SelectAll($limit = 10000) | ||
{ | ||
return $this->hts->HTSselect("$this->table ORDER BY id DESC LIMIT $limit"); | ||
} | ||
|
||
/* | ||
* SELECT ONE RECORD | ||
* @param $id | ||
* @return array|bool|mixed | ||
*/ | ||
public function SelectOne($id) | ||
{ | ||
$bind = array(":id" =>$id); | ||
return $this->hts->HTSselect("$this->table WHERE id=:id",$bind,1); | ||
} | ||
|
||
/* | ||
* DELETE RECORD | ||
* @param $id | ||
* @return array|bool|mixed | ||
*/ | ||
public function Delete($id) | ||
{ | ||
$bind = array(":id" =>$id); | ||
return $this->hts->Hdelete("$this->table","id=:id",$bind); | ||
|
||
} | ||
|
||
/* | ||
* SELECT MULTIPLE FILES | ||
* @param $id | ||
* @return array|bool|mixed | ||
*/ | ||
public function MultiDelete($ids) | ||
{ | ||
return $this->hts->Hcustom('DELETE FROM $this->table WHERE id IN ('.$ids.')'); | ||
} | ||
|
||
|
||
/* | ||
* INSERT | ||
*/ | ||
public function Insert($name,$gender,$date_registered,$others) | ||
{ | ||
$newupload = new HTSUploadControl; | ||
$uploadname=$newupload->ImageUplaodResize('picture',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90); | ||
if($uploadname===false){ | ||
$values = array(array( 'name'=>$name,'gender'=>$gender,'date_registered'=>$date_registered,'others'=>$others )); | ||
}else{ | ||
$values = array(array( 'picture'=>$uploadname,'name'=>$name,'gender'=>$gender,'date_registered'=>$date_registered,'others'=>$others )); | ||
} | ||
$this->hts->Hinsert($this->table, $values); | ||
} | ||
|
||
/* | ||
* UPDATE | ||
*/ | ||
public function Update($name,$gender,$date_registered,$others,$id) | ||
{ | ||
$newupload = new HTSUploadControl; | ||
$uploadname=$newupload->ImageUplaodResize('picture',THUMB_IMAGE_WIDTH,BIG_IMAGE_WIDTH,UPLOAD_PATH,THUMB_PATH,90); | ||
$where = array('id' => $id); | ||
if($uploadname===false){ | ||
$values = array('name'=>$name,'gender'=>$gender,'date_registered'=>$date_registered,'others'=>$others); | ||
}else{ | ||
$values = array('picture'=>$uploadname, 'name'=>$name,'gender'=>$gender,'date_registered'=>$date_registered,'others'=>$others); | ||
} | ||
$this->hts->HTSupdate($this->table,$values,$where); | ||
|
||
} | ||
|
||
|
||
} /*end class*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
$app->group('/admin/people/', function () { | ||
$this->get('view', 'App\Controller\PeopleController:View')->setName('people-view'); | ||
$this->get('details/{id}', 'App\Controller\PeopleController:Details')->setName('people-details'); | ||
$this->get('export', 'App\Controller\PeopleController:Export')->setName('people-export'); | ||
$this->post('viewpro', 'App\Controller\PeopleController:ViewPro')->setName('people-viewpro'); | ||
$this->get('add', 'App\Controller\PeopleController:Add')->setName('people-add'); | ||
$this->post('addpro', 'App\Controller\PeopleController:AddPro')->setName('people-addpro'); | ||
$this->get('update/{id}', 'App\Controller\PeopleController:Update')->setName('people-update'); | ||
$this->post('updatepro', 'App\Controller\PeopleController:UpdatePro')->setName('people-updatepro'); | ||
$this->get('delete', 'App\Controller\PeopleController:Delete')->setName('people-delete'); | ||
})->add(\App\Model\HTSAuth::class); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<li class="bold"><a href="{{ base_url() }}/admin/people/view" class="waves-effect waves-cyan"><i class="material-icons">code</i> {{lang.HTS_PEOPLE}} </a></li> |
Oops, something went wrong.