_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q23000
Loader.set
train
public function set($fx = [], $args = null) { if (!is_callable($fx)) { throw new Exception('Error: Need to pass a callable function to Loader::set()'); } $this->cb->set(function () use ($fx) {
php
{ "resource": "" }
q23001
Loader.renderView
train
public function renderView() { if (!$this->cb->triggered()) { if ($this->loadEvent) { $this->js($this->loadEvent, $this->jsLoad()); }
php
{ "resource": "" }
q23002
Accordion.addSection
train
public function addSection($title, $callback = null, $icon = 'dropdown') { $section = $this->add(['AccordionSection', 'title' => $title, 'icon' => $icon]); // if there is callback action, then use VirtualPage if ($callback) { $section->virtualPage = $section->add(['VirtualPage',...
php
{ "resource": "" }
q23003
Accordion.getSectionIdx
train
public function getSectionIdx($section) { $idx = -1; foreach ($this->sections as $key => $accordion_section) {
php
{ "resource": "" }
q23004
Menu.addMenu
train
public function addMenu($name) { if (is_array($name)) { $label = $name[0]; unset($name[0]); } else { $label = $name; $name = []; } $sub_menu = $this->add([new self(), 'defaultTemplate' => 'submenu.html', 'ui' => 'dropdown', 'in_dropdow...
php
{ "resource": "" }
q23005
Menu.addGroup
train
public function addGroup($title) { $group = $this->add([new self(), 'defaultTemplate' => 'menugroup.html', 'ui' => false]); if (is_string($title)) { $group->set('title', $title); } else { if (isset($title['icon']) && $title['icon']) {
php
{ "resource": "" }
q23006
Menu.addMenuRight
train
public function addMenuRight() { $menu = $this->add([new self(), 'ui' => false], 'RightMenu');
php
{ "resource": "" }
q23007
Menu.add
train
public function add($object, $region = null) { $item = parent::add($object, $region);
php
{ "resource": "" }
q23008
CRUD.setModel
train
public function setModel(\atk4\data\Model $m, $defaultFields = null) { if ($defaultFields !== null) { $this->fieldsDefault = $defaultFields; } parent::setModel($m, $this->fieldsRead ?: $this->fieldsDefault); $this->model->unload(); if ($this->canCreate) { ...
php
{ "resource": "" }
q23009
CRUD.initCreate
train
public function initCreate() { // setting itemCreate manually is possible. if (!$this->itemCreate) { $this->itemCreate = $this->menu->addItem($this->itemCreate ?: ['Add new', 'icon' => 'plus']); $this->itemCreate->on('click.atk_CRUD', new jsModal('Add new', $this->pageCreate,...
php
{ "resource": "" }
q23010
CRUD.initUpdate
train
public function initUpdate() { $this->addAction(['icon' => 'edit'], new jsModal('Edit', $this->pageUpdate, [$this->name => $this->jsRow()->data('id'), $this->name.'_sort' => $this->getSortBy()])); $this->pageUpdate->set(function () { $this->model->load($this->app->stickyGet($this->name)...
php
{ "resource": "" }
q23011
CRUD.jsSave
train
public function jsSave($notifier) { return [ // close modal new jsExpression('$(".atk-dialog-content").trigger("close")'), // display notification $this->factory($notifier),
php
{ "resource": "" }
q23012
CRUD.initDelete
train
public function initDelete() { $this->addAction(['icon' => 'red trash'], function ($jschain, $id) { $this->model->load($id)->delete();
php
{ "resource": "" }
q23013
Upload.set
train
public function set($fileId = null, $fileName = null, $junk = null) { $this->setFileId($fileId); if (!$fileName) {
php
{ "resource": "" }
q23014
Upload.addJSAction
train
public function addJSAction($action) { if (is_array($action)) { $this->jsActions = array_merge($action, $this->jsActions);
php
{ "resource": "" }
q23015
Upload.onDelete
train
public function onDelete($fx = null) { if (is_callable($fx)) { $this->hasDeleteCb = true; if ($this->cb->triggered() && @$_POST['action'] === 'delete') { $fileName = @$_POST['f_name']; $this->cb->set(function () use
php
{ "resource": "" }
q23016
Upload.onUpload
train
public function onUpload($fx = null) { if (is_callable($fx)) { $this->hasUploadCb = true; if ($this->cb->triggered()) { $action = @$_POST['action']; if ($files = @$_FILES) { //set fileId to file name as default. ...
php
{ "resource": "" }
q23017
Upload.renderView
train
public function renderView() { //need before parent rendering. if ($this->disabled) { $this->addClass('disabled'); } parent::renderView(); if (!$this->hasUploadCb || !$this->hasDeleteCb) { throw new Exception('onUpload and onDelete callback must be ca...
php
{ "resource": "" }
q23018
Lookup.addFilter
train
public function addFilter($field, $label = null) { if (!$this->model->hasElement($field) instanceof \atk4\data\Field) { throw new \atk4\ui\Exception([ 'Unable to filter by non-existant field',
php
{ "resource": "" }
q23019
Lookup.applyFilters
train
public function applyFilters() { if ($this->filters) { foreach ($this->filters as $k => $filter) { if ( isset($_GET[$filter['field']]) && !empty($_GET[$filter['field']]) && $_GET[$filter['field']] != $this->filterEmpty &...
php
{ "resource": "" }
q23020
Lookup.renderFilters
train
public function renderFilters() { if (isset($_GET['filter'])) { if (isset($_GET['q'])) { $this->model->addCondition($_GET['filter'], 'like', '%'.$_GET['q'].'%'); } // Apply filtering to filter. $this->applyFilters(); $action = $this...
php
{ "resource": "" }
q23021
Lookup.createFilterJsDropdown
train
public function createFilterJsDropdown() { foreach ($this->filters as $k => $filter) { $f_name = $this->name.'-ac_f'.$k; $chain = new jQuery('#'.$f_name); $options = [ 'fields' => ['name' => 'name', 'value' => 'id'], 'match' =>...
php
{ "resource": "" }
q23022
Lookup.getFilterQuery
train
public function getFilterQuery() { $q = []; foreach ($this->filters as $key => $filter) { $q[$filter['field']] = new jsExpression('$([input]).parent().dropdown("get
php
{ "resource": "" }
q23023
Generic.addGroup
train
public function addGroup($label = null) { if (!is_array($label)) { $label = ['label' => $label]; } elseif (isset($label[0])) {
php
{ "resource": "" }
q23024
Generic.addSubLayout
train
public function addSubLayout($seed = 'Generic', $addDivider = true) { $v = $this->add($this->factory($seed, ['form' => $this->form], 'FormLayout/Section'));
php
{ "resource": "" }
q23025
Generic.set
train
public function set($value = null, $junk = null) { if ($this->field) { $this->field->set($value);
php
{ "resource": "" }
q23026
Generic.renderView
train
public function renderView() { if ($this->form) {
php
{ "resource": "" }
q23027
Callback.getURL
train
public function getURL($mode = 'callback') { return $this->owner->url([$this->urlTrigger => $mode,
php
{ "resource": "" }
q23028
Wizard.addStep
train
public function addStep($name, $callback) { $step = $this->factory([ 'Step', 'wizard' => $this, 'template'=> clone $this->stepTemplate, 'sequence'=> count($this->steps), ], $name); // add tabs menu item $this->steps[] = $this->add($st...
php
{ "resource": "" }
q23029
Wizard.addFinish
train
public function addFinish($callback) { if (count($this->steps) == $this->currentStep + 1) { $this->buttonFinish->link($this->stepCallback->getURL(count($this->steps))); } elseif ($this->currentStep == count($this->steps)) { $this->buttonPrev->destroy(); $this->but...
php
{ "resource": "" }
q23030
jsExpression.jsRender
train
public function jsRender() { $namelessCount = 0; $res = preg_replace_callback( '/\[[a-z0-9_]*\]|{[a-z0-9_]*}/', function ($matches) use (&$namelessCount) { $identifier = substr($matches[0], 1, -1); // Allow template to contain [] ...
php
{ "resource": "" }
q23031
Generic.addPopup
train
public function addPopup($popup = null, $icon = 'caret square down') { if (!$this->app) { throw new Exception('Columns\'s popup need to have a layout.'); }
php
{ "resource": "" }
q23032
Generic.setHeaderPopup
train
public function setHeaderPopup($popup, $icon = 'caret square down') { $this->hasHeaderAction = true; $id = $this->name.'_ac'; $this->headerActionTag = ['div', ['class'=>'atk-table-dropdown'], [ ['i', ['id' => $id, 'class' => $icon.' icon']], ], ...
php
{ "resource": "" }
q23033
Generic.addDropdown
train
public function addDropdown($items, $fx, $icon = 'caret square down', $menuId = null) { $menuITems = []; foreach ($items as $key => $item) { if (is_int($key)) { $menuITems[] = ['name' => $item, 'value' => $item]; } else { $menuITems[] = ['name'...
php
{ "resource": "" }
q23034
Generic.setAttr
train
public function setAttr($attr, $value, $position = 'body') {
php
{ "resource": "" }
q23035
Generic.getTag
train
public function getTag($position, $value, $attr = []) { $attr = $this->getTagAttributes($position, $attr); if (isset($attr['class'])) { $attr['class'] =
php
{ "resource": "" }
q23036
Generic.getTotalsCellHTML
train
public function getTotalsCellHTML(\atk4\data\Field $f, $value) { return
php
{ "resource": "" }
q23037
Input.getValue
train
public function getValue() { return isset($this->field) ? $this->app->ui_persistence->typecastSaveField($this->field,
php
{ "resource": "" }
q23038
Input.addAction
train
public function addAction($defaults = []) { if (!is_array($defaults)) { $defaults = [$defaults]; }
php
{ "resource": "" }
q23039
InlineEdit.setModel
train
public function setModel(\atk4\data\Model $model) { parent::setModel($model); $this->field = $this->field ? $this->field : $this->model->title_field; if ($this->autoSave && $this->model->loaded()) { if ($this->cb->triggered()) { $value = $_POST['value'] ? $_POST['...
php
{ "resource": "" }
q23040
InlineEdit.renderView
train
public function renderView() { parent::renderView(); $type = ($this->model && $this->field) ? $this->model->elements[$this->field]->type : 'text'; $type = ($type === 'string') ? 'text' : $type; if ($type != 'text' && $type != 'number') { throw new Exception('Error: Only...
php
{ "resource": "" }
q23041
ItemSearch.setModelCondition
train
public function setModelCondition($m) { $q = $this->getQuery(); if ($q && ($_GET['__atk_reload'] ? $_GET['__atk_reload'] : null) === $this->reload->name) {
php
{ "resource": "" }
q23042
VirtualPage.set
train
public function set($fx = [], $junk = null) { if (!$fx) { return $this; } if ($this->fx) { throw new Exception([ 'Callback for this Virtual Page is already defined',
php
{ "resource": "" }
q23043
VirtualPage.getHTML
train
public function getHTML() { $this->cb->set(function () { // if virtual page callback is triggered if ($type = $this->cb->triggered()) { // process callback if ($this->fx) { call_user_func($this->fx, $this); } ...
php
{ "resource": "" }
q23044
Grid.setIpp
train
public function setIpp($ipp, $label = 'Item per pages:') { if (is_array($ipp)) { $this->addItemsPerPageSelector($ipp, $label); if (@$_GET['ipp']) { $this->ipp = $_GET['ipp'];
php
{ "resource": "" }
q23045
Grid.addItemsPerPageSelector
train
public function addItemsPerPageSelector($items = [10, 25, 50, 100], $label = 'Item per pages:') { if ($ipp = $this->container->stickyGet('ipp')) { $this->ipp = $ipp; } else { $this->ipp = $items[0]; } $pageLength = $this->paginator->add(['ItemsPerPageSelector...
php
{ "resource": "" }
q23046
Grid.addJsPaginator
train
public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = 'Body') { if ($this->paginator) { $this->paginator->destroy(); //prevent action(count) to be output twice. $this->paginator = null; }
php
{ "resource": "" }
q23047
Grid.addJsPaginatorInContainer
train
public function addJsPaginatorInContainer($ipp, $containerHeight, $options = [], $container = null, $scrollRegion = 'Body') { $this->table->hasCollapsingCssActionColumn = false; $options = array_merge($options, [ 'hasFixTableHeader' => true, 'tableContainerHeight' => $containe...
php
{ "resource": "" }
q23048
Grid.addAction
train
public function addAction($button, $action, $confirm = false) { if (!$this->actions) { $this->actions = $this->table->addColumn(null, $this->actionDecorator);
php
{ "resource": "" }
q23049
Grid.addFilterColumn
train
public function addFilterColumn($names = null) { $this->menu->addItem(['Clear Filters'], new \atk4\ui\jsReload($this->table->reload, ['atk_clear_filter' =>
php
{ "resource": "" }
q23050
Grid.addDropdown
train
public function addDropdown($columnName, $items, $fx, $icon = 'caret square down', $menuId = null) { $column = $this->table->columns[$columnName]; if (!isset($column)) { throw new Exception('The column where you want to add dropdown does not exist: '.$columnName); } if (!...
php
{ "resource": "" }
q23051
Grid.addPopup
train
public function addPopup($columnName, $popup = null, $icon = 'caret square down') { $column = $this->table->columns[$columnName];
php
{ "resource": "" }
q23052
Grid.setModel
train
public function setModel(\atk4\data\Model $model, $columns = null) { $this->model = $this->table->setModel($model, $columns); if ($this->quickSearch && is_array($this->quickSearch)) {
php
{ "resource": "" }
q23053
Grid.addSelection
train
public function addSelection() { $this->selection = $this->table->addColumn(null, 'CheckBox'); // Move element to the beginning $k = array_search($this->selection, $this->table->columns);
php
{ "resource": "" }
q23054
Grid.addDragHandler
train
public function addDragHandler() { $handler = $this->table->addColumn(null, 'DragHandler'); // Move last column to the beginning in table column array.
php
{ "resource": "" }
q23055
Grid.setModelLimitFromPaginator
train
private function setModelLimitFromPaginator() { $this->paginator->setTotal(ceil($this->model->action('count')->getOne() / $this->ipp));
php
{ "resource": "" }
q23056
Grid.recursiveRender
train
public function recursiveRender() { // bind with paginator if ($this->paginator) { $this->setModelLimitFromPaginator(); } if ($this->quickSearch instanceof jsSearch) { if ($sortBy = $this->getSortBy()) {
php
{ "resource": "" }
q23057
ItemsPerPageSelector.onPageLengthSelect
train
public function onPageLengthSelect($fx = null) { if (is_callable($fx)) { if ($this->cb->triggered()) { $this->cb->set(function () use ($fx) { $ipp = @$_GET['ipp']; //$this->pageLength->set(preg_replace("/\[ipp\]/", $ipp, $this->label)); ...
php
{ "resource": "" }
q23058
App.isJsonRequest
train
protected function isJsonRequest() { $ajax = false; if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
php
{ "resource": "" }
q23059
App.terminate
train
public function terminate($output = null) { if ($output !== null) { echo $output; }
php
{ "resource": "" }
q23060
App.initLayout
train
public function initLayout($seed) { $layout = $this->factory($seed, null, 'Layout'); $layout->app = $this; if (!$this->html) { $this->html = new
php
{ "resource": "" }
q23061
App.initIncludes
train
public function initIncludes() { // jQuery $url = isset($this->cdn['jquery']) ? $this->cdn['jquery'] : '../public'; $this->requireJS($url.'/jquery.min.js'); // Semantic UI $url = isset($this->cdn['semantic-ui']) ? $this->cdn['semantic-ui'] : '../public'; $this->requi...
php
{ "resource": "" }
q23062
App.add
train
public function add($seed, $region = null) { if (!$this->layout) { throw new
php
{ "resource": "" }
q23063
App.run
train
public function run() { $this->run_called = true; $this->hook('beforeRender'); $this->is_rendering = true; // if no App layout set if (!isset($this->html)) { throw new Exception(['App layout should be set.']); } $this->html->template->set('title'...
php
{ "resource": "" }
q23064
App.loadTemplate
train
public function loadTemplate($name) { $template = new Template(); $template->app = $this; if (in_array($name[0], ['.', '/', '\\']) || strpos($name, ':\\') !== false) { return $template->load($name); } else { $dir = is_array($this->template_dir) ? $this->templ...
php
{ "resource": "" }
q23065
App.jsURL
train
public function jsURL($page = [], $needRequestUri = false, $extra_args =
php
{ "resource": "" }
q23066
App.url
train
public function url($page = [], $needRequestUri = false, $extra_args = []) { if ($needRequestUri) { return $_SERVER['REQUEST_URI']; } $sticky = $this->sticky_get_arguments; $result = $extra_args; if ($this->page === null) { $uri = $this->getRequestUR...
php
{ "resource": "" }
q23067
App.stickyGet
train
public function stickyGet($name) { if (isset($_GET[$name])) {
php
{ "resource": "" }
q23068
App.requireJS
train
public function requireJS($url, $isAsync = false, $isDefer = false) { $this->html->template->appendHTML('HEAD', $this->getTag('script', ['src' => $url,
php
{ "resource": "" }
q23069
App.requireCSS
train
public function requireCSS($url) { $this->html->template->appendHTML('HEAD', $this->getTag('link/', ['rel' => 'stylesheet',
php
{ "resource": "" }
q23070
App.redirect
train
public function redirect($page) { header('Location: '.$this->url($page));
php
{ "resource": "" }
q23071
App.useSuiVue
train
public function useSuiVue() { if (!$this->is_sui_init) { $this->requireJS('https://unpkg.com/semantic-ui-vue/dist/umd/semantic-ui-vue.min.js');
php
{ "resource": "" }
q23072
CallbackLater.set
train
public function set($callback, $args = []) { if (!$this->app) { throw new Exception(['Call-back must be part of a RenderTree']); } if ($this->app->is_rendering) { return parent::set($callback, $args); } $this->app->addHook('beforeRender', function (....
php
{ "resource": "" }
q23073
Tab.setPath
train
public function setPath($path) { if (!is_string($path)) { $path = $this->app->url($path);
php
{ "resource": "" }
q23074
Tab.renderView
train
public function renderView() { if ($this->path) { $this->js(true)->tab( ['cache' => false, 'auto' => true, 'path' => $this->path, 'apiSettings' => ['data' => ['__atk_tab' => 1]]] ); } else {
php
{ "resource": "" }
q23075
View.setSource
train
public function setSource(array $data, $fields = null) { $this->setModel(new
php
{ "resource": "" }
q23076
View.init
train
public function init() { // set name and id of view if (!$this->name) { if (!$this->id) { $this->id = $this->name = 'atk'; } else { $this->name = $this->id; } } elseif (!$this->id) { $this->id = $this->name; ...
php
{ "resource": "" }
q23077
View.initDefaultApp
train
protected function initDefaultApp() { $this->app = new App([ 'skin' => $this->skin, 'catch_exceptions' => false, 'always_run'
php
{ "resource": "" }
q23078
View.add
train
public function add($seed, $region = null) { if ($this->_rendered) { throw new Exception('You cannot add anything into the view after it was rendered'); } if (!$this->app) { $this->_add_later[] = [$seed, $region]; return $seed; } if (is_a...
php
{ "resource": "" }
q23079
View.getClosestOwner
train
public function getClosestOwner($object, $class) { if (!isset($object->owner)) { return;
php
{ "resource": "" }
q23080
View.set
train
public function set($arg1 = null, $arg2 = null) { if (is_string($arg1) && $arg2 !== null) { // must be initialized $this->template->set($arg1, $arg2); return $this; } if ($arg2 !== null) { throw new Exception([ 'Second argume...
php
{ "resource": "" }
q23081
View.removeAttr
train
public function removeAttr($property) { if (is_array($property)) { foreach ($property as $v) { unset($this->attr[$v]); }
php
{ "resource": "" }
q23082
View.recursiveRender
train
public function recursiveRender() { foreach ($this->elements as $view) { if (!$view instanceof self) { continue; } $this->template->appendHTML($view->region, $view->getHTML()); if ($view->_js_actions) { $this->_js_actions = ar...
php
{ "resource": "" }
q23083
View.renderAll
train
public function renderAll() { if (!$this->_initialized) { $this->init(); } if (!$this->_rendered) { $this->renderView();
php
{ "resource": "" }
q23084
View.render
train
public function render($force_echo = true) { $this->renderAll(); return
php
{ "resource": "" }
q23085
View.renderJSON
train
public function renderJSON($force_echo = true, $region = null) { try { $this->renderAll(); return json_encode(['success' => true, 'message' => 'Success', 'atkjs' => $this->getJS($force_echo), ...
php
{ "resource": "" }
q23086
View.vue
train
public function vue($component, $initData = [], $componentDefinition = null, $selector = null) { if (!$selector) { $selector = '#'.$this->name; } if ($componentDefinition) { $chain = (new jsVueService())->createVue($selector, $component, $componentDefinition, $initDa...
php
{ "resource": "" }
q23087
View.jsVueEmit
train
public function jsVueEmit($eventName, $eventData = []) { // adding this view id to data. // Usually, you would check if the event
php
{ "resource": "" }
q23088
View.getJS
train
public function getJS($force_echo = false) { $actions = []; foreach ($this->_js_actions as $eventActions) { foreach ($eventActions as $action) { $actions[] = $action; } } if (!$actions) { return ''; } $actions['in...
php
{ "resource": "" }
q23089
Form.initLayout
train
protected function initLayout() { if ($this->layout === null) { $this->layout = 'Generic'; } if (is_string($this->layout) || is_array($this->layout)) { $this->layout = $this->factory($this->layout, ['form'=>$this], 'FormLayout'); $this->layout = $this->ad...
php
{ "resource": "" }
q23090
Form.setGroupDisplayRules
train
public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group') { if (is_object($selector) && isset($selector->name)) {
php
{ "resource": "" }
q23091
Form.setModel
train
public function setModel(\atk4\data\Model $model, $fields = null) { // Model is set for the form and also for the current layout try { $model = parent::setModel($model); $this->layout->setModel($model, $fields);
php
{ "resource": "" }
q23092
Form.error
train
public function error($fieldName, $str) { // by using this hook you can overwrite default behavior of this method if ($this->hookHasCallbacks('displayError')) { return $this->hook('displayError', [$fieldName, $str]);
php
{ "resource": "" }
q23093
Form.success
train
public function success($str = 'Success', $sub_header = null) { // by using this hook you can overwrite default behavior of this method if ($this->hookHasCallbacks('displaySuccess')) { return $this->hook('displaySuccess', [$str, $sub_header]); } /* below code works, but ...
php
{ "resource": "" }
q23094
Form.addField
train
public function addField($name, $decorator = null, $field = null) { if (!$this->model) { $this->model = new \atk4\ui\misc\ProxyModel();
php
{ "resource": "" }
q23095
Form.addFields
train
public function addFields($fields) { foreach ($fields as $field) { if (is_array($field)) { $this->addField(...$field); } else {
php
{ "resource": "" }
q23096
Form.loadPOST
train
public function loadPOST() { $post = $_POST; $this->hook('loadPOST', [&$post]); $errors = []; foreach ($this->fields as $key => $field) { try { $value = isset($post[$key]) ? $post[$key] : null; // save field value only if field was edita...
php
{ "resource": "" }
q23097
Form.ajaxSubmit
train
public function ajaxSubmit() { $this->_add($cb = new jsCallback(), ['desired_name' => 'submit', 'postTrigger' => true]); $this->add(new View(['element' => 'input'])) ->setAttr('name', $cb->postTrigger) ->setAttr('value', 'submit') ->setStyle(['display' => 'none']...
php
{ "resource": "" }
q23098
Text.addParagraph
train
public function addParagraph($text) { $this->content .= isset($this->app) ? $this->app->getTag('p', $text)
php
{ "resource": "" }
q23099
Image.getDataCellTemplate
train
public function getDataCellTemplate(\atk4\data\Field $f = null) { $caption = $f ? $f->getCaption() : $this->short_name;
php
{ "resource": "" }