function endWith($a, $b) { // if(preg_match($a, $b)){ //echo 'match is:' . $a . '<br>'; // } $a = boolToStr($a); return preg_match("/{$b}\$/", $a); }
protected function render() { $prop = $this->props; $context = $this->context; $viewModel = $this->getViewModel(); $context->getAssetsService()->addInlineScript(<<<JS function check(ev,id,action) { action = action || 'check'; ev.stopPropagation(); \$.post(location.href, { _action: action, id: id }); } \$.extend(true, \$.fn.dataTable.Buttons.defaults, { dom: { button: { className: 'btn' }, } }); function dataGridMultiSearch (ev) { var table = \$(\$(ev.target).parents('table')[0]).DataTable() , value = ev.target.value , idx = ev.target.getAttribute('data-col'); table.column(idx).search(value).draw(); } JS , 'datagridInit'); $id = $prop->id; $minPagItems = self::$MIN_PAGE_ITEMS[$prop->pagingType]; $PUBLIC_URI = self::PUBLIC_URI; $language = $prop->lang != 'en-US' ? "language: { url: '{$PUBLIC_URI}/js/datatables/{$prop->lang}.json' }," : ''; $this->setupColumns($prop->column); $this->enableRowClick = $this->isPropertySet('onClick') || $this->isPropertySet('onClickGoTo'); $paging = boolToStr($prop->paging); $searching = boolToStr($prop->searching); $ordering = boolToStr($prop->ordering); $info = boolToStr($prop->info); $responsive = $prop->responsive; if ($responsive) { $responsive = "{\n details: {\n type: 'inline'\n }\n}"; } $lengthChange = boolToStr($prop->lengthChange); ob_start(); $this->runChildren('plugins'); $plugins = ob_get_clean(); $this->beginContent(); $layout = "<'row'<'col-xs-4'f><'col-xs-8'<'dataTables_buttons'B>>><'row'<'col-xs-12'tr>><'row'<'col-xs-7'li><'col-xs-5'p>>"; $buttons = ''; if ($prop->actions) { $btns = []; $prop->actions->preRun(); foreach ($prop->actions->getChildren() as $btn) { if (!$btn instanceof Button) { if ($btn instanceof CompositeComponent) { $btn->preRun(); $b = $btn->provideShadowDOM()->getFirstChild(); if ($b instanceof Button) { $b->preRun(); $btn = $b; goto addBtn; } } throw new ComponentException($this, "Invalid content for the <kbd>actions</kbd> property.\n<p>You can only use Button instances or components whose skin contains a button component as the first child", true); } addBtn: $bp = $btn->props; if ($bp->action) { $action = "selenia.doAction('{$bp->action}')"; } elseif ($bp->script) { $action = $bp->script; } elseif ($v = $btn->getComputedPropValue('url')) { $action = "location.href='{$v}'"; } else { $action = ''; } $class = enum(' ', $bp->class, $bp->icon ? 'with-icon' : ''); $bLabel = $btn->getComputedPropValue('label'); $label = $bp->icon ? "<i class=\"{$bp->icon}\"></i>{$bLabel}" : $bLabel; $btns[] = sprintf("{className:'%s',text:'%s',action:function(e,dt,node,config){%s}}", $class, $label, $action); } $buttons = 'buttons:[' . implode(',', $btns) . '],'; } $initScript = ''; if ($prop->multiSearch) { $initScript = <<<JS var tfoot = this.find('tfoot') , r = tfoot.find ('tr'); this.find('thead').append(r); JS; } $notSortable = []; foreach ($prop->column as $i => $col) { if ($col->props->notSortable) { $notSortable[] = $i + ($this->props->rowSelector ? 1 : 0); } } $columns = "columnDefs: ["; if ($notSortable) { $columns .= sprintf('{ "orderable": false, targets: [%s] }', implode(',', $notSortable)); } $columns .= "],"; if ($prop->initScript) { $initScript .= $prop->initScript->getRendering(); } // AJAX MODE if ($prop->ajax) { $url = $_SERVER['REQUEST_URI']; $action = $prop->action; $detailUrl = $prop->detailUrl; $this->enableRowClick = $prop->clickable; $context->getAssetsService()->addInlineScript(<<<JS \$('#{$id} table').dataTable({ serverSide: true, paging: {$paging}, lengthChange: {$lengthChange}, searching: {$searching}, ordering: {$ordering}, info: {$info}, autoWidth: false, responsive: {$responsive}, pageLength: {$prop->pageLength}, lengthMenu: {$prop->lengthMenu}, pagingType: '{$prop->pagingType}', dom: "{$layout}", {$columns} {$language} {$plugins} {$buttons} ajax: { url: '{$url}', type: 'POST', data: { _action: '{$action}' } }, initComplete: function() { {$initScript} \$('#{$id}').show(); } }).on ('length.dt', function (e,cfg,len) { {$prop->lengthChangeScript} }).on ('click', 'tbody tr', function () { location.href = '{$detailUrl}' + \$(this).attr('rowid'); }); JS ); } else { // IMMEDIATE MODE $context->getAssetsService()->addInlineScript(<<<JS \$('#{$id} table').dataTable({ paging: {$paging}, lengthChange: {$lengthChange}, searching: {$searching}, ordering: {$ordering}, info: {$info}, autoWidth: false, responsive: {$responsive}, pageLength: {$prop->pageLength}, lengthMenu: {$prop->lengthMenu}, pagingType: '{$prop->pagingType}', dom: "{$layout}", {$columns} {$language} {$plugins} {$buttons} initComplete: function() { {$initScript} \$('#{$id}').show(); }, drawCallback: function() { var p = \$('#{$id} .pagination'); p.css ('display', p.children().length <= {$minPagItems} ? 'none' : 'block'); } }).on ('length.dt', function (e,cfg,len) { {$prop->lengthChangeScript} }); JS ); if (isset($prop->data)) { /** @var \Iterator $dataIter */ $dataIter = iterator($prop->data); $dataIter->rewind(); $valid = $dataIter->valid(); } else { $valid = false; } if ($valid) { $this->parseIteratorExp($prop->as, $idxVar, $itVar); $columnsCfg = $prop->column; foreach ($columnsCfg as &$col) { $col->databind(); $col->applyPresetsOnSelf(); } $this->begin('table', ['class' => enum(' ', $prop->tableClass, $this->enableRowClick ? 'table-clickable' : '')]); $this->beginContent(); $this->renderHeader($columnsCfg); if (!$prop->ajax) { $idx = 0; /** @noinspection PhpUndefinedVariableInspection */ foreach ($dataIter as $i => $v) { if ($idxVar) { $viewModel->{$idxVar} = $i; } $viewModel->{$itVar} = $v; $this->renderRow($idx++, $columnsCfg); } } $this->end(); } else { $this->renderSet($this->getChildren('noData')); $this->context->getAssetsService()->addInlineScript(<<<JS \$('#{$id}').show(); JS ); } } }
function displayPermissions(User $obj) { print "Права доступа пользователя " . $obj->getName() . ":\n"; print "Чтение: " . boolToStr($obj->hasReadPermission()); print "Изменение: " . boolToStr($obj->hasModifyPermission()); print "Удаление: " . boolToStr($obj->hasDeletePermission()); }