5use Ajax\common\html\HtmlContentOnly;
6use Ajax\semantic\html\collections\HtmlMessage;
7use Ajax\semantic\widgets\datatable\Pagination;
25 abstract public function loadView(
string $viewName, $pData =
null,
bool $asString =
false);
27 abstract public function index();
40 protected function getInstances(&$totalCount, $page = 1, $id =
null) {
41 $this->activePage = $page;
42 $model = $this->model;
43 $condition = $this->
_getAdminData()->_getInstancesFilter($model);
44 $totalCount = DAO::count($model, $condition);
46 $recordsPerPage = $this->
_getModelViewer()->recordsPerPage($model, $totalCount);
47 if (is_numeric($recordsPerPage)) {
49 $rownum = DAO::getRownum($model, $id);
50 $this->activePage = Pagination::getPageOfRow($rownum, $recordsPerPage);
52 return DAO::paginate($model, $this->activePage, $recordsPerPage, $condition);
55 return DAO::getAll($model, $condition);
58 protected function search($model, $search) {
59 $fields = $this->
_getAdminData()->getSearchFieldNames($model);
60 $condition = $this->
_getAdminData()->_getInstancesFilter($model);
72 $ids = \explode(
"_", $ids);
73 if (!is_bool($included)) {
74 if (!is_array($included)) {
75 $included = [$included];
78 DAO::$useTransformers = $transform;
79 $instance = DAO::getById($this->model, $ids, $included);
80 if (isset ($instance)) {
83 $message =
new CRUDMessage (
"This object does not exist!",
"Get object",
"warning",
"warning circle");
84 $message = $this->
_getEvents()->onNotFoundMessage($message, $ids);
86 echo $this->jquery->compile($this->view);
91 $dt = $this->
_getModelViewer()->getModelDataElement($instance, $this->model,
false);
93 echo
new HtmlContentOnly ($dt->getFieldValue($member));
97 $compo = $this->
_getModelViewer()->getModelDataTable($instances, $model, $totalCount)->refresh([
"tbody"]);
98 $this->
_getEvents()->onDisplayElements($compo, $instances,
true);
99 $compo->setLibraryId(
"_compo_");
100 $this->jquery->renderView(
"@framework/main/component.html");
103 protected function _edit($instance, $modal =
"no") {
104 $_SESSION [
"instance"] = $instance;
105 $modal = ($modal ==
"modal");
109 $this->jquery->click(
"#action-modal-frmEdit-0",
"$('#frmEdit').form('submit');",
false);
111 $this->jquery->click(
"#bt-cancel",
"$('#form-container').transition('drop');");
112 $this->jquery->compile($this->view);
113 $this->
loadView($this->
_getFiles()->getViewForm(), [
"modal" => $modal,
"instance" => $instance,
"isNew" => $instance->_new,
'inverted' => $this->style]);
115 $this->jquery->exec(
"$('#modal-frmEdit').modal('show');",
true);
116 $form = $form->asModal(
$modelViewer->getFormModalTitle($instance));
117 $form->addClass($this->style);
118 [$btOkay, $btCancel] = $form->setActions([
"Okay_",
"Cancel"]);
119 $btOkay->addClass(
'green ' . $this->style);
120 $btCancel->addClass($this->style);
122 $form->onHidden(
"$('#modal-frmEdit').remove();");
123 echo $form->compile($this->jquery);
124 echo $this->jquery->compile($this->view);
129 $model = $this->model;
131 return $this->
_getModelViewer()->getModelDataTable($datas, $model, $totalCount, $this->activePage);
143 protected function _deleteMultiple($data, $action, $target, $condition, $params = []) {
144 if (URequest::isPost()) {
145 if (\is_callable($condition)) {
146 $condition = $condition ($data);
148 $rep = DAO::deleteAll($this->model, $condition, $params);
150 $message =
new CRUDMessage (
"Deleting {count} objects",
"Deletion",
"info",
"info circle", 4000);
151 $message = $this->
_getEvents()->onSuccessDeleteMultipleMessage($message, $rep);
154 if (isset ($message)) {
159 $message =
new CRUDMessage (
"Do you confirm the deletion of this objects?",
"Remove confirmation",
"error " . $this->style);
160 $this->
_getEvents()->onConfDeleteMultipleMessage($message, $data);
161 $message = $this->
showConfMessage_($message, $this->
_getBaseRoute() .
"/{$action}/{$data}", $target, $data, [
"jqueryDone" =>
"replaceWith"]);
163 echo $this->jquery->compile($this->view);
168 if ($this->
_getAdminData()->refreshPartialInstance() && !$isNew) {
169 $this->jquery->setJsonToElement(OrmUtils::objectAsJSON($instance));
171 $pk = OrmUtils::getFirstKeyValue($instance);
172 $this->jquery->get($this->
_getBaseRoute() .
"/refreshTable/" . $pk,
"#lv", [
"jqueryDone" =>
"replaceWith"]);
186 return $this->getSingleton($this->adminDatas,
'getAdminData');
195 return new
ModelViewer ($this, $this->style ?? null);
199 return $this->getSingleton($this->modelViewer,
'getModelViewer');
216 return $this->getSingleton($this->crudFiles,
'getFiles');
229 return $this->getSingleton($this->events,
'getEvents');
233 if (!isset ($value)) {
234 $value = $this->$method ();
240 $vars[
'inverted'] = $this->style;
241 $this->_getEvents()->beforeLoadView($viewName, $vars);
242 if (!URequest::isAjax()) {
243 $files = $this->_getFiles();
244 $mainTemplate = $files->getBaseTemplate();
245 if (isset ($mainTemplate)) {
246 $vars [
'_viewname'] = $viewName;
247 $vars [
'_base'] = $mainTemplate;
248 $this->jquery->renderView($files->getViewBaseTemplate(), $vars);
250 $vars [
'hasScript'] =
true;
251 $this->jquery->renderView($viewName, $vars);
254 $vars [
'hasScript'] =
true;
255 $this->jquery->renderView($viewName, $vars);
265 if (\method_exists($instance,
'__toString')) {
266 return $instance .
'';
268 return \get_class($instance);
getInstanceToString($instance)
getModelInstance($ids, $transform=true, $included=true)
_edit($instance, $modal="no")
getAdminData()
To override for defining a new adminData.
_renderDataTableForRefresh($instances, $model, $totalCount)
showConfMessage_(CRUDMessage $message, $url, $responseElement, $data, $attributes=null)
updateMemberDataElement($member, $instance)
getEvents()
To override for changing events.
getModelViewer()
To override for defining a new ModelViewer.
crudLoadView($viewName, $vars=[])
getFiles()
To override for changing view files.
_deleteMultiple($data, $action, $target, $condition, $params=[])
Helper to delete multiple objects.
showSimpleMessage_(CRUDMessage $message, $staticName=null)
getSingleton(&$value, $method)
getInstances(&$totalCount, $page=1, $id=null)
refreshInstance($instance, $isNew)
loadView(string $viewName, $pData=null, bool $asString=false)
The base class for displaying datas in CRUD controllers Ubiquity\controllers\crud$CRUDDatas This clas...
static search($model, $search, $fields, $initialCondition='1=1')
parseContent(array $keyValues)
Associated with a CRUDController class Responsible of the display.
Gateway class between database and object model.
Object/relational mapping utilities.
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.