37 abstract protected function _createController($controllerName,$variables=[],$ctrlTemplate=
'controller.tpl',$hasView=
false,$jsCallback=
"");
41 abstract public function showSimpleMessage($content, $type, $title=null,$icon=
"info", $timeout=NULL, $staticName=null):HtmlMessage;
45 $this->
_createController($_POST[
"name"],[
"%baseClass%"=>
"ControllerBase"],
'controller.tpl',isset($_POST[
"lbl-ck-div-name"]));
52 $action=$_POST[
"action"];
53 $controller=$_POST[
"controller"];
54 $controllerFullname=$_POST[
"controllerFullname"];
55 $viewName=$controller .
"/" . $action .
".html";
57 if (\file_exists(ROOT . DS .
"views" . DS . $viewName)) {
58 $this->jquery->exec(
'$("#msgControllers").transition("show");$("#msgControllers .content").transition("show").append("<br><b>' . $viewName .
'</b> created !");',
true);
60 $r=new \ReflectionMethod($controllerFullname, $action);
61 $lines=file($r->getFileName());
62 $views=$this->
_getAdminViewer()->getActionViews($controllerFullname, $controller, $action, $r, $lines);
63 foreach ( $views as $view ) {
64 echo $view->compile($this->jquery);
67 echo $this->jquery->compile($this->view);
72 $viewName=$controller .
"/" . $action .
".html";
82 $controller=$_POST[
"controller"];
83 $modal=$this->jquery->semantic()->htmlModal(
"modalNewAction",
"Creating a new action in controller");
84 $modal->setInverted();
85 $frm=$this->jquery->semantic()->htmlForm(
"frmNewAction");
86 $dd=$frm->addDropdown(
'controller', \array_combine($controllers, $controllers),
"Controller", $controller);
87 $dd->getField()->setShowOnFocus(
false);
88 $fields=$frm->addFields([
"action",
"parameters" ],
"Action & parameters");
89 $fields->getItem(0)->addRules([
"empty",[
"checkAction",
"Action {value} already exists!" ] ]);
90 $frm->addTextarea(
"content",
"Implementation")->addRule([
"checkContent",
"Errors parsing action content!" ]);
92 $frm->addCheckbox(
"ck-view",
"Create associated view");
93 $frm->addCheckbox(
"ck-add-route",
"Add route...");
95 $frm->addContent(
"<div id='div-new-route' style='display: none;'>");
97 $fields=$frm->addFields();
98 $fields->addInput(
"path",
"",
"text",
"")->addRule([
"checkRoute",
"Route {value} already exists!" ]);
100 $duration=$fields->addInput(
"duration",
"",
"number");
101 $ck=$duration->labeledCheckbox(
"left", null);
102 $ck->getField()->setProperty(
"name",
"ck-Cache");
103 $frm->addContent(
"</div>");
105 $frm->setValidationParams([
"on" =>
"blur",
"inline" =>
true ]);
106 $frm->setSubmitParams($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_newAction",
"#messages");
107 $modal->setContent($frm);
108 $modal->addAction(
"Validate");
109 $this->jquery->click(
"#action-modalNewAction-0",
"$('#frmNewAction').form('submit');",
false,
false);
110 $modal->addAction(
"Close");
111 $this->jquery->exec(
"$('.dimmer.modals.page').html('');$('#modalNewAction').modal('show');",
true);
112 $this->jquery->jsonOn(
"change",
"#ck-add-route", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_addRouteWithNewAction",
"post", [
"context" =>
"$('#frmNewAction')",
"params" =>
"$('#frmNewAction').serialize()",
"jsCondition" =>
"$('#ck-add-route').is(':checked')" ]);
113 $this->jquery->exec(Rule::ajax($this->jquery,
"checkAction", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_methodExists",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
114 $this->jquery->exec(Rule::ajax($this->jquery,
"checkContent", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkContent",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
115 $this->jquery->exec(Rule::ajax($this->jquery,
"checkRoute", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/_checkRoute",
"{}",
"result=data.result;",
"postForm", [
"form" =>
"frmNewAction" ]),
true);
116 $this->jquery->change(
"#ck-add-route",
"$('#div-new-route').toggle($(this).is(':checked'));");
118 echo $this->jquery->compile($this->view);
125 header(
'Content-type: application/json');
126 $controller=ucfirst($_POST[$fieldname]);
128 $result[
"result"]=!class_exists($controllerNS.$controller);
129 echo json_encode($result);
136 header(
'Content-type: application/json');
137 $controller=$_POST[
"controller"];
138 $action=$_POST[
"action"];
139 if (\method_exists($controller, $action)) {
140 $result[
"result"]=
false;
142 $result[
"result"]=
true;
144 echo json_encode($result);
151 header(
'Content-type: application/json');
152 $content=$_POST[
"content"];
154 echo json_encode($result);
161 header(
'Content-type: application/json');
162 $path=$_POST[
"path"];
165 echo json_encode($result);
172 header(
'Content-type: application/json');
174 $controller=$_POST[
"controller"];
175 $action=$_POST[
"action"];
176 $parameters=$_POST[
"parameters"];
180 $urlParts=\array_diff(\array_merge([ $controller,$action ], $parameters), [
"",
"{}" ]);
181 $result[
"path"]=\implode(
'/', $urlParts);
182 echo json_encode($result);
190 $controller=$_POST[
"controller"];
191 $r=new \ReflectionClass($controller);
192 $ctrlFilename=$r->getFileName();
193 $action=$_POST[
"action"];
194 $parameters=$_POST[
"parameters"];
195 $content=$_POST[
"content"];
197 $createView=isset($_POST[
"ck-view"]);
198 $createRoute=isset($_POST[
"ck-add-route"]);
200 $fileContent=\trim($fileContent);
201 $posLast=\strrpos($fileContent,
"}");
202 if ($posLast !==
false) {
205 $content.=
"\n\t\t\$this->loadView('" . $viewname .
"');\n";
206 $msgContent.=
"<br>Created view : <b>" . $viewname .
"</b>";
211 $path=$_POST[
"path"];
212 $routeProperties=[
'"' . $path .
'"' ];
213 $methods=$_POST[
"methods"];
215 $routeProperties[]=
'"methods"=>' . $this->
getMethods($methods);
217 if (isset($_POST[
"ck-Cache"])) {
218 $routeProperties[]=
'"cache"=>true';
219 if (isset($_POST[
"duration"])) {
220 $duration=$_POST[
"duration"];
221 if (\ctype_digit($duration)) {
222 $routeProperties[]=
'"duration"=>' . $duration;
226 $routeProperties=\implode(
",", $routeProperties);
232 $actionContent=
UFileSystem::openReplaceInTemplateFile($frameworkDir .
"/admin/templates/action.tpl", [
"%route%" =>
"\n" . $routeAnnotation,
"%actionName%" => $action,
"%parameters%" => $parameters,
"%content%" => $content ]);
233 $fileContent=\substr_replace($fileContent,
"\n%content%", $posLast - 1, 0);
235 echo $this->
showSimpleMessage(
"Errors parsing action content!",
"warning",
"Creation",
"warning circle", null,
"msgControllers");
236 echo $this->jquery->compile($this->view);
240 $msgContent=
"The action <b>{$action}</b> is created in controller <b>{$controller}</b>" . $msgContent;
241 echo $this->
showSimpleMessage($msgContent,
"info",
"Creation",
"info circle", null,
"msgControllers");
246 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
247 echo $this->jquery->compile($this->view);
254 $message=\ob_get_clean();
256 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_refreshControllers/refresh",
"#dtControllers", [
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"dataType" =>
"html" ]);
257 echo $this->jquery->compile($this->view);
261 $methods=\explode(
",", $strMethods);
263 foreach ( $methods as $method ) {
264 $result[]=
'"' . $method .
'"';
266 return "[" . \implode(
",", $result) .
"]";
272 $this->jquery->postFormOn(
"click",
"#validate-btn", $this->
_getAdminFiles()->getAdminBaseRoute().
"/filterControllers",
"filtering-frm",
"#dtControllers",[
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false,
"jsCallback"=>
'$("#frm").html("");']);
273 $this->jquery->execOn(
"click",
"#cancel-btn",
'$("#frm").html("");');
274 $this->jquery->renderView($this->
_getAdminFiles()->getViewControllersFiltering());
277 protected function _createClass($template,$classname,$namespace,$uses,$extendsOrImplements,$classContent){
280 $namespaceVar=
"namespace {$namespace};";
282 $variables=[
"%classname%"=>$classname,
"%namespace%"=>$namespaceVar,
"%uses%"=>$uses,
"%extendsOrImplements%"=>$extendsOrImplements,
"%classContent%"=>$classContent];
287 if(!file_exists($filename)){
289 $message = $this->
showSimpleMessage (
"The <b>" . $classname .
"</b> class has been created in <b>" . $filename .
"</b>.",
"success",
"Creation",
"checkmark circle");
291 $message = $this->
showSimpleMessage (
"The file <b>" . $filename .
"</b> already exists.<br>Can not create the <b>" . $classname .
"</b> class!",
"warning",
"Creation",
"warning circle");
296 protected function _createMethod($access,$name,$parameters=
"",$return=
"",$content=
"",$comment=
""){
298 $keyAndValues=[
"%access%"=>$access,
"%name%"=>$name,
"%parameters%"=>$parameters,
"%content%"=>$content,
"%comment%"=>$comment,
"%return%"=>$return];
showSimpleMessage($content, $type, $title=null, $icon="info", $timeout=NULL, $staticName=null)
static isPost()
Returns true if the request is sent by the POST method.
static getClassCode($classname)
_refreshCacheControllers()
static getRouteInfo($path)
static indent($code, $count=2)
static cleanFilePathname($path)
_addMessageForRouteCreation($path)
static post($key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
static isValidCode($code)
static getNS($part="controllers")
static getDirFromNamespace($ns)
static set($key, $value)
Adds or sets a value to the Session at position $key.
static openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues)
_createViewOp($controller, $action)
_refreshControllers($refresh=false)
createController($force=null)
static openReplaceInTemplateFile($source, $keyAndValues)
static getControllers($subClass="\biquity\ontrollers\ontroller", $backslash=false, $includeSubclass=false)
_createMethod($access, $name, $parameters="", $return="", $content="", $comment="")
static cleanParameters($parameters)
static replaceWriteFromContent($content, $destination, $keyAndValues)
_createController($controllerName, $variables=[], $ctrlTemplate='controller.tpl', $hasView=false, $jsCallback="")
static getParametersForRoute($parameters)
_createClass($template, $classname, $namespace, $uses, $extendsOrImplements, $classContent)
static initCache(&$config, $type="all", $silent=false)
static getClassSimpleName($classnameWithNamespace)
_controllerExists($fieldname)