repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Gernott/mask
Classes/Controller/WizardContentController.php
WizardContentController.activateAction
public function activateAction($key) { $this->storageRepository->activate("tt_content", $key); $this->generateAction(); $this->addFlashMessage(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_mask.content.activatedcontentelement', 'mask')); $this->redirect('list'); }
php
public function activateAction($key) { $this->storageRepository->activate("tt_content", $key); $this->generateAction(); $this->addFlashMessage(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_mask.content.activatedcontentelement', 'mask')); $this->redirect('list'); }
[ "public", "function", "activateAction", "(", "$", "key", ")", "{", "$", "this", "->", "storageRepository", "->", "activate", "(", "\"tt_content\"", ",", "$", "key", ")", ";", "$", "this", "->", "generateAction", "(", ")", ";", "$", "this", "->", "addFlas...
action activate @param string $key @return void
[ "action", "activate" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardContentController.php#L187-L194
Gernott/mask
Classes/Controller/WizardContentController.php
WizardContentController.deleteHtml
protected function deleteHtml($key): void { $paths = []; $paths[] = MaskUtility::getTemplatePath($this->extSettings, $key); $paths[] = MaskUtility::getTemplatePath($this->extSettings, $key, false, $this->extSettings['backend']); foreach ($paths as $path) { if (file_exists($path)) { unlink($path); } } }
php
protected function deleteHtml($key): void { $paths = []; $paths[] = MaskUtility::getTemplatePath($this->extSettings, $key); $paths[] = MaskUtility::getTemplatePath($this->extSettings, $key, false, $this->extSettings['backend']); foreach ($paths as $path) { if (file_exists($path)) { unlink($path); } } }
[ "protected", "function", "deleteHtml", "(", "$", "key", ")", ":", "void", "{", "$", "paths", "=", "[", "]", ";", "$", "paths", "[", "]", "=", "MaskUtility", "::", "getTemplatePath", "(", "$", "this", "->", "extSettings", ",", "$", "key", ")", ";", ...
Deletes Fluid html, if file exists @param string $key @author Benjamin Butschell <bb@webprofil.at>
[ "Deletes", "Fluid", "html", "if", "file", "exists" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardContentController.php#L202-L212
Gernott/mask
Classes/Controller/WizardContentController.php
WizardContentController.createHtmlAction
protected function createHtmlAction($key) { $html = $this->htmlCodeGenerator->generateHtml($key, 'tt_content'); $this->saveHtml($key, $html); $this->redirect('list'); }
php
protected function createHtmlAction($key) { $html = $this->htmlCodeGenerator->generateHtml($key, 'tt_content'); $this->saveHtml($key, $html); $this->redirect('list'); }
[ "protected", "function", "createHtmlAction", "(", "$", "key", ")", "{", "$", "html", "=", "$", "this", "->", "htmlCodeGenerator", "->", "generateHtml", "(", "$", "key", ",", "'tt_content'", ")", ";", "$", "this", "->", "saveHtml", "(", "$", "key", ",", ...
Create single Fluid html @param string $key @author Gernot Ploiner <gp@webprofil.at>
[ "Create", "single", "Fluid", "html" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardContentController.php#L220-L225
Gernott/mask
Classes/ViewHelpers/JsOpenParamsViewHelper.php
JsOpenParamsViewHelper.render
public function render() { $fieldKey = $this->arguments['fieldKey']; $elementKey = $this->arguments['elementKey']; $property = $this->arguments['property']; $field = $this->arguments['field']; $this->generalUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Utility\\GeneralUtility'); $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); if ($field) { if ($field["inlineParent"]) { $type = $field["inlineParent"]; $fieldKey = "tx_mask_" . $field["key"]; } else { $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, true); } } else { $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey); } return $this->generalUtility->getJsOpenParamValue($fieldKey, $property, $type); }
php
public function render() { $fieldKey = $this->arguments['fieldKey']; $elementKey = $this->arguments['elementKey']; $property = $this->arguments['property']; $field = $this->arguments['field']; $this->generalUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Utility\\GeneralUtility'); $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); if ($field) { if ($field["inlineParent"]) { $type = $field["inlineParent"]; $fieldKey = "tx_mask_" . $field["key"]; } else { $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, true); } } else { $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey); } return $this->generalUtility->getJsOpenParamValue($fieldKey, $property, $type); }
[ "public", "function", "render", "(", ")", "{", "$", "fieldKey", "=", "$", "this", "->", "arguments", "[", "'fieldKey'", "]", ";", "$", "elementKey", "=", "$", "this", "->", "arguments", "[", "'elementKey'", "]", ";", "$", "property", "=", "$", "this", ...
Returns value from jsopenParams @return boolean $evalValue is set @author Benjamin Butschell bb@webprofil.at>
[ "Returns", "value", "from", "jsopenParams" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/JsOpenParamsViewHelper.php#L49-L70
Gernott/mask
Classes/ViewHelpers/LinkoptionViewHelper.php
LinkoptionViewHelper.render
public function render() { $fieldKey = $this->arguments['fieldKey']; $elementKey = $this->arguments['elementKey']; $evalValue = $this->arguments['evalValue']; $this->generalUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Utility\\GeneralUtility'); $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey); return $this->generalUtility->isBlindLinkOptionSet($fieldKey, $evalValue, $type); }
php
public function render() { $fieldKey = $this->arguments['fieldKey']; $elementKey = $this->arguments['elementKey']; $evalValue = $this->arguments['evalValue']; $this->generalUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Utility\\GeneralUtility'); $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey); return $this->generalUtility->isBlindLinkOptionSet($fieldKey, $evalValue, $type); }
[ "public", "function", "render", "(", ")", "{", "$", "fieldKey", "=", "$", "this", "->", "arguments", "[", "'fieldKey'", "]", ";", "$", "elementKey", "=", "$", "this", "->", "arguments", "[", "'elementKey'", "]", ";", "$", "evalValue", "=", "$", "this",...
Checks if a $evalValue is set in a field @param string $fieldKey TCA Type @param string $elementKey key of the element @param string $evalValue value to search for @return boolean $evalValue is set @author Benjamin Butschell bb@webprofil.at>
[ "Checks", "if", "a", "$evalValue", "is", "set", "in", "a", "field" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/LinkoptionViewHelper.php#L51-L62
Gernott/mask
Classes/Helper/InlineHelper.php
InlineHelper.addFilesToData
public function addFilesToData(&$data, $table = "tt_content") { if ($data["_LOCALIZED_UID"]) { $uid = $data["_LOCALIZED_UID"]; } else { $uid = $data["uid"]; } // using is_numeric in favor to is_int // due to some rare cases where uids are provided as strings if (!is_numeric($uid)) { return; } $fieldHelper = GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); if (!$this->objectManager) { $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); } $storage = $this->storageRepository->load(); /* @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */ $fileRepository = $this->objectManager->get("TYPO3\CMS\Core\Resource\FileRepository"); $contentFields = array("media", "image", "assets"); if ($storage[$table]["tca"]) { foreach ($storage[$table]["tca"] as $fieldKey => $field) { $contentFields[] = $fieldKey; } } if ($contentFields) { foreach ($contentFields as $fieldKey) { if ($fieldHelper->getFormType($fieldKey, "", $table) == "File") { $data[$fieldKey] = $fileRepository->findByRelation($table, $fieldKey, $uid); } } } }
php
public function addFilesToData(&$data, $table = "tt_content") { if ($data["_LOCALIZED_UID"]) { $uid = $data["_LOCALIZED_UID"]; } else { $uid = $data["uid"]; } // using is_numeric in favor to is_int // due to some rare cases where uids are provided as strings if (!is_numeric($uid)) { return; } $fieldHelper = GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); if (!$this->objectManager) { $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); } $storage = $this->storageRepository->load(); /* @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */ $fileRepository = $this->objectManager->get("TYPO3\CMS\Core\Resource\FileRepository"); $contentFields = array("media", "image", "assets"); if ($storage[$table]["tca"]) { foreach ($storage[$table]["tca"] as $fieldKey => $field) { $contentFields[] = $fieldKey; } } if ($contentFields) { foreach ($contentFields as $fieldKey) { if ($fieldHelper->getFormType($fieldKey, "", $table) == "File") { $data[$fieldKey] = $fileRepository->findByRelation($table, $fieldKey, $uid); } } } }
[ "public", "function", "addFilesToData", "(", "&", "$", "data", ",", "$", "table", "=", "\"tt_content\"", ")", "{", "if", "(", "$", "data", "[", "\"_LOCALIZED_UID\"", "]", ")", "{", "$", "uid", "=", "$", "data", "[", "\"_LOCALIZED_UID\"", "]", ";", "}",...
Adds FAL-Files to the data-array if available @param array $data @param string $table @author Benjamin Butschell <bb@webprofil.at>
[ "Adds", "FAL", "-", "Files", "to", "the", "data", "-", "array", "if", "available" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/InlineHelper.php#L83-L117
Gernott/mask
Classes/Helper/InlineHelper.php
InlineHelper.addIrreToData
public function addIrreToData(&$data, $table = "tt_content", $cType = "") { if ($cType == "") { $cType = $data["CType"]; } $fieldHelper = GeneralUtility::makeInstance(FieldHelper::class); $storage = $this->storageRepository->load(); $elementFields = []; // if the table is tt_content, load the element and all its columns if ($table == "tt_content") { $element = $this->storageRepository->loadElement($table, str_replace("mask_", "", $cType)); $elementFields = $element["columns"]; } elseif ($table == "pages") { // if the table is pages, then load the pid if (isset($data['uid'])) { // find the backendlayout by the pid $backendLayoutIdentifier = $this->backendLayoutRepository->findIdentifierByPid($data['uid']); // if a backendlayout was found, then load its elements if ($backendLayoutIdentifier) { $element = $this->storageRepository->loadElement( $table, str_replace('pagets__', '', $backendLayoutIdentifier) ); $elementFields = $element["columns"]; } else { // if no backendlayout was found, just load all fields, if there are fields if (isset($storage[$table]['tca'])) { $elementFields = array_keys($storage[$table]['tca']); } } } } elseif (isset($storage[$table])) { // otherwise check if its a table at all, if yes load all fields $elementFields = array_keys($storage[$table]['tca']); } // if the element has columns if ($elementFields) { // check foreach column foreach ($elementFields as $field) { $fieldKeyPrefix = $field; $fieldKey = str_replace("tx_mask_", "", $field); $type = $fieldHelper->getFormType($fieldKey, $cType, $table); // if it is of type inline and has to be filled (IRRE, FAL) if ($type == "Inline") { $elements = $this->getInlineElements($data, $fieldKeyPrefix, $cType, "parentid", $table); $data[$fieldKeyPrefix] = $elements; // or if it is of type Content (Nested Content) and has to be filled } elseif ($type == "Content") { $elements = $this->getInlineElements($data, $fieldKeyPrefix, $cType, $fieldKeyPrefix . "_parent", "tt_content", "tt_content"); $data[$fieldKeyPrefix] = $elements; } } } }
php
public function addIrreToData(&$data, $table = "tt_content", $cType = "") { if ($cType == "") { $cType = $data["CType"]; } $fieldHelper = GeneralUtility::makeInstance(FieldHelper::class); $storage = $this->storageRepository->load(); $elementFields = []; // if the table is tt_content, load the element and all its columns if ($table == "tt_content") { $element = $this->storageRepository->loadElement($table, str_replace("mask_", "", $cType)); $elementFields = $element["columns"]; } elseif ($table == "pages") { // if the table is pages, then load the pid if (isset($data['uid'])) { // find the backendlayout by the pid $backendLayoutIdentifier = $this->backendLayoutRepository->findIdentifierByPid($data['uid']); // if a backendlayout was found, then load its elements if ($backendLayoutIdentifier) { $element = $this->storageRepository->loadElement( $table, str_replace('pagets__', '', $backendLayoutIdentifier) ); $elementFields = $element["columns"]; } else { // if no backendlayout was found, just load all fields, if there are fields if (isset($storage[$table]['tca'])) { $elementFields = array_keys($storage[$table]['tca']); } } } } elseif (isset($storage[$table])) { // otherwise check if its a table at all, if yes load all fields $elementFields = array_keys($storage[$table]['tca']); } // if the element has columns if ($elementFields) { // check foreach column foreach ($elementFields as $field) { $fieldKeyPrefix = $field; $fieldKey = str_replace("tx_mask_", "", $field); $type = $fieldHelper->getFormType($fieldKey, $cType, $table); // if it is of type inline and has to be filled (IRRE, FAL) if ($type == "Inline") { $elements = $this->getInlineElements($data, $fieldKeyPrefix, $cType, "parentid", $table); $data[$fieldKeyPrefix] = $elements; // or if it is of type Content (Nested Content) and has to be filled } elseif ($type == "Content") { $elements = $this->getInlineElements($data, $fieldKeyPrefix, $cType, $fieldKeyPrefix . "_parent", "tt_content", "tt_content"); $data[$fieldKeyPrefix] = $elements; } } } }
[ "public", "function", "addIrreToData", "(", "&", "$", "data", ",", "$", "table", "=", "\"tt_content\"", ",", "$", "cType", "=", "\"\"", ")", "{", "if", "(", "$", "cType", "==", "\"\"", ")", "{", "$", "cType", "=", "$", "data", "[", "\"CType\"", "]"...
Adds FAL-Files to the data-array if available @param array $data @param string $table @param string $cType @author Benjamin Butschell <bb@webprofil.at>
[ "Adds", "FAL", "-", "Files", "to", "the", "data", "-", "array", "if", "available" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/InlineHelper.php#L127-L192
Gernott/mask
Classes/Helper/InlineHelper.php
InlineHelper.getInlineElements
public function getInlineElements( $data, $name, $cType, $parentFieldName = "parentid", $parenttable = "tt_content", $childTable = null ) { // if the name of the child table is not explicitely given, take field key if (!$childTable) { $childTable = $name; } // If this method is called in backend, there is no $GLOBALS['TSFE'] if (TYPO3_MODE == 'FE' && isset($GLOBALS['TSFE']->sys_language_uid)) { $sysLangUid = $GLOBALS['TSFE']->sys_language_uid; $enableFields = $GLOBALS['TSFE']->cObj->enableFields($childTable); } else { $sysLangUid = $data['sys_language_uid']; $enableFields = " AND " . $childTable . ".deleted = 0"; } // by default, the uid of the parent is $data["uid"] $parentUid = $data["uid"]; if ($GLOBALS['TSFE']->sys_language_uid != 0 && $data["_LOCALIZED_UID"] != "") { $parentUid = $data["_LOCALIZED_UID"]; } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($childTable); $queryBuilder ->select('*') ->from($childTable) ->where($queryBuilder->expr()->eq($parentFieldName, $parentUid)) ->orderBy('sorting'); if ($childTable !== 'tt_content') { $queryBuilder->andWhere('parenttable LIKE :parenttable'); $queryBuilder->setParameter('parenttable', $parenttable); } $rows = $queryBuilder->execute()->fetchAll(); // and recursively add them to an array $elements = array(); foreach ($rows as $element) { if (TYPO3_MODE == 'FE') { $GLOBALS['TSFE']->sys_page->versionOL($childTable, $element); } else { $element = BackendUtility::getRecordWSOL($childTable, $element['uid']); } if ($element && empty($elements[$element['uid']])) { $this->addIrreToData($element, $name, $cType); $this->addFilesToData($element, $name); $elements[$element['uid']] = $element; } } return $elements; }
php
public function getInlineElements( $data, $name, $cType, $parentFieldName = "parentid", $parenttable = "tt_content", $childTable = null ) { // if the name of the child table is not explicitely given, take field key if (!$childTable) { $childTable = $name; } // If this method is called in backend, there is no $GLOBALS['TSFE'] if (TYPO3_MODE == 'FE' && isset($GLOBALS['TSFE']->sys_language_uid)) { $sysLangUid = $GLOBALS['TSFE']->sys_language_uid; $enableFields = $GLOBALS['TSFE']->cObj->enableFields($childTable); } else { $sysLangUid = $data['sys_language_uid']; $enableFields = " AND " . $childTable . ".deleted = 0"; } // by default, the uid of the parent is $data["uid"] $parentUid = $data["uid"]; if ($GLOBALS['TSFE']->sys_language_uid != 0 && $data["_LOCALIZED_UID"] != "") { $parentUid = $data["_LOCALIZED_UID"]; } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($childTable); $queryBuilder ->select('*') ->from($childTable) ->where($queryBuilder->expr()->eq($parentFieldName, $parentUid)) ->orderBy('sorting'); if ($childTable !== 'tt_content') { $queryBuilder->andWhere('parenttable LIKE :parenttable'); $queryBuilder->setParameter('parenttable', $parenttable); } $rows = $queryBuilder->execute()->fetchAll(); // and recursively add them to an array $elements = array(); foreach ($rows as $element) { if (TYPO3_MODE == 'FE') { $GLOBALS['TSFE']->sys_page->versionOL($childTable, $element); } else { $element = BackendUtility::getRecordWSOL($childTable, $element['uid']); } if ($element && empty($elements[$element['uid']])) { $this->addIrreToData($element, $name, $cType); $this->addFilesToData($element, $name); $elements[$element['uid']] = $element; } } return $elements; }
[ "public", "function", "getInlineElements", "(", "$", "data", ",", "$", "name", ",", "$", "cType", ",", "$", "parentFieldName", "=", "\"parentid\"", ",", "$", "parenttable", "=", "\"tt_content\"", ",", "$", "childTable", "=", "null", ")", "{", "// if the name...
Returns Inline-Elements of Data-Object @param array $data the parent object @param string $name The name of the irre attribut @param string $cType The name of the irre attribut @param string $parentFieldName The name of the irre parentid @param string $parenttable The table where the parent element is stored @param string $childTable name of childtable @return array all irre elements of this attribut @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "Inline", "-", "Elements", "of", "Data", "-", "Object" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/InlineHelper.php#L206-L265
Gernott/mask
Classes/Helper/FieldHelper.php
FieldHelper.getElementsWhichUseField
public function getElementsWhichUseField($key, $type = "tt_content") { $storage = $this->storageRepository->load(); $elementsInUse = array(); if ($storage[$type]["elements"]) { foreach ($storage[$type]["elements"] as $element) { if ($element["columns"]) { foreach ($element["columns"] as $column) { if ($column == $key) { $elementsInUse[] = $element; } } } } } return $elementsInUse; }
php
public function getElementsWhichUseField($key, $type = "tt_content") { $storage = $this->storageRepository->load(); $elementsInUse = array(); if ($storage[$type]["elements"]) { foreach ($storage[$type]["elements"] as $element) { if ($element["columns"]) { foreach ($element["columns"] as $column) { if ($column == $key) { $elementsInUse[] = $element; } } } } } return $elementsInUse; }
[ "public", "function", "getElementsWhichUseField", "(", "$", "key", ",", "$", "type", "=", "\"tt_content\"", ")", "{", "$", "storage", "=", "$", "this", "->", "storageRepository", "->", "load", "(", ")", ";", "$", "elementsInUse", "=", "array", "(", ")", ...
Returns all elements that use this field @param string $key TCA Type @param string $type elementtype @return array elements in use @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "all", "elements", "that", "use", "this", "field" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/FieldHelper.php#L64-L81
Gernott/mask
Classes/Helper/FieldHelper.php
FieldHelper.getLabel
public function getLabel($elementKey, $fieldKey, $type = "tt_content") { $storage = $this->storageRepository->load(); $fieldIndex = -1; if ($storage[$type]["elements"][$elementKey]["columns"] && count($storage[$type]["elements"][$elementKey]["columns"]) > 0) { foreach ($storage[$type]["elements"][$elementKey]["columns"] as $index => $column) { if ($column == $fieldKey) { $fieldIndex = $index; } } } if ($fieldIndex >= 0) { $label = $storage[$type]["elements"][$elementKey]["labels"][$fieldIndex]; } else { $label = ""; } return $label; }
php
public function getLabel($elementKey, $fieldKey, $type = "tt_content") { $storage = $this->storageRepository->load(); $fieldIndex = -1; if ($storage[$type]["elements"][$elementKey]["columns"] && count($storage[$type]["elements"][$elementKey]["columns"]) > 0) { foreach ($storage[$type]["elements"][$elementKey]["columns"] as $index => $column) { if ($column == $fieldKey) { $fieldIndex = $index; } } } if ($fieldIndex >= 0) { $label = $storage[$type]["elements"][$elementKey]["labels"][$fieldIndex]; } else { $label = ""; } return $label; }
[ "public", "function", "getLabel", "(", "$", "elementKey", ",", "$", "fieldKey", ",", "$", "type", "=", "\"tt_content\"", ")", "{", "$", "storage", "=", "$", "this", "->", "storageRepository", "->", "load", "(", ")", ";", "$", "fieldIndex", "=", "-", "1...
Returns the label of a field in an element @param string $elementKey Key of Element @param string $fieldKey Key if Field @param string $type elementtype @return string Label @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "the", "label", "of", "a", "field", "in", "an", "element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/FieldHelper.php#L92-L109
Gernott/mask
Classes/Helper/FieldHelper.php
FieldHelper.getFormType
public function getFormType($fieldKey, $elementKey = "", $type = "tt_content") { $formType = "String"; // Load element and TCA of field if ($elementKey) { $element = $this->storageRepository->loadElement($type, $elementKey); } // load tca for field from $GLOBALS $tca = $GLOBALS["TCA"][$type]["columns"][$fieldKey]; if (!$tca["config"]) { $tca = $GLOBALS["TCA"][$type]["columns"]["tx_mask_" . $fieldKey]; } if (!$tca["config"]) { $tca = $element["tca"][$fieldKey]; } // if field is in inline table or $GLOBALS["TCA"] is not yet filled, load tca from json if (!in_array($type, array("tt_content", "pages")) || $tca == null) { $tca = $this->storageRepository->loadField($type, $fieldKey); if (!$tca["config"]) { $tca = $this->storageRepository->loadField($type, "tx_mask_" . $fieldKey); } } $tcaType = $tca["config"]["type"]; $evals = explode(",", $tca["config"]["eval"]); if ($tca["options"] == "file") { $formType = "File"; } // And decide via different tca settings which formType it is switch ($tcaType) { case "input": $formType = "String"; if (array_search(strtolower("int"), $evals) !== false) { $formType = "Integer"; } else { if (array_search(strtolower("double2"), $evals) !== false) { $formType = "Float"; } else { if (array_search(strtolower("date"), $evals) !== false) { $formType = "Date"; } else { if (array_search(strtolower("datetime"), $evals) !== false) { $formType = "Datetime"; } else { if (isset($tca["config"]["renderType"]) && $tca["config"]["renderType"] === "inputLink") { $formType = "Link"; } else { $formType = "String"; } } } } } break; case "text": $formType = "Text"; if (in_array($type, array("tt_content", "pages"))) { if ($elementKey) { $fieldNumberKey = -1; if (is_array($element["columns"])) { foreach ($element["columns"] as $numberKey => $column) { if ($column == $fieldKey) { $fieldNumberKey = $numberKey; } } } if ($fieldNumberKey >= 0) { $option = $element["options"][$fieldNumberKey]; if ($option == "rte") { $formType = "Richtext"; } else { $formType = "Text"; } } } else { $formType = "Text"; } } else { if ($tca["rte"]) { $formType = "Richtext"; } else { $formType = "Text"; } } break; case "check": $formType = "Check"; break; case "radio": $formType = "Radio"; break; case "select": $formType = "Select"; break; case "group": break; case "none": break; case "passthrough": break; case "user": break; case "flex": break; case "inline": $formType = "Inline"; if ($tca["config"]["foreign_table"] == "sys_file_reference") { $formType = "File"; } else { if ($tca["config"]["foreign_table"] == "tt_content") { $formType = "Content"; } else { $formType = "Inline"; } } break; case "tab": $formType = "Tab"; break; default: break; } return $formType; }
php
public function getFormType($fieldKey, $elementKey = "", $type = "tt_content") { $formType = "String"; // Load element and TCA of field if ($elementKey) { $element = $this->storageRepository->loadElement($type, $elementKey); } // load tca for field from $GLOBALS $tca = $GLOBALS["TCA"][$type]["columns"][$fieldKey]; if (!$tca["config"]) { $tca = $GLOBALS["TCA"][$type]["columns"]["tx_mask_" . $fieldKey]; } if (!$tca["config"]) { $tca = $element["tca"][$fieldKey]; } // if field is in inline table or $GLOBALS["TCA"] is not yet filled, load tca from json if (!in_array($type, array("tt_content", "pages")) || $tca == null) { $tca = $this->storageRepository->loadField($type, $fieldKey); if (!$tca["config"]) { $tca = $this->storageRepository->loadField($type, "tx_mask_" . $fieldKey); } } $tcaType = $tca["config"]["type"]; $evals = explode(",", $tca["config"]["eval"]); if ($tca["options"] == "file") { $formType = "File"; } // And decide via different tca settings which formType it is switch ($tcaType) { case "input": $formType = "String"; if (array_search(strtolower("int"), $evals) !== false) { $formType = "Integer"; } else { if (array_search(strtolower("double2"), $evals) !== false) { $formType = "Float"; } else { if (array_search(strtolower("date"), $evals) !== false) { $formType = "Date"; } else { if (array_search(strtolower("datetime"), $evals) !== false) { $formType = "Datetime"; } else { if (isset($tca["config"]["renderType"]) && $tca["config"]["renderType"] === "inputLink") { $formType = "Link"; } else { $formType = "String"; } } } } } break; case "text": $formType = "Text"; if (in_array($type, array("tt_content", "pages"))) { if ($elementKey) { $fieldNumberKey = -1; if (is_array($element["columns"])) { foreach ($element["columns"] as $numberKey => $column) { if ($column == $fieldKey) { $fieldNumberKey = $numberKey; } } } if ($fieldNumberKey >= 0) { $option = $element["options"][$fieldNumberKey]; if ($option == "rte") { $formType = "Richtext"; } else { $formType = "Text"; } } } else { $formType = "Text"; } } else { if ($tca["rte"]) { $formType = "Richtext"; } else { $formType = "Text"; } } break; case "check": $formType = "Check"; break; case "radio": $formType = "Radio"; break; case "select": $formType = "Select"; break; case "group": break; case "none": break; case "passthrough": break; case "user": break; case "flex": break; case "inline": $formType = "Inline"; if ($tca["config"]["foreign_table"] == "sys_file_reference") { $formType = "File"; } else { if ($tca["config"]["foreign_table"] == "tt_content") { $formType = "Content"; } else { $formType = "Inline"; } } break; case "tab": $formType = "Tab"; break; default: break; } return $formType; }
[ "public", "function", "getFormType", "(", "$", "fieldKey", ",", "$", "elementKey", "=", "\"\"", ",", "$", "type", "=", "\"tt_content\"", ")", "{", "$", "formType", "=", "\"String\"", ";", "// Load element and TCA of field", "if", "(", "$", "elementKey", ")", ...
Returns the formType of a field in an element @param string $fieldKey Key if Field @param string $elementKey Key of Element @param string $type elementtype @return string formType @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "the", "formType", "of", "a", "field", "in", "an", "element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/FieldHelper.php#L120-L249
Gernott/mask
Classes/Helper/FieldHelper.php
FieldHelper.getFieldType
public function getFieldType($fieldKey, $elementKey = "", $excludeInlineFields = false) { $storage = $this->storageRepository->load(); // get all possible types (tables) if ($storage && !$excludeInlineFields) { $types = array_keys($storage); } else { $types = array(); } $types[] = "pages"; $types[] = "tt_content"; $types = array_unique($types); $fieldType = ""; $found = false; foreach ($types as $type) { if ($storage[$type]["elements"] && !$found) { foreach ($storage[$type]["elements"] as $element) { // if this is the element we search for, or no special element was given, // and the element has columns and the fieldType wasn't found yet if (($element["key"] == $elementKey || $elementKey == "") && $element["columns"] && !$found) { foreach ($element["columns"] as $column) { if ($column == $fieldKey && !$found) { $fieldType = $type; $found = true; } } } } } else { if (is_array($storage[$type]["tca"][$fieldKey])) { $fieldType = $type; $found = true; } } } return $fieldType; }
php
public function getFieldType($fieldKey, $elementKey = "", $excludeInlineFields = false) { $storage = $this->storageRepository->load(); // get all possible types (tables) if ($storage && !$excludeInlineFields) { $types = array_keys($storage); } else { $types = array(); } $types[] = "pages"; $types[] = "tt_content"; $types = array_unique($types); $fieldType = ""; $found = false; foreach ($types as $type) { if ($storage[$type]["elements"] && !$found) { foreach ($storage[$type]["elements"] as $element) { // if this is the element we search for, or no special element was given, // and the element has columns and the fieldType wasn't found yet if (($element["key"] == $elementKey || $elementKey == "") && $element["columns"] && !$found) { foreach ($element["columns"] as $column) { if ($column == $fieldKey && !$found) { $fieldType = $type; $found = true; } } } } } else { if (is_array($storage[$type]["tca"][$fieldKey])) { $fieldType = $type; $found = true; } } } return $fieldType; }
[ "public", "function", "getFieldType", "(", "$", "fieldKey", ",", "$", "elementKey", "=", "\"\"", ",", "$", "excludeInlineFields", "=", "false", ")", "{", "$", "storage", "=", "$", "this", "->", "storageRepository", "->", "load", "(", ")", ";", "// get all ...
Returns type of field (tt_content or pages) @param string $fieldKey key of field @param string $elementKey key of element @return string $fieldType returns fieldType or null if not found @return string $excludeInlineFields only search in tt_content and pages @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "type", "of", "field", "(", "tt_content", "or", "pages", ")" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/FieldHelper.php#L260-L300
Gernott/mask
Classes/Helper/FieldHelper.php
FieldHelper.getFieldsByType
public function getFieldsByType($key, $type) { $storage = $this->storageRepository->load(); if (empty($storage[$type]) || empty($storage[$type]['tca'])) { return []; } $fields = []; foreach ($storage[$type]['tca'] as $field => $config) { if ($config['config']['type'] !== strtolower($key)) { continue; } $elements = $this->getElementsWhichUseField($field, $type); if (empty($elements)) { continue; } $fields[] = [ 'field' => $field, 'label' => $this->getLabel($elements[0]['key'], $field, $type), ]; } return $fields; }
php
public function getFieldsByType($key, $type) { $storage = $this->storageRepository->load(); if (empty($storage[$type]) || empty($storage[$type]['tca'])) { return []; } $fields = []; foreach ($storage[$type]['tca'] as $field => $config) { if ($config['config']['type'] !== strtolower($key)) { continue; } $elements = $this->getElementsWhichUseField($field, $type); if (empty($elements)) { continue; } $fields[] = [ 'field' => $field, 'label' => $this->getLabel($elements[0]['key'], $field, $type), ]; } return $fields; }
[ "public", "function", "getFieldsByType", "(", "$", "key", ",", "$", "type", ")", "{", "$", "storage", "=", "$", "this", "->", "storageRepository", "->", "load", "(", ")", ";", "if", "(", "empty", "(", "$", "storage", "[", "$", "type", "]", ")", "||...
Returns all fields of a type from a table @param string $key TCA Type @param string $type elementtype @return array fields
[ "Returns", "all", "fields", "of", "a", "type", "from", "a", "table" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Helper/FieldHelper.php#L309-L334
Gernott/mask
Classes/ViewHelpers/ShuttleViewHelper.php
ShuttleViewHelper.render
public function render() { $table = $this->arguments['table']; $field = $this->arguments['field']; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder ->select('*') ->where('uid IN (' . $field . ')'); $queryBuilder->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); return $queryBuilder->execute()->fetchAll(); }
php
public function render() { $table = $this->arguments['table']; $field = $this->arguments['field']; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder ->select('*') ->where('uid IN (' . $field . ')'); $queryBuilder->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); return $queryBuilder->execute()->fetchAll(); }
[ "public", "function", "render", "(", ")", "{", "$", "table", "=", "$", "this", "->", "arguments", "[", "'table'", "]", ";", "$", "field", "=", "$", "this", "->", "arguments", "[", "'field'", "]", ";", "$", "queryBuilder", "=", "GeneralUtility", "::", ...
Returns Shuttle-Elements of Data-Object @return array all irre elements of this attribut @author Gernot Ploiner <gp@webprofil.at>
[ "Returns", "Shuttle", "-", "Elements", "of", "Data", "-", "Object" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/ShuttleViewHelper.php#L36-L51
Gernott/mask
Classes/ViewHelpers/ItemsViewHelper.php
ItemsViewHelper.render
public function render() { $itemArray = []; if ($this->arguments['items']) { foreach ($this->arguments['items'] as $item) { $itemArray[] = implode(",", $item); } } return implode("\n", $itemArray); }
php
public function render() { $itemArray = []; if ($this->arguments['items']) { foreach ($this->arguments['items'] as $item) { $itemArray[] = implode(",", $item); } } return implode("\n", $itemArray); }
[ "public", "function", "render", "(", ")", "{", "$", "itemArray", "=", "[", "]", ";", "if", "(", "$", "this", "->", "arguments", "[", "'items'", "]", ")", "{", "foreach", "(", "$", "this", "->", "arguments", "[", "'items'", "]", "as", "$", "item", ...
Returns all elements that use this field @return string items as string @author Benjamin Butschell bb@webprofil.at>
[ "Returns", "all", "elements", "that", "use", "this", "field" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/ItemsViewHelper.php#L28-L39
Gernott/mask
Classes/Domain/Service/SettingsService.php
SettingsService.get
public function get() { if ($this->extSettings === null) { $this->extSettings = $this->getExtSettings(); } return $this->extSettings; }
php
public function get() { if ($this->extSettings === null) { $this->extSettings = $this->getExtSettings(); } return $this->extSettings; }
[ "public", "function", "get", "(", ")", "{", "if", "(", "$", "this", "->", "extSettings", "===", "null", ")", "{", "$", "this", "->", "extSettings", "=", "$", "this", "->", "getExtSettings", "(", ")", ";", "}", "return", "$", "this", "->", "extSetting...
Returns the settings @return array
[ "Returns", "the", "settings" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Service/SettingsService.php#L66-L73
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.load
public function load() { if (self::$json === null) { self::$json = array(); if (!empty($this->extSettings['json'])) { $file = MaskUtility::getFileAbsFileName($this->extSettings['json']); if (file_exists($file)) { self::$json = json_decode(file_get_contents($file), true); } } } return self::$json; }
php
public function load() { if (self::$json === null) { self::$json = array(); if (!empty($this->extSettings['json'])) { $file = MaskUtility::getFileAbsFileName($this->extSettings['json']); if (file_exists($file)) { self::$json = json_decode(file_get_contents($file), true); } } } return self::$json; }
[ "public", "function", "load", "(", ")", "{", "if", "(", "self", "::", "$", "json", "===", "null", ")", "{", "self", "::", "$", "json", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "extSettings", "[", "'json'", "...
Load Storage @return array
[ "Load", "Storage" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L92-L104
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.write
public function write($json) { if (!empty($this->extSettings['json'])) { $file = MaskUtility::getFileAbsFileName($this->extSettings['json']); GeneralUtility::writeFile( $file, json_encode($json, JSON_PRETTY_PRINT) ); } self::$json = $json; }
php
public function write($json) { if (!empty($this->extSettings['json'])) { $file = MaskUtility::getFileAbsFileName($this->extSettings['json']); GeneralUtility::writeFile( $file, json_encode($json, JSON_PRETTY_PRINT) ); } self::$json = $json; }
[ "public", "function", "write", "(", "$", "json", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "extSettings", "[", "'json'", "]", ")", ")", "{", "$", "file", "=", "MaskUtility", "::", "getFileAbsFileName", "(", "$", "this", "->", "extSet...
Write Storage @param $json @return void
[ "Write", "Storage" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L112-L122
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.loadInlineFields
public function loadInlineFields($parentKey) { $json = $this->load(); $inlineFields = array(); foreach ($json as $table) { if ($table["tca"]) { foreach ($table["tca"] as $key => $tca) { if ($tca["inlineParent"] == $parentKey) { if ($tca["config"]["type"] == "inline") { $tca["inlineFields"] = $this->loadInlineFields($key); } $tca["maskKey"] = "tx_mask_" . $tca["key"]; $inlineFields[] = $tca; } } } } return $inlineFields; }
php
public function loadInlineFields($parentKey) { $json = $this->load(); $inlineFields = array(); foreach ($json as $table) { if ($table["tca"]) { foreach ($table["tca"] as $key => $tca) { if ($tca["inlineParent"] == $parentKey) { if ($tca["config"]["type"] == "inline") { $tca["inlineFields"] = $this->loadInlineFields($key); } $tca["maskKey"] = "tx_mask_" . $tca["key"]; $inlineFields[] = $tca; } } } } return $inlineFields; }
[ "public", "function", "loadInlineFields", "(", "$", "parentKey", ")", "{", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "$", "inlineFields", "=", "array", "(", ")", ";", "foreach", "(", "$", "json", "as", "$", "table", ")", "{", "if"...
Loads all the inline fields of an inline-field, recursively! @param string $parentKey key of the inline-field @author Benjamin Butschell <bb@webprofil.at> @return array
[ "Loads", "all", "the", "inline", "fields", "of", "an", "inline", "-", "field", "recursively!" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L142-L160
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.loadElement
public function loadElement($type, $key) { $json = $this->load(); $fields = array(); $columns = $json[$type]["elements"][$key]["columns"]; //Check if it is an array before trying to count it if (is_array($columns) && count($columns) > 0) { foreach ($columns as $fieldName) { $fields[$fieldName] = $json[$type]["tca"][$fieldName]; } } if (count($fields) > 0) { $json[$type]["elements"][$key]["tca"] = $fields; } return $json[$type]["elements"][$key]; }
php
public function loadElement($type, $key) { $json = $this->load(); $fields = array(); $columns = $json[$type]["elements"][$key]["columns"]; //Check if it is an array before trying to count it if (is_array($columns) && count($columns) > 0) { foreach ($columns as $fieldName) { $fields[$fieldName] = $json[$type]["tca"][$fieldName]; } } if (count($fields) > 0) { $json[$type]["elements"][$key]["tca"] = $fields; } return $json[$type]["elements"][$key]; }
[ "public", "function", "loadElement", "(", "$", "type", ",", "$", "key", ")", "{", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "$", "fields", "=", "array", "(", ")", ";", "$", "columns", "=", "$", "json", "[", "$", "type", "]", ...
Load Element with all the field configurations @return array
[ "Load", "Element", "with", "all", "the", "field", "configurations" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L167-L183
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.add
public function add($content) { // Load $json = $this->load(); // Create JSON elements Array: foreach ($content["elements"] as $key => $value) { // delete columns and labels of irre-fields from elements if ($key == "columns" || $key == "labels") { foreach ($value as $index => $column) { if (!$content["tca"][$index]["inlineParent"]) { $contentColumns[] = $column; } else { unset($value[$index]); unset($value[$index]); } if ($key === 'labels' && empty($column) && isset($json[$content['type']]['tca'][$content['elements']['columns'][$index]]) ) { // If using a mask field with empty label, we have to set the "default" label $label = ''; foreach ($json[$content['type']]['elements'] as $element) { if (in_array($content['elements']['columns'][$index], $element['columns'], true)) { $i = array_search($content['elements']['columns'][$index], $element['columns'], true); if (!empty($element['labels'][$i])) { $label = $element['labels'][$i]; break; } } } $value[$index] = $label; } } } $json[$content["type"]]["elements"][$content["elements"]["key"]][$key] = $value; } $contentColumns = array(); $columns = array(); // delete columns and labels of irre-fields from elements if ($content["elements"]["columns"]) { foreach ($content["elements"]["columns"] as $index => $column) { if (!$content["tca"][$index]["inlineParent"]) { $contentColumns[] = $column; } else { unset($content["elements"]["columns"][$index]); unset($content["elements"]["labels"][$index]); } $columns[] = $column; } } // Create JSON sql Array: if (is_array($content["sql"])) { foreach ($content["sql"] as $table => $sqlArray) { foreach ($sqlArray as $index => $type) { $fieldname = "tx_mask_" . $columns[$index]; $json[$table]["sql"][$fieldname][$table][$fieldname] = $type; } } } // Create JSON tca Array: if (is_array($content["tca"])) { foreach ($content["tca"] as $key => $value) { $inlineField = false; // if this field is inline-field if ($value["inlineParent"]) { $type = $value["inlineParent"]; $inlineField = true; } else { $type = $content["type"]; } $json[$type]["tca"][$columns[$key]] = $value; // add rte flag if inline and rte if ($inlineField) { if ($content["elements"]["options"][$key] == "rte") { $json[$type]["tca"][$columns[$key]]["rte"] = "1"; } } // Only add columns to elements if it is no inlinefield if (!$inlineField) { $json[$type]["elements"][$content["elements"]["key"]]["columns"][$key] = "tx_mask_" . $columns[$key]; } $json[$type]["tca"]["tx_mask_" . $columns[$key]] = $json[$type]["tca"][$columns[$key]]; $json[$type]["tca"]["tx_mask_" . $columns[$key]]["key"] = $columns[$key]; if ($inlineField) { $json[$type]["tca"]["tx_mask_" . $columns[$key]]["order"] = $key; } unset($json[$type]["tca"][$columns[$key]]); } } // sort content elements by key before saving $this->sortJson($json); $this->write($json); }
php
public function add($content) { // Load $json = $this->load(); // Create JSON elements Array: foreach ($content["elements"] as $key => $value) { // delete columns and labels of irre-fields from elements if ($key == "columns" || $key == "labels") { foreach ($value as $index => $column) { if (!$content["tca"][$index]["inlineParent"]) { $contentColumns[] = $column; } else { unset($value[$index]); unset($value[$index]); } if ($key === 'labels' && empty($column) && isset($json[$content['type']]['tca'][$content['elements']['columns'][$index]]) ) { // If using a mask field with empty label, we have to set the "default" label $label = ''; foreach ($json[$content['type']]['elements'] as $element) { if (in_array($content['elements']['columns'][$index], $element['columns'], true)) { $i = array_search($content['elements']['columns'][$index], $element['columns'], true); if (!empty($element['labels'][$i])) { $label = $element['labels'][$i]; break; } } } $value[$index] = $label; } } } $json[$content["type"]]["elements"][$content["elements"]["key"]][$key] = $value; } $contentColumns = array(); $columns = array(); // delete columns and labels of irre-fields from elements if ($content["elements"]["columns"]) { foreach ($content["elements"]["columns"] as $index => $column) { if (!$content["tca"][$index]["inlineParent"]) { $contentColumns[] = $column; } else { unset($content["elements"]["columns"][$index]); unset($content["elements"]["labels"][$index]); } $columns[] = $column; } } // Create JSON sql Array: if (is_array($content["sql"])) { foreach ($content["sql"] as $table => $sqlArray) { foreach ($sqlArray as $index => $type) { $fieldname = "tx_mask_" . $columns[$index]; $json[$table]["sql"][$fieldname][$table][$fieldname] = $type; } } } // Create JSON tca Array: if (is_array($content["tca"])) { foreach ($content["tca"] as $key => $value) { $inlineField = false; // if this field is inline-field if ($value["inlineParent"]) { $type = $value["inlineParent"]; $inlineField = true; } else { $type = $content["type"]; } $json[$type]["tca"][$columns[$key]] = $value; // add rte flag if inline and rte if ($inlineField) { if ($content["elements"]["options"][$key] == "rte") { $json[$type]["tca"][$columns[$key]]["rte"] = "1"; } } // Only add columns to elements if it is no inlinefield if (!$inlineField) { $json[$type]["elements"][$content["elements"]["key"]]["columns"][$key] = "tx_mask_" . $columns[$key]; } $json[$type]["tca"]["tx_mask_" . $columns[$key]] = $json[$type]["tca"][$columns[$key]]; $json[$type]["tca"]["tx_mask_" . $columns[$key]]["key"] = $columns[$key]; if ($inlineField) { $json[$type]["tca"]["tx_mask_" . $columns[$key]]["order"] = $key; } unset($json[$type]["tca"][$columns[$key]]); } } // sort content elements by key before saving $this->sortJson($json); $this->write($json); }
[ "public", "function", "add", "(", "$", "content", ")", "{", "// Load", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "// Create JSON elements Array:", "foreach", "(", "$", "content", "[", "\"elements\"", "]", "as", "$", "key", "=>", "$", ...
Adds new Content-Element @param array $content
[ "Adds", "new", "Content", "-", "Element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L190-L296
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.remove
public function remove($type, $key, $remainingFields = array()) { // Load $json = $this->load(); // Remove $columns = $json[$type]["elements"][$key]["columns"]; unset($json[$type]["elements"][$key]); if (is_array($columns)) { foreach ($columns as $field) { $json = $this->removeField($type, $field, $json, $remainingFields); } } $this->sortJson($json); $this->write($json); }
php
public function remove($type, $key, $remainingFields = array()) { // Load $json = $this->load(); // Remove $columns = $json[$type]["elements"][$key]["columns"]; unset($json[$type]["elements"][$key]); if (is_array($columns)) { foreach ($columns as $field) { $json = $this->removeField($type, $field, $json, $remainingFields); } } $this->sortJson($json); $this->write($json); }
[ "public", "function", "remove", "(", "$", "type", ",", "$", "key", ",", "$", "remainingFields", "=", "array", "(", ")", ")", "{", "// Load", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "// Remove", "$", "columns", "=", "$", "json", ...
Removes Content-Element @param string $type @param string $key @param array $remainingFields
[ "Removes", "Content", "-", "Element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L305-L320
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.hide
public function hide($type, $key) { // Load $json = $this->load(); $json[$type]["elements"][$key]["hidden"] = 1; $this->sortJson($json); $this->write($json); }
php
public function hide($type, $key) { // Load $json = $this->load(); $json[$type]["elements"][$key]["hidden"] = 1; $this->sortJson($json); $this->write($json); }
[ "public", "function", "hide", "(", "$", "type", ",", "$", "key", ")", "{", "// Load", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "$", "json", "[", "$", "type", "]", "[", "\"elements\"", "]", "[", "$", "key", "]", "[", "\"hidden...
Hides Content-Element @param string $type @param string $key
[ "Hides", "Content", "-", "Element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L328-L335
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.activate
public function activate($type, $key) { // Load $json = $this->load(); unset($json[$type]["elements"][$key]["hidden"]); $this->sortJson($json); $this->write($json); }
php
public function activate($type, $key) { // Load $json = $this->load(); unset($json[$type]["elements"][$key]["hidden"]); $this->sortJson($json); $this->write($json); }
[ "public", "function", "activate", "(", "$", "type", ",", "$", "key", ")", "{", "// Load", "$", "json", "=", "$", "this", "->", "load", "(", ")", ";", "unset", "(", "$", "json", "[", "$", "type", "]", "[", "\"elements\"", "]", "[", "$", "key", "...
Activates Content-Element @param string $type @param string $key
[ "Activates", "Content", "-", "Element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L343-L350
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.removeField
private function removeField($table, $field, $json, $remainingFields = array()) { $this->fieldHelper = GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // check if this field is used in any other elements $elementsInUse = array(); if ($json[$table]["elements"]) { foreach ($json[$table]["elements"] as $element) { if ($element["columns"]) { foreach ($element["columns"] as $column) { if ($column == $field) { $elementsInUse[] = $element; } } } } } // check if father gets deleted $fatherFound = false; if ($remainingFields) { foreach ($remainingFields as $remainingField) { if ($field == "tx_mask_" . $remainingField) { $fatherFound = true; } } } $fatherGetsDeleted = !$fatherFound; // if the field is a repeating field, make some exceptions if ($json[$table]["tca"][$field]["config"]["type"] == "inline") { $inlineFields = $this->loadInlineFields($field); if ($inlineFields) { // Recursively delete all inline-fields if necessary foreach ($inlineFields as $inlineField) { $found = false; // check if the fields are really deleted, or if they are just deleted temporarly for update action if ($remainingFields) { foreach ($remainingFields as $remainingField) { if ($inlineField["key"] == $remainingField) { $found = true; } } } if ($found) { // was not really deleted => can be deleted temporarly because it will be readded $json = $this->removeField($inlineField["inlineParent"], "tx_mask_" . $inlineField["key"], $json); } else { // was really deleted and can only be deleted if father is not in use in another element if (($fatherGetsDeleted && count($elementsInUse) == 0) || !$fatherGetsDeleted) { $json = $this->removeField($inlineField["inlineParent"], "tx_mask_" . $inlineField["key"], $json); } } } } } // then delete the field, if it is not in use in another element if (count($elementsInUse) < 1) { unset($json[$table]["tca"][$field]); unset($json[$table]["sql"][$field]); // If field is of type file, also delete entry in sys_file_reference if ($this->fieldHelper->getFormType($field) == "File") { unset($json["sys_file_reference"]["sql"][$field]); $json = $this->cleanTable("sys_file_reference", $json); } } return $this->cleanTable($table, $json); }
php
private function removeField($table, $field, $json, $remainingFields = array()) { $this->fieldHelper = GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // check if this field is used in any other elements $elementsInUse = array(); if ($json[$table]["elements"]) { foreach ($json[$table]["elements"] as $element) { if ($element["columns"]) { foreach ($element["columns"] as $column) { if ($column == $field) { $elementsInUse[] = $element; } } } } } // check if father gets deleted $fatherFound = false; if ($remainingFields) { foreach ($remainingFields as $remainingField) { if ($field == "tx_mask_" . $remainingField) { $fatherFound = true; } } } $fatherGetsDeleted = !$fatherFound; // if the field is a repeating field, make some exceptions if ($json[$table]["tca"][$field]["config"]["type"] == "inline") { $inlineFields = $this->loadInlineFields($field); if ($inlineFields) { // Recursively delete all inline-fields if necessary foreach ($inlineFields as $inlineField) { $found = false; // check if the fields are really deleted, or if they are just deleted temporarly for update action if ($remainingFields) { foreach ($remainingFields as $remainingField) { if ($inlineField["key"] == $remainingField) { $found = true; } } } if ($found) { // was not really deleted => can be deleted temporarly because it will be readded $json = $this->removeField($inlineField["inlineParent"], "tx_mask_" . $inlineField["key"], $json); } else { // was really deleted and can only be deleted if father is not in use in another element if (($fatherGetsDeleted && count($elementsInUse) == 0) || !$fatherGetsDeleted) { $json = $this->removeField($inlineField["inlineParent"], "tx_mask_" . $inlineField["key"], $json); } } } } } // then delete the field, if it is not in use in another element if (count($elementsInUse) < 1) { unset($json[$table]["tca"][$field]); unset($json[$table]["sql"][$field]); // If field is of type file, also delete entry in sys_file_reference if ($this->fieldHelper->getFormType($field) == "File") { unset($json["sys_file_reference"]["sql"][$field]); $json = $this->cleanTable("sys_file_reference", $json); } } return $this->cleanTable($table, $json); }
[ "private", "function", "removeField", "(", "$", "table", ",", "$", "field", ",", "$", "json", ",", "$", "remainingFields", "=", "array", "(", ")", ")", "{", "$", "this", "->", "fieldHelper", "=", "GeneralUtility", "::", "makeInstance", "(", "'MASK\\\\Mask\...
Removes a field from the json, also recursively all inline-fields @author Benjamin Butschell <bb@webprofil.at> @param string $table @param string $field @param array $json @param array $remainingFields @return array
[ "Removes", "a", "field", "from", "the", "json", "also", "recursively", "all", "inline", "-", "fields", "@author", "Benjamin", "Butschell", "<bb@webprofil", ".", "at", ">" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L362-L435
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.cleanTable
private function cleanTable($table, $json) { if ($json[$table]["tca"] && count($json[$table]["tca"]) < 1) { unset($json[$table]["tca"]); } if ($json[$table]["sql"] && count($json[$table]["sql"]) < 1) { unset($json[$table]["sql"]); } if ($json[$table] && count($json[$table]) < 1) { unset($json[$table]); } return $json; }
php
private function cleanTable($table, $json) { if ($json[$table]["tca"] && count($json[$table]["tca"]) < 1) { unset($json[$table]["tca"]); } if ($json[$table]["sql"] && count($json[$table]["sql"]) < 1) { unset($json[$table]["sql"]); } if ($json[$table] && count($json[$table]) < 1) { unset($json[$table]); } return $json; }
[ "private", "function", "cleanTable", "(", "$", "table", ",", "$", "json", ")", "{", "if", "(", "$", "json", "[", "$", "table", "]", "[", "\"tca\"", "]", "&&", "count", "(", "$", "json", "[", "$", "table", "]", "[", "\"tca\"", "]", ")", "<", "1"...
Deletes all the empty settings of a table @author Benjamin Butschell <bb@webprofil.at> @param string $table @param array $json @return array
[ "Deletes", "all", "the", "empty", "settings", "of", "a", "table" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L445-L457
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.update
public function update($content) { $this->remove($content["type"], $content["orgkey"], $content["elements"]["columns"]); $this->add($content); }
php
public function update($content) { $this->remove($content["type"], $content["orgkey"], $content["elements"]["columns"]); $this->add($content); }
[ "public", "function", "update", "(", "$", "content", ")", "{", "$", "this", "->", "remove", "(", "$", "content", "[", "\"type\"", "]", ",", "$", "content", "[", "\"orgkey\"", "]", ",", "$", "content", "[", "\"elements\"", "]", "[", "\"columns\"", "]", ...
Updates Content-Element in Storage-Repository @param array $content
[ "Updates", "Content", "-", "Element", "in", "Storage", "-", "Repository" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L464-L468
Gernott/mask
Classes/Domain/Repository/StorageRepository.php
StorageRepository.sortJson
private function sortJson(array &$array) { // check if array is not a hash table, because we only want to sort hash tables if ( [] === $array || !(array_keys($array) !== range(0, count($array) - 1)) ) { return false; } ksort($array); foreach ($array as &$item) { if (is_array($item)) { $this->sortJson($item); } } }
php
private function sortJson(array &$array) { // check if array is not a hash table, because we only want to sort hash tables if ( [] === $array || !(array_keys($array) !== range(0, count($array) - 1)) ) { return false; } ksort($array); foreach ($array as &$item) { if (is_array($item)) { $this->sortJson($item); } } }
[ "private", "function", "sortJson", "(", "array", "&", "$", "array", ")", "{", "// check if array is not a hash table, because we only want to sort hash tables", "if", "(", "[", "]", "===", "$", "array", "||", "!", "(", "array_keys", "(", "$", "array", ")", "!==", ...
Sorts the json entries @param array $json
[ "Sorts", "the", "json", "entries" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Domain/Repository/StorageRepository.php#L474-L490
Gernott/mask
Classes/ViewHelpers/MultiuseViewHelper.php
MultiuseViewHelper.render
public function render() { $key = $this->arguments['key']; $elementKey = $this->arguments['elementKey']; $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); $type = $this->fieldHelper->getFieldType($key, $elementKey); return $this->fieldHelper->getElementsWhichUseField($key, $type); }
php
public function render() { $key = $this->arguments['key']; $elementKey = $this->arguments['elementKey']; $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); $type = $this->fieldHelper->getFieldType($key, $elementKey); return $this->fieldHelper->getElementsWhichUseField($key, $type); }
[ "public", "function", "render", "(", ")", "{", "$", "key", "=", "$", "this", "->", "arguments", "[", "'key'", "]", ";", "$", "elementKey", "=", "$", "this", "->", "arguments", "[", "'elementKey'", "]", ";", "$", "this", "->", "fieldHelper", "=", "\\"...
Returns all elements that use this field @return array elements in use @author Benjamin Butschell bb@webprofil.at>
[ "Returns", "all", "elements", "that", "use", "this", "field" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/MultiuseViewHelper.php#L39-L48
Gernott/mask
Classes/CodeGenerator/SqlCodeGenerator.php
SqlCodeGenerator.performDbUpdates
protected function performDbUpdates(array $sqlStatements) { /** @var ConnectionPool $connectionPool */ $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); $schemaMigrator = GeneralUtility::makeInstance(SchemaMigrator::class); $sqlUpdateSuggestions = $schemaMigrator->getUpdateSuggestions($sqlStatements); $hasErrors = false; foreach ($sqlUpdateSuggestions as $connectionName => $updateConnection) { $connection = $connectionPool->getConnectionByName($connectionName); foreach ($updateConnection as $updateStatements) { foreach ($updateStatements as $statement) { try { $connection->exec($statement); } catch (DBALException $exception) { $hasErrors = true; GeneralUtility::devlog( 'SQL error', 'mask', 0, [ 'statement' => $statement, 'error' => $exception->getMessage() ]); } } } } if ($hasErrors) { return [ 'error' => 'Database could not be updated. Please check it in the update wizard of the install tool' ]; } return ['success' => 'Database was successfully updated']; }
php
protected function performDbUpdates(array $sqlStatements) { /** @var ConnectionPool $connectionPool */ $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); $schemaMigrator = GeneralUtility::makeInstance(SchemaMigrator::class); $sqlUpdateSuggestions = $schemaMigrator->getUpdateSuggestions($sqlStatements); $hasErrors = false; foreach ($sqlUpdateSuggestions as $connectionName => $updateConnection) { $connection = $connectionPool->getConnectionByName($connectionName); foreach ($updateConnection as $updateStatements) { foreach ($updateStatements as $statement) { try { $connection->exec($statement); } catch (DBALException $exception) { $hasErrors = true; GeneralUtility::devlog( 'SQL error', 'mask', 0, [ 'statement' => $statement, 'error' => $exception->getMessage() ]); } } } } if ($hasErrors) { return [ 'error' => 'Database could not be updated. Please check it in the update wizard of the install tool' ]; } return ['success' => 'Database was successfully updated']; }
[ "protected", "function", "performDbUpdates", "(", "array", "$", "sqlStatements", ")", "{", "/** @var ConnectionPool $connectionPool */", "$", "connectionPool", "=", "GeneralUtility", "::", "makeInstance", "(", "ConnectionPool", "::", "class", ")", ";", "$", "schemaMigra...
Performs updates, adjusted function from extension_builder @param array $params @param string[] $sql @return array @throws DBALException @throws \Doctrine\DBAL\Schema\SchemaException @throws \TYPO3\CMS\Core\Database\Schema\Exception\StatementException @throws \TYPO3\CMS\Core\Database\Schema\Exception\UnexpectedSignalReturnValueTypeException @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
[ "Performs", "updates", "adjusted", "function", "from", "extension_builder" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/CodeGenerator/SqlCodeGenerator.php#L58-L95
Gernott/mask
Classes/CodeGenerator/SqlCodeGenerator.php
SqlCodeGenerator.updateDatabase
public function updateDatabase() { $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Repository\\StorageRepository'); $json = $storageRepository->load(); $sqlStatements = $this->getSqlByConfiguration($json); if (count($sqlStatements) > 0) { $response = $this->performDbUpdates($sqlStatements); } return $response; }
php
public function updateDatabase() { $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Repository\\StorageRepository'); $json = $storageRepository->load(); $sqlStatements = $this->getSqlByConfiguration($json); if (count($sqlStatements) > 0) { $response = $this->performDbUpdates($sqlStatements); } return $response; }
[ "public", "function", "updateDatabase", "(", ")", "{", "$", "storageRepository", "=", "\\", "TYPO3", "\\", "CMS", "\\", "Core", "\\", "Utility", "\\", "GeneralUtility", "::", "makeInstance", "(", "'MASK\\\\Mask\\\\Domain\\\\Repository\\\\StorageRepository'", ")", ";",...
Updates the database if necessary @author Benjamin Butschell <bb@webprofil.at> @return array
[ "Updates", "the", "database", "if", "necessary" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/CodeGenerator/SqlCodeGenerator.php#L103-L112
Gernott/mask
Classes/CodeGenerator/SqlCodeGenerator.php
SqlCodeGenerator.getSqlByConfiguration
public function getSqlByConfiguration($json) { $sql_content = array(); $types = array_keys($json); $nonIrreTables = array("pages", "tt_content"); $fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // Generate SQL-Statements if ($types) { foreach ($types as $type) { if ($json[$type]["sql"]) { // If type/table is an irre table, then create table for it if (array_search($type, $nonIrreTables) === false) { $sql_content[] = "CREATE TABLE " . $type . " ( uid int(11) NOT NULL auto_increment, pid int(11) DEFAULT '0' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, cruser_id int(11) unsigned DEFAULT '0' NOT NULL, deleted SMALLINT unsigned DEFAULT '0' NOT NULL, hidden SMALLINT unsigned DEFAULT '0' NOT NULL, starttime int(11) unsigned DEFAULT '0' NOT NULL, endtime int(11) unsigned DEFAULT '0' NOT NULL, t3ver_oid int(11) DEFAULT '0' NOT NULL, t3ver_id int(11) DEFAULT '0' NOT NULL, t3ver_wsid int(11) DEFAULT '0' NOT NULL, t3ver_label varchar(255) DEFAULT '' NOT NULL, t3ver_state SMALLINT DEFAULT '0' NOT NULL, t3ver_stage int(11) DEFAULT '0' NOT NULL, t3ver_count int(11) DEFAULT '0' NOT NULL, t3ver_tstamp int(11) DEFAULT '0' NOT NULL, t3ver_move_id int(11) DEFAULT '0' NOT NULL, sys_language_uid int(11) DEFAULT '0' NOT NULL, l10n_parent int(11) DEFAULT '0' NOT NULL, l10n_diffsource mediumblob, l10n_state text, PRIMARY KEY (uid), KEY parent (pid), KEY t3ver_oid (t3ver_oid,t3ver_wsid), KEY language (l10n_parent,sys_language_uid), parentid int(11) DEFAULT '0' NOT NULL, parenttable varchar(255) DEFAULT '', sorting int(11) DEFAULT '0' NOT NULL, );\n"; } foreach ($json[$type]["sql"] as $field) { if ($field) { foreach ($field as $table => $fields) { if ($fields) { foreach ($fields as $field => $definition) { $sql_content[] = "CREATE TABLE " . $table . " (\n\t" . $field . " " . $definition . "\n);\n"; // if this field is a content field, also add parent columns $fieldType = $fieldHelper->getFormType($field, "", $table); if ($fieldType == "Content") { $sql_content[] = "CREATE TABLE tt_content (\n\t" . $field . "_parent" . " " . $definition . "\n);\n"; } } } } } } } } } return $sql_content; }
php
public function getSqlByConfiguration($json) { $sql_content = array(); $types = array_keys($json); $nonIrreTables = array("pages", "tt_content"); $fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // Generate SQL-Statements if ($types) { foreach ($types as $type) { if ($json[$type]["sql"]) { // If type/table is an irre table, then create table for it if (array_search($type, $nonIrreTables) === false) { $sql_content[] = "CREATE TABLE " . $type . " ( uid int(11) NOT NULL auto_increment, pid int(11) DEFAULT '0' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, cruser_id int(11) unsigned DEFAULT '0' NOT NULL, deleted SMALLINT unsigned DEFAULT '0' NOT NULL, hidden SMALLINT unsigned DEFAULT '0' NOT NULL, starttime int(11) unsigned DEFAULT '0' NOT NULL, endtime int(11) unsigned DEFAULT '0' NOT NULL, t3ver_oid int(11) DEFAULT '0' NOT NULL, t3ver_id int(11) DEFAULT '0' NOT NULL, t3ver_wsid int(11) DEFAULT '0' NOT NULL, t3ver_label varchar(255) DEFAULT '' NOT NULL, t3ver_state SMALLINT DEFAULT '0' NOT NULL, t3ver_stage int(11) DEFAULT '0' NOT NULL, t3ver_count int(11) DEFAULT '0' NOT NULL, t3ver_tstamp int(11) DEFAULT '0' NOT NULL, t3ver_move_id int(11) DEFAULT '0' NOT NULL, sys_language_uid int(11) DEFAULT '0' NOT NULL, l10n_parent int(11) DEFAULT '0' NOT NULL, l10n_diffsource mediumblob, l10n_state text, PRIMARY KEY (uid), KEY parent (pid), KEY t3ver_oid (t3ver_oid,t3ver_wsid), KEY language (l10n_parent,sys_language_uid), parentid int(11) DEFAULT '0' NOT NULL, parenttable varchar(255) DEFAULT '', sorting int(11) DEFAULT '0' NOT NULL, );\n"; } foreach ($json[$type]["sql"] as $field) { if ($field) { foreach ($field as $table => $fields) { if ($fields) { foreach ($fields as $field => $definition) { $sql_content[] = "CREATE TABLE " . $table . " (\n\t" . $field . " " . $definition . "\n);\n"; // if this field is a content field, also add parent columns $fieldType = $fieldHelper->getFormType($field, "", $table); if ($fieldType == "Content") { $sql_content[] = "CREATE TABLE tt_content (\n\t" . $field . "_parent" . " " . $definition . "\n);\n"; } } } } } } } } } return $sql_content; }
[ "public", "function", "getSqlByConfiguration", "(", "$", "json", ")", "{", "$", "sql_content", "=", "array", "(", ")", ";", "$", "types", "=", "array_keys", "(", "$", "json", ")", ";", "$", "nonIrreTables", "=", "array", "(", "\"pages\"", ",", "\"tt_cont...
returns sql statements of all elements and pages and irre @param array $json @return string
[ "returns", "sql", "statements", "of", "all", "elements", "and", "pages", "and", "irre" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/CodeGenerator/SqlCodeGenerator.php#L119-L195
Gernott/mask
Classes/CodeGenerator/SqlCodeGenerator.php
SqlCodeGenerator.addDatabaseTablesDefinition
public function addDatabaseTablesDefinition(array $sqlString) { $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Repository\\StorageRepository'); $json = $storageRepository->load(); $sql = $this->getSqlByConfiguration($json); $mergedSqlString = array_merge($sqlString, $sql); return array('sqlString' => $mergedSqlString); }
php
public function addDatabaseTablesDefinition(array $sqlString) { $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Repository\\StorageRepository'); $json = $storageRepository->load(); $sql = $this->getSqlByConfiguration($json); $mergedSqlString = array_merge($sqlString, $sql); return array('sqlString' => $mergedSqlString); }
[ "public", "function", "addDatabaseTablesDefinition", "(", "array", "$", "sqlString", ")", "{", "$", "storageRepository", "=", "\\", "TYPO3", "\\", "CMS", "\\", "Core", "\\", "Utility", "\\", "GeneralUtility", "::", "makeInstance", "(", "'MASK\\\\Mask\\\\Domain\\\\Re...
Returns the SQL of all elements and merges it with already existing sql statements for the signal slot dispatcher @param array $sqlString @return array
[ "Returns", "the", "SQL", "of", "all", "elements", "and", "merges", "it", "with", "already", "existing", "sql", "statements", "for", "the", "signal", "slot", "dispatcher" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/CodeGenerator/SqlCodeGenerator.php#L204-L211
Gernott/mask
Classes/ViewHelpers/CTypesViewHelper.php
CTypesViewHelper.render
public function render() { $items = array(); $cTypes = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items']; if ($cTypes) { foreach ($cTypes as $type) { if ($type[1] !== "--div--") { if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($type[0], 'LLL:')) { $items[$type[1]] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($type[0], "mask") . " (" . $type[1] . ")"; } else { $items[$type[1]] = $type[0] . " (" . $type[1] . ")"; } } } return $items; } }
php
public function render() { $items = array(); $cTypes = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items']; if ($cTypes) { foreach ($cTypes as $type) { if ($type[1] !== "--div--") { if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($type[0], 'LLL:')) { $items[$type[1]] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($type[0], "mask") . " (" . $type[1] . ")"; } else { $items[$type[1]] = $type[0] . " (" . $type[1] . ")"; } } } return $items; } }
[ "public", "function", "render", "(", ")", "{", "$", "items", "=", "array", "(", ")", ";", "$", "cTypes", "=", "$", "GLOBALS", "[", "'TCA'", "]", "[", "'tt_content'", "]", "[", "'columns'", "]", "[", "'CType'", "]", "[", "'config'", "]", "[", "'item...
Returns an array with all content element cTypes @return array $items an array with all content element cTypes @author Benjamin Butschell <bb@webprofil.at>
[ "Returns", "an", "array", "with", "all", "content", "element", "cTypes" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/CTypesViewHelper.php#L26-L43
Gernott/mask
Classes/ViewHelpers/LabelViewHelper.php
LabelViewHelper.render
public function render(): string { $elementKey = $this->arguments['elementKey']; $fieldKey = $this->arguments['fieldKey']; $field = $this->arguments['field']; $table = $this->arguments['table']; $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // if we have the whole field configuration if ($field) { // check if this field is in an repeating field if ($field["inlineParent"]) { // if yes, the label is in the configuration $label = $field["label"]; } else { // otherwise the type can only be tt_content or pages if ($table) { // if we have table param, the type must be the table $type = $table; } else { // otherwise try to get the label, set param $excludeInlineFields to true $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, true); } $label = $this->fieldHelper->getLabel($elementKey, $fieldKey, $type); } } else { // if we don't have the field configuration, try the best to fetch the type and the correct label $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, false); $label = $this->fieldHelper->getLabel($elementKey, $fieldKey, $type); } return $label; }
php
public function render(): string { $elementKey = $this->arguments['elementKey']; $fieldKey = $this->arguments['fieldKey']; $field = $this->arguments['field']; $table = $this->arguments['table']; $this->fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper'); // if we have the whole field configuration if ($field) { // check if this field is in an repeating field if ($field["inlineParent"]) { // if yes, the label is in the configuration $label = $field["label"]; } else { // otherwise the type can only be tt_content or pages if ($table) { // if we have table param, the type must be the table $type = $table; } else { // otherwise try to get the label, set param $excludeInlineFields to true $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, true); } $label = $this->fieldHelper->getLabel($elementKey, $fieldKey, $type); } } else { // if we don't have the field configuration, try the best to fetch the type and the correct label $type = $this->fieldHelper->getFieldType($fieldKey, $elementKey, false); $label = $this->fieldHelper->getLabel($elementKey, $fieldKey, $type); } return $label; }
[ "public", "function", "render", "(", ")", ":", "string", "{", "$", "elementKey", "=", "$", "this", "->", "arguments", "[", "'elementKey'", "]", ";", "$", "fieldKey", "=", "$", "this", "->", "arguments", "[", "'fieldKey'", "]", ";", "$", "field", "=", ...
Returns the label of a field in an element
[ "Returns", "the", "label", "of", "a", "field", "in", "an", "element" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/LabelViewHelper.php#L38-L69
Gernott/mask
Classes/DataProcessing/MaskProcessor.php
MaskProcessor.process
public function process( ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData ) { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $this->inlineHelper = $objectManager->get(InlineHelper::class); $this->inlineHelper->addFilesToData($processedData['data'], "tt_content"); $this->inlineHelper->addIrreToData($processedData['data']); return $processedData; }
php
public function process( ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData ) { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $this->inlineHelper = $objectManager->get(InlineHelper::class); $this->inlineHelper->addFilesToData($processedData['data'], "tt_content"); $this->inlineHelper->addIrreToData($processedData['data']); return $processedData; }
[ "public", "function", "process", "(", "ContentObjectRenderer", "$", "cObj", ",", "array", "$", "contentObjectConfiguration", ",", "array", "$", "processorConfiguration", ",", "array", "$", "processedData", ")", "{", "$", "objectManager", "=", "GeneralUtility", "::",...
Process data of a record to add files and inline elements of mask fields @param ContentObjectRenderer $cObj The data of the content element or page @param array $contentObjectConfiguration The configuration of Content Object @param array $processorConfiguration The configuration of this processor @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) @return array the processed data as key/value store
[ "Process", "data", "of", "a", "record", "to", "add", "files", "and", "inline", "elements", "of", "mask", "fields" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/DataProcessing/MaskProcessor.php#L31-L43
Gernott/mask
Classes/Controller/WizardController.php
WizardController.generateAction
public function generateAction() { // Update Database $this->sqlCodeGenerator->updateDatabase(); // Clear system cache to force new TCA caching $cacheManager = GeneralUtility::makeInstance(CacheManager::class); $cacheManager->flushCachesInGroup('system'); }
php
public function generateAction() { // Update Database $this->sqlCodeGenerator->updateDatabase(); // Clear system cache to force new TCA caching $cacheManager = GeneralUtility::makeInstance(CacheManager::class); $cacheManager->flushCachesInGroup('system'); }
[ "public", "function", "generateAction", "(", ")", "{", "// Update Database", "$", "this", "->", "sqlCodeGenerator", "->", "updateDatabase", "(", ")", ";", "// Clear system cache to force new TCA caching", "$", "cacheManager", "=", "GeneralUtility", "::", "makeInstance", ...
Generates all the necessary files @author Gernot Ploiner <gp@webprofil.at> @author Benjamin Butschell <bb@webprofil.at> @todo clear typoscript cache after generating
[ "Generates", "all", "the", "necessary", "files" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L142-L150
Gernott/mask
Classes/Controller/WizardController.php
WizardController.prepareStorage
protected function prepareStorage(&$storage) { // Fill storage with additional data before assigning to view if ($storage["tca"]) { foreach ($storage["tca"] as $key => $field) { if (is_array($field)) { if ($field["config"]["type"] == "inline") { $storage["tca"][$key]["inlineFields"] = $this->storageRepository->loadInlineFields($key); uasort($storage["tca"][$key]["inlineFields"], function ($columnA, $columnB) { $a = isset($columnA['order']) ? (int)$columnA['order'] : 0; $b = isset($columnB['order']) ? (int)$columnB['order'] : 0; return $a - $b; }); } } } } }
php
protected function prepareStorage(&$storage) { // Fill storage with additional data before assigning to view if ($storage["tca"]) { foreach ($storage["tca"] as $key => $field) { if (is_array($field)) { if ($field["config"]["type"] == "inline") { $storage["tca"][$key]["inlineFields"] = $this->storageRepository->loadInlineFields($key); uasort($storage["tca"][$key]["inlineFields"], function ($columnA, $columnB) { $a = isset($columnA['order']) ? (int)$columnA['order'] : 0; $b = isset($columnB['order']) ? (int)$columnB['order'] : 0; return $a - $b; }); } } } } }
[ "protected", "function", "prepareStorage", "(", "&", "$", "storage", ")", "{", "// Fill storage with additional data before assigning to view", "if", "(", "$", "storage", "[", "\"tca\"", "]", ")", "{", "foreach", "(", "$", "storage", "[", "\"tca\"", "]", "as", "...
Prepares the storage array for fluid view @param array $storage @author Benjamin Butschell <bb@webprofil.at>
[ "Prepares", "the", "storage", "array", "for", "fluid", "view" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L158-L175
Gernott/mask
Classes/Controller/WizardController.php
WizardController.showHtmlAction
protected function showHtmlAction($key, $table) { $html = $this->htmlCodeGenerator->generateHtml($key, $table); $this->view->assign('html', $html); }
php
protected function showHtmlAction($key, $table) { $html = $this->htmlCodeGenerator->generateHtml($key, $table); $this->view->assign('html', $html); }
[ "protected", "function", "showHtmlAction", "(", "$", "key", ",", "$", "table", ")", "{", "$", "html", "=", "$", "this", "->", "htmlCodeGenerator", "->", "generateHtml", "(", "$", "key", ",", "$", "table", ")", ";", "$", "this", "->", "view", "->", "a...
Generates Fluid HTML for Contentelements @param string $key @param string $table @author Gernot Ploiner <gp@webprofil.at>
[ "Generates", "Fluid", "HTML", "for", "Contentelements" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L184-L188
Gernott/mask
Classes/Controller/WizardController.php
WizardController.saveHtml
protected function saveHtml($key, $html) { # fallback to prevent breaking change $path = MaskUtility::getTemplatePath($this->extSettings, $key); if (file_exists($path)) { return false; } GeneralUtility::writeFile($path, $html); return true; }
php
protected function saveHtml($key, $html) { # fallback to prevent breaking change $path = MaskUtility::getTemplatePath($this->extSettings, $key); if (file_exists($path)) { return false; } GeneralUtility::writeFile($path, $html); return true; }
[ "protected", "function", "saveHtml", "(", "$", "key", ",", "$", "html", ")", "{", "# fallback to prevent breaking change", "$", "path", "=", "MaskUtility", "::", "getTemplatePath", "(", "$", "this", "->", "extSettings", ",", "$", "key", ")", ";", "if", "(", ...
Saves Fluid HTML for Contentelements, if File not exists @param string $key @param string $html @author Gernot Ploiner <gp@webprofil.at>
[ "Saves", "Fluid", "HTML", "for", "Contentelements", "if", "File", "not", "exists" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L197-L206
Gernott/mask
Classes/Controller/WizardController.php
WizardController.checkFieldKey
public function checkFieldKey(ServerRequest $request, Response $response): Response { $queryParams = $request->getQueryParams(); $fieldKey = $queryParams['key']; $table = 'tt_content'; if (isset($queryParams['table'])) { $table = $queryParams['table']; } $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $storageRepository = $objectManager->get(StorageRepository::class); // check if fieldKey is available for this table $isAvailable = true; if ($storageRepository->loadField($table, $fieldKey)) { $isAvailable = false; } return new JsonResponse(['isAvailable' => $isAvailable]); }
php
public function checkFieldKey(ServerRequest $request, Response $response): Response { $queryParams = $request->getQueryParams(); $fieldKey = $queryParams['key']; $table = 'tt_content'; if (isset($queryParams['table'])) { $table = $queryParams['table']; } $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $storageRepository = $objectManager->get(StorageRepository::class); // check if fieldKey is available for this table $isAvailable = true; if ($storageRepository->loadField($table, $fieldKey)) { $isAvailable = false; } return new JsonResponse(['isAvailable' => $isAvailable]); }
[ "public", "function", "checkFieldKey", "(", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", ":", "Response", "{", "$", "queryParams", "=", "$", "request", "->", "getQueryParams", "(", ")", ";", "$", "fieldKey", "=", "$", "queryParams"...
Checks if a key for a field is available
[ "Checks", "if", "a", "key", "for", "a", "field", "is", "available" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L211-L230
Gernott/mask
Classes/Controller/WizardController.php
WizardController.checkElementKey
public function checkElementKey(ServerRequest $request, Response $response): Response { $elementKey = $request->getQueryParams()['key']; $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $storageRepository = $objectManager->get(StorageRepository::class); $isAvailable = true; if ($storageRepository->loadElement('tt_content', $elementKey)) { $isAvailable = false; } return new JsonResponse(['isAvailable' => $isAvailable]); }
php
public function checkElementKey(ServerRequest $request, Response $response): Response { $elementKey = $request->getQueryParams()['key']; $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $storageRepository = $objectManager->get(StorageRepository::class); $isAvailable = true; if ($storageRepository->loadElement('tt_content', $elementKey)) { $isAvailable = false; } return new JsonResponse(['isAvailable' => $isAvailable]); }
[ "public", "function", "checkElementKey", "(", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", ":", "Response", "{", "$", "elementKey", "=", "$", "request", "->", "getQueryParams", "(", ")", "[", "'key'", "]", ";", "$", "objectManager"...
Checks if a key for an element is available
[ "Checks", "if", "a", "key", "for", "an", "element", "is", "available" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L235-L248
Gernott/mask
Classes/Controller/WizardController.php
WizardController.redirectByAction
protected function redirectByAction() { $params = $this->request->getArguments(); $formAction = $params["formAction"]; $arguments = array(); if ($params["storage"]["type"] == "pages") { $arguments["layoutIdentifier"] = $this->backendLayoutRepository->findByIdentifier($params["storage"]["elements"]["key"], explode(",", $this->extSettings['backendlayout_pids']))->getIdentifier(); } else { $arguments["key"] = $params["storage"]["elements"]["key"]; $arguments["type"] = $params["storage"]["type"]; } if (key_exists("save", $formAction)) { $this->redirect('edit', null, null, $arguments); } else { if (key_exists("saveAndExit", $formAction)) { $this->redirect('list'); } } }
php
protected function redirectByAction() { $params = $this->request->getArguments(); $formAction = $params["formAction"]; $arguments = array(); if ($params["storage"]["type"] == "pages") { $arguments["layoutIdentifier"] = $this->backendLayoutRepository->findByIdentifier($params["storage"]["elements"]["key"], explode(",", $this->extSettings['backendlayout_pids']))->getIdentifier(); } else { $arguments["key"] = $params["storage"]["elements"]["key"]; $arguments["type"] = $params["storage"]["type"]; } if (key_exists("save", $formAction)) { $this->redirect('edit', null, null, $arguments); } else { if (key_exists("saveAndExit", $formAction)) { $this->redirect('list'); } } }
[ "protected", "function", "redirectByAction", "(", ")", "{", "$", "params", "=", "$", "this", "->", "request", "->", "getArguments", "(", ")", ";", "$", "formAction", "=", "$", "params", "[", "\"formAction\"", "]", ";", "$", "arguments", "=", "array", "("...
Redirects the request to the correct view @author Benjamin Butschell <bb@webprofil.at>
[ "Redirects", "the", "request", "to", "the", "correct", "view" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L254-L273
Gernott/mask
Classes/Controller/WizardController.php
WizardController.checkFolders
protected function checkFolders(): void { foreach (self::$folderPathKeys as $key) { $this->checkFolder($this->extSettings[$key], 'tx_mask.all.error.missingfolder'); } $this->checkFolder($this->extSettings['json'], 'tx_mask.all.error.missingjson'); }
php
protected function checkFolders(): void { foreach (self::$folderPathKeys as $key) { $this->checkFolder($this->extSettings[$key], 'tx_mask.all.error.missingfolder'); } $this->checkFolder($this->extSettings['json'], 'tx_mask.all.error.missingjson'); }
[ "protected", "function", "checkFolders", "(", ")", ":", "void", "{", "foreach", "(", "self", "::", "$", "folderPathKeys", "as", "$", "key", ")", "{", "$", "this", "->", "checkFolder", "(", "$", "this", "->", "extSettings", "[", "$", "key", "]", ",", ...
Check, if folders from extensionmanager-settings are existing @author Gernot Ploiner <gp@webprofil.at> @return void
[ "Check", "if", "folders", "from", "extensionmanager", "-", "settings", "are", "existing" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L281-L287
Gernott/mask
Classes/Controller/WizardController.php
WizardController.createMissingFolders
protected function createMissingFolders(): bool { $success = true; foreach (self::$folderPathKeys as $key) { $success = $success && $this->createFolder($this->extSettings[$key]); } $success = $success && $this->createFile($this->extSettings['json']); return $success; }
php
protected function createMissingFolders(): bool { $success = true; foreach (self::$folderPathKeys as $key) { $success = $success && $this->createFolder($this->extSettings[$key]); } $success = $success && $this->createFile($this->extSettings['json']); return $success; }
[ "protected", "function", "createMissingFolders", "(", ")", ":", "bool", "{", "$", "success", "=", "true", ";", "foreach", "(", "self", "::", "$", "folderPathKeys", "as", "$", "key", ")", "{", "$", "success", "=", "$", "success", "&&", "$", "this", "->"...
Creates missing folders that are needed for the use of mask @author Benjamin Butschell <bb@webprofil.at> @return bool $success
[ "Creates", "missing", "folders", "that", "are", "needed", "for", "the", "use", "of", "mask" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L294-L302
Gernott/mask
Classes/Controller/WizardController.php
WizardController.createMissingFoldersAction
public function createMissingFoldersAction(): void { if ($this->createMissingFolders()) { $this->addFlashMessage(LocalizationUtility::translate('tx_mask.all.createdmissingfolders', 'mask')); } $this->redirect('list'); }
php
public function createMissingFoldersAction(): void { if ($this->createMissingFolders()) { $this->addFlashMessage(LocalizationUtility::translate('tx_mask.all.createdmissingfolders', 'mask')); } $this->redirect('list'); }
[ "public", "function", "createMissingFoldersAction", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "createMissingFolders", "(", ")", ")", "{", "$", "this", "->", "addFlashMessage", "(", "LocalizationUtility", "::", "translate", "(", "'tx_mask.all.crea...
action creates missing folders @author Benjamin Butschell <bb@webprofil.at>
[ "action", "creates", "missing", "folders" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/Controller/WizardController.php#L308-L315
Gernott/mask
Classes/ViewHelpers/EditLinkViewHelper.php
EditLinkViewHelper.render
public function render() { $element = $this->arguments['element']; if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $element)) { $urlParameters = [ 'edit' => [ 'tt_content' => [ $element['uid'] => 'edit' ] ], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') ]; $uri = BackendUtility::getModuleUrl('record_edit', $urlParameters); $this->tag->addAttribute('href', $uri); } $this->tag->setContent($this->renderChildren()); $this->tag->forceClosingTag(true); return $this->tag->render(); }
php
public function render() { $element = $this->arguments['element']; if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $element)) { $urlParameters = [ 'edit' => [ 'tt_content' => [ $element['uid'] => 'edit' ] ], 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') ]; $uri = BackendUtility::getModuleUrl('record_edit', $urlParameters); $this->tag->addAttribute('href', $uri); } $this->tag->setContent($this->renderChildren()); $this->tag->forceClosingTag(true); return $this->tag->render(); }
[ "public", "function", "render", "(", ")", "{", "$", "element", "=", "$", "this", "->", "arguments", "[", "'element'", "]", ";", "if", "(", "$", "this", "->", "doEdit", "&&", "$", "this", "->", "getBackendUser", "(", ")", "->", "recordEditAccessInternals"...
returning a EditLink-Tag for TYPO3 Backend @param array $element @return mixed
[ "returning", "a", "EditLink", "-", "Tag", "for", "TYPO3", "Backend" ]
train
https://github.com/Gernott/mask/blob/21fd1814eaff4dfbfed34fbed64369918381c77a/Classes/ViewHelpers/EditLinkViewHelper.php#L40-L62
staudenmeir/dusk-updater
src/UpdateCommand.php
UpdateCommand.handle
public function handle() { $version = $this->version(); foreach (static::$slugs as $os => $slug) { $archive = $this->download($version, $slug); $binary = $this->extract($archive); $this->rename($binary, $os); } $message = "ChromeDriver binaries successfully updated to version %s."; $this->info(sprintf($message, $version)); }
php
public function handle() { $version = $this->version(); foreach (static::$slugs as $os => $slug) { $archive = $this->download($version, $slug); $binary = $this->extract($archive); $this->rename($binary, $os); } $message = "ChromeDriver binaries successfully updated to version %s."; $this->info(sprintf($message, $version)); }
[ "public", "function", "handle", "(", ")", "{", "$", "version", "=", "$", "this", "->", "version", "(", ")", ";", "foreach", "(", "static", "::", "$", "slugs", "as", "$", "os", "=>", "$", "slug", ")", "{", "$", "archive", "=", "$", "this", "->", ...
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/staudenmeir/dusk-updater/blob/a92b183070f4d37eedbd4a64465c7bda023aa1e2/src/UpdateCommand.php#L68-L83
staudenmeir/dusk-updater
src/UpdateCommand.php
UpdateCommand.version
protected function version() { $version = $this->argument('version'); if (!$version) { return $this->latestVersion(); } if (!ctype_digit($version)) { return $version; } $version = (int) $version; if ($version < 70) { return $this->legacyVersion($version); } $url = sprintf(static::$versionUrl, $version); return trim(file_get_contents($url)); }
php
protected function version() { $version = $this->argument('version'); if (!$version) { return $this->latestVersion(); } if (!ctype_digit($version)) { return $version; } $version = (int) $version; if ($version < 70) { return $this->legacyVersion($version); } $url = sprintf(static::$versionUrl, $version); return trim(file_get_contents($url)); }
[ "protected", "function", "version", "(", ")", "{", "$", "version", "=", "$", "this", "->", "argument", "(", "'version'", ")", ";", "if", "(", "!", "$", "version", ")", "{", "return", "$", "this", "->", "latestVersion", "(", ")", ";", "}", "if", "("...
Get the desired ChromeDriver version. @return string
[ "Get", "the", "desired", "ChromeDriver", "version", "." ]
train
https://github.com/staudenmeir/dusk-updater/blob/a92b183070f4d37eedbd4a64465c7bda023aa1e2/src/UpdateCommand.php#L90-L111
staudenmeir/dusk-updater
src/UpdateCommand.php
UpdateCommand.legacyVersion
protected function legacyVersion($version) { $legacy = file_get_contents(__DIR__.'/../resources/legacy.json'); $legacy = json_decode($legacy, true); return $legacy[$version]; }
php
protected function legacyVersion($version) { $legacy = file_get_contents(__DIR__.'/../resources/legacy.json'); $legacy = json_decode($legacy, true); return $legacy[$version]; }
[ "protected", "function", "legacyVersion", "(", "$", "version", ")", "{", "$", "legacy", "=", "file_get_contents", "(", "__DIR__", ".", "'/../resources/legacy.json'", ")", ";", "$", "legacy", "=", "json_decode", "(", "$", "legacy", ",", "true", ")", ";", "ret...
Get the ChromeDriver version for a legacy version of Chrome. @param int $version @return string
[ "Get", "the", "ChromeDriver", "version", "for", "a", "legacy", "version", "of", "Chrome", "." ]
train
https://github.com/staudenmeir/dusk-updater/blob/a92b183070f4d37eedbd4a64465c7bda023aa1e2/src/UpdateCommand.php#L133-L140
staudenmeir/dusk-updater
src/UpdateCommand.php
UpdateCommand.download
protected function download($version, $slug) { $archive = $this->directory.'chromedriver.zip'; $url = sprintf(static::$downloadUrl, $version, $slug); file_put_contents($archive, fopen($url, 'r')); return $archive; }
php
protected function download($version, $slug) { $archive = $this->directory.'chromedriver.zip'; $url = sprintf(static::$downloadUrl, $version, $slug); file_put_contents($archive, fopen($url, 'r')); return $archive; }
[ "protected", "function", "download", "(", "$", "version", ",", "$", "slug", ")", "{", "$", "archive", "=", "$", "this", "->", "directory", ".", "'chromedriver.zip'", ";", "$", "url", "=", "sprintf", "(", "static", "::", "$", "downloadUrl", ",", "$", "v...
Download the ChromeDriver archive. @param string $version @param string $slug @return string
[ "Download", "the", "ChromeDriver", "archive", "." ]
train
https://github.com/staudenmeir/dusk-updater/blob/a92b183070f4d37eedbd4a64465c7bda023aa1e2/src/UpdateCommand.php#L149-L158
chrisbjr/api-guard
database/migrations/2016_09_13_042808_create_api_keys_table.php
CreateApiKeysTable.up
public function up() { Schema::create('api_keys', function (Blueprint $table) { $table->increments('id'); $table->nullableMorphs('apikeyable'); $table->string('key', 50); $table->string('last_ip_address', 50)->nullable(); $table->dateTime('last_used_at')->nullable(); $table->nullableTimestamps(); $table->softDeletes(); $table->index('key'); }); }
php
public function up() { Schema::create('api_keys', function (Blueprint $table) { $table->increments('id'); $table->nullableMorphs('apikeyable'); $table->string('key', 50); $table->string('last_ip_address', 50)->nullable(); $table->dateTime('last_used_at')->nullable(); $table->nullableTimestamps(); $table->softDeletes(); $table->index('key'); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "create", "(", "'api_keys'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "'id'", ")", ";", "$", "table", "->", "nullableMorphs", "(", "'api...
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/database/migrations/2016_09_13_042808_create_api_keys_table.php#L14-L27
chrisbjr/api-guard
src/Models/ApiKey.php
ApiKey.make
public static function make($apikeyable) { $apiKey = new ApiKey([ 'key' => self::generateKey(), 'apikeyable_id' => $apikeyable->id, 'apikeyable_type' => get_class($apikeyable), 'last_ip_address' => Request::ip(), 'last_used_at' => Carbon::now(), ]); $apiKey->save(); return $apiKey; }
php
public static function make($apikeyable) { $apiKey = new ApiKey([ 'key' => self::generateKey(), 'apikeyable_id' => $apikeyable->id, 'apikeyable_type' => get_class($apikeyable), 'last_ip_address' => Request::ip(), 'last_used_at' => Carbon::now(), ]); $apiKey->save(); return $apiKey; }
[ "public", "static", "function", "make", "(", "$", "apikeyable", ")", "{", "$", "apiKey", "=", "new", "ApiKey", "(", "[", "'key'", "=>", "self", "::", "generateKey", "(", ")", ",", "'apikeyable_id'", "=>", "$", "apikeyable", "->", "id", ",", "'apikeyable_...
@param $apikeyable @return ApiKey
[ "@param", "$apikeyable" ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/src/Models/ApiKey.php#L35-L48
chrisbjr/api-guard
src/Models/ApiKey.php
ApiKey.generateKey
public static function generateKey() { do { $salt = sha1(time() . mt_rand()); $newKey = substr($salt, 0, 40); } // Already in the DB? Fail. Try again while (self::keyExists($newKey)); return $newKey; }
php
public static function generateKey() { do { $salt = sha1(time() . mt_rand()); $newKey = substr($salt, 0, 40); } // Already in the DB? Fail. Try again while (self::keyExists($newKey)); return $newKey; }
[ "public", "static", "function", "generateKey", "(", ")", "{", "do", "{", "$", "salt", "=", "sha1", "(", "time", "(", ")", ".", "mt_rand", "(", ")", ")", ";", "$", "newKey", "=", "substr", "(", "$", "salt", ",", "0", ",", "40", ")", ";", "}", ...
A sure method to generate a unique API key @return string
[ "A", "sure", "method", "to", "generate", "a", "unique", "API", "key" ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/src/Models/ApiKey.php#L55-L64
chrisbjr/api-guard
src/Models/ApiKey.php
ApiKey.keyExists
private static function keyExists($key) { $apiKeyCount = self::where('key', '=', $key)->limit(1)->count(); if ($apiKeyCount > 0) return true; return false; }
php
private static function keyExists($key) { $apiKeyCount = self::where('key', '=', $key)->limit(1)->count(); if ($apiKeyCount > 0) return true; return false; }
[ "private", "static", "function", "keyExists", "(", "$", "key", ")", "{", "$", "apiKeyCount", "=", "self", "::", "where", "(", "'key'", ",", "'='", ",", "$", "key", ")", "->", "limit", "(", "1", ")", "->", "count", "(", ")", ";", "if", "(", "$", ...
Checks whether a key exists in the database or not @param $key @return bool
[ "Checks", "whether", "a", "key", "exists", "in", "the", "database", "or", "not" ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/src/Models/ApiKey.php#L72-L79
chrisbjr/api-guard
src/Http/Middleware/AuthenticateApiKey.php
AuthenticateApiKey.handle
public function handle($request, Closure $next, $guard = null) { $apiKeyValue = $request->header(config('apiguard.header_key', 'X-Authorization')); $apiKey = app(config('apiguard.models.api_key', 'Chrisbjr\ApiGuard\Models\ApiKey'))->where('key', $apiKeyValue) ->first(); if (empty($apiKey)) { return $this->unauthorizedResponse(); } // Update this api key's last_used_at and last_ip_address $apiKey->update([ 'last_used_at' => Carbon::now(), 'last_ip_address' => $request->ip(), ]); $apikeyable = $apiKey->apikeyable; // Bind the user or object to the request // By doing this, we can now get the specified user through the request object in the controller using: // $request->user() $request->setUserResolver(function () use ($apikeyable) { return $apikeyable; }); // Attach the apikey object to the request $request->apiKey = $apiKey; event(new ApiKeyAuthenticated($request, $apiKey)); return $next($request); }
php
public function handle($request, Closure $next, $guard = null) { $apiKeyValue = $request->header(config('apiguard.header_key', 'X-Authorization')); $apiKey = app(config('apiguard.models.api_key', 'Chrisbjr\ApiGuard\Models\ApiKey'))->where('key', $apiKeyValue) ->first(); if (empty($apiKey)) { return $this->unauthorizedResponse(); } // Update this api key's last_used_at and last_ip_address $apiKey->update([ 'last_used_at' => Carbon::now(), 'last_ip_address' => $request->ip(), ]); $apikeyable = $apiKey->apikeyable; // Bind the user or object to the request // By doing this, we can now get the specified user through the request object in the controller using: // $request->user() $request->setUserResolver(function () use ($apikeyable) { return $apikeyable; }); // Attach the apikey object to the request $request->apiKey = $apiKey; event(new ApiKeyAuthenticated($request, $apiKey)); return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ",", "$", "guard", "=", "null", ")", "{", "$", "apiKeyValue", "=", "$", "request", "->", "header", "(", "config", "(", "'apiguard.header_key'", ",", "'X-Authorization'", ")",...
Handle an incoming request. @param \Illuminate\Http\Request $request @param Closure $next @param string|null $guard @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/src/Http/Middleware/AuthenticateApiKey.php#L20-L52
chrisbjr/api-guard
src/Console/Commands/GenerateApiKey.php
GenerateApiKey.handle
public function handle() { $apiKeyableId = $this->option('id'); $apiKeyableType = $this->option('type'); $apiKey = new ApiKey([ 'key' => ApiKey::generateKey(), 'apikeyable_id' => $apiKeyableId, 'apikeyable_type' => $apiKeyableType, ]); $apiKey->save(); $this->info('An API key was created with the following key: ' . $apiKey->key); return; }
php
public function handle() { $apiKeyableId = $this->option('id'); $apiKeyableType = $this->option('type'); $apiKey = new ApiKey([ 'key' => ApiKey::generateKey(), 'apikeyable_id' => $apiKeyableId, 'apikeyable_type' => $apiKeyableType, ]); $apiKey->save(); $this->info('An API key was created with the following key: ' . $apiKey->key); return; }
[ "public", "function", "handle", "(", ")", "{", "$", "apiKeyableId", "=", "$", "this", "->", "option", "(", "'id'", ")", ";", "$", "apiKeyableType", "=", "$", "this", "->", "option", "(", "'type'", ")", ";", "$", "apiKey", "=", "new", "ApiKey", "(", ...
Execute the console command. @return mixed
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/chrisbjr/api-guard/blob/61643eabdb5d4e1ec1b105a7dc142f4cceff1c33/src/Console/Commands/GenerateApiKey.php#L40-L56
luyadev/luya-module-cms
src/frontend/base/Controller.php
Controller.renderItem
public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false) { $model = NavItem::find()->where(['id' => $navItemId])->with(['nav'])->one(); if (!$model) { throw new NotFoundHttpException('The requested nav item could not found.'); } Yii::$app->urlManager->contextNavItemId = $navItemId; $currentMenu = Yii::$app->menu->current; $event = new BeforeRenderEvent(); $event->menu = $currentMenu; foreach ($model->nav->properties as $property) { $object = $property->getObject(); $object->trigger($object::EVENT_BEFORE_RENDER, $event); if (!$event->isValid) { throw new MethodNotAllowedHttpException('Your are not allowed to see this page.'); return Yii::$app->end(); } } if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) { $model->nav_item_type_id = $setNavItemTypeId; } $typeModel = $model->getType(); if (!$typeModel) { throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type."); } $typeModel->setOptions([ 'navItemId' => $navItemId, 'restString' => $appendix, ]); $content = $typeModel->getContent(); if ($content instanceof Response) { return Yii::$app->end(0, $content); } // it seems to be a json response as it is an array if (is_array($content)) { return $content; } // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed // as its already renderd by the module controller itself. if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) { $this->layout = false; } // If the user has defined a layout file, this will be ensured and set as layout file. $layoutFile = $model->nav->layout_file; if (!empty($layoutFile)) { $this->layout = StringHelper::startsWith($layoutFile, '@') ? $layoutFile : '/' . ltrim($layoutFile, '/'); } if ($this->view->title === null) { if (empty($model->title_tag)) { $this->view->title = $model->title; } else { $this->view->title = $model->title_tag; } } $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], self::META_OG_TYPE); $this->view->registerMetaTag(['name' => 'twitter:card', 'content' => 'summary'], self::META_TWITTER_CARD); $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], self::META_OG_TITLE); $this->view->registerMetaTag(['name' => 'twitter:title', 'content' => $this->view->title], self::META_TWITTER_TITLE); $this->view->registerLinkTag(['rel' => 'canonical', 'href' => Yii::$app->request->absoluteUrl], self::LINK_CANONICAL); $this->view->registerMetaTag(['name' => 'og:url', 'content' => Yii::$app->request->absoluteUrl], self::META_OG_URL); $this->view->registerMetaTag(['name' => 'twitter:url', 'content' => Yii::$app->request->absoluteUrl], self::META_TWITTER_URL); if (!empty($model->description)) { $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], self::META_DESCRIPTION); $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], self::META_OG_DESCRIPTION); $this->view->registerMetaTag(['name' => 'twitter:description', 'content' => $model->description], self::META_TWITTER_DESCRIPTION); } if (!empty($model->keywords)) { $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], self::META_KEYWORDS); } if (!empty($model->image_id)) { $image = Yii::$app->storage->getImage($model->image_id); if ($image) { $this->view->registerMetaTag(['name' => 'og:image', 'content' => $image->applyFilter(LargeThumbnail::identifier())->sourceAbsolute], self::META_OG_IMAGE); $this->view->registerMetaTag(['name' => 'twitter:image', 'content' => $image->applyFilter(LargeThumbnail::identifier())->sourceAbsolute], self::META_TWITTER_IMAGE); } } if ($this->module->enableTagParsing) { $content = TagParser::convert($content); } if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) { $this->view->registerCssFile('//fonts.googleapis.com/icon?family=Material+Icons'); $this->view->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]); } return $content; }
php
public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false) { $model = NavItem::find()->where(['id' => $navItemId])->with(['nav'])->one(); if (!$model) { throw new NotFoundHttpException('The requested nav item could not found.'); } Yii::$app->urlManager->contextNavItemId = $navItemId; $currentMenu = Yii::$app->menu->current; $event = new BeforeRenderEvent(); $event->menu = $currentMenu; foreach ($model->nav->properties as $property) { $object = $property->getObject(); $object->trigger($object::EVENT_BEFORE_RENDER, $event); if (!$event->isValid) { throw new MethodNotAllowedHttpException('Your are not allowed to see this page.'); return Yii::$app->end(); } } if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) { $model->nav_item_type_id = $setNavItemTypeId; } $typeModel = $model->getType(); if (!$typeModel) { throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type."); } $typeModel->setOptions([ 'navItemId' => $navItemId, 'restString' => $appendix, ]); $content = $typeModel->getContent(); if ($content instanceof Response) { return Yii::$app->end(0, $content); } // it seems to be a json response as it is an array if (is_array($content)) { return $content; } // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed // as its already renderd by the module controller itself. if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) { $this->layout = false; } // If the user has defined a layout file, this will be ensured and set as layout file. $layoutFile = $model->nav->layout_file; if (!empty($layoutFile)) { $this->layout = StringHelper::startsWith($layoutFile, '@') ? $layoutFile : '/' . ltrim($layoutFile, '/'); } if ($this->view->title === null) { if (empty($model->title_tag)) { $this->view->title = $model->title; } else { $this->view->title = $model->title_tag; } } $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], self::META_OG_TYPE); $this->view->registerMetaTag(['name' => 'twitter:card', 'content' => 'summary'], self::META_TWITTER_CARD); $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], self::META_OG_TITLE); $this->view->registerMetaTag(['name' => 'twitter:title', 'content' => $this->view->title], self::META_TWITTER_TITLE); $this->view->registerLinkTag(['rel' => 'canonical', 'href' => Yii::$app->request->absoluteUrl], self::LINK_CANONICAL); $this->view->registerMetaTag(['name' => 'og:url', 'content' => Yii::$app->request->absoluteUrl], self::META_OG_URL); $this->view->registerMetaTag(['name' => 'twitter:url', 'content' => Yii::$app->request->absoluteUrl], self::META_TWITTER_URL); if (!empty($model->description)) { $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], self::META_DESCRIPTION); $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], self::META_OG_DESCRIPTION); $this->view->registerMetaTag(['name' => 'twitter:description', 'content' => $model->description], self::META_TWITTER_DESCRIPTION); } if (!empty($model->keywords)) { $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], self::META_KEYWORDS); } if (!empty($model->image_id)) { $image = Yii::$app->storage->getImage($model->image_id); if ($image) { $this->view->registerMetaTag(['name' => 'og:image', 'content' => $image->applyFilter(LargeThumbnail::identifier())->sourceAbsolute], self::META_OG_IMAGE); $this->view->registerMetaTag(['name' => 'twitter:image', 'content' => $image->applyFilter(LargeThumbnail::identifier())->sourceAbsolute], self::META_TWITTER_IMAGE); } } if ($this->module->enableTagParsing) { $content = TagParser::convert($content); } if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) { $this->view->registerCssFile('//fonts.googleapis.com/icon?family=Material+Icons'); $this->view->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]); } return $content; }
[ "public", "function", "renderItem", "(", "$", "navItemId", ",", "$", "appendix", "=", "null", ",", "$", "setNavItemTypeId", "=", "false", ")", "{", "$", "model", "=", "NavItem", "::", "find", "(", ")", "->", "where", "(", "[", "'id'", "=>", "$", "nav...
Render the NavItem content and set several view specific data. @param integer $navItemId @param string $appendix @param boolean|integer $setNavItemTypeId To get the content of a version this parameter will change the database value from the nav item Model to this provided value @return string @throws NotFoundHttpException @throws MethodNotAllowedHttpException
[ "Render", "the", "NavItem", "content", "and", "set", "several", "view", "specific", "data", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/base/Controller.php#L115-L223
luyadev/luya-module-cms
src/frontend/base/Controller.php
Controller.renderToolbar
public function renderToolbar($event) { Yii::info('LUYA CMS Toolbar rendering start', __METHOD__); $props = []; foreach (Yii::$app->menu->current->model->properties as $prop) { $o = $prop->getObject(); $props[] = ['label' => $o->label(), 'value' => $o->getValue()]; } $menu = Yii::$app->menu; // seo keyword frequency $seoAlert = 0; $keywords = []; $content = strip_tags($event->data['content']); if (empty($menu->current->description)) { $seoAlert++; } if (empty($menu->current->keywords)) { $seoAlert++; } else { foreach ($menu->current->keywords as $word) { if (preg_match_all('/' . preg_quote($word, '/') . '/i', $content, $matches)) { $keywords[] = [$word, count($matches[0])]; } else { $keywords[] = [$word, 0]; $seoAlert++; } } } // As the view path can not evaluated from controller context, we have to force the viewPath trough // the module instance. // @see https://github.com/luyadev/luya/issues/1768 $viewSourcePath = Module::getInstance()->viewPath; // echo is used in order to support cases where asset manager is not available echo '<style>' . $this->view->renderFile($viewSourcePath . '/inline/toolbar.css') . '</style>'; // mabye ensure that jquery is loaded, better put this at the End of body tag echo '<script>' . $this->view->renderFile($viewSourcePath . '/inline/toolbar.js') . '</script>'; echo $this->view->renderFile($viewSourcePath . '/_toolbar.php', [ 'keywords' => $keywords, 'seoAlertCount' => $seoAlert, 'menu' => $menu, 'composition' => Yii::$app->composition, 'luyaTagParsing' => $event->sender->context->module->enableTagParsing, 'properties' => $props, 'content' => $content, ]); Yii::info('LUYA CMS Toolbar rendering is finished', __METHOD__); }
php
public function renderToolbar($event) { Yii::info('LUYA CMS Toolbar rendering start', __METHOD__); $props = []; foreach (Yii::$app->menu->current->model->properties as $prop) { $o = $prop->getObject(); $props[] = ['label' => $o->label(), 'value' => $o->getValue()]; } $menu = Yii::$app->menu; // seo keyword frequency $seoAlert = 0; $keywords = []; $content = strip_tags($event->data['content']); if (empty($menu->current->description)) { $seoAlert++; } if (empty($menu->current->keywords)) { $seoAlert++; } else { foreach ($menu->current->keywords as $word) { if (preg_match_all('/' . preg_quote($word, '/') . '/i', $content, $matches)) { $keywords[] = [$word, count($matches[0])]; } else { $keywords[] = [$word, 0]; $seoAlert++; } } } // As the view path can not evaluated from controller context, we have to force the viewPath trough // the module instance. // @see https://github.com/luyadev/luya/issues/1768 $viewSourcePath = Module::getInstance()->viewPath; // echo is used in order to support cases where asset manager is not available echo '<style>' . $this->view->renderFile($viewSourcePath . '/inline/toolbar.css') . '</style>'; // mabye ensure that jquery is loaded, better put this at the End of body tag echo '<script>' . $this->view->renderFile($viewSourcePath . '/inline/toolbar.js') . '</script>'; echo $this->view->renderFile($viewSourcePath . '/_toolbar.php', [ 'keywords' => $keywords, 'seoAlertCount' => $seoAlert, 'menu' => $menu, 'composition' => Yii::$app->composition, 'luyaTagParsing' => $event->sender->context->module->enableTagParsing, 'properties' => $props, 'content' => $content, ]); Yii::info('LUYA CMS Toolbar rendering is finished', __METHOD__); }
[ "public", "function", "renderToolbar", "(", "$", "event", ")", "{", "Yii", "::", "info", "(", "'LUYA CMS Toolbar rendering start'", ",", "__METHOD__", ")", ";", "$", "props", "=", "[", "]", ";", "foreach", "(", "Yii", "::", "$", "app", "->", "menu", "->"...
Render the LUYA Toolbar. @param \yii\base\Event $event
[ "Render", "the", "LUYA", "Toolbar", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/base/Controller.php#L230-L285
luyadev/luya-module-cms
src/admin/controllers/BlockController.php
BlockController.actionPreview
public function actionPreview($blockId) { $blockItem = Block::findOne($blockId); if (!$blockItem) { throw new NotFoundHttpException(); } /** @var $blockObject \luya\cms\base\InternalBaseBlock */ $blockObject = $blockItem->getObject('preview', 'admin-preview'); return $blockObject->renderAdminPreview(); }
php
public function actionPreview($blockId) { $blockItem = Block::findOne($blockId); if (!$blockItem) { throw new NotFoundHttpException(); } /** @var $blockObject \luya\cms\base\InternalBaseBlock */ $blockObject = $blockItem->getObject('preview', 'admin-preview'); return $blockObject->renderAdminPreview(); }
[ "public", "function", "actionPreview", "(", "$", "blockId", ")", "{", "$", "blockItem", "=", "Block", "::", "findOne", "(", "$", "blockId", ")", ";", "if", "(", "!", "$", "blockItem", ")", "{", "throw", "new", "NotFoundHttpException", "(", ")", ";", "}...
Generate the the block preview. @param int $blockId @return string @throws NotFoundHttpException @since 1.0.8
[ "Generate", "the", "the", "block", "preview", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/controllers/BlockController.php#L27-L38
luyadev/luya-module-cms
src/admin/apis/NavController.php
NavController.actionDeepPageCopyAsTemplate
public function actionDeepPageCopyAsTemplate() { $navId = (int) Yii::$app->request->getBodyParam('navId'); if (empty($navId)) { throw new InvalidCallException("navId can not be empty."); } $nav = Nav::findOne($navId); if (!$nav) { throw new InvalidCallException("Unable to find the requested model."); } $model = $nav->createCopy(true); foreach ($nav->navItems as $item) { $newItem = new NavItem(); $newItem->attributes = $item->toArray(); $newItem->nav_id = $model->id; $newItem->parent_nav_id = $model->parent_nav_id; $newItem->title = $item->title . ' (template copy)'; $newItem->alias = $item->alias . '-' . time(); if ($newItem->save() && !empty($newItem->nav_item_type_id)) { $item->copyTypeContent($newItem); } } return true; }
php
public function actionDeepPageCopyAsTemplate() { $navId = (int) Yii::$app->request->getBodyParam('navId'); if (empty($navId)) { throw new InvalidCallException("navId can not be empty."); } $nav = Nav::findOne($navId); if (!$nav) { throw new InvalidCallException("Unable to find the requested model."); } $model = $nav->createCopy(true); foreach ($nav->navItems as $item) { $newItem = new NavItem(); $newItem->attributes = $item->toArray(); $newItem->nav_id = $model->id; $newItem->parent_nav_id = $model->parent_nav_id; $newItem->title = $item->title . ' (template copy)'; $newItem->alias = $item->alias . '-' . time(); if ($newItem->save() && !empty($newItem->nav_item_type_id)) { $item->copyTypeContent($newItem); } } return true; }
[ "public", "function", "actionDeepPageCopyAsTemplate", "(", ")", "{", "$", "navId", "=", "(", "int", ")", "Yii", "::", "$", "app", "->", "request", "->", "getBodyParam", "(", "'navId'", ")", ";", "if", "(", "empty", "(", "$", "navId", ")", ")", "{", "...
Create a page template from a existing page. @return bool @since 1.0.6
[ "Create", "a", "page", "template", "from", "a", "existing", "page", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavController.php#L93-L121
luyadev/luya-module-cms
src/admin/apis/NavController.php
NavController.actionCreatePage
public function actionCreatePage() { $this->menuFlush(); $model = new Nav(); $fromDraft = $this->postArg('use_draft'); $parentNavId = $this->postArg('parent_nav_id'); $navContainerId = $this->postArg('nav_container_id'); if (!empty($parentNavId)) { $navContainerId = Nav::findOne($parentNavId)->nav_container_id; } if (!empty($fromDraft)) { $create = $model->createPageFromDraft($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('description'), $this->postArg('from_draft_id'), $this->postArg('is_draft')); } else { $create = $model->createPage($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('layout_id'), $this->postArg('description'), $this->postArg('is_draft')); } if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
php
public function actionCreatePage() { $this->menuFlush(); $model = new Nav(); $fromDraft = $this->postArg('use_draft'); $parentNavId = $this->postArg('parent_nav_id'); $navContainerId = $this->postArg('nav_container_id'); if (!empty($parentNavId)) { $navContainerId = Nav::findOne($parentNavId)->nav_container_id; } if (!empty($fromDraft)) { $create = $model->createPageFromDraft($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('description'), $this->postArg('from_draft_id'), $this->postArg('is_draft')); } else { $create = $model->createPage($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('layout_id'), $this->postArg('description'), $this->postArg('is_draft')); } if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
[ "public", "function", "actionCreatePage", "(", ")", "{", "$", "this", "->", "menuFlush", "(", ")", ";", "$", "model", "=", "new", "Nav", "(", ")", ";", "$", "fromDraft", "=", "$", "this", "->", "postArg", "(", "'use_draft'", ")", ";", "$", "parentNav...
Create a new nav entry for the type page (nav_id will be created. This methods is execute via post.
[ "Create", "a", "new", "nav", "entry", "for", "the", "type", "page", "(", "nav_id", "will", "be", "created", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavController.php#L293-L316
luyadev/luya-module-cms
src/admin/apis/NavController.php
NavController.actionCreatePageItem
public function actionCreatePageItem() { $this->menuFlush(); $model = new Nav(); $create = $model->createPageItem($this->postArg('nav_id'), $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('layout_id'), $this->postArg('description')); if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
php
public function actionCreatePageItem() { $this->menuFlush(); $model = new Nav(); $create = $model->createPageItem($this->postArg('nav_id'), $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('layout_id'), $this->postArg('description')); if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
[ "public", "function", "actionCreatePageItem", "(", ")", "{", "$", "this", "->", "menuFlush", "(", ")", ";", "$", "model", "=", "new", "Nav", "(", ")", ";", "$", "create", "=", "$", "model", "->", "createPageItem", "(", "$", "this", "->", "postArg", "...
creates a new nav_item entry for the type page (it means nav_id will be delivered).
[ "creates", "a", "new", "nav_item", "entry", "for", "the", "type", "page", "(", "it", "means", "nav_id", "will", "be", "delivered", ")", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavController.php#L321-L331
luyadev/luya-module-cms
src/admin/apis/NavController.php
NavController.actionCreateRedirect
public function actionCreateRedirect() { $this->menuFlush(); $model = new Nav(); $parentNavId = $this->postArg('parent_nav_id'); $navContainerId = $this->postArg('nav_container_id'); if (!empty($parentNavId)) { $navContainerId = Nav::findOne($parentNavId)->nav_container_id; } $redirect = $this->postArg('redirect'); $create = $model->createRedirect($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $redirect['type'], $redirect['value'], $this->postArg('description'), isset($redirect['target']) ? $redirect['target'] : null); if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
php
public function actionCreateRedirect() { $this->menuFlush(); $model = new Nav(); $parentNavId = $this->postArg('parent_nav_id'); $navContainerId = $this->postArg('nav_container_id'); if (!empty($parentNavId)) { $navContainerId = Nav::findOne($parentNavId)->nav_container_id; } $redirect = $this->postArg('redirect'); $create = $model->createRedirect($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $redirect['type'], $redirect['value'], $this->postArg('description'), isset($redirect['target']) ? $redirect['target'] : null); if (is_array($create)) { Yii::$app->response->statusCode = 422; } return $create; }
[ "public", "function", "actionCreateRedirect", "(", ")", "{", "$", "this", "->", "menuFlush", "(", ")", ";", "$", "model", "=", "new", "Nav", "(", ")", ";", "$", "parentNavId", "=", "$", "this", "->", "postArg", "(", "'parent_nav_id'", ")", ";", "$", ...
/* redirect
[ "/", "*", "redirect" ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavController.php#L367-L387
luyadev/luya-module-cms
src/admin/apis/NavController.php
NavController.actionCreateFromPage
public function actionCreateFromPage() { $this->menuFlush(); $model = new Nav(); $response = $model->createItemLanguageCopy($this->postArg('id'), $this->postArg('toLangId'), $this->postArg('title'), $this->postArg('alias')); if (is_array($response)) { return $this->sendArrayError($response); } return $response; }
php
public function actionCreateFromPage() { $this->menuFlush(); $model = new Nav(); $response = $model->createItemLanguageCopy($this->postArg('id'), $this->postArg('toLangId'), $this->postArg('title'), $this->postArg('alias')); if (is_array($response)) { return $this->sendArrayError($response); } return $response; }
[ "public", "function", "actionCreateFromPage", "(", ")", "{", "$", "this", "->", "menuFlush", "(", ")", ";", "$", "model", "=", "new", "Nav", "(", ")", ";", "$", "response", "=", "$", "model", "->", "createItemLanguageCopy", "(", "$", "this", "->", "pos...
Create a new page from another existing Page. @return boolean|array
[ "Create", "a", "new", "page", "from", "another", "existing", "Page", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavController.php#L407-L418
luyadev/luya-module-cms
src/widgets/NavTree.php
NavTree.buildList
private function buildList(QueryIteratorFilter $iterator, $i = 1) { // Abort if maxDepth is set & reached if ($this->maxDepth !== null && $i >= ($this->maxDepth + 1)) { return ""; } // Add the listDepthClassPrefix manually $listOptions = $this->listOptions; if (!isset($listOptions['class'])) { $listOptions['class'] = ""; } $listOptions['class'] .= " " . $this->listDepthClassPrefix . $i; // <ul> $html = ""; if ($this->ignoreFirstListTag && $i !== 1 || !$this->ignoreFirstListTag) { $html = Html::beginTag($this->_listTag, $listOptions); } foreach ($iterator as $item) { $itemOptions = $this->itemOptions; $linkOptions = array_merge($this->linkOptions, ['href' => $item->link]); // Set the active classes if item is active if ($item->isActive) { $itemOptions['class'] .= $this->itemActiveClass !== null ? ' ' . $this->itemActiveClass : ''; $linkOptions['class'] .= $this->linkActiveClass !== null ? ' ' . $this->linkActiveClass : ''; } // <li> $html .= Html::beginTag($this->_itemTag, $this->compileOption($item, $itemOptions)); // <a></a> $html .= Html::tag($this->_linkTag, $item->title, $this->compileOption($item, $linkOptions)); // Recursive iterate if item has Children if ($item->hasChildren) { $html .= $this->buildList($item->children, $i + 1); } // </li> $html .= Html::endTag($this->_itemTag); } if ($this->ignoreFirstListTag && $i !== 1 || !$this->ignoreFirstListTag) { // </ul> $html .= Html::endTag($this->_listTag); } return $html; }
php
private function buildList(QueryIteratorFilter $iterator, $i = 1) { // Abort if maxDepth is set & reached if ($this->maxDepth !== null && $i >= ($this->maxDepth + 1)) { return ""; } // Add the listDepthClassPrefix manually $listOptions = $this->listOptions; if (!isset($listOptions['class'])) { $listOptions['class'] = ""; } $listOptions['class'] .= " " . $this->listDepthClassPrefix . $i; // <ul> $html = ""; if ($this->ignoreFirstListTag && $i !== 1 || !$this->ignoreFirstListTag) { $html = Html::beginTag($this->_listTag, $listOptions); } foreach ($iterator as $item) { $itemOptions = $this->itemOptions; $linkOptions = array_merge($this->linkOptions, ['href' => $item->link]); // Set the active classes if item is active if ($item->isActive) { $itemOptions['class'] .= $this->itemActiveClass !== null ? ' ' . $this->itemActiveClass : ''; $linkOptions['class'] .= $this->linkActiveClass !== null ? ' ' . $this->linkActiveClass : ''; } // <li> $html .= Html::beginTag($this->_itemTag, $this->compileOption($item, $itemOptions)); // <a></a> $html .= Html::tag($this->_linkTag, $item->title, $this->compileOption($item, $linkOptions)); // Recursive iterate if item has Children if ($item->hasChildren) { $html .= $this->buildList($item->children, $i + 1); } // </li> $html .= Html::endTag($this->_itemTag); } if ($this->ignoreFirstListTag && $i !== 1 || !$this->ignoreFirstListTag) { // </ul> $html .= Html::endTag($this->_listTag); } return $html; }
[ "private", "function", "buildList", "(", "QueryIteratorFilter", "$", "iterator", ",", "$", "i", "=", "1", ")", "{", "// Abort if maxDepth is set & reached", "if", "(", "$", "this", "->", "maxDepth", "!==", "null", "&&", "$", "i", ">=", "(", "$", "this", "-...
Builds the list for the given Iterator and recursively calls itself to also generate the menu for all children @param QueryIteratorFilter $iterator The iterator used to build the list @param int $i The counter that is used to set the list depth @return string Part of the menu
[ "Builds", "the", "list", "for", "the", "given", "Iterator", "and", "recursively", "calls", "itself", "to", "also", "generate", "the", "menu", "for", "all", "children" ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/widgets/NavTree.php#L195-L249
luyadev/luya-module-cms
src/widgets/NavTree.php
NavTree.compileOption
private function compileOption(Item $item, array $options) { foreach ($options as $key => $option) { $options[$key] = preg_replace_callback('/{{([^}]*)}}/', function ($match) use ($item) { if ($item && $item->hasProperty($match[1])) { $f = $match[1]; return $item->$f; } return $match[1]; }, $option); } return $options; }
php
private function compileOption(Item $item, array $options) { foreach ($options as $key => $option) { $options[$key] = preg_replace_callback('/{{([^}]*)}}/', function ($match) use ($item) { if ($item && $item->hasProperty($match[1])) { $f = $match[1]; return $item->$f; } return $match[1]; }, $option); } return $options; }
[ "private", "function", "compileOption", "(", "Item", "$", "item", ",", "array", "$", "options", ")", "{", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "option", ")", "{", "$", "options", "[", "$", "key", "]", "=", "preg_replace_callback...
Replaces the placeholders, for example {{alias}}, with the value stored in $item If the placeholder name isn't found as a property, it will be returned (e.g. alias) @param Item|null $item @param array $options @return array
[ "Replaces", "the", "placeholders", "for", "example", "{{", "alias", "}}", "with", "the", "value", "stored", "in", "$item", "If", "the", "placeholder", "name", "isn", "t", "found", "as", "a", "property", "it", "will", "be", "returned", "(", "e", ".", "g",...
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/widgets/NavTree.php#L259-L273
luyadev/luya-module-cms
src/admin/importers/CmslayoutImporter.php
CmslayoutImporter.handleLayoutFile
protected function handleLayoutFile(&$layoutFiles, $path) { $aliased = Yii::getAlias($path, false); $filePath = $aliased ? $aliased : $path; if (is_dir($filePath)) { foreach ($this->getFilesFromFolder($filePath) as $file) { $handler = $this->importLayoutFile($file, $path); if ($handler) { $layoutFiles[] = $handler; } } } else { $handler = $this->importLayoutFile($filePath, $path); if ($handler) { $layoutFiles[] = $handler; } } }
php
protected function handleLayoutFile(&$layoutFiles, $path) { $aliased = Yii::getAlias($path, false); $filePath = $aliased ? $aliased : $path; if (is_dir($filePath)) { foreach ($this->getFilesFromFolder($filePath) as $file) { $handler = $this->importLayoutFile($file, $path); if ($handler) { $layoutFiles[] = $handler; } } } else { $handler = $this->importLayoutFile($filePath, $path); if ($handler) { $layoutFiles[] = $handler; } } }
[ "protected", "function", "handleLayoutFile", "(", "&", "$", "layoutFiles", ",", "$", "path", ")", "{", "$", "aliased", "=", "Yii", "::", "getAlias", "(", "$", "path", ",", "false", ")", ";", "$", "filePath", "=", "$", "aliased", "?", "$", "aliased", ...
Assigne saved files into the layoutFiles array defintion. @param array $layoutFiles @param string $path
[ "Assigne", "saved", "files", "into", "the", "layoutFiles", "array", "defintion", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/CmslayoutImporter.php#L59-L77
luyadev/luya-module-cms
src/admin/importers/CmslayoutImporter.php
CmslayoutImporter.getFilesFromFolder
protected function getFilesFromFolder($folderPath) { return FileHelper::findFiles($folderPath, [ 'recursive' => false, 'caseSensitive' => false, 'only' => ['*.php'], 'filter' => function ($path) { return in_array(substr(basename($path), 0, 1), $this->ignorePrefix) ? false : null; }]); }
php
protected function getFilesFromFolder($folderPath) { return FileHelper::findFiles($folderPath, [ 'recursive' => false, 'caseSensitive' => false, 'only' => ['*.php'], 'filter' => function ($path) { return in_array(substr(basename($path), 0, 1), $this->ignorePrefix) ? false : null; }]); }
[ "protected", "function", "getFilesFromFolder", "(", "$", "folderPath", ")", "{", "return", "FileHelper", "::", "findFiles", "(", "$", "folderPath", ",", "[", "'recursive'", "=>", "false", ",", "'caseSensitive'", "=>", "false", ",", "'only'", "=>", "[", "'*.php...
Get files from a given folder. @param string $folderPath @return array
[ "Get", "files", "from", "a", "given", "folder", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/CmslayoutImporter.php#L85-L94
luyadev/luya-module-cms
src/admin/importers/CmslayoutImporter.php
CmslayoutImporter.importLayoutFile
protected function importLayoutFile($file, $aliased) { if (!file_exists($file)) { return false; } $fileinfo = FileHelper::getFileInfo($file); $baseName = $fileinfo->name . '.' . $fileinfo->extension; $fileBaseName = $aliased . DIRECTORY_SEPARATOR . $baseName; $json = false; if (file_exists($fileinfo->sourceFilename. '.json')) { $json = FileHelper::getFileContent($fileinfo->sourceFilename. '.json'); try { if ($json) { $json = Json::decode($json); // the rows column defines the placeholders // if the rows column does not exists fail back to normal layout processing if (isset($json['rows'])) { $json = $json['rows']; } else { $json = false; } } } catch (\Exception $e) { $json = false; } } $readableFileName = $this->generateReadableName($fileinfo->name); $content = file_get_contents($file); preg_match_all("/placeholders\[[\'\"](.*?)[\'\"]\]/", $content, $results); if (!$json) { $placeholder = []; foreach (array_unique($results[1]) as $holderName) { if (!$this->isValidPlaceholderName($holderName)) { throw new Exception("Wrong variable name detected '".$holderName."'. Special chars are not allowed in placeholder variables, allowed chars are a-zA-Z0-9"); } $placeholder[] = ['label' => $this->generateReadableName($holderName), 'var' => $holderName]; } $_placeholders = ['placeholders' => [$placeholder]]; } else { $_placeholders = ['placeholders' => $json]; } $layoutItem = Layout::find()->where(['or', ['view_file' => $fileBaseName], ['view_file' => $baseName]])->one(); if ($layoutItem) { $match = $this->comparePlaceholders($_placeholders, json_decode($layoutItem->json_config, true)); $matchRevert = $this->comparePlaceholders(json_decode($layoutItem->json_config, true), $_placeholders); if ($match && $matchRevert) { $layoutItem->updateAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, ]); } else { $layoutItem->updateAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders), ]); $this->addLog('Existing file '.$readableFileName.' updated.'); } return $layoutItem->id; } // add item into the database table $data = new Layout(); $data->scenario = 'restcreate'; $data->setAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders), ]); $data->save(false); $this->addLog('New file '.$readableFileName.' found and registered.'); return $data->id; }
php
protected function importLayoutFile($file, $aliased) { if (!file_exists($file)) { return false; } $fileinfo = FileHelper::getFileInfo($file); $baseName = $fileinfo->name . '.' . $fileinfo->extension; $fileBaseName = $aliased . DIRECTORY_SEPARATOR . $baseName; $json = false; if (file_exists($fileinfo->sourceFilename. '.json')) { $json = FileHelper::getFileContent($fileinfo->sourceFilename. '.json'); try { if ($json) { $json = Json::decode($json); // the rows column defines the placeholders // if the rows column does not exists fail back to normal layout processing if (isset($json['rows'])) { $json = $json['rows']; } else { $json = false; } } } catch (\Exception $e) { $json = false; } } $readableFileName = $this->generateReadableName($fileinfo->name); $content = file_get_contents($file); preg_match_all("/placeholders\[[\'\"](.*?)[\'\"]\]/", $content, $results); if (!$json) { $placeholder = []; foreach (array_unique($results[1]) as $holderName) { if (!$this->isValidPlaceholderName($holderName)) { throw new Exception("Wrong variable name detected '".$holderName."'. Special chars are not allowed in placeholder variables, allowed chars are a-zA-Z0-9"); } $placeholder[] = ['label' => $this->generateReadableName($holderName), 'var' => $holderName]; } $_placeholders = ['placeholders' => [$placeholder]]; } else { $_placeholders = ['placeholders' => $json]; } $layoutItem = Layout::find()->where(['or', ['view_file' => $fileBaseName], ['view_file' => $baseName]])->one(); if ($layoutItem) { $match = $this->comparePlaceholders($_placeholders, json_decode($layoutItem->json_config, true)); $matchRevert = $this->comparePlaceholders(json_decode($layoutItem->json_config, true), $_placeholders); if ($match && $matchRevert) { $layoutItem->updateAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, ]); } else { $layoutItem->updateAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders), ]); $this->addLog('Existing file '.$readableFileName.' updated.'); } return $layoutItem->id; } // add item into the database table $data = new Layout(); $data->scenario = 'restcreate'; $data->setAttributes([ 'name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders), ]); $data->save(false); $this->addLog('New file '.$readableFileName.' found and registered.'); return $data->id; }
[ "protected", "function", "importLayoutFile", "(", "$", "file", ",", "$", "aliased", ")", "{", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "return", "false", ";", "}", "$", "fileinfo", "=", "FileHelper", "::", "getFileInfo", "(", "$"...
Importer the given layout file from a path. @param string $file The path to the layout file. @throws Exception @return string
[ "Importer", "the", "given", "layout", "file", "from", "a", "path", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/CmslayoutImporter.php#L102-L185
luyadev/luya-module-cms
src/admin/importers/CmslayoutImporter.php
CmslayoutImporter.comparePlaceholders
public function comparePlaceholders($array1, $array2) { if (!array_key_exists('placeholders', $array1) || !array_key_exists('placeholders', $array2)) { return false; } $a1 = $array1['placeholders']; $a2 = $array2['placeholders']; if (count($a1) !== count($a2)) { return false; } foreach ($a1 as $key => $holder) { if (!array_key_exists($key, $a2)) { return false; } foreach ($holder as $var => $value) { if ($var == "label") { continue; } if (!array_key_exists($var, $a2[$key])) { return false; } if ($value != $a2[$key][$var]) { return false; } } } return true; }
php
public function comparePlaceholders($array1, $array2) { if (!array_key_exists('placeholders', $array1) || !array_key_exists('placeholders', $array2)) { return false; } $a1 = $array1['placeholders']; $a2 = $array2['placeholders']; if (count($a1) !== count($a2)) { return false; } foreach ($a1 as $key => $holder) { if (!array_key_exists($key, $a2)) { return false; } foreach ($holder as $var => $value) { if ($var == "label") { continue; } if (!array_key_exists($var, $a2[$key])) { return false; } if ($value != $a2[$key][$var]) { return false; } } } return true; }
[ "public", "function", "comparePlaceholders", "(", "$", "array1", ",", "$", "array2", ")", "{", "if", "(", "!", "array_key_exists", "(", "'placeholders'", ",", "$", "array1", ")", "||", "!", "array_key_exists", "(", "'placeholders'", ",", "$", "array2", ")", ...
Compare two arrays with each in order to determined whether they have differences or not. An array must contain the keys `placeholders` otherwise false is returned too. @param array $array1 @param array $array2 @return bool true if the same, false if not the same
[ "Compare", "two", "arrays", "with", "each", "in", "order", "to", "determined", "whether", "they", "have", "differences", "or", "not", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/CmslayoutImporter.php#L222-L256
luyadev/luya-module-cms
src/LinkConverter.php
LinkConverter.fromArray
public static function fromArray(array $configuration) { $type = ArrayHelper::getValue($configuration, 'type'); $value = ArrayHelper::getValue($configuration, 'value'); $target = ArrayHelper::getValue($configuration, 'target'); if (empty($type)) { return false; } return (new self(['type' => $type, 'value' => $value, 'target' => $target])); }
php
public static function fromArray(array $configuration) { $type = ArrayHelper::getValue($configuration, 'type'); $value = ArrayHelper::getValue($configuration, 'value'); $target = ArrayHelper::getValue($configuration, 'target'); if (empty($type)) { return false; } return (new self(['type' => $type, 'value' => $value, 'target' => $target])); }
[ "public", "static", "function", "fromArray", "(", "array", "$", "configuration", ")", "{", "$", "type", "=", "ArrayHelper", "::", "getValue", "(", "$", "configuration", ",", "'type'", ")", ";", "$", "value", "=", "ArrayHelper", "::", "getValue", "(", "$", ...
Generate a link converter object from an array. If type is empty, false is returned. This allows us to have predefined values from value and target and do not throw an exception. @param array $configuration @return \luya\cms\LinkConverter|false
[ "Generate", "a", "link", "converter", "object", "from", "an", "array", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/LinkConverter.php#L102-L113
luyadev/luya-module-cms
src/LinkConverter.php
LinkConverter.getLink
public function getLink() { switch ($this->type) { // internal page case self::TYPE_INTERNAL_PAGE: return $this->getPageLink($this->value, $this->target); break; // external url case self::TYPE_EXTERNAL_URL: return $this->getWebsiteLink($this->value, $this->target); break; // file from storage case self::TYPE_LINK_TO_FILE: return $this->getFileLink($this->value, $this->target); break; // mailto link case self::TYPE_LINK_TO_EMAIL: return $this->getEmailLink($this->value); break; // tel link case self::TYPE_LINK_TO_TELEPHONE: return $this->getTelephoneLink($this->value); break; } return false; }
php
public function getLink() { switch ($this->type) { // internal page case self::TYPE_INTERNAL_PAGE: return $this->getPageLink($this->value, $this->target); break; // external url case self::TYPE_EXTERNAL_URL: return $this->getWebsiteLink($this->value, $this->target); break; // file from storage case self::TYPE_LINK_TO_FILE: return $this->getFileLink($this->value, $this->target); break; // mailto link case self::TYPE_LINK_TO_EMAIL: return $this->getEmailLink($this->value); break; // tel link case self::TYPE_LINK_TO_TELEPHONE: return $this->getTelephoneLink($this->value); break; } return false; }
[ "public", "function", "getLink", "(", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "// internal page", "case", "self", "::", "TYPE_INTERNAL_PAGE", ":", "return", "$", "this", "->", "getPageLink", "(", "$", "this", "->", "value", ",", "$"...
Get the {{luya\web\LinkInterface}} from the given configuration trough type. @return \luya\web\LinkInterface|boolean
[ "Get", "the", "{{", "luya", "\\", "web", "\\", "LinkInterface", "}}", "from", "the", "given", "configuration", "trough", "type", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/LinkConverter.php#L120-L151
luyadev/luya-module-cms
src/LinkConverter.php
LinkConverter.getFileLink
public function getFileLink($fileId, $target) { $file = Yii::$app->storage->getFile($fileId); if ($file) { $file->setTarget($target); } return $file; }
php
public function getFileLink($fileId, $target) { $file = Yii::$app->storage->getFile($fileId); if ($file) { $file->setTarget($target); } return $file; }
[ "public", "function", "getFileLink", "(", "$", "fileId", ",", "$", "target", ")", "{", "$", "file", "=", "Yii", "::", "$", "app", "->", "storage", "->", "getFile", "(", "$", "fileId", ")", ";", "if", "(", "$", "file", ")", "{", "$", "file", "->",...
Get a File Link Object. @param integer $fileId @param string $target @return \luya\admin\file\Item|boolean
[ "Get", "a", "File", "Link", "Object", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/LinkConverter.php#L172-L179
luyadev/luya-module-cms
src/LinkConverter.php
LinkConverter.getPageLink
public function getPageLink($navId, $target, $lang = null) { $linkQuery = Yii::$app->menu->find(); $linkQuery->where(['nav_id' => $navId]); $linkQuery->with(['hidden']); if ($lang) { $linkQuery->lang($lang); } $link = $linkQuery->one(); // if a page is found, set the target value from the config. if ($link) { $link->setTarget($target); } return $link; }
php
public function getPageLink($navId, $target, $lang = null) { $linkQuery = Yii::$app->menu->find(); $linkQuery->where(['nav_id' => $navId]); $linkQuery->with(['hidden']); if ($lang) { $linkQuery->lang($lang); } $link = $linkQuery->one(); // if a page is found, set the target value from the config. if ($link) { $link->setTarget($target); } return $link; }
[ "public", "function", "getPageLink", "(", "$", "navId", ",", "$", "target", ",", "$", "lang", "=", "null", ")", "{", "$", "linkQuery", "=", "Yii", "::", "$", "app", "->", "menu", "->", "find", "(", ")", ";", "$", "linkQuery", "->", "where", "(", ...
Get CMS Page Link Object. @param integer $navId @param string $target @param string $lang @return \luya\cms\menu\Item|boolean
[ "Get", "CMS", "Page", "Link", "Object", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/LinkConverter.php#L189-L205
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.getItem
public function getItem() { if ($this->_item === null) { $this->_item = Yii::$app->menu->find()->where(['id' => $this->childOf])->with('hidden')->one(); if (!$this->_item) { throw new Exception("Unable to find item with id " . $this->childOf); } } return $this->_item; }
php
public function getItem() { if ($this->_item === null) { $this->_item = Yii::$app->menu->find()->where(['id' => $this->childOf])->with('hidden')->one(); if (!$this->_item) { throw new Exception("Unable to find item with id " . $this->childOf); } } return $this->_item; }
[ "public", "function", "getItem", "(", ")", "{", "if", "(", "$", "this", "->", "_item", "===", "null", ")", "{", "$", "this", "->", "_item", "=", "Yii", "::", "$", "app", "->", "menu", "->", "find", "(", ")", "->", "where", "(", "[", "'id'", "=>...
Returns the evalutead menu item whether from the childOf property or set from the setter method. @return Item @throws Exception
[ "Returns", "the", "evalutead", "menu", "item", "whether", "from", "the", "childOf", "property", "or", "set", "from", "the", "setter", "method", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L105-L116
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.setItem
public function setItem(Item $item) { $this->childOf = $item->id; $this->_item = $item; return $this; }
php
public function setItem(Item $item) { $this->childOf = $item->id; $this->_item = $item; return $this; }
[ "public", "function", "setItem", "(", "Item", "$", "item", ")", "{", "$", "this", "->", "childOf", "=", "$", "item", "->", "id", ";", "$", "this", "->", "_item", "=", "$", "item", ";", "return", "$", "this", ";", "}" ]
Setter method for the item property. @param \luya\cms\menu\Item $item @return \luya\cms\menu\InjectItem
[ "Setter", "method", "for", "the", "item", "property", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L124-L130
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.getAlias
public function getAlias() { if ($this->_alias === null) { throw new Exception('The $alias property can not be null and must be set.'); } return $this->item->alias . '/' . $this->_alias; }
php
public function getAlias() { if ($this->_alias === null) { throw new Exception('The $alias property can not be null and must be set.'); } return $this->item->alias . '/' . $this->_alias; }
[ "public", "function", "getAlias", "(", ")", "{", "if", "(", "$", "this", "->", "_alias", "===", "null", ")", "{", "throw", "new", "Exception", "(", "'The $alias property can not be null and must be set.'", ")", ";", "}", "return", "$", "this", "->", "item", ...
Getter method for the alias. @return string The alias with the parent childOf alias prefixed. @throws Exception
[ "Getter", "method", "for", "the", "alias", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L181-L188
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.getLink
public function getLink() { return ($this->_link === null) ? Yii::$app->menu->buildItemLink($this->alias, $this->getLang()) : $this->_link; }
php
public function getLink() { return ($this->_link === null) ? Yii::$app->menu->buildItemLink($this->alias, $this->getLang()) : $this->_link; }
[ "public", "function", "getLink", "(", ")", "{", "return", "(", "$", "this", "->", "_link", "===", "null", ")", "?", "Yii", "::", "$", "app", "->", "menu", "->", "buildItemLink", "(", "$", "this", "->", "alias", ",", "$", "this", "->", "getLang", "(...
Getter method for the menu link. @return string The built link.
[ "Getter", "method", "for", "the", "menu", "link", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L210-L213
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.setTitle
public function setTitle($title) { // if the alias is empty use the title for the alias. if ($this->_alias === null) { $this->setAlias($title); } $this->_title = $title; return $this; }
php
public function setTitle($title) { // if the alias is empty use the title for the alias. if ($this->_alias === null) { $this->setAlias($title); } $this->_title = $title; return $this; }
[ "public", "function", "setTitle", "(", "$", "title", ")", "{", "// if the alias is empty use the title for the alias.", "if", "(", "$", "this", "->", "_alias", "===", "null", ")", "{", "$", "this", "->", "setAlias", "(", "$", "title", ")", ";", "}", "$", "...
Setter method for the menu title. @param string $title The menu item title. @return \luya\cms\menu\InjectItem
[ "Setter", "method", "for", "the", "menu", "title", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L223-L233
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.getLang
public function getLang() { if ($this->_lang === null) { $this->_lang = $this->item->lang; } return $this->_lang; }
php
public function getLang() { if ($this->_lang === null) { $this->_lang = $this->item->lang; } return $this->_lang; }
[ "public", "function", "getLang", "(", ")", "{", "if", "(", "$", "this", "->", "_lang", "===", "null", ")", "{", "$", "this", "->", "_lang", "=", "$", "this", "->", "item", "->", "lang", ";", "}", "return", "$", "this", "->", "_lang", ";", "}" ]
Returns the language from the childOf item. @return string
[ "Returns", "the", "language", "from", "the", "childOf", "item", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L304-L311
luyadev/luya-module-cms
src/menu/InjectItem.php
InjectItem.toArray
public function toArray() { return [ 'id' => $this->getId(), 'nav_id' => $this->getNavId(), 'lang' => $this->getLang(), 'link' => $this->getLink(), 'title' => Yii::$app->menu->encodeValue($this->title), 'title_tag' => Yii::$app->menu->encodeValue($this->title), 'alias' => $this->getAlias(), 'description' => Yii::$app->menu->encodeValue($this->description), 'keywords' => null, 'create_user_id' => $this->createUserId, 'update_user_id' => $this->updateUserId, 'timestamp_create' => $this->getTimestampCreate(), 'timestamp_update' => $this->getTimestampUpdate(), 'is_home' => $this->getIsHome(), 'parent_nav_id' => $this->getParentNavId(), 'sort_index' => $this->sortIndex, 'is_hidden' => (bool) $this->isHidden, 'type' => $this->getType(), 'redirect' => $this->getRedirect(), 'container' => $this->getContainer(), 'depth' => $this->getDept(), ]; }
php
public function toArray() { return [ 'id' => $this->getId(), 'nav_id' => $this->getNavId(), 'lang' => $this->getLang(), 'link' => $this->getLink(), 'title' => Yii::$app->menu->encodeValue($this->title), 'title_tag' => Yii::$app->menu->encodeValue($this->title), 'alias' => $this->getAlias(), 'description' => Yii::$app->menu->encodeValue($this->description), 'keywords' => null, 'create_user_id' => $this->createUserId, 'update_user_id' => $this->updateUserId, 'timestamp_create' => $this->getTimestampCreate(), 'timestamp_update' => $this->getTimestampUpdate(), 'is_home' => $this->getIsHome(), 'parent_nav_id' => $this->getParentNavId(), 'sort_index' => $this->sortIndex, 'is_hidden' => (bool) $this->isHidden, 'type' => $this->getType(), 'redirect' => $this->getRedirect(), 'container' => $this->getContainer(), 'depth' => $this->getDept(), ]; }
[ "public", "function", "toArray", "(", ")", "{", "return", "[", "'id'", "=>", "$", "this", "->", "getId", "(", ")", ",", "'nav_id'", "=>", "$", "this", "->", "getNavId", "(", ")", ",", "'lang'", "=>", "$", "this", "->", "getLang", "(", ")", ",", "...
Parse the injected item to an array. @return array
[ "Parse", "the", "injected", "item", "to", "an", "array", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/InjectItem.php#L439-L464
luyadev/luya-module-cms
src/models/Nav.php
Nav.getActiveLanguageItem
public function getActiveLanguageItem() { return $this->hasOne(NavItem::className(), ['nav_id' => 'id'])->andWhere(['lang_id' => Yii::$app->adminLanguage->activeId]); }
php
public function getActiveLanguageItem() { return $this->hasOne(NavItem::className(), ['nav_id' => 'id'])->andWhere(['lang_id' => Yii::$app->adminLanguage->activeId]); }
[ "public", "function", "getActiveLanguageItem", "(", ")", "{", "return", "$", "this", "->", "hasOne", "(", "NavItem", "::", "className", "(", ")", ",", "[", "'nav_id'", "=>", "'id'", "]", ")", "->", "andWhere", "(", "[", "'lang_id'", "=>", "Yii", "::", ...
Get the cms_nav_item for this nav object with the corresponding current active language id (based on the composition component). @return \luya\cms\models\NavItem The corresponding nav item object for the active language.
[ "Get", "the", "cms_nav_item", "for", "this", "nav", "object", "with", "the", "corresponding", "current", "active", "language", "id", "(", "based", "on", "the", "composition", "component", ")", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L80-L83
luyadev/luya-module-cms
src/models/Nav.php
Nav.hasGroupPermission
public function hasGroupPermission(Group $group) { $definitions = (new Query())->select("nav_id")->from("cms_nav_permission")->where(['group_id' => $group->id])->all(); // the group has no permission defined, this means he can access ALL cms pages if (count($definitions) == 0) { return true; } foreach ($definitions as $permission) { if ($this->id == $permission['nav_id']) { return true; } } return false; }
php
public function hasGroupPermission(Group $group) { $definitions = (new Query())->select("nav_id")->from("cms_nav_permission")->where(['group_id' => $group->id])->all(); // the group has no permission defined, this means he can access ALL cms pages if (count($definitions) == 0) { return true; } foreach ($definitions as $permission) { if ($this->id == $permission['nav_id']) { return true; } } return false; }
[ "public", "function", "hasGroupPermission", "(", "Group", "$", "group", ")", "{", "$", "definitions", "=", "(", "new", "Query", "(", ")", ")", "->", "select", "(", "\"nav_id\"", ")", "->", "from", "(", "\"cms_nav_permission\"", ")", "->", "where", "(", "...
See if a given group has perrmission for the current nav model. @param Group $group @return boolean
[ "See", "if", "a", "given", "group", "has", "perrmission", "for", "the", "current", "nav", "model", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L152-L168
luyadev/luya-module-cms
src/models/Nav.php
Nav.hasGroupPermissionSelected
public function hasGroupPermissionSelected(Group $group) { $definition = (new Query())->select("inheritance")->from("cms_nav_permission")->where(['group_id' => $group->id, 'nav_id' => $this->id])->one(); if ($definition) { return true; } return false; }
php
public function hasGroupPermissionSelected(Group $group) { $definition = (new Query())->select("inheritance")->from("cms_nav_permission")->where(['group_id' => $group->id, 'nav_id' => $this->id])->one(); if ($definition) { return true; } return false; }
[ "public", "function", "hasGroupPermissionSelected", "(", "Group", "$", "group", ")", "{", "$", "definition", "=", "(", "new", "Query", "(", ")", ")", "->", "select", "(", "\"inheritance\"", ")", "->", "from", "(", "\"cms_nav_permission\"", ")", "->", "where"...
See if the given group has permission to the current nav model. @param Group $group @return boolean
[ "See", "if", "the", "given", "group", "has", "permission", "to", "the", "current", "nav", "model", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L176-L185
luyadev/luya-module-cms
src/models/Nav.php
Nav.isGroupPermissionInheritNode
public function isGroupPermissionInheritNode(Group $group) { $definition = (new Query())->select("inheritance")->from("cms_nav_permission")->where(['group_id' => $group->id, 'nav_id' => $this->id])->one(); if ($definition) { return (bool) $definition['inheritance']; } return false; }
php
public function isGroupPermissionInheritNode(Group $group) { $definition = (new Query())->select("inheritance")->from("cms_nav_permission")->where(['group_id' => $group->id, 'nav_id' => $this->id])->one(); if ($definition) { return (bool) $definition['inheritance']; } return false; }
[ "public", "function", "isGroupPermissionInheritNode", "(", "Group", "$", "group", ")", "{", "$", "definition", "=", "(", "new", "Query", "(", ")", ")", "->", "select", "(", "\"inheritance\"", ")", "->", "from", "(", "\"cms_nav_permission\"", ")", "->", "wher...
See if a given group has inherited permission to the current nav model. @param Group $group @return boolean
[ "See", "if", "a", "given", "group", "has", "inherited", "permission", "to", "the", "current", "nav", "model", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L193-L202
luyadev/luya-module-cms
src/models/Nav.php
Nav.eventBeforeInsert
public function eventBeforeInsert() { $item = self::find()->where([ 'nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id ])->orderBy('sort_index DESC')->limit(1)->asArray()->one(); if (!$item) { $this->sort_index = 1; } else { $this->sort_index = $item['sort_index'] + 1; } }
php
public function eventBeforeInsert() { $item = self::find()->where([ 'nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id ])->orderBy('sort_index DESC')->limit(1)->asArray()->one(); if (!$item) { $this->sort_index = 1; } else { $this->sort_index = $item['sort_index'] + 1; } }
[ "public", "function", "eventBeforeInsert", "(", ")", "{", "$", "item", "=", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'nav_container_id'", "=>", "$", "this", "->", "nav_container_id", ",", "'parent_nav_id'", "=>", "$", "this", "->", "parent...
find the latest sort index cms_nav item for the current nav_container_id and parent_nav_id and set internal index count plus one.
[ "find", "the", "latest", "sort", "index", "cms_nav", "item", "for", "the", "current", "nav_container_id", "and", "parent_nav_id", "and", "set", "internal", "index", "count", "plus", "one", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L207-L218
luyadev/luya-module-cms
src/models/Nav.php
Nav.reindex
public function reindex($e) { $i = 1; foreach (self::find()->where([ 'nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id ])->orderBy('sort_index ASC')->asArray()->all() as $model) { Yii::$app->db->createCommand()->update( self::tableName(), ['sort_index' => $i], 'id=:id', ['id' => $model['id']] )->execute(); ++$i; } switch ($e->name) { case 'afterInsert': Log::add(1, ['tableName' => 'cms_nav', 'action' => 'insert', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterUpdate': Log::add(2, ['tableName' => 'cms_nav', 'action' => 'update', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterDelete': Log::add(3, ['tableName' => 'cms_nav', 'action' => 'delete', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; } }
php
public function reindex($e) { $i = 1; foreach (self::find()->where([ 'nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id ])->orderBy('sort_index ASC')->asArray()->all() as $model) { Yii::$app->db->createCommand()->update( self::tableName(), ['sort_index' => $i], 'id=:id', ['id' => $model['id']] )->execute(); ++$i; } switch ($e->name) { case 'afterInsert': Log::add(1, ['tableName' => 'cms_nav', 'action' => 'insert', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterUpdate': Log::add(2, ['tableName' => 'cms_nav', 'action' => 'update', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; case 'afterDelete': Log::add(3, ['tableName' => 'cms_nav', 'action' => 'delete', 'row' => $this->id], 'cms_nav', $this->id, $this->toArray()); break; } }
[ "public", "function", "reindex", "(", "$", "e", ")", "{", "$", "i", "=", "1", ";", "foreach", "(", "self", "::", "find", "(", ")", "->", "where", "(", "[", "'nav_container_id'", "=>", "$", "this", "->", "nav_container_id", ",", "'parent_nav_id'", "=>",...
Rindex the current pages. @param \yii\base\Event $e
[ "Rindex", "the", "current", "pages", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L225-L252
luyadev/luya-module-cms
src/models/Nav.php
Nav.moveToContainer
public static function moveToContainer($moveNavId, $toCatId) { $move = self::findOne($moveNavId); $move->nav_container_id = $toCatId; $move->parent_nav_id = 0; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $toCatId]); } return true; }
php
public static function moveToContainer($moveNavId, $toCatId) { $move = self::findOne($moveNavId); $move->nav_container_id = $toCatId; $move->parent_nav_id = 0; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $toCatId]); } return true; }
[ "public", "static", "function", "moveToContainer", "(", "$", "moveNavId", ",", "$", "toCatId", ")", "{", "$", "move", "=", "self", "::", "findOne", "(", "$", "moveNavId", ")", ";", "$", "move", "->", "nav_container_id", "=", "$", "toCatId", ";", "$", "...
Move a nav model to a container. @param integer $moveNavId @param integer $toCatId @return boolean
[ "Move", "a", "nav", "model", "to", "a", "container", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L284-L297
luyadev/luya-module-cms
src/models/Nav.php
Nav.checkDuplicateAlias
public static function checkDuplicateAlias($currentNavId, $parentNavId) { $currentNavItems = NavItem::find()->where(['nav_id' => $currentNavId])->asArray()->all(); foreach (self::find()->where(['parent_nav_id' => $parentNavId, 'is_deleted' => false])->andWhere(['<>', 'id', $currentNavId])->asArray()->all() as $item) { foreach ($currentNavItems as $currentNavItem) { $itemNavItem = NavItem::find()->asArray()->where(['nav_id' => $item['id'], 'lang_id' => $currentNavItem['lang_id']])->one(); if ($itemNavItem && $currentNavItem['alias'] == $itemNavItem['alias']) { return $itemNavItem; } } } return true; }
php
public static function checkDuplicateAlias($currentNavId, $parentNavId) { $currentNavItems = NavItem::find()->where(['nav_id' => $currentNavId])->asArray()->all(); foreach (self::find()->where(['parent_nav_id' => $parentNavId, 'is_deleted' => false])->andWhere(['<>', 'id', $currentNavId])->asArray()->all() as $item) { foreach ($currentNavItems as $currentNavItem) { $itemNavItem = NavItem::find()->asArray()->where(['nav_id' => $item['id'], 'lang_id' => $currentNavItem['lang_id']])->one(); if ($itemNavItem && $currentNavItem['alias'] == $itemNavItem['alias']) { return $itemNavItem; } } } return true; }
[ "public", "static", "function", "checkDuplicateAlias", "(", "$", "currentNavId", ",", "$", "parentNavId", ")", "{", "$", "currentNavItems", "=", "NavItem", "::", "find", "(", ")", "->", "where", "(", "[", "'nav_id'", "=>", "$", "currentNavId", "]", ")", "-...
Check for duplicate alias in same parent_nav_id context of targetNav, comparing with currentNav item. Additional this checks for matching language contexts when comparing aliases. @param $currentNavId @param $parentNavId @return boolean|mixed returns `true` if no duplication has been found, otherwhise returns an array with the duplicated existing item.
[ "Check", "for", "duplicate", "alias", "in", "same", "parent_nav_id", "context", "of", "targetNav", "comparing", "with", "currentNav", "item", ".", "Additional", "this", "checks", "for", "matching", "language", "contexts", "when", "comparing", "aliases", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L307-L319
luyadev/luya-module-cms
src/models/Nav.php
Nav.moveToBefore
public static function moveToBefore($moveNavId, $toBeforeNavId) { $move = self::findOne($moveNavId); $to = self::findOne($toBeforeNavId); if (!$move || !$to) { return false; } $response = self::checkDuplicateAlias($move->id, $to->parent_nav_id); if ($response !== true) { return $response; } $to->moveUpstairs(); $move->nav_container_id = $to->nav_container_id; $move->parent_nav_id = $to->parent_nav_id; $move->sort_index = $to->sort_index; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $to->nav_container_id]); } return true; }
php
public static function moveToBefore($moveNavId, $toBeforeNavId) { $move = self::findOne($moveNavId); $to = self::findOne($toBeforeNavId); if (!$move || !$to) { return false; } $response = self::checkDuplicateAlias($move->id, $to->parent_nav_id); if ($response !== true) { return $response; } $to->moveUpstairs(); $move->nav_container_id = $to->nav_container_id; $move->parent_nav_id = $to->parent_nav_id; $move->sort_index = $to->sort_index; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $to->nav_container_id]); } return true; }
[ "public", "static", "function", "moveToBefore", "(", "$", "moveNavId", ",", "$", "toBeforeNavId", ")", "{", "$", "move", "=", "self", "::", "findOne", "(", "$", "moveNavId", ")", ";", "$", "to", "=", "self", "::", "findOne", "(", "$", "toBeforeNavId", ...
Move a nav model before another nav model. @param integer $moveNavId @param integer $toBeforeNavId @return boolean|boolean|mixed
[ "Move", "a", "nav", "model", "before", "another", "nav", "model", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L328-L355
luyadev/luya-module-cms
src/models/Nav.php
Nav.moveToChild
public static function moveToChild($moveNavId, $droppedOnItemId) { $move = self::findOne($moveNavId); $on = self::findOne($droppedOnItemId); if (!$move || !$on) { return false; } $response = self::checkDuplicateAlias($move->id, $on->id); if ($response !== true) { return $response; } $move->nav_container_id = $on->nav_container_id; $move->parent_nav_id = $on->id; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $on->nav_container_id]); } return true; }
php
public static function moveToChild($moveNavId, $droppedOnItemId) { $move = self::findOne($moveNavId); $on = self::findOne($droppedOnItemId); if (!$move || !$on) { return false; } $response = self::checkDuplicateAlias($move->id, $on->id); if ($response !== true) { return $response; } $move->nav_container_id = $on->nav_container_id; $move->parent_nav_id = $on->id; $move->update(); foreach ($move->getRecursiveChildren() as $child) { $child->updateAttributes(['nav_container_id' => $on->nav_container_id]); } return true; }
[ "public", "static", "function", "moveToChild", "(", "$", "moveNavId", ",", "$", "droppedOnItemId", ")", "{", "$", "move", "=", "self", "::", "findOne", "(", "$", "moveNavId", ")", ";", "$", "on", "=", "self", "::", "findOne", "(", "$", "droppedOnItemId",...
Move a nav model to a child. @param integer $moveNavId @param integer $droppedOnItemId @return boolean|boolean|mixed
[ "Move", "a", "nav", "model", "to", "a", "child", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L399-L423
luyadev/luya-module-cms
src/models/Nav.php
Nav.moveUpstairs
public function moveUpstairs($withCurrentElement = true) { $operator = $withCurrentElement ? '>=' : '>'; $startIndex = $withCurrentElement ? (int) $this->sort_index : (int) $this->sort_index + 1; foreach (self::find()->where('sort_index '.$operator.' :index', ['index' => (int) $this->sort_index])->andWhere(['nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id])->orderBy('sort_index ASC')->asArray()->all() as $item) { ++$startIndex; Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $startIndex], 'id=:id', ['id' => $item['id']])->execute(); } }
php
public function moveUpstairs($withCurrentElement = true) { $operator = $withCurrentElement ? '>=' : '>'; $startIndex = $withCurrentElement ? (int) $this->sort_index : (int) $this->sort_index + 1; foreach (self::find()->where('sort_index '.$operator.' :index', ['index' => (int) $this->sort_index])->andWhere(['nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id])->orderBy('sort_index ASC')->asArray()->all() as $item) { ++$startIndex; Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $startIndex], 'id=:id', ['id' => $item['id']])->execute(); } }
[ "public", "function", "moveUpstairs", "(", "$", "withCurrentElement", "=", "true", ")", "{", "$", "operator", "=", "$", "withCurrentElement", "?", "'>='", ":", "'>'", ";", "$", "startIndex", "=", "$", "withCurrentElement", "?", "(", "int", ")", "$", "this"...
Raise the sort_index value for all elements where the current sort index is larger or equal. id|sort_index -------- 1|0 2|1 3|2 4|3 apply moveUpstairs() to id 2 would produce the following output: id|sort_index 1|0 2|2 3|3 4|4 if you disabled $withCurrentElement the output would be: id|sort_index 1|0 2|1 3|3 4|4 @param $withCurrentElement boolean Whether the current element should be moved along with the others or not.
[ "Raise", "the", "sort_index", "value", "for", "all", "elements", "where", "the", "current", "sort", "index", "is", "larger", "or", "equal", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L453-L461
luyadev/luya-module-cms
src/models/Nav.php
Nav.moveDownstairs
public function moveDownstairs() { $startIndex = (int)$this->sort_index; foreach (self::find()->where('sort_index >= :index', ['index' => $startIndex])->andWhere(['nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id])->orderBy('sort_index ASC')->asArray()->all() as $item) { --$startIndex; Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $startIndex], 'id=:id', ['id' => $item['id']])->execute(); } }
php
public function moveDownstairs() { $startIndex = (int)$this->sort_index; foreach (self::find()->where('sort_index >= :index', ['index' => $startIndex])->andWhere(['nav_container_id' => $this->nav_container_id, 'parent_nav_id' => $this->parent_nav_id])->orderBy('sort_index ASC')->asArray()->all() as $item) { --$startIndex; Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $startIndex], 'id=:id', ['id' => $item['id']])->execute(); } }
[ "public", "function", "moveDownstairs", "(", ")", "{", "$", "startIndex", "=", "(", "int", ")", "$", "this", "->", "sort_index", ";", "foreach", "(", "self", "::", "find", "(", ")", "->", "where", "(", "'sort_index >= :index'", ",", "[", "'index'", "=>",...
Reduces the sort_index value for all elements where the current sort index is larger or equal. id|index -------- 1|0 2|1 3|2 4|3 apply moveDownstairs() to id 2 would produce the following output: id|index 1|0 2|0 3|1 4|2 > This method is therefore only usefull when you want to push the latest item upstairs.
[ "Reduces", "the", "sort_index", "value", "for", "all", "elements", "where", "the", "current", "sort", "index", "is", "larger", "or", "equal", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L483-L490
luyadev/luya-module-cms
src/models/Nav.php
Nav.createItemLanguageCopy
public function createItemLanguageCopy($navItemId, $langId, $title, $alias) { $sourceNavItem = NavItem::findOne($navItemId); if (!$sourceNavItem) { return ['id' => ["Unable to find nav item id {$navItemId}"]]; } if (NavItem::find()->where(['nav_id' => $sourceNavItem->nav_id, 'lang_id' => $langId])->exists()) { return ['lang_id' => ["A translation for the given page already exists."]]; } $navItem = new NavItem(); $navItem->attributes = $sourceNavItem->toArray(); $navItem->title = $title; $navItem->alias = $alias; $navItem->lang_id = $langId; $navItem->setParentFromModel(); if (!$navItem->save()) { return $navItem->getErrors(); } // we have created the copy, but its seems like no version existis for the original to copy page, // so we can not copy any content, lets return true and skip copy process. if (empty($sourceNavItem->nav_item_type_id)) { return true; } return $sourceNavItem->copyTypeContent($navItem); }
php
public function createItemLanguageCopy($navItemId, $langId, $title, $alias) { $sourceNavItem = NavItem::findOne($navItemId); if (!$sourceNavItem) { return ['id' => ["Unable to find nav item id {$navItemId}"]]; } if (NavItem::find()->where(['nav_id' => $sourceNavItem->nav_id, 'lang_id' => $langId])->exists()) { return ['lang_id' => ["A translation for the given page already exists."]]; } $navItem = new NavItem(); $navItem->attributes = $sourceNavItem->toArray(); $navItem->title = $title; $navItem->alias = $alias; $navItem->lang_id = $langId; $navItem->setParentFromModel(); if (!$navItem->save()) { return $navItem->getErrors(); } // we have created the copy, but its seems like no version existis for the original to copy page, // so we can not copy any content, lets return true and skip copy process. if (empty($sourceNavItem->nav_item_type_id)) { return true; } return $sourceNavItem->copyTypeContent($navItem); }
[ "public", "function", "createItemLanguageCopy", "(", "$", "navItemId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ")", "{", "$", "sourceNavItem", "=", "NavItem", "::", "findOne", "(", "$", "navItemId", ")", ";", "if", "(", "!", "$", "sou...
Create a new nav item with a specific language, title and alias based on a given nav item id. All content of the source nav item will be copied dependent on the nav item type (page content, module link, redirect informations). @param integer $navItemId @param integer $langId @param string $title @param string $alias @return boolean|array If an array is returned, the creation had an error, the array contains the messages.
[ "Create", "a", "new", "nav", "item", "with", "a", "specific", "language", "title", "and", "alias", "based", "on", "a", "given", "nav", "item", "id", ".", "All", "content", "of", "the", "source", "nav", "item", "will", "be", "copied", "dependent", "on", ...
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L502-L532
luyadev/luya-module-cms
src/models/Nav.php
Nav.createPageFromDraft
public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false) { if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) { $isDraft = 0; } $errors = []; // nav $nav = $this; $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, 'is_draft' => $isDraft ]; // nav item $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1 ]; if (!$nav->validate()) { $errors = ArrayHelper::merge($nav->getErrors(), $errors); } if (!$navItem->validate()) { $errors = ArrayHelper::merge($navItem->getErrors(), $errors); } if (empty($fromDraftNavId)) { $errors['from_draft_id'] = [Module::t('model_navitempage_empty_draft_id')]; } if (!empty($errors)) { return $errors; } // get draft nav item data $draftNavItem = NavItem::findOne(['nav_id' => $fromDraftNavId]); $navItemPageId = $draftNavItem->type->id; $layoutId = $draftNavItem->type->layout_id; $pageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $navItemPageId]); // proceed save process $nav->save(); $navItemPage = new NavItemPage(); $navItemPage->layout_id = $layoutId; $navItemPage->timestamp_create = time(); $navItemPage->version_alias = Module::VERSION_INIT_LABEL; $navItemPage->create_user_id = Module::getAuthorUserId(); $navItemPage->nav_item_id = 0; if (!$navItemPage->validate()) { return $navItemPage->getErrors(); } $navItemPage->save(); $idLink = []; foreach ($pageBlocks as $block) { $i = new NavItemPageBlockItem(); $i->attributes = $block->toArray(); $i->nav_item_page_id = $navItemPage->id; $i->insert(); $idLink[$block->id] = $i->id; } // check if prev_id is used, check if id is in set - get new id and set new prev_ids in copied items $newPageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $navItemPage->id]); foreach ($newPageBlocks as $block) { if ($block->prev_id && isset($idLink[$block->prev_id])) { $block->updateAttributes(['prev_id' => $idLink[$block->prev_id]]); } } $navItem->nav_id = $nav->id; $navItem->nav_item_type_id = $navItemPage->id; $navItem->save(); $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return true; }
php
public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false) { if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) { $isDraft = 0; } $errors = []; // nav $nav = $this; $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, 'is_draft' => $isDraft ]; // nav item $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1 ]; if (!$nav->validate()) { $errors = ArrayHelper::merge($nav->getErrors(), $errors); } if (!$navItem->validate()) { $errors = ArrayHelper::merge($navItem->getErrors(), $errors); } if (empty($fromDraftNavId)) { $errors['from_draft_id'] = [Module::t('model_navitempage_empty_draft_id')]; } if (!empty($errors)) { return $errors; } // get draft nav item data $draftNavItem = NavItem::findOne(['nav_id' => $fromDraftNavId]); $navItemPageId = $draftNavItem->type->id; $layoutId = $draftNavItem->type->layout_id; $pageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $navItemPageId]); // proceed save process $nav->save(); $navItemPage = new NavItemPage(); $navItemPage->layout_id = $layoutId; $navItemPage->timestamp_create = time(); $navItemPage->version_alias = Module::VERSION_INIT_LABEL; $navItemPage->create_user_id = Module::getAuthorUserId(); $navItemPage->nav_item_id = 0; if (!$navItemPage->validate()) { return $navItemPage->getErrors(); } $navItemPage->save(); $idLink = []; foreach ($pageBlocks as $block) { $i = new NavItemPageBlockItem(); $i->attributes = $block->toArray(); $i->nav_item_page_id = $navItemPage->id; $i->insert(); $idLink[$block->id] = $i->id; } // check if prev_id is used, check if id is in set - get new id and set new prev_ids in copied items $newPageBlocks = NavItemPageBlockItem::findAll(['nav_item_page_id' => $navItemPage->id]); foreach ($newPageBlocks as $block) { if ($block->prev_id && isset($idLink[$block->prev_id])) { $block->updateAttributes(['prev_id' => $idLink[$block->prev_id]]); } } $navItem->nav_id = $nav->id; $navItem->nav_item_type_id = $navItemPage->id; $navItem->save(); $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return true; }
[ "public", "function", "createPageFromDraft", "(", "$", "parentNavId", ",", "$", "navContainerId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ",", "$", "description", ",", "$", "fromDraftNavId", ",", "$", "isDraft", "=", "false", ")", "{", ...
Create a page from a from a draft. @param integer $parentNavId @param integer $navContainerId @param integer $langId @param string $title @param string $alias @param string $description @param integer $fromDraftNavId @param string $isDraft @return boolean|array If an array is returned, the creation had an error, the array contains the messages.
[ "Create", "a", "page", "from", "a", "from", "a", "draft", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L547-L636
luyadev/luya-module-cms
src/models/Nav.php
Nav.createPage
public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false) { $_errors = []; $nav = $this; $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItemPage = new NavItemPage(); if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) { $isDraft = 0; } $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, 'is_draft' => $isDraft ]; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1 ]; $navItemPage->attributes = ['nav_item_id' => 0, 'layout_id' => $layoutId, 'create_user_id' => Module::getAuthorUserId(), 'timestamp_create' => time(), 'version_alias' => Module::VERSION_INIT_LABEL]; if (!$nav->validate()) { $_errors = ArrayHelper::merge($nav->getErrors(), $_errors); } if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemPage->validate()) { $_errors = ArrayHelper::merge($navItemPage->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemPage->save(false); // as validation is done already $nav->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemPage->id; $navItem->nav_id = $nav->id; $navItemId = $navItem->save(false); // as validation is done already $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return $nav->id; }
php
public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false) { $_errors = []; $nav = $this; $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItemPage = new NavItemPage(); if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) { $isDraft = 0; } $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, 'is_draft' => $isDraft ]; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1 ]; $navItemPage->attributes = ['nav_item_id' => 0, 'layout_id' => $layoutId, 'create_user_id' => Module::getAuthorUserId(), 'timestamp_create' => time(), 'version_alias' => Module::VERSION_INIT_LABEL]; if (!$nav->validate()) { $_errors = ArrayHelper::merge($nav->getErrors(), $_errors); } if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemPage->validate()) { $_errors = ArrayHelper::merge($navItemPage->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemPage->save(false); // as validation is done already $nav->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemPage->id; $navItem->nav_id = $nav->id; $navItemId = $navItem->save(false); // as validation is done already $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return $nav->id; }
[ "public", "function", "createPage", "(", "$", "parentNavId", ",", "$", "navContainerId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ",", "$", "layoutId", ",", "$", "description", ",", "$", "isDraft", "=", "false", ")", "{", "$", "_errors...
Create a new page. @param integer $parentNavId @param integer $navContainerId @param integer $langId @param string $title @param string $alias @param integer $layoutId @param string $description @param string $isDraft @return array|integer If an array is returned the validationed failed, the array contains the error messages. If sucess the nav ID is returned.
[ "Create", "a", "new", "page", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L651-L706
luyadev/luya-module-cms
src/models/Nav.php
Nav.createPageItem
public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description) { $_errors = []; $navItem = new NavItem(); $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id; $navItemPage = new NavItemPage(); $navItem->attributes = [ 'nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1, ]; $navItemPage->attributes = [ 'nav_item_id' => 0, 'layout_id' => $layoutId, 'create_user_id' => Module::getAuthorUserId(), 'timestamp_create' => time(), 'version_alias' => Module::VERSION_INIT_LABEL, ]; if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemPage->validate()) { $_errors = ArrayHelper::merge($navItemPage->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemPage->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemPage->id; $navItemId = $navItem->save(false); // as validation is done already $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return $navItem->id; }
php
public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description) { $_errors = []; $navItem = new NavItem(); $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id; $navItemPage = new NavItemPage(); $navItem->attributes = [ 'nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 1, ]; $navItemPage->attributes = [ 'nav_item_id' => 0, 'layout_id' => $layoutId, 'create_user_id' => Module::getAuthorUserId(), 'timestamp_create' => time(), 'version_alias' => Module::VERSION_INIT_LABEL, ]; if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemPage->validate()) { $_errors = ArrayHelper::merge($navItemPage->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemPage->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemPage->id; $navItemId = $navItem->save(false); // as validation is done already $navItemPage->updateAttributes(['nav_item_id' => $navItem->id]); return $navItem->id; }
[ "public", "function", "createPageItem", "(", "$", "navId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ",", "$", "layoutId", ",", "$", "description", ")", "{", "$", "_errors", "=", "[", "]", ";", "$", "navItem", "=", "new", "NavItem", ...
Create a nav item for a given NavId. If an array occurs an array with all errors is returned, if success the NavItem id is returned. @param integer $navId @param integer $langId @param string $title @param string $alias @param integer $layoutId @param string $description @return array|integer If an array is returned the validationed failed, the array contains the error messages. If sucess the navItem ID is returned.
[ "Create", "a", "nav", "item", "for", "a", "given", "NavId", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L721-L765
luyadev/luya-module-cms
src/models/Nav.php
Nav.createModule
public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description) { $_errors = []; $nav = $this; $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItemModule = new NavItemModule(); $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, ]; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 2 ]; $navItemModule->attributes = ['module_name' => $moduleName]; if (!$nav->validate()) { $_errors = ArrayHelper::merge($nav->getErrors(), $_errors); } if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemModule->validate()) { $_errors = ArrayHelper::merge($navItemModule->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemModule->save(false); // as validation is done already $nav->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemModule->id; $navItem->nav_id = $nav->id; $navItemId = $navItem->save(false); // as validation is done already return $nav->id; }
php
public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description) { $_errors = []; $nav = $this; $navItem = new NavItem(); $navItem->parent_nav_id = $parentNavId; $navItemModule = new NavItemModule(); $nav->attributes = [ 'parent_nav_id' => $parentNavId, 'nav_container_id' => $navContainerId, 'is_hidden' => true, 'is_offline' => true, ]; $navItem->attributes = [ 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 2 ]; $navItemModule->attributes = ['module_name' => $moduleName]; if (!$nav->validate()) { $_errors = ArrayHelper::merge($nav->getErrors(), $_errors); } if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemModule->validate()) { $_errors = ArrayHelper::merge($navItemModule->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemModule->save(false); // as validation is done already $nav->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemModule->id; $navItem->nav_id = $nav->id; $navItemId = $navItem->save(false); // as validation is done already return $nav->id; }
[ "public", "function", "createModule", "(", "$", "parentNavId", ",", "$", "navContainerId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ",", "$", "moduleName", ",", "$", "description", ")", "{", "$", "_errors", "=", "[", "]", ";", "$", "...
Create a new Module Page. @param integer $parentNavId @param integer $navContainerId @param integer $langId @param string $title @param string $alias @param string $moduleName @param string $description @return array|integer If an array is returned the validationed failed, the array contains the error messages. If sucess the nav ID is returned.
[ "Create", "a", "new", "Module", "Page", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L779-L827
luyadev/luya-module-cms
src/models/Nav.php
Nav.createModuleItem
public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description) { $_errors = []; $navItem = new NavItem(); $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id; $navItemModule = new NavItemModule(); $navItem->attributes = [ 'nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 2 ]; $navItemModule->attributes = ['module_name' => $moduleName]; if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemModule->validate()) { $_errors = ArrayHelper::merge($navItemModule->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemModule->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemModule->id; $navItemId = $navItem->save(false); // as validation is done already return $navItem->id; }
php
public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description) { $_errors = []; $navItem = new NavItem(); $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id; $navItemModule = new NavItemModule(); $navItem->attributes = [ 'nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 2 ]; $navItemModule->attributes = ['module_name' => $moduleName]; if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemModule->validate()) { $_errors = ArrayHelper::merge($navItemModule->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemModule->save(false); // as validation is done already $navItem->nav_item_type_id = $navItemModule->id; $navItemId = $navItem->save(false); // as validation is done already return $navItem->id; }
[ "public", "function", "createModuleItem", "(", "$", "navId", ",", "$", "langId", ",", "$", "title", ",", "$", "alias", ",", "$", "moduleName", ",", "$", "description", ")", "{", "$", "_errors", "=", "[", "]", ";", "$", "navItem", "=", "new", "NavItem...
Create a module for a given Nav Model. @param integer $navId @param integer $langId @param string $title @param string $alias @param string $moduleName @param string $description @return array|integer If an array is returned the validationed failed, the array contains the error messages. If sucess the navItem ID is returned.
[ "Create", "a", "module", "for", "a", "given", "Nav", "Model", "." ]
train
https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L901-L936