29 abstract protected function showSimpleMessage($content, $type, $icon=
"info", $timeout=NULL, $staticName=null);
33 $model=$this->
getModelsNS() .
"\\" . ucfirst($table);
35 $bt=$this->jquery->semantic()->htmlButton(
"btYuml",
"Class diagram");
36 $bt->postOnClick($this->
_getAdminFiles()->getAdminBaseRoute() .
"/_showDiagram/",
"{model:'" . \str_replace(
"\\",
"|", $model) .
"'}",
"#modal", [
"attr" =>
"" ]);
37 $this->jquery->exec(
'$("#models-tab .item").tab();',
true);
38 $this->jquery->compile($this->view);
39 $this->loadView($this->
_getAdminFiles()->getViewShowTable(), [
"classname" => $model ]);
43 $table=$_SESSION[
"table"];
45 echo $this->jquery->compile($this->view);
49 $array=\explode(
".", $tableAndId);
50 if (\is_array($array)) {
53 $this->jquery->exec(
"$('#menuDbs .active').removeClass('active');$('.ui.label.left.pointing.teal').removeClass('left pointing teal active');$(\"[data-ajax='" . $table .
"']\").addClass('active');$(\"[data-ajax='" . $table .
"']\").find('.ui.label').addClass('left pointing teal');",
true);
55 $this->jquery->exec(
"$(\"tr[data-ajax='" . $id .
"']\").click();",
true);
56 echo $this->jquery->compile();
61 $_SESSION[
"table"]=$table;
62 $model=$this->
getModelsNS() .
"\\" . ucfirst($table);
67 protected function _edit($instance, $modal=
"no") {
68 $_SESSION[
"instance"]=$instance;
69 $modal=($modal ==
"modal");
71 $this->jquery->click(
"#action-modal-frmEdit-0",
"$('#frmEdit').form('submit');",
false);
73 $this->jquery->click(
"#bt-cancel",
"$('#form-container').transition('drop');");
74 $this->jquery->compile($this->view);
75 $this->loadView($this->
_getAdminFiles()->getViewEditTable(), [
"modal" => $modal ]);
77 $this->jquery->exec(
"$('#modal-frmEdit').modal('show');",
true);
78 $form=$form->asModal(\get_class($instance));
79 $form->setActions([
"Okay",
"Cancel" ]);
80 $btOkay=$form->getAction(0);
81 $btOkay->addClass(
"green")->setValue(
"Validate modifications");
82 $form->onHidden(
"$('#modal-frmEdit').remove();");
83 echo $form->compile($this->jquery, $this->view);
84 echo $this->jquery->compile($this->view);
88 public function edit($modal=
"no", $ids=
"") {
90 $instance->_new=
false;
91 $this->
_edit($instance, $modal);
95 $model=$this->
getModelsNS() .
"\\" . ucfirst($_SESSION[
"table"]);
96 $instance=
new $model();
98 $this->
_edit($instance, $modal);
102 $message=$this->jquery->semantic()->htmlMessage(
"msgUpdate",
"Modifications were successfully saved",
"info");
103 $instance=@$_SESSION[
"instance"];
104 $className=\get_class($instance);
107 foreach ( $fieldTypes as $property => $type ) {
108 if ($type ==
"tinyint(1)") {
109 if (isset($_POST[$property])) {
117 foreach ( $relations as $member ) {
121 $fkClass=$joinColumn[
"className"];
122 $fkField=$joinColumn[
"name"];
123 if (isset($_POST[$fkField])) {
124 $fkObject=
DAO::getOne($fkClass, $_POST[
"$fkField"]);
130 if (isset($instance)) {
131 if ($instance->_new) {
142 foreach ( $relations as $member ) {
144 $newField=$member .
"Ids";
145 $fkClass=$annot[
"targetEntity"];
153 $message->setStyle(
"success")->setIcon(
"checkmark");
154 $this->jquery->get($this->
_getAdminFiles()->getAdminBaseRoute() .
"/refreshTable",
"#lv", [
"jqueryDone" =>
"replaceWith" ]);
156 $message->setContent(
"An error has occurred. Can not save changes.")->setStyle(
"error")->setIcon(
"warning circle");
159 echo $this->jquery->compile($this->view);
164 $instance=
new $model();
170 $ids=explode(
",", $ids);
171 if (
sizeof($ids) < 1)
174 $idCount=\sizeof($ids);
175 for($i=0; $i < $idCount; $i++) {
176 $strs[]=$pk .
"='" . $ids[$i] .
"'";
178 return implode(
" OR ", $strs);
182 $ids=explode(
"_", $ids);
183 if (
sizeof($ids) < 1)
185 $pks=$this->
getPks(ucfirst($table));
187 $idCount=\sizeof($ids);
188 for($i=0; $i < $idCount; $i++) {
189 $strs[]=$pks[$i] .
"='" . $ids[$i] .
"'";
191 return implode(
" AND ", $strs);
195 $table=$_SESSION[
'table'];
196 $model=$this->
getModelsNS() .
"\\" . ucfirst($table);
197 $ids=\explode(
"_", $ids);
201 public function delete($ids) {
203 if (method_exists($instance,
"__toString"))
204 $instanceString=$instance .
"";
206 $instanceString=get_class($instance);
207 if (
sizeof($_POST) > 0) {
209 $message=$this->
showSimpleMessage(
"Deletion of `<b>" . $instanceString .
"</b>`",
"info",
"info", 4000);
210 $this->jquery->exec(
"$('tr[data-ajax={$ids}]').remove();",
true);
212 $message=$this->
showSimpleMessage(
"Can not delete `" . $instanceString .
"`",
"warning",
"warning");
215 $message=$this->showConfMessage(
"Do you confirm the deletion of `<b>" . $instanceString .
"</b>`?",
"error", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/delete/{$ids}",
"#table-messages", $ids);
218 echo $this->jquery->compile($this->view);
222 $reflection=new \ReflectionClass($model);
223 $publicMethods=$reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
225 foreach ( $publicMethods as $method ) {
226 $methodName=$method->getName();
227 if (JString::startswith($methodName,
"get")) {
228 $attributeName=lcfirst(JString::replaceAtFirst($methodName,
"get",
""));
229 if (!property_exists($model, $attributeName))
230 $result[]=$methodName;
240 $table=$_SESSION[
'table'];
241 $model=$this->
getModelsNS() .
"\\" . ucfirst($table);
243 $semantic=$this->jquery->semantic();
244 $grid=$semantic->htmlGrid(
"detail");
245 if (
sizeof($relations) > 0) {
246 $wide=intval(16 /
sizeof($relations));
249 foreach ( $relations as $member ) {
252 $fkClass=$annot[
"className"];
255 $fkClass=$annot[
"targetEntity"];
258 if (isset($objectFK))
259 $fkClass=\get_class($objectFK);
261 if (isset($fkClass)) {
265 $header=
new HtmlHeader(
"", 4, $memberFK,
"content");
266 if (is_array($objectFK) || $objectFK instanceof \Traversable) {
267 $header=$viewer->getFkHeaderList($memberFK, $fkClass, $objectFK);
268 $element=$viewer->getFkList($memberFK, $fkClass, $objectFK);
269 foreach ( $objectFK as $item ) {
270 if (method_exists($item,
"__toString")) {
271 $id=($this->getIdentifierFunction($fkClass))(0, $item);
272 $item=$element->addItem($item .
"");
273 $item->setProperty(
"data-ajax", $fkTable .
"." . $id);
274 $item->addClass(
"showTable");
276 $this->
_getAdminViewer()->displayFkElementList($item, $memberFK, $fkClass, $item);
280 if (method_exists($objectFK,
"__toString")) {
281 $header=$viewer->getFkHeaderElement($memberFK, $fkClass, $objectFK);
282 $id=($this->getIdentifierFunction($fkClass))(0, $objectFK);
283 $element=$viewer->getFkElement($memberFK, $fkClass, $objectFK);
284 $element->setProperty(
"data-ajax", $fkTable .
"." . $id)->addClass(
"showTable");
287 if (isset($element)) {
288 $grid->addCol($wide)->setContent($header . $element);
295 $this->jquery->getOnClick(
".showTable", $this->
_getAdminFiles()->getAdminBaseRoute() .
"/showTableClick",
"#divTable", [
"attr" =>
"data-ajax",
"ajaxTransition" =>
"random" ]);
296 echo $this->jquery->compile($this->view);
306 foreach ( $array as $dataAjax => $caption ) {
307 $result[]=$this->
_getCk($caption, $dataAjax);
312 private function _getCk($caption, $dataAjax) {
313 $ck=
new HtmlCheckbox(
"ck-" . $dataAjax, $caption,
"1");
314 $ck->setProperty(
"name",
"ck[]");
315 $ck->setProperty(
"data-ajax", $dataAjax);
static getFieldsInRelations($class)
getOneWhere($ids, $table)
getMultiWhere($ids, $class)
static getOne($className, $keyValues, $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an instance of $className from the database, from $keyvalues values of the primary key...
showTableClick($tableAndId)
static getAnnotationInfoMember($class, $keyAnnotation, $member)
edit($modal="no", $ids="")
static setValuesToObject($object, $values=null)
Affects member to member the values of the associative array $values to the members of the object $ob...
static setMemberValue($instance, $member, $value)
static insertOrUpdateManyToMany($instance, $member)
Updates the $member member of $instance annotated by a ManyToMany.
static getFirstKey($class)
showSimpleMessage($content, $type, $icon="info", $timeout=NULL, $staticName=null)
static getManyToMany($instance, $member, $array=null, $useCache=NULL)
Assigns / loads the child records in the $member member of $instance.
static getAll($className, $condition='', $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an array of $className objects from the database.
_getCk($caption, $dataAjax)
_edit($instance, $modal="no")
static getMemberValue($instance, $member)
static getFieldTypes($className)
static getModelMetadata($className)
static getManyToManyFields($class)
static getTableName($class)
static getOneToMany($instance, $member, $useCache=NULL, $annot=null)
Assign / load the child records in the $member member of $instance.
static getManyToOneFields($class)
static getKeyFields($instance)
static remove($instance)
Deletes the object $instance from the database.
static update($instance, $updateMany=false)
Updates an existing $instance in the database.
static insert($instance, $insertMany=false)
Inserts a new instance $ instance into the database.