66 * Time: 9:59 PM
77 */
88
9- class GroupController extends Controller {
10-
11- /*
12- * Construct init
13- * */
14- public function __construct ( $ arrParams ){
15- parent ::__construct ( $ arrParams );
16- $ this ->_templateObj ->setFolderTemplate ( 'admin/yivic-admin-theme/ ' );
17- $ this ->_templateObj ->setFileTemplate ( 'index-template.php ' );
18- $ this ->_templateObj ->setFileConfig ( 'template.ini ' );
19- $ this ->_templateObj ->load ();
20- }
9+ class GroupController extends AdminController {
2110
2211 /*
2312 * Display group list items
2413 * */
2514 public function indexAction (){
2615 $ this ->_view ->_title = 'User Manager: User Groups ' ;
27- $ totalItems = $ this ->_model ->countItem ( $ this ->_arrParam , null );
16+ $ totalItems = $ this ->_model ->countItems ( $ this ->_arrParam , [ ' task ' => ' admin-count-items ' ] );
2817
2918 $ configPagination = [
3019 'totalItemsPerPage ' => 4 ,
@@ -33,8 +22,7 @@ public function indexAction(){
3322
3423 $ this ->setPagination ( $ configPagination );
3524 $ this ->_view ->pagination = new Pagination ( $ totalItems , $ this ->_pagination );
36- $ this ->_arrParam ['filter_status ' ] = ( !empty ( $ _GET ['filter_status ' ] ) ) ? $ _GET ['filter_status ' ] : 'all ' ;
37- $ this ->_arrParam ['filter_search ' ] = ( !empty ( $ _GET ['search ' ] ) ) ? $ _GET ['search ' ] : '' ;
25+ $ this ->_view ->itemsStatusCount = $ this ->_model ->countItems ( $ this ->_arrParam , ['task ' => 'admin-count-items-group-by-status ' ] );
3826 $ this ->_view ->Items = $ this ->_model ->listItem ( $ this ->_arrParam , null );
3927 $ this ->_view ->countItem = $ this ->_model ->totalFilterItem ();
4028
@@ -45,97 +33,31 @@ public function indexAction(){
4533 /*
4634 * Add group
4735 * */
48- /* comment */
49- public function formAction (){
50- $ this ->_view ->_title = 'User Groups : Add ' ;
51- if ( isset ( $ this ->_arrParam ['id ' ] ) ){
52- $ this ->_view ->_title = 'User Groups : Edit ' ;
53- $ this ->_arrParam [ 'form ' ] = $ this ->_model ->infoItem ( $ this ->_arrParam );
54- if ( empty ( $ this ->_arrParam ['form ' ] ) ) URL ::redirect ( 'backend ' , 'group ' , 'index ' );
36+ public function formAction () {
37+
38+ if ( ($ this ->_arrParam ['id ' ] ?? '' ) == Session::get ( 'user ' )['info ' ]['id ' ] ) URL ::redirect ( $ this ->_arrParam ['module ' ], $ this ->_controllerName , 'index ' );
39+ $ this ->_view ->_title = ucfirst ($ this ->_controllerName ) . ' Manager :: Add ' ;
40+ if ( isset ( $ this ->_arrParam ['id ' ] ) ) {
41+ $ this ->_view ->_title = ucfirst ($ this ->_controllerName ) . ' Manager :: Edit ' ;
42+ $ this ->_arrParam ['form ' ] = $ this ->_model ->getItem ( $ this ->_arrParam );
43+ if ( empty ( $ this ->_arrParam ['form ' ] ) ) URL ::redirect ( $ this ->_arrParam ['module ' ], $ this ->_controllerName , 'index ' );
5544 }
45+ if ( isset ( $ this ->_arrParam ['form ' ]['token ' ] ) ) {
46+ $ this ->_validate ->validate ();
5647
57- if ( isset ( $ this ->_arrParam ['form ' ]['token ' ] ) > 0 ){
58- $ validate = new Validate ( $ this ->_arrParam ['form ' ] );
59- $ validate ->addRule ( 'name ' , 'string ' , [ 'min ' => 3 , 'max ' => 255 ] )
60- ->addRule ( 'ordering ' , 'int ' , [ 'min ' => 1 , 'max ' => 100 ] )
61- ->addRule ( 'status ' , 'status ' , [ 'deny ' => [ 'default ' ] ] )
62- ->addRule ( 'group_acp ' , 'status ' , [ 'deny ' => [ 'default ' ] ] );
63- $ validate ->run ();
64- $ this ->_arrParam ['form ' ] = $ validate ->getResult ();
65- if ( $ validate ->isValid () == false ){
66- $ this ->_view ->errors = $ validate ->showErrors ();
48+ $ this ->_arrParam ['form ' ] = $ this ->_validate ->getResults ();
49+ if ( !$ this ->_validate ->isValid () ) {
50+ $ this ->_view ->errors = $ this ->_validate ->showErrors ();
6751 } else {
68- $ task = ( isset ( $ this ->_arrParam ['form ' ]['id ' ] ) ) ? 'edit ' : 'add ' ;
69- $ id = $ this ->_model ->saveItem ( $ this ->_arrParam , [ 'task ' => $ task ] );
70- if ( $ this ->_arrParam ['type ' ] == 'save-close ' ) URL ::redirect ( ' backend ' , ' group ' , 'index ' );
71- if ( $ this ->_arrParam ['type ' ] == 'save-new ' ) URL ::redirect ( ' backend ' , ' group ' , 'form ' );
72- if ( $ this ->_arrParam ['type ' ] == 'save ' ) URL ::redirect ( ' backend ' , ' group ' , 'form ' , [ 'id ' => $ id ] );
52+ $ task = isset ( $ this ->_arrParam ['form ' ]['id ' ] ) ? 'edit ' : 'add ' ;
53+ $ id = $ this ->_model ->saveItem ( $ this ->_arrParam , ['task ' => $ task ] );
54+ if ( $ this ->_arrParam ['type ' ] == 'save-close ' ) URL ::redirect ( $ this -> _arrParam [ ' module ' ], $ this -> _controllerName , 'index ' );
55+ if ( $ this ->_arrParam ['type ' ] == 'save-new ' ) URL ::redirect ( $ this -> _arrParam [ ' module ' ], $ this -> _controllerName , 'form ' );
56+ if ( $ this ->_arrParam ['type ' ] == 'save ' ) URL ::redirect ( $ this -> _arrParam [ ' module ' ], $ this -> _controllerName , 'form ' , ['id ' => $ id ] );
7357 }
7458 }
75-
76- $ this ->_view ->arrParam = $ this ->_arrParam ;
77- $ this ->_view ->render ( 'group/form ' );
78- }
79-
80- /*
81- * Action: Ajax status (*)
82- * */
83- public function ajaxStatusAction (){
84- $ result = $ this ->_model ->changeStatus ( $ this ->_arrParam , [ 'task ' => 'change-ajax-status ' ] );
85- echo json_encode ( $ result );
86- }
87-
88- /*
89- * Action: Ajax Group ACP (*)
90- * */
91- public function ajaxACPAction (){
92- $ result = $ this ->_model ->changeStatus ( $ this ->_arrParam , [ 'task ' => 'change-ajax-group-acp ' ] );
93- echo json_encode ( $ result );
94- }
95-
96- /*
97- * Action: Status (*)
98- * */
99- public function statusAction (){
100- $ result = $ this ->_model ->changeStatus ( $ this ->_arrParam , [ 'task ' => 'change-status ' ] );
101- URL ::redirect ( 'backend ' , 'group ' , 'index ' );
102- }
103-
104- /*
105- * Action: Trash (*)
106- * */
107- /* comment */
108- public function trashAction (){
109- $ this ->_arrParam ['id ' ] = $ _GET ['id ' ];
110- $ result = $ this ->_model ->deleteItem ( $ this ->_arrParam );
111- URL ::redirect ( 'backend ' , 'group ' , 'index ' );
112- }
113-
114- /*
115- * ACTION: Ordering (*)
116- * */
117- public function orderingAction (){
118- $ this ->_model ->ordering ( $ this ->_arrParam );
119- URL ::redirect ( 'backend ' , 'group ' , 'index ' );
120- }
121-
122-
123- /*
124- * ACTION: Change Ajax (*)
125- * */
126- public function changeAjaxAction (){
127- $ this ->_arrParam ['value ' ] = $ _GET ['valueOrdering ' ];
128- $ this ->_arrParam ['id ' ] = $ _GET ['id ' ];
129- $ result = $ this ->_model ->changeStatus ( $ this ->_arrParam , [ 'task ' => 'changeOrderingField ' ] );
130- echo json_encode ($ result );
131- }
132-
133- /*
134- * ACTION: Bulk (*)
135- * */
136- public function bulkAction (){
137- $ result = $ this ->_model ->changeBulk ( $ this ->_arrParam , null );
138- URL ::redirect ( 'backend ' , 'group ' , 'index ' );
59+ $ this ->_view ->params = $ this ->_arrParam ;
60+ $ this ->_view ->render ("{$ this ->_controllerName }/form " );
13961 }
14062
14163}
0 commit comments