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 |
|---|---|---|---|---|---|---|---|---|---|---|
luyadev/luya-module-cms | src/models/Nav.php | Nav.createRedirectItem | public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget)
{
$_errors = [];
$navItem = new NavItem();
$navItem->parent_nav_id = self::findOne($navId)->parent_nav_id;
$navItemRedirect = new NavItemRedirect();
$navItem->attributes = [
'nav_id' => $navId,
'lang_id' => $langId,
'title' => $title,
'alias' => $alias,
'description' => $description,
'nav_item_type' => 3
];
$navItemRedirect->attributes = ['type' => $redirectType, 'value' => $redirectTypeValue, 'target' => $redirectTypeTarget];
if (!$navItem->validate()) {
$_errors = ArrayHelper::merge($navItem->getErrors(), $_errors);
}
if (!$navItemRedirect->validate()) {
$_errors = ArrayHelper::merge($navItemRedirect->getErrors(), $_errors);
}
if (!empty($_errors)) {
return $_errors;
}
$navItemRedirect->save(false); // as validation is done already
$navItem->nav_item_type_id = $navItemRedirect->id;
$navItemId = $navItem->save(false); // as validation is done already
return $navItem->id;
} | php | public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget)
{
$_errors = [];
$navItem = new NavItem();
$navItem->parent_nav_id = self::findOne($navId)->parent_nav_id;
$navItemRedirect = new NavItemRedirect();
$navItem->attributes = [
'nav_id' => $navId,
'lang_id' => $langId,
'title' => $title,
'alias' => $alias,
'description' => $description,
'nav_item_type' => 3
];
$navItemRedirect->attributes = ['type' => $redirectType, 'value' => $redirectTypeValue, 'target' => $redirectTypeTarget];
if (!$navItem->validate()) {
$_errors = ArrayHelper::merge($navItem->getErrors(), $_errors);
}
if (!$navItemRedirect->validate()) {
$_errors = ArrayHelper::merge($navItemRedirect->getErrors(), $_errors);
}
if (!empty($_errors)) {
return $_errors;
}
$navItemRedirect->save(false); // as validation is done already
$navItem->nav_item_type_id = $navItemRedirect->id;
$navItemId = $navItem->save(false); // as validation is done already
return $navItem->id;
} | [
"public",
"function",
"createRedirectItem",
"(",
"$",
"navId",
",",
"$",
"langId",
",",
"$",
"title",
",",
"$",
"alias",
",",
"$",
"redirectType",
",",
"$",
"redirectTypeValue",
",",
"$",
"description",
",",
"$",
"redirectTypeTarget",
")",
"{",
"$",
"_erro... | Create a redirecte for a given Nav Model.
@param integer $navId
@param integer $langId
@param string $title
@param string $alias
@param integer $redirectType The type of redirect (1 = page, 2 = URL, 3 = Link to File)
@param string $redirectTypeValue Depending on the type (1 = cms_nav.id, 2 = http://luya.io)
@param string $description
@param string $redirectTypeTarget redirect target (_blank, self) (since 2.0)
@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",
"redirecte",
"for",
"a",
"given",
"Nav",
"Model",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Nav.php#L950-L985 |
luyadev/luya-module-cms | src/admin/migrations/m180723_123237_indexes.php | m180723_123237_indexes.safeUp | public function safeUp()
{
// cms_block
$this->createIndex('index_group_id', 'cms_block', ['group_id']);
$this->createIndex('index_class', 'cms_block', ['class']);
// cms log
$this->createIndex('index_user_id', 'cms_log', ['user_id']);
// cms_nav
$this->createIndex('index_nav_container', 'cms_nav', ['nav_container_id']);
$this->createIndex('index_parent_nav_id', 'cms_nav', ['parent_nav_id']);
// cms_nav_item
$this->createIndex('index_alias', 'cms_nav_item', ['alias']);
$this->createIndex('index_nav_id', 'cms_nav_item', ['nav_id']);
$this->createIndex('index_lang_id', 'cms_nav_item', ['lang_id']);
$this->createIndex('index_nav_item_type_id', 'cms_nav_item', ['nav_item_type_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item', ['create_user_id']);
$this->createIndex('index_update_user_id', 'cms_nav_item', ['update_user_id']);
// cms_nav_item_page
$this->createIndex('index_layout_id', 'cms_nav_item_page', ['layout_id']);
$this->createIndex('index_nav_item_id', 'cms_nav_item_page', ['nav_item_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item_page', ['create_user_id']);
// cms_nav_item_page_block_item
$this->createIndex('index_block_id', 'cms_nav_item_page_block_item', ['block_id']);
$this->createIndex('index_placeholder_var', 'cms_nav_item_page_block_item', ['placeholder_var']);
$this->createIndex('index_nav_item_page_id', 'cms_nav_item_page_block_item', ['nav_item_page_id']);
$this->createIndex('index_prev_id', 'cms_nav_item_page_block_item', ['prev_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item_page_block_item', ['create_user_id']);
$this->createIndex('index_update_user_id', 'cms_nav_item_page_block_item', ['update_user_id']);
//index_nav_item_page_id_paceholder_var_prev_id_is_hidden_sort_index
$this->createIndex('index_nipi_pv_pi_ih_si', 'cms_nav_item_page_block_item', ['nav_item_page_id', 'placeholder_var', 'prev_id', 'is_hidden', 'sort_index']);
// cms_nav_permission
$this->createIndex('index_group_id', 'cms_nav_permission', ['group_id']);
$this->createIndex('index_nav_id', 'cms_nav_permission', ['nav_id']);
$this->createIndex('index_group_id_nav_id', 'cms_nav_permission', ['group_id', 'nav_id']);
// cms_nav_property
$this->createIndex('index_nav_id', 'cms_nav_property', ['nav_id']);
$this->createIndex('index_admin_prop_id', 'cms_nav_property', ['admin_prop_id']);
} | php | public function safeUp()
{
// cms_block
$this->createIndex('index_group_id', 'cms_block', ['group_id']);
$this->createIndex('index_class', 'cms_block', ['class']);
// cms log
$this->createIndex('index_user_id', 'cms_log', ['user_id']);
// cms_nav
$this->createIndex('index_nav_container', 'cms_nav', ['nav_container_id']);
$this->createIndex('index_parent_nav_id', 'cms_nav', ['parent_nav_id']);
// cms_nav_item
$this->createIndex('index_alias', 'cms_nav_item', ['alias']);
$this->createIndex('index_nav_id', 'cms_nav_item', ['nav_id']);
$this->createIndex('index_lang_id', 'cms_nav_item', ['lang_id']);
$this->createIndex('index_nav_item_type_id', 'cms_nav_item', ['nav_item_type_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item', ['create_user_id']);
$this->createIndex('index_update_user_id', 'cms_nav_item', ['update_user_id']);
// cms_nav_item_page
$this->createIndex('index_layout_id', 'cms_nav_item_page', ['layout_id']);
$this->createIndex('index_nav_item_id', 'cms_nav_item_page', ['nav_item_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item_page', ['create_user_id']);
// cms_nav_item_page_block_item
$this->createIndex('index_block_id', 'cms_nav_item_page_block_item', ['block_id']);
$this->createIndex('index_placeholder_var', 'cms_nav_item_page_block_item', ['placeholder_var']);
$this->createIndex('index_nav_item_page_id', 'cms_nav_item_page_block_item', ['nav_item_page_id']);
$this->createIndex('index_prev_id', 'cms_nav_item_page_block_item', ['prev_id']);
$this->createIndex('index_create_user_id', 'cms_nav_item_page_block_item', ['create_user_id']);
$this->createIndex('index_update_user_id', 'cms_nav_item_page_block_item', ['update_user_id']);
//index_nav_item_page_id_paceholder_var_prev_id_is_hidden_sort_index
$this->createIndex('index_nipi_pv_pi_ih_si', 'cms_nav_item_page_block_item', ['nav_item_page_id', 'placeholder_var', 'prev_id', 'is_hidden', 'sort_index']);
// cms_nav_permission
$this->createIndex('index_group_id', 'cms_nav_permission', ['group_id']);
$this->createIndex('index_nav_id', 'cms_nav_permission', ['nav_id']);
$this->createIndex('index_group_id_nav_id', 'cms_nav_permission', ['group_id', 'nav_id']);
// cms_nav_property
$this->createIndex('index_nav_id', 'cms_nav_property', ['nav_id']);
$this->createIndex('index_admin_prop_id', 'cms_nav_property', ['admin_prop_id']);
} | [
"public",
"function",
"safeUp",
"(",
")",
"{",
"// cms_block",
"$",
"this",
"->",
"createIndex",
"(",
"'index_group_id'",
",",
"'cms_block'",
",",
"[",
"'group_id'",
"]",
")",
";",
"$",
"this",
"->",
"createIndex",
"(",
"'index_class'",
",",
"'cms_block'",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/migrations/m180723_123237_indexes.php#L13-L58 |
luyadev/luya-module-cms | src/base/BaseBlockInjector.php | BaseBlockInjector.getContextConfigValue | public function getContextConfigValue($varName, $defaultValue = null)
{
if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
return $this->context->getVarValue($varName, $defaultValue);
}
if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
return $this->context->getCfgValue($varName, $defaultValue);
}
throw new InvalidConfigException("The type '{$this->type}' is not supported.");
} | php | public function getContextConfigValue($varName, $defaultValue = null)
{
if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
return $this->context->getVarValue($varName, $defaultValue);
}
if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
return $this->context->getCfgValue($varName, $defaultValue);
}
throw new InvalidConfigException("The type '{$this->type}' is not supported.");
} | [
"public",
"function",
"getContextConfigValue",
"(",
"$",
"varName",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"InternalBaseBlock",
"::",
"INJECTOR_VAR",
")",
"{",
"return",
"$",
"this",
"->",
"context",
"-... | Returns the value of the variable which is defined for this injector object based on it given type.
@param string $varName
@param mixed $defaultValue The default value for the variable if not found.
@return mixed
@throws InvalidConfigException | [
"Returns",
"the",
"value",
"of",
"the",
"variable",
"which",
"is",
"defined",
"for",
"this",
"injector",
"object",
"based",
"on",
"it",
"given",
"type",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/BaseBlockInjector.php#L85-L96 |
luyadev/luya-module-cms | src/base/BaseBlockInjector.php | BaseBlockInjector.setContextConfig | public function setContextConfig(array $config)
{
if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
return $this->context->addVar($config, $this->append);
}
if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
return $this->context->addCfg($config, $this->append);
}
throw new InvalidConfigException("The type '{$this->type}' is not supported.");
} | php | public function setContextConfig(array $config)
{
if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
return $this->context->addVar($config, $this->append);
}
if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
return $this->context->addCfg($config, $this->append);
}
throw new InvalidConfigException("The type '{$this->type}' is not supported.");
} | [
"public",
"function",
"setContextConfig",
"(",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"InternalBaseBlock",
"::",
"INJECTOR_VAR",
")",
"{",
"return",
"$",
"this",
"->",
"context",
"->",
"addVar",
"(",
"$",
"config",
... | Set a new configuration value for a variable based on its context (cfg or var).
@param array $config The config of the variable to inject
@throws InvalidConfigException | [
"Set",
"a",
"new",
"configuration",
"value",
"for",
"a",
"variable",
"based",
"on",
"its",
"context",
"(",
"cfg",
"or",
"var",
")",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/BaseBlockInjector.php#L104-L115 |
luyadev/luya-module-cms | src/widgets/LangSwitcher.php | LangSwitcher.generateHtml | private function generateHtml($href, $isActive, $lang)
{
if (!isset(static::$registerLinkTags[$href])) {
$this->view->registerLinkTag(['rel' => 'alternate', 'hreflang' => $lang['short_code'], 'href' => Yii::$app->urlManager->hostInfo . $href]);
static::$registerLinkTags[$href] = true;
}
$elementOptions = $this->elementOptions;
$linkOptions = $this->linkOptions;
if ($isActive) {
if (isset($linkOptions['class'])) {
$linkOptions['class'] = $linkOptions['class'] . ' ' . $this->linkActiveClass;
} else {
$linkOptions['class'] = $this->linkActiveClass;
}
if (isset($elementOptions['class'])) {
$elementOptions['class'] = $elementOptions['class'] . ' ' . $this->elementActiveClass;
} else {
$elementOptions['class'] = $this->elementActiveClass;
}
}
$tag = ArrayHelper::remove($elementOptions, 'tag', 'li');
$text = is_callable($this->linkLabel) ? call_user_func($this->linkLabel, $lang) : $lang[$this->linkLabel];
return Html::tag($tag, Html::a($text, $href, $linkOptions), $elementOptions);
} | php | private function generateHtml($href, $isActive, $lang)
{
if (!isset(static::$registerLinkTags[$href])) {
$this->view->registerLinkTag(['rel' => 'alternate', 'hreflang' => $lang['short_code'], 'href' => Yii::$app->urlManager->hostInfo . $href]);
static::$registerLinkTags[$href] = true;
}
$elementOptions = $this->elementOptions;
$linkOptions = $this->linkOptions;
if ($isActive) {
if (isset($linkOptions['class'])) {
$linkOptions['class'] = $linkOptions['class'] . ' ' . $this->linkActiveClass;
} else {
$linkOptions['class'] = $this->linkActiveClass;
}
if (isset($elementOptions['class'])) {
$elementOptions['class'] = $elementOptions['class'] . ' ' . $this->elementActiveClass;
} else {
$elementOptions['class'] = $this->elementActiveClass;
}
}
$tag = ArrayHelper::remove($elementOptions, 'tag', 'li');
$text = is_callable($this->linkLabel) ? call_user_func($this->linkLabel, $lang) : $lang[$this->linkLabel];
return Html::tag($tag, Html::a($text, $href, $linkOptions), $elementOptions);
} | [
"private",
"function",
"generateHtml",
"(",
"$",
"href",
",",
"$",
"isActive",
",",
"$",
"lang",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"registerLinkTags",
"[",
"$",
"href",
"]",
")",
")",
"{",
"$",
"this",
"->",
"view",
"->",... | Generate the item element.
@param string $href
@param boolean $isActive
@param array $lang
@return string | [
"Generate",
"the",
"item",
"element",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/widgets/LangSwitcher.php#L133-L161 |
luyadev/luya-module-cms | src/widgets/LangSwitcher.php | LangSwitcher.getDataArray | private static function getDataArray()
{
if (self::$_dataArray === null) {
$currentMenuItem = Yii::$app->menu->current;
$array = [];
foreach (Yii::$app->adminLanguage->getLanguages() as $lang) {
$array[] = [
'lang' => $lang,
'item' => Yii::$app->menu->find()->where(['nav_id' => $currentMenuItem->navId])->lang($lang['short_code'])->with('hidden')->one(),
];
}
self::$_dataArray = $array;
}
return self::$_dataArray;
} | php | private static function getDataArray()
{
if (self::$_dataArray === null) {
$currentMenuItem = Yii::$app->menu->current;
$array = [];
foreach (Yii::$app->adminLanguage->getLanguages() as $lang) {
$array[] = [
'lang' => $lang,
'item' => Yii::$app->menu->find()->where(['nav_id' => $currentMenuItem->navId])->lang($lang['short_code'])->with('hidden')->one(),
];
}
self::$_dataArray = $array;
}
return self::$_dataArray;
} | [
"private",
"static",
"function",
"getDataArray",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_dataArray",
"===",
"null",
")",
"{",
"$",
"currentMenuItem",
"=",
"Yii",
"::",
"$",
"app",
"->",
"menu",
"->",
"current",
";",
"$",
"array",
"=",
"[",
"]"... | Add Singleton Container.
@return array | [
"Add",
"Singleton",
"Container",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/widgets/LangSwitcher.php#L168-L184 |
luyadev/luya-module-cms | src/models/NavItemRedirect.php | NavItemRedirect.resolveValue | public function resolveValue()
{
$converter = new LinkConverter();
$converter->value = $this->value;
$converter->type = $this->type;
$converter->target = $this->target;
return $converter->getLink();
} | php | public function resolveValue()
{
$converter = new LinkConverter();
$converter->value = $this->value;
$converter->type = $this->type;
$converter->target = $this->target;
return $converter->getLink();
} | [
"public",
"function",
"resolveValue",
"(",
")",
"{",
"$",
"converter",
"=",
"new",
"LinkConverter",
"(",
")",
";",
"$",
"converter",
"->",
"value",
"=",
"$",
"this",
"->",
"value",
";",
"$",
"converter",
"->",
"type",
"=",
"$",
"this",
"->",
"type",
... | Resolve the values with {{luya\cms\LinkConverter}}.
@return \luya\web\LinkInterface|boolean | [
"Resolve",
"the",
"values",
"with",
"{{",
"luya",
"\\",
"cms",
"\\",
"LinkConverter",
"}}",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemRedirect.php#L73-L80 |
luyadev/luya-module-cms | src/models/NavContainer.php | NavContainer.getNavs | public function getNavs()
{
return $this->hasMany(Nav::className(), ['nav_container_id' => 'id'])->where(['is_deleted' => false, 'is_draft' => false])->orderBy(['sort_index' => SORT_ASC]);
} | php | public function getNavs()
{
return $this->hasMany(Nav::className(), ['nav_container_id' => 'id'])->where(['is_deleted' => false, 'is_draft' => false])->orderBy(['sort_index' => SORT_ASC]);
} | [
"public",
"function",
"getNavs",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"hasMany",
"(",
"Nav",
"::",
"className",
"(",
")",
",",
"[",
"'nav_container_id'",
"=>",
"'id'",
"]",
")",
"->",
"where",
"(",
"[",
"'is_deleted'",
"=>",
"false",
",",
"'is_d... | Relation returns all `cms_nav` rows belongs to this container sort by index without deleted or draf items.
@return \yii\db\ActiveQuery | [
"Relation",
"returns",
"all",
"cms_nav",
"rows",
"belongs",
"to",
"this",
"container",
"sort",
"by",
"index",
"without",
"deleted",
"or",
"draf",
"items",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavContainer.php#L65-L68 |
luyadev/luya-module-cms | src/frontend/commands/PageController.php | PageController.actionCleanup | public function actionCleanup()
{
// return all pages with deleted items
$navIds = Nav::find()->where(['is_deleted' => true])->select(['id'])->column();
// get all nav items where the page is deleted.
$navItemIds = NavItem::find()->joinWith(['nav' => function ($q) {
$q->where(['is_deleted' => true]);
}])->select(['{{cms_nav_item}}.id'])->column();
// get all nav item pages from the missing navItems list
$navItemPageIds = NavItemPage::find()->where(['in', 'nav_item_id', $navItemIds])->select(['id'])->column();
// get all blocks from those pages
$navItemPageBlockIds = NavItemPageBlockItem::find()->where(['in', 'nav_item_page_id', $navItemPageIds])->select(['id'])->column();
$table = new Table();
$table->setHeaders(['Type', 'Items to delete']);
$table->setRows([
['Pages', count($navIds)],
['Page language', count($navItemIds)],
['Page versions', count($navItemPageIds)],
['Blocks', count($navItemPageBlockIds)],
]);
echo $table->run();
if ($this->confirm('The delete process can not be undone! Are you sure you want to delete those data?')) {
$this->printRows(Nav::deleteAll(['in', 'id', $navIds]), 'Page');
$this->printRows(NavItem::deleteAll(['in', 'id', $navItemIds]), 'Page language');
$this->printRows(NavItemPage::deleteAll(['in', 'id', $navItemPageIds]), 'Page version');
$this->printRows(NavItemPageBlockItem::deleteAll(['in', 'id', $navItemPageBlockIds]), 'Block');
// cleanup depending table data.
$this->printRows(Property::deleteAll(['in', 'nav_id', $navIds]), 'Property');
$this->printRows(NavPermission::deleteAll(['in', 'nav_id', $navIds]), 'Permission');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navIds], ['table_name' => 'cms_nav']]), 'Page log');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navItemIds], ['table_name' => 'cms_nav_item']]), 'Page language log');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navItemPageBlockIds], ['table_name' => 'cms_nav_item_page_block_item']]), 'Block log');
return $this->outputSuccess('Done');
}
return $this->outputError('Abort by user.');
} | php | public function actionCleanup()
{
// return all pages with deleted items
$navIds = Nav::find()->where(['is_deleted' => true])->select(['id'])->column();
// get all nav items where the page is deleted.
$navItemIds = NavItem::find()->joinWith(['nav' => function ($q) {
$q->where(['is_deleted' => true]);
}])->select(['{{cms_nav_item}}.id'])->column();
// get all nav item pages from the missing navItems list
$navItemPageIds = NavItemPage::find()->where(['in', 'nav_item_id', $navItemIds])->select(['id'])->column();
// get all blocks from those pages
$navItemPageBlockIds = NavItemPageBlockItem::find()->where(['in', 'nav_item_page_id', $navItemPageIds])->select(['id'])->column();
$table = new Table();
$table->setHeaders(['Type', 'Items to delete']);
$table->setRows([
['Pages', count($navIds)],
['Page language', count($navItemIds)],
['Page versions', count($navItemPageIds)],
['Blocks', count($navItemPageBlockIds)],
]);
echo $table->run();
if ($this->confirm('The delete process can not be undone! Are you sure you want to delete those data?')) {
$this->printRows(Nav::deleteAll(['in', 'id', $navIds]), 'Page');
$this->printRows(NavItem::deleteAll(['in', 'id', $navItemIds]), 'Page language');
$this->printRows(NavItemPage::deleteAll(['in', 'id', $navItemPageIds]), 'Page version');
$this->printRows(NavItemPageBlockItem::deleteAll(['in', 'id', $navItemPageBlockIds]), 'Block');
// cleanup depending table data.
$this->printRows(Property::deleteAll(['in', 'nav_id', $navIds]), 'Property');
$this->printRows(NavPermission::deleteAll(['in', 'nav_id', $navIds]), 'Permission');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navIds], ['table_name' => 'cms_nav']]), 'Page log');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navItemIds], ['table_name' => 'cms_nav_item']]), 'Page language log');
$this->printRows(Log::deleteAll(['and', ['in', 'row_id', $navItemPageBlockIds], ['table_name' => 'cms_nav_item_page_block_item']]), 'Block log');
return $this->outputSuccess('Done');
}
return $this->outputError('Abort by user.');
} | [
"public",
"function",
"actionCleanup",
"(",
")",
"{",
"// return all pages with deleted items",
"$",
"navIds",
"=",
"Nav",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'is_deleted'",
"=>",
"true",
"]",
")",
"->",
"select",
"(",
"[",
"'id'",
"]",
")",
... | Cleanup routine.
The are differente cases which are part of the cleanup process:
+ find is_deleted cms nav items and remove them (with all its depending items, blocks etc.)
+ see if cms_nav_item has a none existing cms_nav and remove them.
+ check if cms_nav_item_page has nav_item_id which does not exists anymore if yes delete the page with all its blocks.
+ check of nav_item_page where the nav_container does not exists anymore. | [
"Cleanup",
"routine",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/PageController.php#L35-L79 |
luyadev/luya-module-cms | src/base/NavItemType.php | NavItemType.getOption | public function getOption($key)
{
return (isset($this->_options[$key])) ? $this->_options[$key] : false;
} | php | public function getOption($key)
{
return (isset($this->_options[$key])) ? $this->_options[$key] : false;
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"_options",
"[",
"$",
"key",
"]",
")",
")",
"?",
"$",
"this",
"->",
"_options",
"[",
"$",
"key",
"]",
":",
"false",
";",
"}"
] | Get a specific option value for a defined eky.
@param string $key The array key to lookup inside the $options array.
@return boolean|mixed | [
"Get",
"a",
"specific",
"option",
"value",
"for",
"a",
"defined",
"eky",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/NavItemType.php#L94-L97 |
luyadev/luya-module-cms | src/tags/PageTag.php | PageTag.parse | public function parse($value, $sub)
{
$page = Nav::findOne($value);
// verify if the page is of type content
if ($page) {
if ($page->activeLanguageItem->nav_item_type !== NavItem::TYPE_PAGE) {
return null;
}
if (empty($sub)) {
return $page->activeLanguageItem->getContent();
} else {
return $page->activeLanguageItem->type->renderPlaceholder($sub);
}
}
return null;
} | php | public function parse($value, $sub)
{
$page = Nav::findOne($value);
// verify if the page is of type content
if ($page) {
if ($page->activeLanguageItem->nav_item_type !== NavItem::TYPE_PAGE) {
return null;
}
if (empty($sub)) {
return $page->activeLanguageItem->getContent();
} else {
return $page->activeLanguageItem->type->renderPlaceholder($sub);
}
}
return null;
} | [
"public",
"function",
"parse",
"(",
"$",
"value",
",",
"$",
"sub",
")",
"{",
"$",
"page",
"=",
"Nav",
"::",
"findOne",
"(",
"$",
"value",
")",
";",
"// verify if the page is of type content",
"if",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
... | Get the content of Nav for the current active language with cmslayout or placeholder.
@param string $value The value of the Nav ID e.g 1 (hover the cms menu to see the ID).
@param string|null $sub If null this parameter will be ignored otherwise its the name of the placeholder inside this cmslayout.
@return string The content rendered with the cmslayout, or if $sub is provided and not null with its placeholder name.
@see \luya\tag\TagInterface::parse() | [
"Get",
"the",
"content",
"of",
"Nav",
"for",
"the",
"current",
"active",
"language",
"with",
"cmslayout",
"or",
"placeholder",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/tags/PageTag.php#L51-L70 |
luyadev/luya-module-cms | src/base/BlockConfigElement.php | BlockConfigElement.has | protected function has($key)
{
if (!is_array($key)) {
return (array_key_exists($key, $this->item));
}
foreach ($key as $value) {
if (!array_key_exists($value, $this->item)) {
return false;
}
}
return true;
} | php | protected function has($key)
{
if (!is_array($key)) {
return (array_key_exists($key, $this->item));
}
foreach ($key as $value) {
if (!array_key_exists($value, $this->item)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"item",
")",
")",
";",
"}",
"foreach",
"(",
"$",
... | Has the config element an element or not.
@param string $key
@return boolean | [
"Has",
"the",
"config",
"element",
"an",
"element",
"or",
"not",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/BlockConfigElement.php#L45-L58 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.setBlockName | public function setBlockName($name)
{
if (!StringHelper::endsWith($name, 'Block')) {
$name .= 'Block';
}
$this->_blockName = Inflector::camelize($name);
} | php | public function setBlockName($name)
{
if (!StringHelper::endsWith($name, 'Block')) {
$name .= 'Block';
}
$this->_blockName = Inflector::camelize($name);
} | [
"public",
"function",
"setBlockName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"StringHelper",
"::",
"endsWith",
"(",
"$",
"name",
",",
"'Block'",
")",
")",
"{",
"$",
"name",
".=",
"'Block'",
";",
"}",
"$",
"this",
"->",
"_blockName",
"=",
"Inflec... | Setter method for $blockName, ensure the correct block name.
@param string $name The name of the block. | [
"Setter",
"method",
"for",
"$blockName",
"ensure",
"the",
"correct",
"block",
"name",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L75-L82 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.getModuleProposal | private function getModuleProposal()
{
$moduleNames = [];
foreach (Yii::$app->getApplicationModules() as $id => $obj) {
$moduleNames[$id] = $id;
}
return $moduleNames;
} | php | private function getModuleProposal()
{
$moduleNames = [];
foreach (Yii::$app->getApplicationModules() as $id => $obj) {
$moduleNames[$id] = $id;
}
return $moduleNames;
} | [
"private",
"function",
"getModuleProposal",
"(",
")",
"{",
"$",
"moduleNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getApplicationModules",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"obj",
")",
"{",
"$",
"moduleNames",
"[",
... | Get an array with all modules where you can generate blocks for.
@return array | [
"Get",
"an",
"array",
"with",
"all",
"modules",
"where",
"you",
"can",
"generate",
"blocks",
"for",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L114-L122 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.varCreator | private function varCreator($prefix, $typeCast)
{
$this->output(PHP_EOL.'-> Create new '.$prefix, Console::FG_YELLOW);
$name = $this->prompt('Variable Name:', ['required' => true]);
$label = $this->prompt('End-User Label:', ['required' => true]);
$type = $this->select('Variable Type:', $this->getVariableTypes());
$v = [
'var' => Inflector::variablize($name),
'label' => $label,
'type' => $this->getVariableTypeInterfaceMap()[$type],
];
if ($this->hasVariableTypeOption($type)) {
$v['options'] = $this->getVariableTypeOption($type);
}
if ($typeCast == 'var') {
$func = 'getVarValue';
} else {
$func = 'getCfgValue';
}
$extra = $this->getExtraVarDef($type, $v['var'], $func);
if ($extra !== false) {
$this->phpdoc[] = '{{extras.'.$v['var'].'}}';
$this->viewFileDoc[] = '$this->extraValue(\''.$v['var'].'\');';
$this->extras[] = $extra;
}
$this->output('Added '.$prefix.PHP_EOL, Console::FG_GREEN);
return $v;
} | php | private function varCreator($prefix, $typeCast)
{
$this->output(PHP_EOL.'-> Create new '.$prefix, Console::FG_YELLOW);
$name = $this->prompt('Variable Name:', ['required' => true]);
$label = $this->prompt('End-User Label:', ['required' => true]);
$type = $this->select('Variable Type:', $this->getVariableTypes());
$v = [
'var' => Inflector::variablize($name),
'label' => $label,
'type' => $this->getVariableTypeInterfaceMap()[$type],
];
if ($this->hasVariableTypeOption($type)) {
$v['options'] = $this->getVariableTypeOption($type);
}
if ($typeCast == 'var') {
$func = 'getVarValue';
} else {
$func = 'getCfgValue';
}
$extra = $this->getExtraVarDef($type, $v['var'], $func);
if ($extra !== false) {
$this->phpdoc[] = '{{extras.'.$v['var'].'}}';
$this->viewFileDoc[] = '$this->extraValue(\''.$v['var'].'\');';
$this->extras[] = $extra;
}
$this->output('Added '.$prefix.PHP_EOL, Console::FG_GREEN);
return $v;
} | [
"private",
"function",
"varCreator",
"(",
"$",
"prefix",
",",
"$",
"typeCast",
")",
"{",
"$",
"this",
"->",
"output",
"(",
"PHP_EOL",
".",
"'-> Create new '",
".",
"$",
"prefix",
",",
"Console",
"::",
"FG_YELLOW",
")",
";",
"$",
"name",
"=",
"$",
"this... | Create a variable based of user input.
@param string $prefix
@param string $typeCast 'var', 'cfg'
@return array | [
"Create",
"a",
"variable",
"based",
"of",
"user",
"input",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L256-L290 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.getFileNamespace | protected function getFileNamespace()
{
if ($this->type == self::TYPE_APP) {
return 'app\\blocks';
}
return Yii::$app->getModule($this->moduleName)->getNamespace() . '\\blocks';
} | php | protected function getFileNamespace()
{
if ($this->type == self::TYPE_APP) {
return 'app\\blocks';
}
return Yii::$app->getModule($this->moduleName)->getNamespace() . '\\blocks';
} | [
"protected",
"function",
"getFileNamespace",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"self",
"::",
"TYPE_APP",
")",
"{",
"return",
"'app\\\\blocks'",
";",
"}",
"return",
"Yii",
"::",
"$",
"app",
"->",
"getModule",
"(",
"$",
"this",
"... | Get the file namespace based on its type.
@return string The full qualified namespace based on the type | [
"Get",
"the",
"file",
"namespace",
"based",
"on",
"its",
"type",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L297-L304 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.getFileBasePath | protected function getFileBasePath()
{
if ($this->type == self::TYPE_APP) {
return Yii::$app->basePath;
}
return Yii::$app->getModule($this->moduleName)->getBasePath();
} | php | protected function getFileBasePath()
{
if ($this->type == self::TYPE_APP) {
return Yii::$app->basePath;
}
return Yii::$app->getModule($this->moduleName)->getBasePath();
} | [
"protected",
"function",
"getFileBasePath",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"self",
"::",
"TYPE_APP",
")",
"{",
"return",
"Yii",
"::",
"$",
"app",
"->",
"basePath",
";",
"}",
"return",
"Yii",
"::",
"$",
"app",
"->",
"getMod... | Get the full base path to the folder of the module
@return string The full path to the module folder. | [
"Get",
"the",
"full",
"base",
"path",
"to",
"the",
"folder",
"of",
"the",
"module"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L311-L318 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.generateViewFile | public function generateViewFile($blockClassName)
{
sort($this->viewFileDoc);
return $this->view->render('@cms/views/commands/block/create_block_view.php', [
'blockClassName' => $blockClassName,
'phpdoc' => $this->viewFileDoc,
'luyaText' => $this->getGeneratorText('block/create'),
]);
} | php | public function generateViewFile($blockClassName)
{
sort($this->viewFileDoc);
return $this->view->render('@cms/views/commands/block/create_block_view.php', [
'blockClassName' => $blockClassName,
'phpdoc' => $this->viewFileDoc,
'luyaText' => $this->getGeneratorText('block/create'),
]);
} | [
"public",
"function",
"generateViewFile",
"(",
"$",
"blockClassName",
")",
"{",
"sort",
"(",
"$",
"this",
"->",
"viewFileDoc",
")",
";",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"'@cms/views/commands/block/create_block_view.php'",
",",
"[",
"'bl... | Generate the view file for the block.
@param string $blockClassName The name of the block class.
@return string The rendered view file. | [
"Generate",
"the",
"view",
"file",
"for",
"the",
"block",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L326-L334 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.actionCreate | public function actionCreate()
{
if (empty($this->type)) {
Console::clearScreenBeforeCursor();
$this->type = $this->select('Do you want to create an app or module Block?', [
self::TYPE_APP => 'Creates a project block inside your @app Namespace (casual).',
self::TYPE_MODULE => 'Creating a block inside a later specified Module.',
]);
}
if ($this->type == self::TYPE_MODULE && count($this->getModuleProposal()) === 0) {
return $this->outputError('Your project does not have Project-Modules registered!');
}
if (empty($this->moduleName) && $this->type == self::TYPE_MODULE) {
$this->moduleName = $this->select('Choose a module to create the block inside:', $this->getModuleProposal());
}
if (empty($this->blockName)) {
$this->blockName = $this->prompt('Insert a name for your Block (e.g. HeadTeaser):', ['required' => true]);
}
if ($this->isContainer === null) {
$this->isContainer = $this->confirm("Do you want to add placeholders to your block that serve as a container for nested blocks?", false);
}
if ($this->cacheEnabled === null) {
$this->cacheEnabled = $this->confirm("Do you want to enable the caching for this block or not?", true);
}
if ($this->config === null) {
$this->config = [
'vars' => [], 'cfgs' => [], 'placeholders' => [],
];
$doConfigure = $this->confirm('Would you like to configure this Block? (vars, cfgs, placeholders)', false);
if ($doConfigure) {
$doVars = $this->confirm('Add new Variable (vars)?', false);
$i = 1;
while ($doVars) {
$item = $this->varCreator('Variabel (vars) #'.$i, 'var');
$this->phpdoc[] = '{{vars.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->varValue(\''.$item['var'].'\');';
$this->config['vars'][] = $item;
$doVars = $this->confirm('Add one more?', false);
++$i;
}
$doCfgs = $this->confirm('Add new Configuration (cfgs)?', false);
$i = 1;
while ($doCfgs) {
$item = $this->varCreator('Configration (cfgs) #'.$i, 'cfg');
$this->phpdoc[] = '{{cfgs.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->cfgValue(\''.$item['var'].'\');';
$this->config['cfgs'][] = $item;
$doCfgs = $this->confirm('Add one more?', false);
++$i;
}
$doPlaceholders = $this->confirm('Add new Placeholder (placeholders)?', false);
$i = 1;
while ($doPlaceholders) {
$item = $this->placeholderCreator('Placeholder (placeholders) #'.$i);
$this->phpdoc[] = '{{placeholders.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->placeholderValue(\''.$item['var'].'\');';
$this->config['placeholders'][] = $item;
$doPlaceholders = $this->confirm('Add one more?', false);
++$i;
}
}
}
$folder = $this->getFileBasePath() . DIRECTORY_SEPARATOR . 'blocks';
$filePath = $folder . DIRECTORY_SEPARATOR . $this->blockName . '.php';
sort($this->phpdoc);
$content = $this->view->render('@cms/views/commands/block/create_block', [
'namespace' => $this->getFileNamespace(),
'className' => $this->blockName,
'name' => Inflector::camel2words($this->blockName),
'type' => $this->type,
'module' => $this->moduleName,
'isContainer' => $this->isContainer,
'cacheEnabled' => $this->cacheEnabled,
'config' => $this->config,
'phpdoc' => $this->phpdoc,
'extras' => $this->extras,
'luyaText' => $this->getGeneratorText('block/create'),
]);
if ($this->dryRun) {
return $content;
}
if (FileHelper::createDirectory($folder) && FileHelper::writeFile($filePath, $content)) {
// generate view file based on block object view context
$object = Yii::createObject(['class' => $this->getFileNamespace() . '\\' . $this->blockName]);
$viewsFolder = Yii::getAlias($object->getViewPath());
$viewFilePath = $viewsFolder . DIRECTORY_SEPARATOR . $object->getViewFileName('php');
if (FileHelper::createDirectory($viewsFolder) && FileHelper::writeFile($viewFilePath, $this->generateViewFile($this->blockName))) {
$this->outputInfo('View file for the block has been created: ' . $viewFilePath);
}
return $this->outputSuccess("Block {$this->blockName} has been created: " . $filePath);
}
return $this->outputError("Error while creating block '$filePath'");
} | php | public function actionCreate()
{
if (empty($this->type)) {
Console::clearScreenBeforeCursor();
$this->type = $this->select('Do you want to create an app or module Block?', [
self::TYPE_APP => 'Creates a project block inside your @app Namespace (casual).',
self::TYPE_MODULE => 'Creating a block inside a later specified Module.',
]);
}
if ($this->type == self::TYPE_MODULE && count($this->getModuleProposal()) === 0) {
return $this->outputError('Your project does not have Project-Modules registered!');
}
if (empty($this->moduleName) && $this->type == self::TYPE_MODULE) {
$this->moduleName = $this->select('Choose a module to create the block inside:', $this->getModuleProposal());
}
if (empty($this->blockName)) {
$this->blockName = $this->prompt('Insert a name for your Block (e.g. HeadTeaser):', ['required' => true]);
}
if ($this->isContainer === null) {
$this->isContainer = $this->confirm("Do you want to add placeholders to your block that serve as a container for nested blocks?", false);
}
if ($this->cacheEnabled === null) {
$this->cacheEnabled = $this->confirm("Do you want to enable the caching for this block or not?", true);
}
if ($this->config === null) {
$this->config = [
'vars' => [], 'cfgs' => [], 'placeholders' => [],
];
$doConfigure = $this->confirm('Would you like to configure this Block? (vars, cfgs, placeholders)', false);
if ($doConfigure) {
$doVars = $this->confirm('Add new Variable (vars)?', false);
$i = 1;
while ($doVars) {
$item = $this->varCreator('Variabel (vars) #'.$i, 'var');
$this->phpdoc[] = '{{vars.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->varValue(\''.$item['var'].'\');';
$this->config['vars'][] = $item;
$doVars = $this->confirm('Add one more?', false);
++$i;
}
$doCfgs = $this->confirm('Add new Configuration (cfgs)?', false);
$i = 1;
while ($doCfgs) {
$item = $this->varCreator('Configration (cfgs) #'.$i, 'cfg');
$this->phpdoc[] = '{{cfgs.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->cfgValue(\''.$item['var'].'\');';
$this->config['cfgs'][] = $item;
$doCfgs = $this->confirm('Add one more?', false);
++$i;
}
$doPlaceholders = $this->confirm('Add new Placeholder (placeholders)?', false);
$i = 1;
while ($doPlaceholders) {
$item = $this->placeholderCreator('Placeholder (placeholders) #'.$i);
$this->phpdoc[] = '{{placeholders.'.$item['var'].'}}';
$this->viewFileDoc[] = '$this->placeholderValue(\''.$item['var'].'\');';
$this->config['placeholders'][] = $item;
$doPlaceholders = $this->confirm('Add one more?', false);
++$i;
}
}
}
$folder = $this->getFileBasePath() . DIRECTORY_SEPARATOR . 'blocks';
$filePath = $folder . DIRECTORY_SEPARATOR . $this->blockName . '.php';
sort($this->phpdoc);
$content = $this->view->render('@cms/views/commands/block/create_block', [
'namespace' => $this->getFileNamespace(),
'className' => $this->blockName,
'name' => Inflector::camel2words($this->blockName),
'type' => $this->type,
'module' => $this->moduleName,
'isContainer' => $this->isContainer,
'cacheEnabled' => $this->cacheEnabled,
'config' => $this->config,
'phpdoc' => $this->phpdoc,
'extras' => $this->extras,
'luyaText' => $this->getGeneratorText('block/create'),
]);
if ($this->dryRun) {
return $content;
}
if (FileHelper::createDirectory($folder) && FileHelper::writeFile($filePath, $content)) {
// generate view file based on block object view context
$object = Yii::createObject(['class' => $this->getFileNamespace() . '\\' . $this->blockName]);
$viewsFolder = Yii::getAlias($object->getViewPath());
$viewFilePath = $viewsFolder . DIRECTORY_SEPARATOR . $object->getViewFileName('php');
if (FileHelper::createDirectory($viewsFolder) && FileHelper::writeFile($viewFilePath, $this->generateViewFile($this->blockName))) {
$this->outputInfo('View file for the block has been created: ' . $viewFilePath);
}
return $this->outputSuccess("Block {$this->blockName} has been created: " . $filePath);
}
return $this->outputError("Error while creating block '$filePath'");
} | [
"public",
"function",
"actionCreate",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"type",
")",
")",
"{",
"Console",
"::",
"clearScreenBeforeCursor",
"(",
")",
";",
"$",
"this",
"->",
"type",
"=",
"$",
"this",
"->",
"select",
"(",
"'Do ... | Wizzard to create a new CMS block.
@return number | [
"Wizzard",
"to",
"create",
"a",
"new",
"CMS",
"block",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L341-L449 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.actionFind | public function actionFind($search = null)
{
$rows = [];
$query = Block::find();
foreach (StringHelper::explode($search) as $q) {
$query->orFilterWhere(['like', 'class', $q]);
}
$blocks = $query->with(['navItemPageBlockItems'])->all();
foreach ($blocks as $block) {
$rows[] = [$block->id, $block->class, $block->usageCount];
}
if ($search) {
$this->outputInfo("Filtering for: {$search}");
}
$table = new Table();
$table->setHeaders(['ID', 'Class', 'Usage count']);
$table->setRows($rows);
echo $table->run();
return $this->outputSuccess(count($blocks) . " block(s) found.");
} | php | public function actionFind($search = null)
{
$rows = [];
$query = Block::find();
foreach (StringHelper::explode($search) as $q) {
$query->orFilterWhere(['like', 'class', $q]);
}
$blocks = $query->with(['navItemPageBlockItems'])->all();
foreach ($blocks as $block) {
$rows[] = [$block->id, $block->class, $block->usageCount];
}
if ($search) {
$this->outputInfo("Filtering for: {$search}");
}
$table = new Table();
$table->setHeaders(['ID', 'Class', 'Usage count']);
$table->setRows($rows);
echo $table->run();
return $this->outputSuccess(count($blocks) . " block(s) found.");
} | [
"public",
"function",
"actionFind",
"(",
"$",
"search",
"=",
"null",
")",
"{",
"$",
"rows",
"=",
"[",
"]",
";",
"$",
"query",
"=",
"Block",
"::",
"find",
"(",
")",
";",
"foreach",
"(",
"StringHelper",
"::",
"explode",
"(",
"$",
"search",
")",
"as",... | Search for a given block by its class or return all.
Returns all blocks:
```
./luya cms/block/find
```
Filter for a given name:
```
./luya cms/block/find html
```
Filter for different names combined as OR conditions:
```
./luya cms/block/find html,module
```
@param string $search Optional query to search inside the class. In order to performe multiple criterias use comma separated list of key words.
@since 1.0.4 | [
"Search",
"for",
"a",
"given",
"block",
"by",
"its",
"class",
"or",
"return",
"all",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L475-L499 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.actionMigrate | public function actionMigrate($old, $replace)
{
$block = Block::find()->where(['like', 'class', $old])->one();
if (!$block) {
return $this->outputError("Unable to find a block for '{$old}'");
}
$this->outputInfo("Found block '{$block->class}' with ID {$block->id} used {$block->usageCount} times.");
// check if existing block have the new replace name
$replaceBlock = Block::find()->where(['like', 'class', $replace])->one();
if ($replaceBlock && $this->confirm("Do you want to replace {$block->class} (used {$block->usageCount}x) with {$replaceBlock->class} (used {$replaceBlock->usageCount}x)?")) {
$block->updateAttributes(['class' => $replaceBlock->class]);
if (empty($replaceBlock->usageCount)) {
$replaceBlock->delete();
return $this->outputSuccess("The block as been migrated, the block used for the replacement has been delete has there was no content.");
} else {
$replaceBlock->updateAttributes(['class' => $block->class]);
return $this->outputSuccess("The block has been migrated and the block class names has swaped as the replacement block had content.");
}
}
return $this->outputError("Abort by user.");
} | php | public function actionMigrate($old, $replace)
{
$block = Block::find()->where(['like', 'class', $old])->one();
if (!$block) {
return $this->outputError("Unable to find a block for '{$old}'");
}
$this->outputInfo("Found block '{$block->class}' with ID {$block->id} used {$block->usageCount} times.");
// check if existing block have the new replace name
$replaceBlock = Block::find()->where(['like', 'class', $replace])->one();
if ($replaceBlock && $this->confirm("Do you want to replace {$block->class} (used {$block->usageCount}x) with {$replaceBlock->class} (used {$replaceBlock->usageCount}x)?")) {
$block->updateAttributes(['class' => $replaceBlock->class]);
if (empty($replaceBlock->usageCount)) {
$replaceBlock->delete();
return $this->outputSuccess("The block as been migrated, the block used for the replacement has been delete has there was no content.");
} else {
$replaceBlock->updateAttributes(['class' => $block->class]);
return $this->outputSuccess("The block has been migrated and the block class names has swaped as the replacement block had content.");
}
}
return $this->outputError("Abort by user.");
} | [
"public",
"function",
"actionMigrate",
"(",
"$",
"old",
",",
"$",
"replace",
")",
"{",
"$",
"block",
"=",
"Block",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'like'",
",",
"'class'",
",",
"$",
"old",
"]",
")",
"->",
"one",
"(",
")",
";",
... | Search for a given block and replace the class by replace argument.
This is commonly used when a block does not exists anymore and you want to provide
another block for the none existing one.
The most common case is to search ($old) for a class which has been used in the content but does not exist anymore,
therfore you can replace it with a new ($replace) block which has not been used in the content. This will change the
class identifier from the old block with the new (replace) ones. If the replace block has not been used, he will be deleted.
Searching for the blocks could look like this:
```sh
./luya cms/block/migrate OldBlockWhichDoesNotExists TheNewBlockWhichShouldReplaceTheOld
```
Example for using different namespaces but the same block name:
```sh
./luya cms/block/migrate \\blocks\\MyBlock \\newblocks\\MyBlock
```
Example usage when working with absolute class names.
```sh
./luya cms/block/migrate app\\blocks\\OldBlockName app\\blocks\\NewBlockName
```
As the search for the old block is done by a like statements this would work as well:
```sh
./luya cms/block/migrate OldBlockName app\\blocks\\NewBlockName
```
@param string $old
@param string $replace
@since 1.0.4 | [
"Search",
"for",
"a",
"given",
"block",
"and",
"replace",
"the",
"class",
"by",
"replace",
"argument",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L539-L568 |
luyadev/luya-module-cms | src/frontend/commands/BlockController.php | BlockController.actionCleanup | public function actionCleanup()
{
$delete = [];
$this->output("Blocks to delete:");
foreach (Block::find()->all() as $block) {
if (!$block->getFileExists()) {
$this->outputInfo("{$block->class} (id: {$block->id}) used {$block->usageCount} times.");
$delete[] = $block;
}
}
if (!empty($delete) && $this->confirm('Are you sure to delete those blocks with its content? This can not be undone!')) {
foreach ($delete as $deleteBlock) {
if ($deleteBlock->delete()) {
$this->outputSuccess('Deleted ' . $deleteBlock->class);
} else {
$this->outputError('Error while deleting ' . $deleteBlock->class);
}
}
return $this->outputSuccess("Clean has been finished successful.");
} elseif (empty($delete)) {
return $this->outputSuccess("Nothing to cleanup.");
}
return $this->outputError("Abort by user.");
} | php | public function actionCleanup()
{
$delete = [];
$this->output("Blocks to delete:");
foreach (Block::find()->all() as $block) {
if (!$block->getFileExists()) {
$this->outputInfo("{$block->class} (id: {$block->id}) used {$block->usageCount} times.");
$delete[] = $block;
}
}
if (!empty($delete) && $this->confirm('Are you sure to delete those blocks with its content? This can not be undone!')) {
foreach ($delete as $deleteBlock) {
if ($deleteBlock->delete()) {
$this->outputSuccess('Deleted ' . $deleteBlock->class);
} else {
$this->outputError('Error while deleting ' . $deleteBlock->class);
}
}
return $this->outputSuccess("Clean has been finished successful.");
} elseif (empty($delete)) {
return $this->outputSuccess("Nothing to cleanup.");
}
return $this->outputError("Abort by user.");
} | [
"public",
"function",
"actionCleanup",
"(",
")",
"{",
"$",
"delete",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"output",
"(",
"\"Blocks to delete:\"",
")",
";",
"foreach",
"(",
"Block",
"::",
"find",
"(",
")",
"->",
"all",
"(",
")",
"as",
"$",
"block",
... | Search for blocks with none existing class files and remove them.
> Attention: Keep in the mind if the blocks do have been used in content, those data will be delete as well!
@since 1.0.4 | [
"Search",
"for",
"blocks",
"with",
"none",
"existing",
"class",
"files",
"and",
"remove",
"them",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/commands/BlockController.php#L577-L603 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getVersionList | public static function getVersionList($navItemId)
{
return self::find()->where(['nav_item_id' => $navItemId])->with('layout')->indexBy('id')->orderBy(['id' => SORT_ASC])->all();
} | php | public static function getVersionList($navItemId)
{
return self::find()->where(['nav_item_id' => $navItemId])->with('layout')->indexBy('id')->orderBy(['id' => SORT_ASC])->all();
} | [
"public",
"static",
"function",
"getVersionList",
"(",
"$",
"navItemId",
")",
"{",
"return",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'nav_item_id'",
"=>",
"$",
"navItemId",
"]",
")",
"->",
"with",
"(",
"'layout'",
")",
"->",
"indexBy",
... | Get the list of version/pages for a specific nav item id
@param integer $navItemId
@return \yii\db\ActiveRecord | [
"Get",
"the",
"list",
"of",
"version",
"/",
"pages",
"for",
"a",
"specific",
"nav",
"item",
"id"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L111-L114 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getContent | public function getContent()
{
if (!$this->layout) {
throw new InvalidConfigException("Unable to find the requested cms layout '{$this->layout_id}' for nav item page id '{$this->id}'. Make sure your page does not have an old inactive/deleted cms layout selected.");
}
$placholders = [];
foreach ($this->layout->getJsonConfig('placeholders') as $row) {
foreach ($row as $item) {
$placholders[$item['var']] = $this->renderPlaceholder($item['var']);
}
}
return Yii::$app->view->render($this->layout->view_file, [
'placeholders' => $placholders,
], $this);
} | php | public function getContent()
{
if (!$this->layout) {
throw new InvalidConfigException("Unable to find the requested cms layout '{$this->layout_id}' for nav item page id '{$this->id}'. Make sure your page does not have an old inactive/deleted cms layout selected.");
}
$placholders = [];
foreach ($this->layout->getJsonConfig('placeholders') as $row) {
foreach ($row as $item) {
$placholders[$item['var']] = $this->renderPlaceholder($item['var']);
}
}
return Yii::$app->view->render($this->layout->view_file, [
'placeholders' => $placholders,
], $this);
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"layout",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Unable to find the requested cms layout '{$this->layout_id}' for nav item page id '{$this->id}'. Make sure your page does ... | Frontend get Content returns the rendered content for this nav item page based on the page logic (placeholders, blocks)
{@inheritDoc}
@see \luya\cms\base\NavItemType::getContent() | [
"Frontend",
"get",
"Content",
"returns",
"the",
"rendered",
"content",
"for",
"this",
"nav",
"item",
"page",
"based",
"on",
"the",
"page",
"logic",
"(",
"placeholders",
"blocks",
")"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L145-L161 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.renderPlaceholderRecursive | private function renderPlaceholderRecursive($navItemPageId, $placeholderVar, $prevId, $layoutBlockInstance = null)
{
$string = '';
$i = 0;
$equalIndex = 1;
$placeholders = $this->getPlaceholders($navItemPageId, $placeholderVar, $prevId);
$blocksCount = count($placeholders);
$variations = Yii::$app->getModule('cmsadmin')->blockVariations;
// foreach all placeholders but preserve varaibles above to make calculations
foreach ($placeholders as $key => $placeholder) {
$i++;
$prev = $key-1;
$next = $key+1;
$cacheKey = ['blockcache', (int) $placeholder['id']];
$blockResponse = $this->getHasCache($cacheKey);
/** @var $blockObject \luya\cms\base\InternalBaseBlock */
//$blockObject = Block::objectId($placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
$blockObject = Block::createObject($placeholder['class'], $placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
if ($blockObject) {
if ($blockResponse === false) {
$className = get_class($blockObject);
// insert var and cfg values from database
$blockObject->setVarValues($this->jsonToArray($placeholder['json_config_values']));
$blockObject->setCfgValues($this->jsonToArray($placeholder['json_config_cfg_values']));
// inject variations variables
$possibleVariations = isset($variations[$className]) ? $variations[$className] : false;
$ensuredVariation = false;
if ($possibleVariations && isset($possibleVariations[$placeholder['variation']])) {
$ensuredVariation = $possibleVariations[$placeholder['variation']];
} elseif ($possibleVariations) {
foreach ($possibleVariations as $name => $content) {
if ($content['is_default']) {
$ensuredVariation = $content;
}
}
}
if ($ensuredVariation) {
// otherwise foreach the configuration variation and assign.
foreach ($ensuredVariation as $type => $typeContent) {
if (!empty($typeContent)) {
$type = strtolower($type);
switch ($type) {
case "vars": $blockObject->setVarValues($typeContent); break;
case "cfgs": $blockObject->setCfgValues($typeContent); break;
case "extras":
foreach ($typeContent as $extraKey => $extraValue) {
$blockObject->addExtraVar($extraKey, $extraValue);
}
break;
}
}
}
}
// set env options from current object environment
foreach ($this->getOptions() as $optKey => $optValue) {
$blockObject->setEnvOption($optKey, $optValue);
}
$blockObject->setEnvOption('index', $i);
$blockObject->setEnvOption('itemsCount', $blocksCount);
$blockObject->setEnvOption('isFirst', ($i == 1));
$blockObject->setEnvOption('isLast', ($i == $blocksCount));
$prevIsEqual = array_key_exists($prev, $placeholders) && $placeholder['block_id'] == $placeholders[$prev]['block_id'];
$blockObject->setEnvOption('isPrevEqual', $prevIsEqual);
$blockObject->setEnvOption('isNextEqual', array_key_exists($next, $placeholders) && $placeholder['block_id'] == $placeholders[$next]['block_id']);
if (!$prevIsEqual) {
$equalIndex = 1;
} else {
$equalIndex++;
}
$blockObject->setEnvOption('equalIndex', $equalIndex);
// render sub placeholders and set into object
$insertedHolders = [];
foreach ($blockObject->getConfigPlaceholdersExport() as $item) {
$insertedHolders[$item['var']] = $this->renderPlaceholderRecursive($navItemPageId, $item['var'], $placeholder['id'], $blockObject);
}
$blockObject->setPlaceholderValues($insertedHolders);
// output buffer the rendered frontend method of the block
if ($layoutBlockInstance) {
$blockResponse = $layoutBlockInstance->placeholderRenderIteration($blockObject);
} else {
$blockResponse = $blockObject->renderFrontend();
}
if ($blockObject->getIsCacheEnabled()) {
$this->setHasCache($cacheKey, $blockResponse, null, $blockObject->getCacheExpirationTime());
$blockObject->onRegister();
}
} else {
$blockObject->onRegisterFromCache();
}
}
$string.= $blockResponse;
unset($blockResponse);
}
unset($variations);
unset($placeholders);
return $string;
} | php | private function renderPlaceholderRecursive($navItemPageId, $placeholderVar, $prevId, $layoutBlockInstance = null)
{
$string = '';
$i = 0;
$equalIndex = 1;
$placeholders = $this->getPlaceholders($navItemPageId, $placeholderVar, $prevId);
$blocksCount = count($placeholders);
$variations = Yii::$app->getModule('cmsadmin')->blockVariations;
// foreach all placeholders but preserve varaibles above to make calculations
foreach ($placeholders as $key => $placeholder) {
$i++;
$prev = $key-1;
$next = $key+1;
$cacheKey = ['blockcache', (int) $placeholder['id']];
$blockResponse = $this->getHasCache($cacheKey);
/** @var $blockObject \luya\cms\base\InternalBaseBlock */
//$blockObject = Block::objectId($placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
$blockObject = Block::createObject($placeholder['class'], $placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
if ($blockObject) {
if ($blockResponse === false) {
$className = get_class($blockObject);
// insert var and cfg values from database
$blockObject->setVarValues($this->jsonToArray($placeholder['json_config_values']));
$blockObject->setCfgValues($this->jsonToArray($placeholder['json_config_cfg_values']));
// inject variations variables
$possibleVariations = isset($variations[$className]) ? $variations[$className] : false;
$ensuredVariation = false;
if ($possibleVariations && isset($possibleVariations[$placeholder['variation']])) {
$ensuredVariation = $possibleVariations[$placeholder['variation']];
} elseif ($possibleVariations) {
foreach ($possibleVariations as $name => $content) {
if ($content['is_default']) {
$ensuredVariation = $content;
}
}
}
if ($ensuredVariation) {
// otherwise foreach the configuration variation and assign.
foreach ($ensuredVariation as $type => $typeContent) {
if (!empty($typeContent)) {
$type = strtolower($type);
switch ($type) {
case "vars": $blockObject->setVarValues($typeContent); break;
case "cfgs": $blockObject->setCfgValues($typeContent); break;
case "extras":
foreach ($typeContent as $extraKey => $extraValue) {
$blockObject->addExtraVar($extraKey, $extraValue);
}
break;
}
}
}
}
// set env options from current object environment
foreach ($this->getOptions() as $optKey => $optValue) {
$blockObject->setEnvOption($optKey, $optValue);
}
$blockObject->setEnvOption('index', $i);
$blockObject->setEnvOption('itemsCount', $blocksCount);
$blockObject->setEnvOption('isFirst', ($i == 1));
$blockObject->setEnvOption('isLast', ($i == $blocksCount));
$prevIsEqual = array_key_exists($prev, $placeholders) && $placeholder['block_id'] == $placeholders[$prev]['block_id'];
$blockObject->setEnvOption('isPrevEqual', $prevIsEqual);
$blockObject->setEnvOption('isNextEqual', array_key_exists($next, $placeholders) && $placeholder['block_id'] == $placeholders[$next]['block_id']);
if (!$prevIsEqual) {
$equalIndex = 1;
} else {
$equalIndex++;
}
$blockObject->setEnvOption('equalIndex', $equalIndex);
// render sub placeholders and set into object
$insertedHolders = [];
foreach ($blockObject->getConfigPlaceholdersExport() as $item) {
$insertedHolders[$item['var']] = $this->renderPlaceholderRecursive($navItemPageId, $item['var'], $placeholder['id'], $blockObject);
}
$blockObject->setPlaceholderValues($insertedHolders);
// output buffer the rendered frontend method of the block
if ($layoutBlockInstance) {
$blockResponse = $layoutBlockInstance->placeholderRenderIteration($blockObject);
} else {
$blockResponse = $blockObject->renderFrontend();
}
if ($blockObject->getIsCacheEnabled()) {
$this->setHasCache($cacheKey, $blockResponse, null, $blockObject->getCacheExpirationTime());
$blockObject->onRegister();
}
} else {
$blockObject->onRegisterFromCache();
}
}
$string.= $blockResponse;
unset($blockResponse);
}
unset($variations);
unset($placeholders);
return $string;
} | [
"private",
"function",
"renderPlaceholderRecursive",
"(",
"$",
"navItemPageId",
",",
"$",
"placeholderVar",
",",
"$",
"prevId",
",",
"$",
"layoutBlockInstance",
"=",
"null",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"$",
"equalIndex... | Render a placeholder recursive based on navItemPageId, a placeholder variable and a previous id.
@param integer $navItemPageId
@param string $placeholderVar
@param integer $prevId
@return string | [
"Render",
"a",
"placeholder",
"recursive",
"based",
"on",
"navItemPageId",
"a",
"placeholder",
"variable",
"and",
"a",
"previous",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L196-L307 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getPlaceholders | private function getPlaceholders($navItemPageId, $placeholderVar, $prevId)
{
return (new Query())
->from('cms_nav_item_page_block_item t1')
->select(['t1.id', 't1.block_id', 't1.json_config_values', 't1.json_config_cfg_values', 't1.variation', 't2.class'])
->innerJoin('cms_block t2', 't2.id=t1.block_id')
->where(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId, 'is_hidden' => 0])
->orderBy(['sort_index' => SORT_ASC])
->all();
} | php | private function getPlaceholders($navItemPageId, $placeholderVar, $prevId)
{
return (new Query())
->from('cms_nav_item_page_block_item t1')
->select(['t1.id', 't1.block_id', 't1.json_config_values', 't1.json_config_cfg_values', 't1.variation', 't2.class'])
->innerJoin('cms_block t2', 't2.id=t1.block_id')
->where(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId, 'is_hidden' => 0])
->orderBy(['sort_index' => SORT_ASC])
->all();
} | [
"private",
"function",
"getPlaceholders",
"(",
"$",
"navItemPageId",
",",
"$",
"placeholderVar",
",",
"$",
"prevId",
")",
"{",
"return",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"'cms_nav_item_page_block_item t1'",
")",
"->",
"select",
"(",
"["... | Get all placeholders as array for a given pageId, placeholder and prevId.
@param integer $navItemPageId
@param string $placeholderVar
@param integer $prevId
@return array | [
"Get",
"all",
"placeholders",
"as",
"array",
"for",
"a",
"given",
"pageId",
"placeholder",
"and",
"prevId",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L317-L326 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getContentAsArray | public function getContentAsArray()
{
//$nav_item_page = (new \yii\db\Query())->select('*')->from('cms_nav_item_page t1')->leftJoin('cms_layout', 'cms_layout.id=t1.layout_id')->where(['t1.id' => $this->id])->one();
$nav_item_page = $this;
if (!$nav_item_page->layout) {
return [];
}
$return = [
'nav_item_page' => ['id' => $nav_item_page->id, 'layout_id' => $nav_item_page->layout_id, 'layout_name' => $nav_item_page->layout->name],
'__placeholders' => [],
];
$config = json_decode($nav_item_page->layout->json_config, true);
if (isset($config['placeholders'])) {
foreach ($config['placeholders'] as $rowKey => $row) {
foreach ($row as $placeholderKey => $placeholder) {
$placeholder['nav_item_page_id'] = $this->id;
$placeholder['prev_id'] = 0;
$placeholder['__nav_item_page_block_items'] = [];
if (!isset($placeholder['cols'])) {
$placeholder['cols'] = '12';
}
$return['__placeholders'][$rowKey][$placeholderKey] = $placeholder;
$placeholderVar = $placeholder['var'];
$return['__placeholders'][$rowKey][$placeholderKey]['__nav_item_page_block_items'] = self::getPlaceholder($placeholderVar, 0, $this);
}
}
}
return $return;
} | php | public function getContentAsArray()
{
//$nav_item_page = (new \yii\db\Query())->select('*')->from('cms_nav_item_page t1')->leftJoin('cms_layout', 'cms_layout.id=t1.layout_id')->where(['t1.id' => $this->id])->one();
$nav_item_page = $this;
if (!$nav_item_page->layout) {
return [];
}
$return = [
'nav_item_page' => ['id' => $nav_item_page->id, 'layout_id' => $nav_item_page->layout_id, 'layout_name' => $nav_item_page->layout->name],
'__placeholders' => [],
];
$config = json_decode($nav_item_page->layout->json_config, true);
if (isset($config['placeholders'])) {
foreach ($config['placeholders'] as $rowKey => $row) {
foreach ($row as $placeholderKey => $placeholder) {
$placeholder['nav_item_page_id'] = $this->id;
$placeholder['prev_id'] = 0;
$placeholder['__nav_item_page_block_items'] = [];
if (!isset($placeholder['cols'])) {
$placeholder['cols'] = '12';
}
$return['__placeholders'][$rowKey][$placeholderKey] = $placeholder;
$placeholderVar = $placeholder['var'];
$return['__placeholders'][$rowKey][$placeholderKey]['__nav_item_page_block_items'] = self::getPlaceholder($placeholderVar, 0, $this);
}
}
}
return $return;
} | [
"public",
"function",
"getContentAsArray",
"(",
")",
"{",
"//$nav_item_page = (new \\yii\\db\\Query())->select('*')->from('cms_nav_item_page t1')->leftJoin('cms_layout', 'cms_layout.id=t1.layout_id')->where(['t1.id' => $this->id])->one();",
"$",
"nav_item_page",
"=",
"$",
"this",
";",
"if"... | Get the full array content from all the blocks, placeholders, vars configs and values recursiv for this current NavItemPage (which is layout version for a nav item)
@return array | [
"Get",
"the",
"full",
"array",
"content",
"from",
"all",
"the",
"blocks",
"placeholders",
"vars",
"configs",
"and",
"values",
"recursiv",
"for",
"this",
"current",
"NavItemPage",
"(",
"which",
"is",
"layout",
"version",
"for",
"a",
"nav",
"item",
")"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L345-L381 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getPlaceholder | public static function getPlaceholder($placeholderVar, $prevId, NavItemPage $navItemPage)
{
$nav_item_page_block_item_data = NavItemPageBlockItem::find()
->where(['prev_id' => $prevId, 'nav_item_page_id' => $navItemPage->id, 'placeholder_var' => $placeholderVar])
->orderBy(['sort_index' => SORT_ASC])
->with(['block'])
->all();
$data = [];
foreach ($nav_item_page_block_item_data as $blockItem) {
$item = self::getBlockItem($blockItem, $navItemPage);
if ($item) {
$data[] = $item;
}
unset($item);
}
return $data;
} | php | public static function getPlaceholder($placeholderVar, $prevId, NavItemPage $navItemPage)
{
$nav_item_page_block_item_data = NavItemPageBlockItem::find()
->where(['prev_id' => $prevId, 'nav_item_page_id' => $navItemPage->id, 'placeholder_var' => $placeholderVar])
->orderBy(['sort_index' => SORT_ASC])
->with(['block'])
->all();
$data = [];
foreach ($nav_item_page_block_item_data as $blockItem) {
$item = self::getBlockItem($blockItem, $navItemPage);
if ($item) {
$data[] = $item;
}
unset($item);
}
return $data;
} | [
"public",
"static",
"function",
"getPlaceholder",
"(",
"$",
"placeholderVar",
",",
"$",
"prevId",
",",
"NavItemPage",
"$",
"navItemPage",
")",
"{",
"$",
"nav_item_page_block_item_data",
"=",
"NavItemPageBlockItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"["... | Get the blocks for a given placeholder, **without recursion**.
@param string $placeholderVar
@param integer $prevId
@param NavItemPage $navItemPage
@return array | [
"Get",
"the",
"blocks",
"for",
"a",
"given",
"placeholder",
"**",
"without",
"recursion",
"**",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L391-L411 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.getBlockItem | public static function getBlockItem(NavItemPageBlockItem $blockItem, NavItemPage $navItemPage)
{
$blockObject = $blockItem->block->getObject($blockItem->id, 'admin', $navItemPage);
//$blockObject = Block::objectId($blockItem['block_id'], $blockItem['id'], 'admin', $navItemPage);
if ($blockObject === false) {
return false;
}
$blockItem['json_config_values'] = json_decode($blockItem['json_config_values'], true);
$blockItem['json_config_cfg_values'] = json_decode($blockItem['json_config_cfg_values'], true);
$blockValue = $blockItem['json_config_values'];
$blockCfgValue = $blockItem['json_config_cfg_values'];
$blockObject->setVarValues((empty($blockValue)) ? [] : $blockValue);
$blockObject->setCfgValues((empty($blockCfgValue)) ? [] : $blockCfgValue);
$placeholders = [];
foreach ($blockObject->getConfigPlaceholdersByRowsExport() as $rowKey => $row) {
foreach ($row as $pk => $pv) {
$pv['nav_item_page_id'] = $blockItem['nav_item_page_id'];
$pv['prev_id'] = $blockItem['id'];
$placeholderVar = $pv['var'];
$pv['__nav_item_page_block_items'] = static::getPlaceholder($placeholderVar, $blockItem['id'], $navItemPage);
$placeholder = $pv;
$placeholders[$rowKey][] = $placeholder;
}
}
if (empty($blockItem['json_config_values'])) {
$blockItem['json_config_values'] = ['__e' => '__o'];
}
if (empty($blockItem['json_config_cfg_values'])) {
$blockItem['json_config_cfg_values'] = ['__e' => '__o'];
}
$variations = Yii::$app->getModule('cmsadmin')->blockVariations;
$className = get_class($blockObject);
$shortName = (new \ReflectionClass($blockObject))->getShortName();
return [
'is_dirty' => (bool) $blockItem['is_dirty'],
'is_container' => (int) $blockObject->getIsContainer(),
'id' => $blockItem['id'],
'block_id' => $blockItem['block_id'],
'block_class' => $className,
'block_class_name' => $shortName,
'is_hidden' => $blockItem['is_hidden'],
'name' => $blockObject->name(),
'icon' => $blockObject->icon(),
'full_name' => ($blockObject->icon() === null) ? $blockObject->name() : '<i class="material-icons">'.$blockObject->icon().'</i> <span>'.$blockObject->name().'</span>',
'twig_admin' => $blockObject->renderAdmin(),
'vars' => $blockObject->getConfigVarsExport(),
'cfgs' => $blockObject->getConfigCfgsExport(),
'extras' => $blockObject->getExtraVarValues(),
'values' => $blockItem['json_config_values'],
'field_help' => $blockObject->getFieldHelp(),
'cfgvalues' => $blockItem['json_config_cfg_values'], // add: t1_json_config_cfg_values
'__placeholders' => $placeholders,
'variations' => isset($variations[$className]) ? $variations[$className] : false,
'variation' => empty($blockItem['variation'])? "0" : $blockItem['variation'], // as by angular selection
'is_dirty_dialog_enabled' => $blockObject->getIsDirtyDialogEnabled(),
];
} | php | public static function getBlockItem(NavItemPageBlockItem $blockItem, NavItemPage $navItemPage)
{
$blockObject = $blockItem->block->getObject($blockItem->id, 'admin', $navItemPage);
//$blockObject = Block::objectId($blockItem['block_id'], $blockItem['id'], 'admin', $navItemPage);
if ($blockObject === false) {
return false;
}
$blockItem['json_config_values'] = json_decode($blockItem['json_config_values'], true);
$blockItem['json_config_cfg_values'] = json_decode($blockItem['json_config_cfg_values'], true);
$blockValue = $blockItem['json_config_values'];
$blockCfgValue = $blockItem['json_config_cfg_values'];
$blockObject->setVarValues((empty($blockValue)) ? [] : $blockValue);
$blockObject->setCfgValues((empty($blockCfgValue)) ? [] : $blockCfgValue);
$placeholders = [];
foreach ($blockObject->getConfigPlaceholdersByRowsExport() as $rowKey => $row) {
foreach ($row as $pk => $pv) {
$pv['nav_item_page_id'] = $blockItem['nav_item_page_id'];
$pv['prev_id'] = $blockItem['id'];
$placeholderVar = $pv['var'];
$pv['__nav_item_page_block_items'] = static::getPlaceholder($placeholderVar, $blockItem['id'], $navItemPage);
$placeholder = $pv;
$placeholders[$rowKey][] = $placeholder;
}
}
if (empty($blockItem['json_config_values'])) {
$blockItem['json_config_values'] = ['__e' => '__o'];
}
if (empty($blockItem['json_config_cfg_values'])) {
$blockItem['json_config_cfg_values'] = ['__e' => '__o'];
}
$variations = Yii::$app->getModule('cmsadmin')->blockVariations;
$className = get_class($blockObject);
$shortName = (new \ReflectionClass($blockObject))->getShortName();
return [
'is_dirty' => (bool) $blockItem['is_dirty'],
'is_container' => (int) $blockObject->getIsContainer(),
'id' => $blockItem['id'],
'block_id' => $blockItem['block_id'],
'block_class' => $className,
'block_class_name' => $shortName,
'is_hidden' => $blockItem['is_hidden'],
'name' => $blockObject->name(),
'icon' => $blockObject->icon(),
'full_name' => ($blockObject->icon() === null) ? $blockObject->name() : '<i class="material-icons">'.$blockObject->icon().'</i> <span>'.$blockObject->name().'</span>',
'twig_admin' => $blockObject->renderAdmin(),
'vars' => $blockObject->getConfigVarsExport(),
'cfgs' => $blockObject->getConfigCfgsExport(),
'extras' => $blockObject->getExtraVarValues(),
'values' => $blockItem['json_config_values'],
'field_help' => $blockObject->getFieldHelp(),
'cfgvalues' => $blockItem['json_config_cfg_values'], // add: t1_json_config_cfg_values
'__placeholders' => $placeholders,
'variations' => isset($variations[$className]) ? $variations[$className] : false,
'variation' => empty($blockItem['variation'])? "0" : $blockItem['variation'], // as by angular selection
'is_dirty_dialog_enabled' => $blockObject->getIsDirtyDialogEnabled(),
];
} | [
"public",
"static",
"function",
"getBlockItem",
"(",
"NavItemPageBlockItem",
"$",
"blockItem",
",",
"NavItemPage",
"$",
"navItemPage",
")",
"{",
"$",
"blockObject",
"=",
"$",
"blockItem",
"->",
"block",
"->",
"getObject",
"(",
"$",
"blockItem",
"->",
"id",
","... | Get the arrayable values from a specific block id.
@param integer $blockId
@return array | [
"Get",
"the",
"arrayable",
"values",
"from",
"a",
"specific",
"block",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L432-L501 |
luyadev/luya-module-cms | src/models/NavItemPage.php | NavItemPage.copyBlocks | public static function copyBlocks($fromPageId, $toPageId)
{
$pageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $fromPageId])->asArray(true)->all();
$idLink = [];
foreach ($pageBlocks as $block) {
$blockItem = new NavItemPageBlockItem();
$blockItem->attributes = $block;
$blockItem->nav_item_page_id = $toPageId;
if ($blockItem->insert()) {
$idLink[$block['id']] = $blockItem->id;
}
}
// as blocks with subblocks have the previous block id stored in prev_id those values must be replaced from the old prev_id
// with the new prev_id
$newPageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $toPageId])->asArray(true)->all();
foreach ($newPageBlocks as $block) {
if ($block['prev_id'] && isset($idLink[$block['prev_id']])) {
// update the given blocks' prev_id
NavItemPageBlockItem::updateAll(['prev_id' => $idLink[$block['prev_id']]], ['id' => $block['id']]);
}
}
return true;
} | php | public static function copyBlocks($fromPageId, $toPageId)
{
$pageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $fromPageId])->asArray(true)->all();
$idLink = [];
foreach ($pageBlocks as $block) {
$blockItem = new NavItemPageBlockItem();
$blockItem->attributes = $block;
$blockItem->nav_item_page_id = $toPageId;
if ($blockItem->insert()) {
$idLink[$block['id']] = $blockItem->id;
}
}
// as blocks with subblocks have the previous block id stored in prev_id those values must be replaced from the old prev_id
// with the new prev_id
$newPageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $toPageId])->asArray(true)->all();
foreach ($newPageBlocks as $block) {
if ($block['prev_id'] && isset($idLink[$block['prev_id']])) {
// update the given blocks' prev_id
NavItemPageBlockItem::updateAll(['prev_id' => $idLink[$block['prev_id']]], ['id' => $block['id']]);
}
}
return true;
} | [
"public",
"static",
"function",
"copyBlocks",
"(",
"$",
"fromPageId",
",",
"$",
"toPageId",
")",
"{",
"$",
"pageBlocks",
"=",
"NavItemPageBlockItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'nav_item_page_id'",
"=>",
"$",
"fromPageId",
"]",
")",
... | Copy blocks from one page to another.
@param integer $fromPageId
@param integer $toPageId
@return boolean | [
"Copy",
"blocks",
"from",
"one",
"page",
"to",
"another",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPage.php#L510-L535 |
luyadev/luya-module-cms | src/base/PhpBlock.php | PhpBlock.getView | public function getView()
{
if ($this->_view === null) {
$this->_view = Yii::createObject(PhpBlockView::class);
}
return $this->_view;
} | php | public function getView()
{
if ($this->_view === null) {
$this->_view = Yii::createObject(PhpBlockView::class);
}
return $this->_view;
} | [
"public",
"function",
"getView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_view",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_view",
"=",
"Yii",
"::",
"createObject",
"(",
"PhpBlockView",
"::",
"class",
")",
";",
"}",
"return",
"$",
"this",
... | View Object getter.
@return \luya\cms\base\PhpBlockView | [
"View",
"Object",
"getter",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/PhpBlock.php#L25-L32 |
luyadev/luya-module-cms | src/base/PhpBlock.php | PhpBlock.onRegister | public function onRegister()
{
if ($this->isCachingEnabled()) {
$phpBlockView = $this->getView();
$blockId = $this->getEnvOption('id');
$cacheKeyAssets = ['blockassets', $blockId];
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
$assets = Yii::$app->cache->getOrSet($cacheKeyAssets, [$phpBlockView, 'getBlockAssets'], $this->getCacheExpirationTime());
$assetBundles = Yii::$app->cache->getOrSet($cacheKeyAssetBundles, [$phpBlockView, 'getAssetBundleNames'], $this->getCacheExpirationTime());
/**
* @todo i think this is not need because in PhpBlockView::init() the EVENT_AFTER_RENDER is listen also.
*/
PhpBlockView::registerToAppView($assets, $assetBundles);
}
} | php | public function onRegister()
{
if ($this->isCachingEnabled()) {
$phpBlockView = $this->getView();
$blockId = $this->getEnvOption('id');
$cacheKeyAssets = ['blockassets', $blockId];
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
$assets = Yii::$app->cache->getOrSet($cacheKeyAssets, [$phpBlockView, 'getBlockAssets'], $this->getCacheExpirationTime());
$assetBundles = Yii::$app->cache->getOrSet($cacheKeyAssetBundles, [$phpBlockView, 'getAssetBundleNames'], $this->getCacheExpirationTime());
/**
* @todo i think this is not need because in PhpBlockView::init() the EVENT_AFTER_RENDER is listen also.
*/
PhpBlockView::registerToAppView($assets, $assetBundles);
}
} | [
"public",
"function",
"onRegister",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCachingEnabled",
"(",
")",
")",
"{",
"$",
"phpBlockView",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"$",
"blockId",
"=",
"$",
"this",
"->",
"getEnvOption",
"(... | Save the registered assets form block to the cache.
@since 1.0.5 | [
"Save",
"the",
"registered",
"assets",
"form",
"block",
"to",
"the",
"cache",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/PhpBlock.php#L76-L94 |
luyadev/luya-module-cms | src/base/PhpBlock.php | PhpBlock.onRegisterFromCache | public function onRegisterFromCache()
{
if ($this->isCachingEnabled()) {
$blockId = $this->getEnvOption('id');
$cacheKeyAssets = ['blockassets', $blockId];
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
$assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
$assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
PhpBlockView::registerToAppView($assets, $assetBundles);
}
} | php | public function onRegisterFromCache()
{
if ($this->isCachingEnabled()) {
$blockId = $this->getEnvOption('id');
$cacheKeyAssets = ['blockassets', $blockId];
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
$assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
$assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
PhpBlockView::registerToAppView($assets, $assetBundles);
}
} | [
"public",
"function",
"onRegisterFromCache",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCachingEnabled",
"(",
")",
")",
"{",
"$",
"blockId",
"=",
"$",
"this",
"->",
"getEnvOption",
"(",
"'id'",
")",
";",
"$",
"cacheKeyAssets",
"=",
"[",
"'blockasset... | Load the block assets from cache and register to the app view.
@since 1.0.5 | [
"Load",
"the",
"block",
"assets",
"from",
"cache",
"and",
"register",
"to",
"the",
"app",
"view",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/PhpBlock.php#L101-L114 |
luyadev/luya-module-cms | src/frontend/controllers/BlockController.php | BlockController.actionIndex | public function actionIndex($callback, $id)
{
$model = NavItemPageBlockItem::findOne($id);
if (!$model) {
throw new Exception("Unable to find item id.");
}
$block = $model->block->getObject($model->id, 'callback');
if (!$block) {
throw new Exception("Unable to find block object.");
}
return ObjectHelper::callMethodSanitizeArguments($block, $this->callbackToMethod($callback), Yii::$app->request->get());
} | php | public function actionIndex($callback, $id)
{
$model = NavItemPageBlockItem::findOne($id);
if (!$model) {
throw new Exception("Unable to find item id.");
}
$block = $model->block->getObject($model->id, 'callback');
if (!$block) {
throw new Exception("Unable to find block object.");
}
return ObjectHelper::callMethodSanitizeArguments($block, $this->callbackToMethod($callback), Yii::$app->request->get());
} | [
"public",
"function",
"actionIndex",
"(",
"$",
"callback",
",",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"NavItemPageBlockItem",
"::",
"findOne",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Un... | Run the callback for a given block.
@param string $callback The name of the callback to call inside the block object.
@param integer $id The id of the block item where the callbacke is located.
@throws \luya\cms\Exception
@return mixed | [
"Run",
"the",
"callback",
"for",
"a",
"given",
"block",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/controllers/BlockController.php#L35-L50 |
luyadev/luya-module-cms | src/frontend/controllers/BlockController.php | BlockController.callbackToMethod | protected function callbackToMethod($callbackName)
{
if (!StringHelper::startsWith($callbackName, 'callback')) {
return 'callback' . Inflector::id2camel($callbackName);
}
return lcfirst(Inflector::id2camel($callbackName));
} | php | protected function callbackToMethod($callbackName)
{
if (!StringHelper::startsWith($callbackName, 'callback')) {
return 'callback' . Inflector::id2camel($callbackName);
}
return lcfirst(Inflector::id2camel($callbackName));
} | [
"protected",
"function",
"callbackToMethod",
"(",
"$",
"callbackName",
")",
"{",
"if",
"(",
"!",
"StringHelper",
"::",
"startsWith",
"(",
"$",
"callbackName",
",",
"'callback'",
")",
")",
"{",
"return",
"'callback'",
".",
"Inflector",
"::",
"id2camel",
"(",
... | Ensure the callback method from a given name.
The callback method must start with 'callback'.
@param string $callbackName The name of the callback, like `my-action`
@return string Convert the callbackname to `callbackMyAction` | [
"Ensure",
"the",
"callback",
"method",
"from",
"a",
"given",
"name",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/frontend/controllers/BlockController.php#L60-L67 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataMenu | public function actionDataMenu()
{
return [
'items' => ArrayHelper::typeCast(MenuHelper::getItems()),
'drafts' => ArrayHelper::typeCast(MenuHelper::getDrafts()),
'containers' => ArrayHelper::typeCast(MenuHelper::getContainers()),
'hiddenCats' => ArrayHelper::typeCast(Yii::$app->adminuser->identity->setting->get("togglecat", [])),
];
} | php | public function actionDataMenu()
{
return [
'items' => ArrayHelper::typeCast(MenuHelper::getItems()),
'drafts' => ArrayHelper::typeCast(MenuHelper::getDrafts()),
'containers' => ArrayHelper::typeCast(MenuHelper::getContainers()),
'hiddenCats' => ArrayHelper::typeCast(Yii::$app->adminuser->identity->setting->get("togglecat", [])),
];
} | [
"public",
"function",
"actionDataMenu",
"(",
")",
"{",
"return",
"[",
"'items'",
"=>",
"ArrayHelper",
"::",
"typeCast",
"(",
"MenuHelper",
"::",
"getItems",
"(",
")",
")",
",",
"'drafts'",
"=>",
"ArrayHelper",
"::",
"typeCast",
"(",
"MenuHelper",
"::",
"getD... | Returns an array with all data for the admin menu.
+ items
+ drafts
+ containers
+ hiddenCats
@return array | [
"Returns",
"an",
"array",
"with",
"all",
"data",
"for",
"the",
"admin",
"menu",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L32-L40 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionItems | public function actionItems($langId, $containerId)
{
$items = Nav::find()
->where(['nav_container_id' => $containerId, 'is_offline' => false, 'ni.lang_id' => $langId, 'is_deleted' => false])
->joinWith(['navItems ni'])
->asArray()
->all();
$result = [];
foreach ($items as $item) {
// rename from navItems to item
$item['item'] = reset($item['navItems']);
unset($item['navItems']);
$result[$item['parent_nav_id']][] = $item;
}
return $result;
} | php | public function actionItems($langId, $containerId)
{
$items = Nav::find()
->where(['nav_container_id' => $containerId, 'is_offline' => false, 'ni.lang_id' => $langId, 'is_deleted' => false])
->joinWith(['navItems ni'])
->asArray()
->all();
$result = [];
foreach ($items as $item) {
// rename from navItems to item
$item['item'] = reset($item['navItems']);
unset($item['navItems']);
$result[$item['parent_nav_id']][] = $item;
}
return $result;
} | [
"public",
"function",
"actionItems",
"(",
"$",
"langId",
",",
"$",
"containerId",
")",
"{",
"$",
"items",
"=",
"Nav",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'nav_container_id'",
"=>",
"$",
"containerId",
",",
"'is_offline'",
"=>",
"false",
","... | Provides all menu items for a given langId and containerId index by the parent_nav_id.
@param $langId
@param $containerId
@since 1.0.3 | [
"Provides",
"all",
"menu",
"items",
"for",
"a",
"given",
"langId",
"and",
"containerId",
"index",
"by",
"the",
"parent_nav_id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L49-L66 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionTree | public function actionDataPermissionTree()
{
$data = [];
// collect data
foreach (NavContainer::find()->with('navs')->all() as $container) {
$this->getItems($container);
$data['containers'][] = [
'containerInfo' => $container,
'items' => isset(self::$_permissionItemData[$container->id]) ? self::$_permissionItemData[$container->id] : [],
];
}
// collect group informations
foreach ($this->getGroups() as $group) {
$data['groups'][] = [
'name' => $group->name,
'id' => $group->id,
'fullPermission' => $this->groupHasFullPermission($group),
];
}
// return array with full data
return $data;
} | php | public function actionDataPermissionTree()
{
$data = [];
// collect data
foreach (NavContainer::find()->with('navs')->all() as $container) {
$this->getItems($container);
$data['containers'][] = [
'containerInfo' => $container,
'items' => isset(self::$_permissionItemData[$container->id]) ? self::$_permissionItemData[$container->id] : [],
];
}
// collect group informations
foreach ($this->getGroups() as $group) {
$data['groups'][] = [
'name' => $group->name,
'id' => $group->id,
'fullPermission' => $this->groupHasFullPermission($group),
];
}
// return array with full data
return $data;
} | [
"public",
"function",
"actionDataPermissionTree",
"(",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"// collect data",
"foreach",
"(",
"NavContainer",
"::",
"find",
"(",
")",
"->",
"with",
"(",
"'navs'",
")",
"->",
"all",
"(",
")",
"as",
"$",
"container",
... | Returns the full tree with groups, pages, is_inherit or not, does have rights or not as it was to hard to
implement this features directly with angular, now we just prepare anything withing php and delivers to angular only to display the data.
@return array | [
"Returns",
"the",
"full",
"tree",
"with",
"groups",
"pages",
"is_inherit",
"or",
"not",
"does",
"have",
"rights",
"or",
"not",
"as",
"it",
"was",
"to",
"hard",
"to",
"implement",
"this",
"features",
"directly",
"with",
"angular",
"now",
"we",
"just",
"prep... | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L74-L96 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.getGroups | private function getGroups()
{
if ($this->_groups === null) {
$this->_groups = Group::find()->all();
}
return $this->_groups;
} | php | private function getGroups()
{
if ($this->_groups === null) {
$this->_groups = Group::find()->all();
}
return $this->_groups;
} | [
"private",
"function",
"getGroups",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_groups",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_groups",
"=",
"Group",
"::",
"find",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",... | Get all groups as singleton instance.
@return \yii\db\ActiveRecord | [
"Get",
"all",
"groups",
"as",
"singleton",
"instance",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L116-L123 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.getItems | private function getItems(NavContainer $container, $parentNavId = 0, $parentGroup = [], $index = 1)
{
$navs = $container->getNavs()->andWhere(['parent_nav_id' => $parentNavId])->all();
foreach ($navs as $nav) {
$array = $nav->toArray();
if (empty($nav->activeLanguageItem)) {
continue;
}
$array['title'] = $nav->activeLanguageItem->title;
foreach ($this->getGroups() as $key => $group) {
$isInheritedFromParent = false;
if (isset($parentGroup[$key])) {
if ($parentGroup[$key]['isGroupPermissionInheritNode'] || $parentGroup[$key]['isInheritedFromParent']) {
$isInheritedFromParent = true;
}
}
$array['groups'][$key] = [
'id' => $group->id,
'isGroupPermissionInheritNode' => $nav->isGroupPermissionInheritNode($group),
'hasGroupPermission' => $nav->hasGroupPermission($group),
'isInheritedFromParent' => $isInheritedFromParent,
'permissionCheckbox' => $nav->hasGroupPermissionSelected($group),
'groupFullPermission' => $this->groupHasFullPermission($group),
];
}
$array['nav_level'] = $index;
self::$_permissionItemData[$container->id][] = $array;
$this->getItems($container, $nav->id, $array['groups'], $index+1);
}
} | php | private function getItems(NavContainer $container, $parentNavId = 0, $parentGroup = [], $index = 1)
{
$navs = $container->getNavs()->andWhere(['parent_nav_id' => $parentNavId])->all();
foreach ($navs as $nav) {
$array = $nav->toArray();
if (empty($nav->activeLanguageItem)) {
continue;
}
$array['title'] = $nav->activeLanguageItem->title;
foreach ($this->getGroups() as $key => $group) {
$isInheritedFromParent = false;
if (isset($parentGroup[$key])) {
if ($parentGroup[$key]['isGroupPermissionInheritNode'] || $parentGroup[$key]['isInheritedFromParent']) {
$isInheritedFromParent = true;
}
}
$array['groups'][$key] = [
'id' => $group->id,
'isGroupPermissionInheritNode' => $nav->isGroupPermissionInheritNode($group),
'hasGroupPermission' => $nav->hasGroupPermission($group),
'isInheritedFromParent' => $isInheritedFromParent,
'permissionCheckbox' => $nav->hasGroupPermissionSelected($group),
'groupFullPermission' => $this->groupHasFullPermission($group),
];
}
$array['nav_level'] = $index;
self::$_permissionItemData[$container->id][] = $array;
$this->getItems($container, $nav->id, $array['groups'], $index+1);
}
} | [
"private",
"function",
"getItems",
"(",
"NavContainer",
"$",
"container",
",",
"$",
"parentNavId",
"=",
"0",
",",
"$",
"parentGroup",
"=",
"[",
"]",
",",
"$",
"index",
"=",
"1",
")",
"{",
"$",
"navs",
"=",
"$",
"container",
"->",
"getNavs",
"(",
")",... | Build a trree with items for a given NavContainer.
@param NavContainer $container
@param int $parentNavId
@param array $parentGroup
@param int $index | [
"Build",
"a",
"trree",
"with",
"items",
"for",
"a",
"given",
"NavContainer",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L135-L172 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionInsert | public function actionDataPermissionInsert()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
return Yii::$app->db->createCommand()->insert('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
} | php | public function actionDataPermissionInsert()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
return Yii::$app->db->createCommand()->insert('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
} | [
"public",
"function",
"actionDataPermissionInsert",
"(",
")",
"{",
"$",
"navId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'navId'",
")",
";",
"$",
"groupId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"... | Save a new permission for a given group and nav id.
@return int | [
"Save",
"a",
"new",
"permission",
"for",
"a",
"given",
"group",
"and",
"nav",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L179-L189 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionInsertInheritance | public function actionDataPermissionInsertInheritance()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
$exists = (new Query())->from("cms_nav_permission")->where(['group_id' => $groupId, 'nav_id' => $navId])->exists();
if ($exists) {
Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
}
return Yii::$app->db->createCommand()->insert('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId, 'inheritance' => true])->execute();
} | php | public function actionDataPermissionInsertInheritance()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
$exists = (new Query())->from("cms_nav_permission")->where(['group_id' => $groupId, 'nav_id' => $navId])->exists();
if ($exists) {
Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
}
return Yii::$app->db->createCommand()->insert('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId, 'inheritance' => true])->execute();
} | [
"public",
"function",
"actionDataPermissionInsertInheritance",
"(",
")",
"{",
"$",
"navId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'navId'",
")",
";",
"$",
"groupId",
"=",
"(",
"int",
")",
"Yii",
"::",... | Save a new permission inhertiance for a given group and nav id.
@return boolean | [
"Save",
"a",
"new",
"permission",
"inhertiance",
"for",
"a",
"given",
"group",
"and",
"nav",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L196-L212 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionDelete | public function actionDataPermissionDelete()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
} | php | public function actionDataPermissionDelete()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
} | [
"public",
"function",
"actionDataPermissionDelete",
"(",
")",
"{",
"$",
"navId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'navId'",
")",
";",
"$",
"groupId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"... | Delete the permission for a given group and nav id.
@return int | [
"Delete",
"the",
"permission",
"for",
"a",
"given",
"group",
"and",
"nav",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L219-L229 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionDeleteInheritance | public function actionDataPermissionDeleteInheritance()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
$exists = (new Query())->from("cms_nav_permission")->where(['group_id' => $groupId, 'nav_id' => $navId])->exists();
if ($exists) {
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
}
return false;
} | php | public function actionDataPermissionDeleteInheritance()
{
$navId = (int) Yii::$app->request->getBodyParam('navId');
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($navId) || empty($groupId)) {
throw new InvalidArgumentException("navId and groupId can not be empty.");
}
$exists = (new Query())->from("cms_nav_permission")->where(['group_id' => $groupId, 'nav_id' => $navId])->exists();
if ($exists) {
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId, 'nav_id' => $navId])->execute();
}
return false;
} | [
"public",
"function",
"actionDataPermissionDeleteInheritance",
"(",
")",
"{",
"$",
"navId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'navId'",
")",
";",
"$",
"groupId",
"=",
"(",
"int",
")",
"Yii",
"::",... | Delete the permission inheritance for a given group and nav id. | [
"Delete",
"the",
"permission",
"inheritance",
"for",
"a",
"given",
"group",
"and",
"nav",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L234-L250 |
luyadev/luya-module-cms | src/admin/apis/MenuController.php | MenuController.actionDataPermissionGrantGroup | public function actionDataPermissionGrantGroup()
{
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($groupId)) {
throw new InvalidArgumentException("groupId can not be empty.");
}
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId])->execute();
} | php | public function actionDataPermissionGrantGroup()
{
$groupId = (int) Yii::$app->request->getBodyParam('groupId');
if (empty($groupId)) {
throw new InvalidArgumentException("groupId can not be empty.");
}
return Yii::$app->db->createCommand()->delete('cms_nav_permission', ['group_id' => $groupId])->execute();
} | [
"public",
"function",
"actionDataPermissionGrantGroup",
"(",
")",
"{",
"$",
"groupId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'groupId'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"groupId",
")",
")",
... | Grant access to a given group. | [
"Grant",
"access",
"to",
"a",
"given",
"group",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/MenuController.php#L255-L264 |
luyadev/luya-module-cms | src/admin/helpers/MenuHelper.php | MenuHelper.getItems | public static function getItems()
{
if (self::$items === null) {
$items = (new Query())
->select(['cms_nav.id', 'nav_item_id' => 'cms_nav_item.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'layout_file', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title', 'publish_from', 'publish_till'])
->from('cms_nav')
->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')
->orderBy(['sort_index' => SORT_ASC])
->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => false, 'cms_nav.is_draft' => false])
->all();
self::loadInheritanceData(0);
$data = [];
foreach ($items as $key => $item) {
$item['is_editable'] = (int) Yii::$app->adminuser->canRoute('cmsadmin/page/update');
$item['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get('tree.'.$item['id']);
// the user have "page edit" permission, now we can check if the this group has more fined tuned permisionss from the
// cms_nav_permissions table or not
if ($item['is_editable']) {
$permitted = false;
foreach (Yii::$app->adminuser->identity->groups as $group) {
if ($permitted) {
continue;
}
$permitted = self::navGroupPermission($item['id'], $group->id);
}
if (!$permitted) {
$value = (isset(self::$_inheritData[$item['id']])) ? self::$_inheritData[$item['id']] : false;
if ($value === true) {
$permitted = true;
}
}
$item['is_editable'] = $permitted;
}
$data[$key] = $item;
}
self::$items = $data;
}
return self::$items;
} | php | public static function getItems()
{
if (self::$items === null) {
$items = (new Query())
->select(['cms_nav.id', 'nav_item_id' => 'cms_nav_item.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'layout_file', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title', 'publish_from', 'publish_till'])
->from('cms_nav')
->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')
->orderBy(['sort_index' => SORT_ASC])
->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => false, 'cms_nav.is_draft' => false])
->all();
self::loadInheritanceData(0);
$data = [];
foreach ($items as $key => $item) {
$item['is_editable'] = (int) Yii::$app->adminuser->canRoute('cmsadmin/page/update');
$item['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get('tree.'.$item['id']);
// the user have "page edit" permission, now we can check if the this group has more fined tuned permisionss from the
// cms_nav_permissions table or not
if ($item['is_editable']) {
$permitted = false;
foreach (Yii::$app->adminuser->identity->groups as $group) {
if ($permitted) {
continue;
}
$permitted = self::navGroupPermission($item['id'], $group->id);
}
if (!$permitted) {
$value = (isset(self::$_inheritData[$item['id']])) ? self::$_inheritData[$item['id']] : false;
if ($value === true) {
$permitted = true;
}
}
$item['is_editable'] = $permitted;
}
$data[$key] = $item;
}
self::$items = $data;
}
return self::$items;
} | [
"public",
"static",
"function",
"getItems",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"items",
"===",
"null",
")",
"{",
"$",
"items",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'cms_nav.id'",
",",
"'nav_item_id'",
"=>",
... | Get all nav data entries with corresponding item content
@return array | [
"Get",
"all",
"nav",
"data",
"entries",
"with",
"corresponding",
"item",
"content"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/helpers/MenuHelper.php#L27-L76 |
luyadev/luya-module-cms | src/admin/helpers/MenuHelper.php | MenuHelper.loadInheritanceData | private static function loadInheritanceData($parentNavId = 0, $fromInheritNode = false)
{
// get items from singleton object
$items = (isset(self::getNavItems()[$parentNavId])) ? self::getNavItems()[$parentNavId] : [];
foreach ($items as $item) {
$internalCheck = false;
foreach (Yii::$app->adminuser->identity->groups as $group) {
if ($internalCheck) {
continue;
}
$internalCheck = self::navGroupInheritanceNode($item['id'], $group);
}
if (!array_key_exists($item['id'], self::$_inheritData)) {
if ($fromInheritNode || $internalCheck) {
self::$_inheritData[$item['id']] = true;
} else {
self::$_inheritData[$item['id']] = false;
}
}
self::loadInheritanceData($item['id'], self::$_inheritData[$item['id']]);
}
} | php | private static function loadInheritanceData($parentNavId = 0, $fromInheritNode = false)
{
// get items from singleton object
$items = (isset(self::getNavItems()[$parentNavId])) ? self::getNavItems()[$parentNavId] : [];
foreach ($items as $item) {
$internalCheck = false;
foreach (Yii::$app->adminuser->identity->groups as $group) {
if ($internalCheck) {
continue;
}
$internalCheck = self::navGroupInheritanceNode($item['id'], $group);
}
if (!array_key_exists($item['id'], self::$_inheritData)) {
if ($fromInheritNode || $internalCheck) {
self::$_inheritData[$item['id']] = true;
} else {
self::$_inheritData[$item['id']] = false;
}
}
self::loadInheritanceData($item['id'], self::$_inheritData[$item['id']]);
}
} | [
"private",
"static",
"function",
"loadInheritanceData",
"(",
"$",
"parentNavId",
"=",
"0",
",",
"$",
"fromInheritNode",
"=",
"false",
")",
"{",
"// get items from singleton object",
"$",
"items",
"=",
"(",
"isset",
"(",
"self",
"::",
"getNavItems",
"(",
")",
"... | Find nav_id inheritances
+ Get all cms_nav items where is deleted 0 and sort_asc
+ foreach items
+ foreach all user groups for this item to check if an inheritance nod exists for this nav_item (self::navGroupInheritanceNode)
+ Set the interanl check to false, if inherit or internal check is true, set value into $data factory
+ proceed nodes of the current item with the information form $data factory as inheritation info.
@param integer $parentNavId
@param string $fromInheritNode | [
"Find",
"nav_id",
"inheritances"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/helpers/MenuHelper.php#L106-L128 |
luyadev/luya-module-cms | src/admin/helpers/MenuHelper.php | MenuHelper.getContainers | public static function getContainers()
{
if (self::$containers === null) {
self::$containers = (new Query())->select(['id', 'name', 'alias'])->from('cms_nav_container')->where(['is_deleted' => false])->indexBy('id')->orderBy(['cms_nav_container.id' => 'ASC'])->all();
}
return self::$containers;
} | php | public static function getContainers()
{
if (self::$containers === null) {
self::$containers = (new Query())->select(['id', 'name', 'alias'])->from('cms_nav_container')->where(['is_deleted' => false])->indexBy('id')->orderBy(['cms_nav_container.id' => 'ASC'])->all();
}
return self::$containers;
} | [
"public",
"static",
"function",
"getContainers",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"containers",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"containers",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'... | Get all cms containers
@return array | [
"Get",
"all",
"cms",
"containers"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/helpers/MenuHelper.php#L200-L207 |
luyadev/luya-module-cms | src/admin/helpers/MenuHelper.php | MenuHelper.getDrafts | public static function getDrafts()
{
if (self::$drafts === null) {
self::$drafts = (new Query())
->select(['cms_nav.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])
->from('cms_nav')
->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')
->orderBy('cms_nav.sort_index ASC')
->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => false, 'cms_nav.is_draft' => true])
->all();
}
return self::$drafts;
} | php | public static function getDrafts()
{
if (self::$drafts === null) {
self::$drafts = (new Query())
->select(['cms_nav.id', 'nav_container_id', 'parent_nav_id', 'is_hidden', 'is_offline', 'is_draft', 'is_home', 'cms_nav_item.title'])
->from('cms_nav')
->leftJoin('cms_nav_item', 'cms_nav.id=cms_nav_item.nav_id')
->orderBy('cms_nav.sort_index ASC')
->where(['cms_nav_item.lang_id' => Lang::getDefault()['id'], 'cms_nav.is_deleted' => false, 'cms_nav.is_draft' => true])
->all();
}
return self::$drafts;
} | [
"public",
"static",
"function",
"getDrafts",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"drafts",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"drafts",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'cms_nav.id'",
",",
"'nav_... | Get all drafts nav items
@return array | [
"Get",
"all",
"drafts",
"nav",
"items"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/helpers/MenuHelper.php#L216-L229 |
luyadev/luya-module-cms | src/admin/Module.php | Module.setBlockVariations | public function setBlockVariations(array $config)
{
$_variations = [];
foreach ($config as $key => $content) {
if (is_numeric($key) && is_array($content)) {
$_variations[key($content)] = array_shift($content);
} else {
$_variations[$key] = $content;
}
}
$this->_blockVariations = $_variations;
} | php | public function setBlockVariations(array $config)
{
$_variations = [];
foreach ($config as $key => $content) {
if (is_numeric($key) && is_array($content)) {
$_variations[key($content)] = array_shift($content);
} else {
$_variations[$key] = $content;
}
}
$this->_blockVariations = $_variations;
} | [
"public",
"function",
"setBlockVariations",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"_variations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"content",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",... | Set block variations.
```php
'blockVariations' => [
TextBlock::class => [
'variation1' => [
'title' => 'Super Bold Text',
'vars' => ['cssClass' => 'bold-font-css-class'],
'cfgs' => [], // will be ignore as its empty, so you can also just remove this part.
'extras' => [], // will be ignore as its empty, so you can also just remove this part.
'is_default' => false, // where this is the default value or not
],
]
]
```
@param array $config | [
"Set",
"block",
"variations",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/Module.php#L228-L239 |
luyadev/luya-module-cms | src/admin/Module.php | Module.getAuthorUserId | public static function getAuthorUserId()
{
return (Yii::$app instanceof \luya\web\Application) ? Yii::$app->adminuser->getId() : self::$_authorUserId;
} | php | public static function getAuthorUserId()
{
return (Yii::$app instanceof \luya\web\Application) ? Yii::$app->adminuser->getId() : self::$_authorUserId;
} | [
"public",
"static",
"function",
"getAuthorUserId",
"(",
")",
"{",
"return",
"(",
"Yii",
"::",
"$",
"app",
"instanceof",
"\\",
"luya",
"\\",
"web",
"\\",
"Application",
")",
"?",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"getId",
"(",
")",
":",
... | Get the user id of the logged in user in web appliation context.
@return integer | [
"Get",
"the",
"user",
"id",
"of",
"the",
"logged",
"in",
"user",
"in",
"web",
"appliation",
"context",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/Module.php#L370-L373 |
luyadev/luya-module-cms | src/base/BlockVariationRegister.php | BlockVariationRegister.add | public function add($identifier, $title)
{
$identifier = Inflector::slug($identifier);
$this->_variations[$identifier] = [
'title' => $title,
'cfgs' => [],
'vars' => [],
'extras' => [],
'is_default' => false,
];
$this->_tempIdentifier = $identifier;
return $this;
} | php | public function add($identifier, $title)
{
$identifier = Inflector::slug($identifier);
$this->_variations[$identifier] = [
'title' => $title,
'cfgs' => [],
'vars' => [],
'extras' => [],
'is_default' => false,
];
$this->_tempIdentifier = $identifier;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"identifier",
",",
"$",
"title",
")",
"{",
"$",
"identifier",
"=",
"Inflector",
"::",
"slug",
"(",
"$",
"identifier",
")",
";",
"$",
"this",
"->",
"_variations",
"[",
"$",
"identifier",
"]",
"=",
"[",
"'title'",
... | Register a new flavor.
@param string $identifier
@param string $title
@return \luya\cms\base\BlockVariationRegister | [
"Register",
"a",
"new",
"flavor",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/base/BlockVariationRegister.php#L62-L74 |
luyadev/luya-module-cms | src/menu/Query.php | Query.getMenu | public function getMenu()
{
if ($this->_menu === null) {
$this->_menu = Yii::$app->get('menu');
}
return $this->_menu;
} | php | public function getMenu()
{
if ($this->_menu === null) {
$this->_menu = Yii::$app->get('menu');
}
return $this->_menu;
} | [
"public",
"function",
"getMenu",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_menu",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_menu",
"=",
"Yii",
"::",
"$",
"app",
"->",
"get",
"(",
"'menu'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_... | Getter method to return menu component
@return \luya\cms\Menu Menu Container object | [
"Getter",
"method",
"to",
"return",
"menu",
"component"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L65-L72 |
luyadev/luya-module-cms | src/menu/Query.php | Query.where | public function where(array $args)
{
foreach ($args as $key => $value) {
if (in_array($value, $this->whereOperators, true)) {
if (count($args) !== 3) {
throw new Exception(sprintf("Wrong where(['%s']) condition, see https://luya.io/api/luya-cms-menu-Query#where()-detail for all available conditions.", implode("', '", $args)));
}
$this->_where[] = ['op' => $args[0], 'field' => $args[1], 'value' => $args[2]];
break;
} else {
$this->_where[] = ['op' => '=', 'field' => $key, 'value' => $value];
}
}
return $this;
} | php | public function where(array $args)
{
foreach ($args as $key => $value) {
if (in_array($value, $this->whereOperators, true)) {
if (count($args) !== 3) {
throw new Exception(sprintf("Wrong where(['%s']) condition, see https://luya.io/api/luya-cms-menu-Query#where()-detail for all available conditions.", implode("', '", $args)));
}
$this->_where[] = ['op' => $args[0], 'field' => $args[1], 'value' => $args[2]];
break;
} else {
$this->_where[] = ['op' => '=', 'field' => $key, 'value' => $value];
}
}
return $this;
} | [
"public",
"function",
"where",
"(",
"array",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"whereOperators",
",",
"true",
")",
... | Query where similar behavior of filtering items.
**Operator Filtering**
```php
where(['operator', 'field', 'value']);
```
Available compare operators:
+ **<** expression where field is smaller then value.
+ **>** expression where field is bigger then value.
+ **=** expression where field is equal value.
+ **<=** expression where field is small or equal then value.
+ **>=** expression where field is bigger or equal then value.
+ **==** expression where field is equal to the value and even the type must be equal.
+ **in** expression where the second value is an array with values to look inside.
Only one operator speific argument can be provided, to chain another expression
use the `andWhere()` method.
**Multi Dimension Filtering**
The most common case for filtering items is the equal expression combined with
add statements.
For example the following expression
```php
where(['=', 'parent_nav_id', 0])->andWhere(['=', 'container', 'footer']);
```
is equal to the short form multi deimnsion filtering expression
```php
where(['parent_nav_id' => 0, 'container' => 'footer']);
```
Its **not possibile** to make where conditions on the **same column name** (id in this example).
```php
where(['>', 'id', 1])->andWHere(['<', 'id', 3]);
```
This will only append the first condition where id is bigger then 1 and ignore the second one.
Example using in operator
```php
where(['in', 'container', ['default', 'footer']); // querys all items from the containers `default` and `footer`.
```
@param array $args The where defintion can be either an key-value pairing or a condition representen as array.
@return Query
@throws Exception | [
"Query",
"where",
"similar",
"behavior",
"of",
"filtering",
"items",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L163-L178 |
luyadev/luya-module-cms | src/menu/Query.php | Query.with | public function with($types)
{
$types = (array) $types;
foreach ($types as $type) {
if (isset($this->_with[$type])) {
$this->_with[$type] = true;
}
}
return $this;
} | php | public function with($types)
{
$types = (array) $types;
foreach ($types as $type) {
if (isset($this->_with[$type])) {
$this->_with[$type] = true;
}
}
return $this;
} | [
"public",
"function",
"with",
"(",
"$",
"types",
")",
"{",
"$",
"types",
"=",
"(",
"array",
")",
"$",
"types",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_with",
"[",
"$",
"type"... | With/Without expression to hidde or display data from the Menu Query.
@param string|array $types can be a string containg "hidden" or an array with multiple with statements
for example `['hidden']`. Further with statements upcoming.
@return \luya\cms\menu\Query | [
"With",
"/",
"Without",
"expression",
"to",
"hidde",
"or",
"display",
"data",
"from",
"the",
"Menu",
"Query",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L219-L229 |
luyadev/luya-module-cms | src/menu/Query.php | Query.getLang | public function getLang()
{
if ($this->_lang === null) {
$this->_lang = $this->menu->composition['langShortCode'];
}
return $this->_lang;
} | php | public function getLang()
{
if ($this->_lang === null) {
$this->_lang = $this->menu->composition['langShortCode'];
}
return $this->_lang;
} | [
"public",
"function",
"getLang",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_lang",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_lang",
"=",
"$",
"this",
"->",
"menu",
"->",
"composition",
"[",
"'langShortCode'",
"]",
";",
"}",
"return",
"$",
"... | Return the current language from composition if not set via `lang()`.
@return string | [
"Return",
"the",
"current",
"language",
"from",
"composition",
"if",
"not",
"set",
"via",
"lang",
"()",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L254-L261 |
luyadev/luya-module-cms | src/menu/Query.php | Query.orderBy | public function orderBy(array $order)
{
$orderBy = ['keys' => [], 'directions' => []];
foreach ($order as $key => $direction) {
$orderBy['keys'][] = $key;
$orderBy['directions'][] = $direction;
}
$this->_order = $orderBy;
return $this;
} | php | public function orderBy(array $order)
{
$orderBy = ['keys' => [], 'directions' => []];
foreach ($order as $key => $direction) {
$orderBy['keys'][] = $key;
$orderBy['directions'][] = $direction;
}
$this->_order = $orderBy;
return $this;
} | [
"public",
"function",
"orderBy",
"(",
"array",
"$",
"order",
")",
"{",
"$",
"orderBy",
"=",
"[",
"'keys'",
"=>",
"[",
"]",
",",
"'directions'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"order",
"as",
"$",
"key",
"=>",
"$",
"direction",
")",
... | Order the query by one or multiple fields asc or desc.
Use following PHP constants for directions:
+ SORT_ASC: 1..10, A..Z
+ SORT_DESC: 10..1, Z..A
Example using orderBy:
```php
$query = new Query()->orderBy([Query::FIELD_TIMESTAMPCREATE => SORT_ASC, Query::FIELD_ALIAS => SORT_DESC'])->all();
```
@param array $order An array with fields to sort where key is the field and value the direction.
@since 1.0.2 | [
"Order",
"the",
"query",
"by",
"one",
"or",
"multiple",
"fields",
"asc",
"or",
"desc",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L318-L330 |
luyadev/luya-module-cms | src/menu/Query.php | Query.one | public function one()
{
$data = $this->filter($this->menu[$this->getLang()], $this->_where, $this->_with);
if (count($data) == 0) {
return false;
}
return static::createItemObject(array_values($data)[0], $this->getLang());
} | php | public function one()
{
$data = $this->filter($this->menu[$this->getLang()], $this->_where, $this->_with);
if (count($data) == 0) {
return false;
}
return static::createItemObject(array_values($data)[0], $this->getLang());
} | [
"public",
"function",
"one",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"this",
"->",
"getLang",
"(",
")",
"]",
",",
"$",
"this",
"->",
"_where",
",",
"$",
"this",
"->",
"_with",
")",... | Retrieve only one result for your query, even if there are more rows then one, it will
just pick the first row from the filtered result and return the item object. If the filtering
based on the query settings does not return any result, the return will be false.
@return \luya\cms\menu\Item|boolean Returns the Item object or false if nothing found. | [
"Retrieve",
"only",
"one",
"result",
"for",
"your",
"query",
"even",
"if",
"there",
"are",
"more",
"rows",
"then",
"one",
"it",
"will",
"just",
"pick",
"the",
"first",
"row",
"from",
"the",
"filtered",
"result",
"and",
"return",
"the",
"item",
"object",
... | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L339-L348 |
luyadev/luya-module-cms | src/menu/Query.php | Query.all | public function all()
{
return static::createArrayIterator($this->filter($this->menu[$this->getLang()], $this->_where, $this->_with), $this->getLang(), $this->_with, $this->_preloadModels);
} | php | public function all()
{
return static::createArrayIterator($this->filter($this->menu[$this->getLang()], $this->_where, $this->_with), $this->getLang(), $this->_with, $this->_preloadModels);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"return",
"static",
"::",
"createArrayIterator",
"(",
"$",
"this",
"->",
"filter",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"this",
"->",
"getLang",
"(",
")",
"]",
",",
"$",
"this",
"->",
"_where",
",",
... | Retrieve all found rows based on the filtering options and returns the the QueryIterator object
which is represents an array.
@return \luya\cms\menu\QueryIterator Returns the QueryIterator object. | [
"Retrieve",
"all",
"found",
"rows",
"based",
"on",
"the",
"filtering",
"options",
"and",
"returns",
"the",
"the",
"QueryIterator",
"object",
"which",
"is",
"represents",
"an",
"array",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L356-L359 |
luyadev/luya-module-cms | src/menu/Query.php | Query.count | public function count()
{
return count($this->filter($this->menu[$this->getLang()], $this->_where, $this->_with));
} | php | public function count()
{
return count($this->filter($this->menu[$this->getLang()], $this->_where, $this->_with));
} | [
"public",
"function",
"count",
"(",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"filter",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"this",
"->",
"getLang",
"(",
")",
"]",
",",
"$",
"this",
"->",
"_where",
",",
"$",
"this",
"->",
"_with"... | Returns the count for the provided filter options.
@return integer The number of rows for your filtering options. | [
"Returns",
"the",
"count",
"for",
"the",
"provided",
"filter",
"options",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L366-L369 |
luyadev/luya-module-cms | src/menu/Query.php | Query.createArrayIterator | public static function createArrayIterator(array $data, $langContext, $with, $preloadModels = false)
{
return (new QueryIteratorFilter(new QueryIterator(['data' => $data, 'lang' => $langContext, 'with' => $with, 'preloadModels' => $preloadModels])));
} | php | public static function createArrayIterator(array $data, $langContext, $with, $preloadModels = false)
{
return (new QueryIteratorFilter(new QueryIterator(['data' => $data, 'lang' => $langContext, 'with' => $with, 'preloadModels' => $preloadModels])));
} | [
"public",
"static",
"function",
"createArrayIterator",
"(",
"array",
"$",
"data",
",",
"$",
"langContext",
",",
"$",
"with",
",",
"$",
"preloadModels",
"=",
"false",
")",
"{",
"return",
"(",
"new",
"QueryIteratorFilter",
"(",
"new",
"QueryIterator",
"(",
"["... | Static method to create an iterator object based on the provided array data with
optional language context.
@param array $data The filtere results where the iterator object should be created with
@param string $langContext The language short code context, if any.
@param integer $preloadModels Whether the models should be preload or not.
@return \luya\cms\menu\QueryIterator | [
"Static",
"method",
"to",
"create",
"an",
"iterator",
"object",
"based",
"on",
"the",
"provided",
"array",
"data",
"with",
"optional",
"language",
"context",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L380-L383 |
luyadev/luya-module-cms | src/menu/Query.php | Query.filter | private function filter(array $containerData, array $whereExpression, array $withCondition)
{
$data = array_filter($containerData, function ($item) use ($whereExpression, $withCondition) {
foreach ($item as $field => $value) {
if (!$this->arrayFilter($value, $field, $whereExpression, $withCondition)) {
return false;
}
}
return true;
});
if ($this->_order !== null) {
ArrayHelper::multisort($data, $this->_order['keys'], $this->_order['directions']);
}
if ($this->_offset !== null) {
$data = array_slice($data, $this->_offset, null, true);
}
if ($this->_limit !== null) {
$data = array_slice($data, 0, $this->_limit, true);
}
return $data;
} | php | private function filter(array $containerData, array $whereExpression, array $withCondition)
{
$data = array_filter($containerData, function ($item) use ($whereExpression, $withCondition) {
foreach ($item as $field => $value) {
if (!$this->arrayFilter($value, $field, $whereExpression, $withCondition)) {
return false;
}
}
return true;
});
if ($this->_order !== null) {
ArrayHelper::multisort($data, $this->_order['keys'], $this->_order['directions']);
}
if ($this->_offset !== null) {
$data = array_slice($data, $this->_offset, null, true);
}
if ($this->_limit !== null) {
$data = array_slice($data, 0, $this->_limit, true);
}
return $data;
} | [
"private",
"function",
"filter",
"(",
"array",
"$",
"containerData",
",",
"array",
"$",
"whereExpression",
",",
"array",
"$",
"withCondition",
")",
"{",
"$",
"data",
"=",
"array_filter",
"(",
"$",
"containerData",
",",
"function",
"(",
"$",
"item",
")",
"u... | Filtering data based on a where expression.
@param array $containerData The data to filter from
@param array $whereExpression An array with `[['op' => '=', 'field' => 'fieldName', 'value' => 'comparevalue'],[]]`
@param array $withCondition An array with with conditions `$with['hidden']`.
@return array | [
"Filtering",
"data",
"based",
"on",
"a",
"where",
"expression",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L407-L432 |
luyadev/luya-module-cms | src/menu/Query.php | Query.arrayFilter | private function arrayFilter($value, $field, array $where, array $with)
{
if ($field == 'is_hidden' && $with['hidden'] === false && $value == 1) {
return false;
}
foreach ($where as $expression) {
if ($expression['field'] == $field) {
switch ($expression['op']) {
case '==':
return ($value === $expression['value']);
case '>':
return ($value > $expression['value']);
case '>=':
return ($value >= $expression['value']);
case '<':
return ($value < $expression['value']);
case '<=':
return ($value <= $expression['value']);
case 'in':
return in_array($value, $expression['value']);
case '!=':
return ($value != $expression['value']);
default:
return ($value == $expression['value']);
}
}
}
return true;
} | php | private function arrayFilter($value, $field, array $where, array $with)
{
if ($field == 'is_hidden' && $with['hidden'] === false && $value == 1) {
return false;
}
foreach ($where as $expression) {
if ($expression['field'] == $field) {
switch ($expression['op']) {
case '==':
return ($value === $expression['value']);
case '>':
return ($value > $expression['value']);
case '>=':
return ($value >= $expression['value']);
case '<':
return ($value < $expression['value']);
case '<=':
return ($value <= $expression['value']);
case 'in':
return in_array($value, $expression['value']);
case '!=':
return ($value != $expression['value']);
default:
return ($value == $expression['value']);
}
}
}
return true;
} | [
"private",
"function",
"arrayFilter",
"(",
"$",
"value",
",",
"$",
"field",
",",
"array",
"$",
"where",
",",
"array",
"$",
"with",
")",
"{",
"if",
"(",
"$",
"field",
"==",
"'is_hidden'",
"&&",
"$",
"with",
"[",
"'hidden'",
"]",
"===",
"false",
"&&",
... | Filter an array item based on the where expression.
@param string $value
@param string $field
@param array $where
@param array $with
@return boolean | [
"Filter",
"an",
"array",
"item",
"based",
"on",
"the",
"where",
"expression",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/menu/Query.php#L443-L473 |
luyadev/luya-module-cms | src/models/NavItemPageBlockItem.php | NavItemPageBlockItem.eventAfterUpdate | public function eventAfterUpdate()
{
$this->updateNavItemTimesamp();
if (!empty($this->_olds)) {
$oldPlaceholderVar = $this->_olds['placeholder_var'];
$oldPrevId = (int) $this->_olds['prev_id'];
if ($oldPlaceholderVar != $this->placeholder_var || $oldPrevId != $this->prev_id) {
$this->reindex($this->nav_item_page_id, $oldPlaceholderVar, $oldPrevId);
}
$this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id);
Log::add(2, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'update', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id);
}
} | php | public function eventAfterUpdate()
{
$this->updateNavItemTimesamp();
if (!empty($this->_olds)) {
$oldPlaceholderVar = $this->_olds['placeholder_var'];
$oldPrevId = (int) $this->_olds['prev_id'];
if ($oldPlaceholderVar != $this->placeholder_var || $oldPrevId != $this->prev_id) {
$this->reindex($this->nav_item_page_id, $oldPlaceholderVar, $oldPrevId);
}
$this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id);
Log::add(2, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'update', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id);
}
} | [
"public",
"function",
"eventAfterUpdate",
"(",
")",
"{",
"$",
"this",
"->",
"updateNavItemTimesamp",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_olds",
")",
")",
"{",
"$",
"oldPlaceholderVar",
"=",
"$",
"this",
"->",
"_olds",
"[",... | Event after update | [
"Event",
"after",
"update"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPageBlockItem.php#L193-L205 |
luyadev/luya-module-cms | src/models/NavItemPageBlockItem.php | NavItemPageBlockItem.eventBeforeDelete | public function eventBeforeDelete()
{
// delete all attached sub blocks
$this->deleteAllSubBlocks($this->id);
//save block data for afterDeleteEvent
$this->_olds = $this->getOldAttributes();
// verify if the block exists or not
$class = ($this->block) ? $this->block->getNameForLog() : '[class has been removed from the filesystem]';
// log event
Log::add(3, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'delete', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $class], 'cms_nav_item_page_block_item', $this->id);
} | php | public function eventBeforeDelete()
{
// delete all attached sub blocks
$this->deleteAllSubBlocks($this->id);
//save block data for afterDeleteEvent
$this->_olds = $this->getOldAttributes();
// verify if the block exists or not
$class = ($this->block) ? $this->block->getNameForLog() : '[class has been removed from the filesystem]';
// log event
Log::add(3, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'delete', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $class], 'cms_nav_item_page_block_item', $this->id);
} | [
"public",
"function",
"eventBeforeDelete",
"(",
")",
"{",
"// delete all attached sub blocks",
"$",
"this",
"->",
"deleteAllSubBlocks",
"(",
"$",
"this",
"->",
"id",
")",
";",
"//save block data for afterDeleteEvent",
"$",
"this",
"->",
"_olds",
"=",
"$",
"this",
... | Event before delete | [
"Event",
"before",
"delete"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPageBlockItem.php#L210-L220 |
luyadev/luya-module-cms | src/models/NavItemPageBlockItem.php | NavItemPageBlockItem.eventAfterDelete | public function eventAfterDelete()
{
$this->updateNavItemTimesamp();
if (!empty($this->_olds)) {
$this->reindex($this->_olds['nav_item_page_id'], $this->_olds['placeholder_var'], $this->_olds['prev_id']);
}
} | php | public function eventAfterDelete()
{
$this->updateNavItemTimesamp();
if (!empty($this->_olds)) {
$this->reindex($this->_olds['nav_item_page_id'], $this->_olds['placeholder_var'], $this->_olds['prev_id']);
}
} | [
"public",
"function",
"eventAfterDelete",
"(",
")",
"{",
"$",
"this",
"->",
"updateNavItemTimesamp",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_olds",
")",
")",
"{",
"$",
"this",
"->",
"reindex",
"(",
"$",
"this",
"->",
"_olds"... | Event after delete | [
"Event",
"after",
"delete"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPageBlockItem.php#L225-L231 |
luyadev/luya-module-cms | src/models/NavItemPageBlockItem.php | NavItemPageBlockItem.eventAfterInsert | public function eventAfterInsert()
{
$this->updateNavItemTimesamp();
$this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id);
Log::add(1, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'insert', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id);
} | php | public function eventAfterInsert()
{
$this->updateNavItemTimesamp();
$this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id);
Log::add(1, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'insert', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id);
} | [
"public",
"function",
"eventAfterInsert",
"(",
")",
"{",
"$",
"this",
"->",
"updateNavItemTimesamp",
"(",
")",
";",
"$",
"this",
"->",
"reindex",
"(",
"$",
"this",
"->",
"nav_item_page_id",
",",
"$",
"this",
"->",
"placeholder_var",
",",
"$",
"this",
"->",... | Event after insert | [
"Event",
"after",
"insert"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPageBlockItem.php#L236-L241 |
luyadev/luya-module-cms | src/models/NavItemPageBlockItem.php | NavItemPageBlockItem.reindex | private function reindex($navItemPageId, $placeholderVar, $prevId)
{
$index = 0;
$datas = self::originalFind()->andWhere(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId])->orderBy(['sort_index' => SORT_ASC, 'timestamp_create' => SORT_DESC])->all();
foreach ($datas as $item) {
Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $index], ['id' => $item->id])->execute();
++$index;
}
} | php | private function reindex($navItemPageId, $placeholderVar, $prevId)
{
$index = 0;
$datas = self::originalFind()->andWhere(['nav_item_page_id' => $navItemPageId, 'placeholder_var' => $placeholderVar, 'prev_id' => $prevId])->orderBy(['sort_index' => SORT_ASC, 'timestamp_create' => SORT_DESC])->all();
foreach ($datas as $item) {
Yii::$app->db->createCommand()->update(self::tableName(), ['sort_index' => $index], ['id' => $item->id])->execute();
++$index;
}
} | [
"private",
"function",
"reindex",
"(",
"$",
"navItemPageId",
",",
"$",
"placeholderVar",
",",
"$",
"prevId",
")",
"{",
"$",
"index",
"=",
"0",
";",
"$",
"datas",
"=",
"self",
"::",
"originalFind",
"(",
")",
"->",
"andWhere",
"(",
"[",
"'nav_item_page_id'... | Reindex the page block items in order to get requestd sorting.
@param unknown $navItemPageId
@param unknown $placeholderVar
@param unknown $prevId | [
"Reindex",
"the",
"page",
"block",
"items",
"in",
"order",
"to",
"get",
"requestd",
"sorting",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/NavItemPageBlockItem.php#L269-L277 |
luyadev/luya-module-cms | src/admin/apis/AdminController.php | AdminController.actionConfig | public function actionConfig()
{
// valid keys
$keys = [Config::HTTP_EXCEPTION_NAV_ID];
foreach (Yii::$app->request->bodyParams as $key => $value) {
if (in_array($key, $keys)) {
Config::set($key, $value);
}
}
$data = [];
$data[Config::HTTP_EXCEPTION_NAV_ID] = Config::get(Config::HTTP_EXCEPTION_NAV_ID, 0);
$data['previewUrl'] = $this->module->previewUrl;
return $data;
} | php | public function actionConfig()
{
// valid keys
$keys = [Config::HTTP_EXCEPTION_NAV_ID];
foreach (Yii::$app->request->bodyParams as $key => $value) {
if (in_array($key, $keys)) {
Config::set($key, $value);
}
}
$data = [];
$data[Config::HTTP_EXCEPTION_NAV_ID] = Config::get(Config::HTTP_EXCEPTION_NAV_ID, 0);
$data['previewUrl'] = $this->module->previewUrl;
return $data;
} | [
"public",
"function",
"actionConfig",
"(",
")",
"{",
"// valid keys",
"$",
"keys",
"=",
"[",
"Config",
"::",
"HTTP_EXCEPTION_NAV_ID",
"]",
";",
"foreach",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"bodyParams",
"as",
"$",
"key",
"=>",
"$",
"va... | Return the general cms page configuration.
@return array | [
"Return",
"the",
"general",
"cms",
"page",
"configuration",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/AdminController.php#L28-L43 |
luyadev/luya-module-cms | src/admin/apis/AdminController.php | AdminController.actionDashboardLog | public function actionDashboardLog()
{
$data = Log::find()->orderBy(['timestamp' => SORT_DESC])->with(['user'])->limit(60)->all();
$log= [];
foreach ($data as $item) {
$log[strtotime('today', $item->timestamp)][] = $item;
}
$array = [];
krsort($log, SORT_NUMERIC);
foreach ($log as $day => $values) {
$array[] = [
'day' => $day,
'items' => $values,
];
}
return $array;
} | php | public function actionDashboardLog()
{
$data = Log::find()->orderBy(['timestamp' => SORT_DESC])->with(['user'])->limit(60)->all();
$log= [];
foreach ($data as $item) {
$log[strtotime('today', $item->timestamp)][] = $item;
}
$array = [];
krsort($log, SORT_NUMERIC);
foreach ($log as $day => $values) {
$array[] = [
'day' => $day,
'items' => $values,
];
}
return $array;
} | [
"public",
"function",
"actionDashboardLog",
"(",
")",
"{",
"$",
"data",
"=",
"Log",
"::",
"find",
"(",
")",
"->",
"orderBy",
"(",
"[",
"'timestamp'",
"=>",
"SORT_DESC",
"]",
")",
"->",
"with",
"(",
"[",
"'user'",
"]",
")",
"->",
"limit",
"(",
"60",
... | Get all logs for the cms in order to render the dashboard
@return array | [
"Get",
"all",
"logs",
"for",
"the",
"cms",
"in",
"order",
"to",
"render",
"the",
"dashboard"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/AdminController.php#L50-L70 |
luyadev/luya-module-cms | src/admin/apis/AdminController.php | AdminController.actionDataBlocks | public function actionDataBlocks()
{
$favs = Yii::$app->adminuser->identity->setting->get("blockfav", []);
$groups = [];
foreach (BlockGroup::find()->with(['blocks'])->all() as $blockGroup) {
$blocks = [];
$groupPosition = null;
foreach ($blockGroup->blocks as $block) {
if ($block->is_disabled) {
continue;
}
// create the block object
/** @var BlockInterface $obj */
$obj = $block->getObject(0, 'admin');
// check if in hidden blocks
if (!$obj || in_array(get_class($obj), $this->module->hiddenBlocks)) {
continue;
}
if ($groupPosition == null) {
$groupObject = Yii::createObject($obj->blockGroup());
$groupPosition = $groupObject->getPosition();
}
$blocks[] = [
'id' => $block->id,
'name' => $obj->name(),
'icon' => $obj->icon(),
'preview_enabled' => $obj->renderAdminPreview() ? true : false,
'full_name' => ($obj->icon() === null) ? $obj->name() : '<i class="material-icons">'.$obj->icon().'</i> <span>'.$obj->name().'</span>',
'favorized' => array_key_exists($block->id, $favs),
'newblock' => 1,
];
}
if (empty($blocks)) {
continue;
}
// extend the group element b
$group = $blockGroup->toArray([]);
$group['name'] = $blockGroup->groupLabel;
$group['is_fav'] = 0;
$group['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get("togglegroup.{$group['id']}", 1);
$groups[] = [
'groupPosition' => $groupPosition,
'group' => $group,
'blocks' => $blocks,
];
}
if (!empty($favs)) {
$favblocks = [];
foreach ($favs as $fav) {
$favblocks[] = $fav;
}
array_unshift($groups, [
'group' => [
'toggle_open' => (int) Yii::$app->adminuser->identity->setting->get("togglegroup.99999", 1),
'id' => '99999',
'is_fav' => 1,
'name' => \luya\cms\admin\Module::t('block_group_favorites'), // translation stored in admin module
'identifier' => 'favs',
'position' => 0,
],
'groupPosition' => 0,
'blocks' => $favblocks,
]);
}
return $groups;
} | php | public function actionDataBlocks()
{
$favs = Yii::$app->adminuser->identity->setting->get("blockfav", []);
$groups = [];
foreach (BlockGroup::find()->with(['blocks'])->all() as $blockGroup) {
$blocks = [];
$groupPosition = null;
foreach ($blockGroup->blocks as $block) {
if ($block->is_disabled) {
continue;
}
// create the block object
/** @var BlockInterface $obj */
$obj = $block->getObject(0, 'admin');
// check if in hidden blocks
if (!$obj || in_array(get_class($obj), $this->module->hiddenBlocks)) {
continue;
}
if ($groupPosition == null) {
$groupObject = Yii::createObject($obj->blockGroup());
$groupPosition = $groupObject->getPosition();
}
$blocks[] = [
'id' => $block->id,
'name' => $obj->name(),
'icon' => $obj->icon(),
'preview_enabled' => $obj->renderAdminPreview() ? true : false,
'full_name' => ($obj->icon() === null) ? $obj->name() : '<i class="material-icons">'.$obj->icon().'</i> <span>'.$obj->name().'</span>',
'favorized' => array_key_exists($block->id, $favs),
'newblock' => 1,
];
}
if (empty($blocks)) {
continue;
}
// extend the group element b
$group = $blockGroup->toArray([]);
$group['name'] = $blockGroup->groupLabel;
$group['is_fav'] = 0;
$group['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get("togglegroup.{$group['id']}", 1);
$groups[] = [
'groupPosition' => $groupPosition,
'group' => $group,
'blocks' => $blocks,
];
}
if (!empty($favs)) {
$favblocks = [];
foreach ($favs as $fav) {
$favblocks[] = $fav;
}
array_unshift($groups, [
'group' => [
'toggle_open' => (int) Yii::$app->adminuser->identity->setting->get("togglegroup.99999", 1),
'id' => '99999',
'is_fav' => 1,
'name' => \luya\cms\admin\Module::t('block_group_favorites'), // translation stored in admin module
'identifier' => 'favs',
'position' => 0,
],
'groupPosition' => 0,
'blocks' => $favblocks,
]);
}
return $groups;
} | [
"public",
"function",
"actionDataBlocks",
"(",
")",
"{",
"$",
"favs",
"=",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"identity",
"->",
"setting",
"->",
"get",
"(",
"\"blockfav\"",
",",
"[",
"]",
")",
";",
"$",
"groups",
"=",
"[",
"]",
";",
... | Get all blocks which can be dropped into a page grouped by group.
@return array An array with list of groups with an array key "blocks" containing the blocks. | [
"Get",
"all",
"blocks",
"which",
"can",
"be",
"dropped",
"into",
"a",
"page",
"grouped",
"by",
"group",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/AdminController.php#L77-L151 |
luyadev/luya-module-cms | src/models/Block.php | Block.afterDelete | public function afterDelete()
{
if ($this->cachedDeletedId) {
foreach (NavItemPageBlockItem::find()->where(['block_id' => $this->cachedDeletedId])->all() as $item) {
$item->delete();
}
}
parent::afterDelete();
} | php | public function afterDelete()
{
if ($this->cachedDeletedId) {
foreach (NavItemPageBlockItem::find()->where(['block_id' => $this->cachedDeletedId])->all() as $item) {
$item->delete();
}
}
parent::afterDelete();
} | [
"public",
"function",
"afterDelete",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cachedDeletedId",
")",
"{",
"foreach",
"(",
"NavItemPageBlockItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'block_id'",
"=>",
"$",
"this",
"->",
"cachedDeletedId"... | Search for entries with cached block id in cms_nav_item_page_block_item and delete them | [
"Search",
"for",
"entries",
"with",
"cached",
"block",
"id",
"in",
"cms_nav_item_page_block_item",
"and",
"delete",
"them"
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Block.php#L199-L207 |
luyadev/luya-module-cms | src/models/Block.php | Block.getNameForLog | public function getNameForLog()
{
if ($this->getClassObject() && $this->getClassObject() instanceof BlockInterface) {
return $this->getClassObject()->name();
}
return $this->class;
} | php | public function getNameForLog()
{
if ($this->getClassObject() && $this->getClassObject() instanceof BlockInterface) {
return $this->getClassObject()->name();
}
return $this->class;
} | [
"public",
"function",
"getNameForLog",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getClassObject",
"(",
")",
"&&",
"$",
"this",
"->",
"getClassObject",
"(",
")",
"instanceof",
"BlockInterface",
")",
"{",
"return",
"$",
"this",
"->",
"getClassObject",
"(... | Try to get the name of the log. | [
"Try",
"to",
"get",
"the",
"name",
"of",
"the",
"log",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Block.php#L233-L240 |
luyadev/luya-module-cms | src/models/Block.php | Block.getObject | public function getObject($id, $context, $pageObject = null)
{
return self::createObject($this->class, $this->id, $id, $context, $pageObject);
} | php | public function getObject($id, $context, $pageObject = null)
{
return self::createObject($this->class, $this->id, $id, $context, $pageObject);
} | [
"public",
"function",
"getObject",
"(",
"$",
"id",
",",
"$",
"context",
",",
"$",
"pageObject",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"createObject",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"this",
"->",
"id",
",",
"$",
"id",
",",
"$",
... | Get the object from current object-context (classname).
@param [type] $id
@param [type] $context
@param [type] $pageObject
@return void
@since 1.0.6 | [
"Get",
"the",
"object",
"from",
"current",
"object",
"-",
"context",
"(",
"classname",
")",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Block.php#L262-L265 |
luyadev/luya-module-cms | src/models/Block.php | Block.createObject | public static function createObject($class, $blockId, $id, $context, $pageObject = null)
{
if (!class_exists($class)) {
return false;
}
$object = Yii::createObject([
'class' => $class,
]);
$object->setEnvOption('id', $id);
$object->setEnvOption('blockId', $blockId);
$object->setEnvOption('context', $context);
$object->setEnvOption('pageObject', $pageObject);
return $object;
} | php | public static function createObject($class, $blockId, $id, $context, $pageObject = null)
{
if (!class_exists($class)) {
return false;
}
$object = Yii::createObject([
'class' => $class,
]);
$object->setEnvOption('id', $id);
$object->setEnvOption('blockId', $blockId);
$object->setEnvOption('context', $context);
$object->setEnvOption('pageObject', $pageObject);
return $object;
} | [
"public",
"static",
"function",
"createObject",
"(",
"$",
"class",
",",
"$",
"blockId",
",",
"$",
"id",
",",
"$",
"context",
",",
"$",
"pageObject",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
... | Creates the block object and stores the object within a static block container.
@param string $class
@param integer $blockId The id of the cms_block table
@param integer $id The context id, for example the id of the text block element
@param string $context admin or frontend
@param mixed $pageObject
@return \luya\cms\base\BlockInterface | [
"Creates",
"the",
"block",
"object",
"and",
"stores",
"the",
"object",
"within",
"a",
"static",
"block",
"container",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Block.php#L277-L293 |
luyadev/luya-module-cms | src/models/Block.php | Block.objectId | public static function objectId($blockId, $id, $context, $pageObject = null)
{
if (isset(self::$blocks[$blockId])) {
$block = self::$blocks[$blockId];
} else {
$block = self::find()->select(['class'])->where(['id' => $blockId])->asArray()->one();
static::$blocks[$blockId] = $block;
}
if (!$block) {
return false;
}
$class = $block['class'];
if (!class_exists($class)) {
return false;
}
$object = Yii::createObject([
'class' => $class,
]);
$object->setEnvOption('id', $id);
$object->setEnvOption('blockId', $blockId);
$object->setEnvOption('context', $context);
$object->setEnvOption('pageObject', $pageObject);
return $object;
} | php | public static function objectId($blockId, $id, $context, $pageObject = null)
{
if (isset(self::$blocks[$blockId])) {
$block = self::$blocks[$blockId];
} else {
$block = self::find()->select(['class'])->where(['id' => $blockId])->asArray()->one();
static::$blocks[$blockId] = $block;
}
if (!$block) {
return false;
}
$class = $block['class'];
if (!class_exists($class)) {
return false;
}
$object = Yii::createObject([
'class' => $class,
]);
$object->setEnvOption('id', $id);
$object->setEnvOption('blockId', $blockId);
$object->setEnvOption('context', $context);
$object->setEnvOption('pageObject', $pageObject);
return $object;
} | [
"public",
"static",
"function",
"objectId",
"(",
"$",
"blockId",
",",
"$",
"id",
",",
"$",
"context",
",",
"$",
"pageObject",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"blocks",
"[",
"$",
"blockId",
"]",
")",
")",
"{",
"$... | Get the block object from the database with context informations.
@param integer $blockId
@param integer $id
@param mixed $context
@param object $pageObject
@return \luya\cms\base\BlockInterface
@deprecated 1.1.0 use createObject() or getObject() instead! | [
"Get",
"the",
"block",
"object",
"from",
"the",
"database",
"with",
"context",
"informations",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/models/Block.php#L307-L335 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionLastUpdates | public function actionLastUpdates()
{
return NavItem::find()
->select(['cms_nav_item.title', 'timestamp_update', 'update_user_id', 'nav_id'])
->limit(10)
->orderBy(['timestamp_update' => SORT_DESC])
->joinWith(['updateUser' => function ($q) {
$q->select(['firstname', 'lastname', 'id'])->where([]);
}, 'nav'])
->where(['cms_nav.is_deleted' => false])
->asArray(true)
->all();
} | php | public function actionLastUpdates()
{
return NavItem::find()
->select(['cms_nav_item.title', 'timestamp_update', 'update_user_id', 'nav_id'])
->limit(10)
->orderBy(['timestamp_update' => SORT_DESC])
->joinWith(['updateUser' => function ($q) {
$q->select(['firstname', 'lastname', 'id'])->where([]);
}, 'nav'])
->where(['cms_nav.is_deleted' => false])
->asArray(true)
->all();
} | [
"public",
"function",
"actionLastUpdates",
"(",
")",
"{",
"return",
"NavItem",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'cms_nav_item.title'",
",",
"'timestamp_update'",
",",
"'update_user_id'",
",",
"'nav_id'",
"]",
")",
"->",
"limit",
"(",
"10",
... | Returns an array of 10 items for last updated pages.
@return array | [
"Returns",
"an",
"array",
"of",
"10",
"items",
"for",
"last",
"updated",
"pages",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L58-L70 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionDelete | public function actionDelete($navItemId)
{
if (!Yii::$app->adminuser->canRoute(Module::ROUTE_PAGE_DELETE)) {
throw new ForbiddenHttpException("Unable to perform this action due to permission restrictions");
}
$model = NavItem::findOne($navItemId);
if ($model) {
return $model->delete();
}
return $this->sendModelError($model);
} | php | public function actionDelete($navItemId)
{
if (!Yii::$app->adminuser->canRoute(Module::ROUTE_PAGE_DELETE)) {
throw new ForbiddenHttpException("Unable to perform this action due to permission restrictions");
}
$model = NavItem::findOne($navItemId);
if ($model) {
return $model->delete();
}
return $this->sendModelError($model);
} | [
"public",
"function",
"actionDelete",
"(",
"$",
"navItemId",
")",
"{",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"adminuser",
"->",
"canRoute",
"(",
"Module",
"::",
"ROUTE_PAGE_DELETE",
")",
")",
"{",
"throw",
"new",
"ForbiddenHttpException",
"(",
"\"... | Delete a nav item based on the id.
@param integer $navItemId The id of the item to delete.
@throws ForbiddenHttpException
@return array|boolean | [
"Delete",
"a",
"nav",
"item",
"based",
"on",
"the",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L79-L92 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionNavLangItem | public function actionNavLangItem($navId, $langId)
{
$item = NavItem::find()->with('nav')->where(['nav_id' => $navId, 'lang_id' => $langId])->one();
if ($item) {
return [
'error' => false,
'item' => $item->toArray(),
'nav' => $item->nav->toArray(),
'typeData' => ($item->nav_item_type == 1) ? NavItemPage::getVersionList($item->id) : ArrayHelper::typeCast($item->getType()->toArray()),
];
}
return ['error' => true];
} | php | public function actionNavLangItem($navId, $langId)
{
$item = NavItem::find()->with('nav')->where(['nav_id' => $navId, 'lang_id' => $langId])->one();
if ($item) {
return [
'error' => false,
'item' => $item->toArray(),
'nav' => $item->nav->toArray(),
'typeData' => ($item->nav_item_type == 1) ? NavItemPage::getVersionList($item->id) : ArrayHelper::typeCast($item->getType()->toArray()),
];
}
return ['error' => true];
} | [
"public",
"function",
"actionNavLangItem",
"(",
"$",
"navId",
",",
"$",
"langId",
")",
"{",
"$",
"item",
"=",
"NavItem",
"::",
"find",
"(",
")",
"->",
"with",
"(",
"'nav'",
")",
"->",
"where",
"(",
"[",
"'nav_id'",
"=>",
"$",
"navId",
",",
"'lang_id'... | The data api for a nav id and correspoding language.
http://example.com/admin/api-cms-navitem/nav-lang-item?access-token=XXX&navId=A&langId=B.
@param integer $navId
@param integer $langId
@return array | [
"The",
"data",
"api",
"for",
"a",
"nav",
"id",
"and",
"correspoding",
"language",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L103-L116 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionReloadPlaceholder | public function actionReloadPlaceholder($navItemPageId, $prevId, $placeholderVar)
{
$navItemPage = NavItemPage::findOne($navItemPageId);
return NavItemPage::getPlaceholder($placeholderVar, $prevId, $navItemPage);
} | php | public function actionReloadPlaceholder($navItemPageId, $prevId, $placeholderVar)
{
$navItemPage = NavItemPage::findOne($navItemPageId);
return NavItemPage::getPlaceholder($placeholderVar, $prevId, $navItemPage);
} | [
"public",
"function",
"actionReloadPlaceholder",
"(",
"$",
"navItemPageId",
",",
"$",
"prevId",
",",
"$",
"placeholderVar",
")",
"{",
"$",
"navItemPage",
"=",
"NavItemPage",
"::",
"findOne",
"(",
"$",
"navItemPageId",
")",
";",
"return",
"NavItemPage",
"::",
"... | Get the data for a given placeholder variable inside a page id.
@param integer $navItemPageId
@param integer $prevId The previous id if its a nested element.
@param string $placeholderVar | [
"Get",
"the",
"data",
"for",
"a",
"given",
"placeholder",
"variable",
"inside",
"a",
"page",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L125-L129 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionUpdateItemTypeData | public function actionUpdateItemTypeData($navItemId)
{
return NavItem::findOne($navItemId)->updateType(Yii::$app->request->post());
} | php | public function actionUpdateItemTypeData($navItemId)
{
return NavItem::findOne($navItemId)->updateType(Yii::$app->request->post());
} | [
"public",
"function",
"actionUpdateItemTypeData",
"(",
"$",
"navItemId",
")",
"{",
"return",
"NavItem",
"::",
"findOne",
"(",
"$",
"navItemId",
")",
"->",
"updateType",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
";",
"}"
... | Update data for a given nav item id.
@param integer $navItemId
@return boolean | [
"Update",
"data",
"for",
"a",
"given",
"nav",
"item",
"id",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L137-L140 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionChangePageVersionLayout | public function actionChangePageVersionLayout()
{
$params = Yii::$app->request->bodyParams;
$pageItemId = $params['pageItemId'];
$layoutId = $params['layoutId'];
$alias = $params['alias'];
$model = NavItemPage::findOne(['id' => $pageItemId]);
if ($model) {
$model->forceNavItem->updateTimestamp();
return $model->updateAttributes(['layout_id' => $layoutId, 'version_alias' => $alias]);
}
return false;
} | php | public function actionChangePageVersionLayout()
{
$params = Yii::$app->request->bodyParams;
$pageItemId = $params['pageItemId'];
$layoutId = $params['layoutId'];
$alias = $params['alias'];
$model = NavItemPage::findOne(['id' => $pageItemId]);
if ($model) {
$model->forceNavItem->updateTimestamp();
return $model->updateAttributes(['layout_id' => $layoutId, 'version_alias' => $alias]);
}
return false;
} | [
"public",
"function",
"actionChangePageVersionLayout",
"(",
")",
"{",
"$",
"params",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"bodyParams",
";",
"$",
"pageItemId",
"=",
"$",
"params",
"[",
"'pageItemId'",
"]",
";",
"$",
"layoutId",
"=",
"$",
... | Change the layout of a page version.
@return number|boolean | [
"Change",
"the",
"layout",
"of",
"a",
"page",
"version",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L147-L162 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionRemovePageVersion | public function actionRemovePageVersion()
{
$pageId = Yii::$app->request->getBodyParam('pageId');
$page = NavItemPage::findOne((int) $pageId);
if ($page) {
$page->forceNavItem->updateTimestamp();
return $page->delete();
}
return false;
} | php | public function actionRemovePageVersion()
{
$pageId = Yii::$app->request->getBodyParam('pageId');
$page = NavItemPage::findOne((int) $pageId);
if ($page) {
$page->forceNavItem->updateTimestamp();
return $page->delete();
}
return false;
} | [
"public",
"function",
"actionRemovePageVersion",
"(",
")",
"{",
"$",
"pageId",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"getBodyParam",
"(",
"'pageId'",
")",
";",
"$",
"page",
"=",
"NavItemPage",
"::",
"findOne",
"(",
"(",
"int",
")",
"$",
... | Delete a given page from pageId body param.
@return boolean | [
"Delete",
"a",
"given",
"page",
"from",
"pageId",
"body",
"param",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L169-L181 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionCreatePageVersion | public function actionCreatePageVersion()
{
$name = Yii::$app->request->post('name');
$fromPageId = (int) Yii::$app->request->post('fromPageId');
$navItemId = (int) Yii::$app->request->post('navItemId');
$layoutId = Yii::$app->request->post('layoutId');
if (empty($name) || empty($navItemId)) {
return ['error' => true];
}
if (empty($fromPageId) && empty($layoutId)) {
return ['error' => true];
}
$navItemModel = NavItem::findOne($navItemId);
if (!$navItemModel) {
throw new Exception("Unable to find nav item model");
}
if (!empty($fromPageId)) {
$fromPageModel = NavItemPage::findOne($fromPageId);
$layoutId = $fromPageModel->layout_id;
}
$model = new NavItemPage();
$model->attributes = [
'nav_item_id' => $navItemId,
'timestamp_create' => time(),
'create_user_id' => Yii::$app->adminuser->getId(),
'version_alias' => $name,
'layout_id' => $layoutId,
];
$save = $model->save(false);
if (!empty($fromPageId) && $save) {
NavItemPage::copyBlocks($fromPageModel->id, $model->id);
}
if (empty($navItemModel->nav_item_type_id) && $navItemModel->nav_item_type == 1) {
$navItemModel->updateAttributes(['nav_item_type_id' => $model->id]);
}
$navItemModel->updateAttributes(['timestamp_update' => time()]);
return ['error' => !$save];
} | php | public function actionCreatePageVersion()
{
$name = Yii::$app->request->post('name');
$fromPageId = (int) Yii::$app->request->post('fromPageId');
$navItemId = (int) Yii::$app->request->post('navItemId');
$layoutId = Yii::$app->request->post('layoutId');
if (empty($name) || empty($navItemId)) {
return ['error' => true];
}
if (empty($fromPageId) && empty($layoutId)) {
return ['error' => true];
}
$navItemModel = NavItem::findOne($navItemId);
if (!$navItemModel) {
throw new Exception("Unable to find nav item model");
}
if (!empty($fromPageId)) {
$fromPageModel = NavItemPage::findOne($fromPageId);
$layoutId = $fromPageModel->layout_id;
}
$model = new NavItemPage();
$model->attributes = [
'nav_item_id' => $navItemId,
'timestamp_create' => time(),
'create_user_id' => Yii::$app->adminuser->getId(),
'version_alias' => $name,
'layout_id' => $layoutId,
];
$save = $model->save(false);
if (!empty($fromPageId) && $save) {
NavItemPage::copyBlocks($fromPageModel->id, $model->id);
}
if (empty($navItemModel->nav_item_type_id) && $navItemModel->nav_item_type == 1) {
$navItemModel->updateAttributes(['nav_item_type_id' => $model->id]);
}
$navItemModel->updateAttributes(['timestamp_update' => time()]);
return ['error' => !$save];
} | [
"public",
"function",
"actionCreatePageVersion",
"(",
")",
"{",
"$",
"name",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"'name'",
")",
";",
"$",
"fromPageId",
"=",
"(",
"int",
")",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->"... | Create a new cms_nav_item_page for an existing nav_item, this is also known as a "new version" of a page item. | [
"Create",
"a",
"new",
"cms_nav_item_page",
"for",
"an",
"existing",
"nav_item",
"this",
"is",
"also",
"known",
"as",
"a",
"new",
"version",
"of",
"a",
"page",
"item",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L187-L235 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionUpdateItem | public function actionUpdateItem($navItemId)
{
$model = NavItem::find()->where(['id' => $navItemId])->one();
if (!$model) {
throw new Exception('Unable to find nav item id '.$navItemId . ' in order to update data.');
}
$model->setParentFromModel();
$model->attributes = Yii::$app->request->post();
$model->timestamp_update = time();
if ($model->validate()) {
if ($model->save()) {
return true;
}
}
return $this->sendModelError($model);
} | php | public function actionUpdateItem($navItemId)
{
$model = NavItem::find()->where(['id' => $navItemId])->one();
if (!$model) {
throw new Exception('Unable to find nav item id '.$navItemId . ' in order to update data.');
}
$model->setParentFromModel();
$model->attributes = Yii::$app->request->post();
$model->timestamp_update = time();
if ($model->validate()) {
if ($model->save()) {
return true;
}
}
return $this->sendModelError($model);
} | [
"public",
"function",
"actionUpdateItem",
"(",
"$",
"navItemId",
")",
"{",
"$",
"model",
"=",
"NavItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'id'",
"=>",
"$",
"navItemId",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"$",
"... | admin/api-cms-navitem/update-item?navItemId=2.
@param int $navItemId
@return mixed
@throws Exception | [
"admin",
"/",
"api",
"-",
"cms",
"-",
"navitem",
"/",
"update",
"-",
"item?navItemId",
"=",
"2",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L244-L261 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.setPostAttribute | public function setPostAttribute($model, $attribute)
{
if ($attributeValue = Yii::$app->request->post($attribute, null)) {
$model->setAttribute($attribute, $attributeValue);
}
} | php | public function setPostAttribute($model, $attribute)
{
if ($attributeValue = Yii::$app->request->post($attribute, null)) {
$model->setAttribute($attribute, $attributeValue);
}
} | [
"public",
"function",
"setPostAttribute",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"attributeValue",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"$",
"attribute",
",",
"null",
")",
")",
"{",
"$",
"mode... | extract a post var and set to model attribute with the same name.
@param $model
@param string $attribute | [
"extract",
"a",
"post",
"var",
"and",
"set",
"to",
"model",
"attribute",
"with",
"the",
"same",
"name",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L269-L274 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionUpdatePageItem | public function actionUpdatePageItem($navItemId, $navItemType)
{
$model = NavItem::findOne($navItemId);
if (!$model) {
throw new Exception('Unable to find the requested nav item object.');
}
$model->setParentFromModel();
$model->title = Yii::$app->request->post('title', false);
$model->alias = Yii::$app->request->post('alias', false);
$model->description = Yii::$app->request->post('description', null);
$model->keywords = Yii::$app->request->post('keywords');
$model->title_tag = Yii::$app->request->post('title_tag');
$model->image_id = Yii::$app->request->post('image_id');
$model->timestamp_create = Yii::$app->request->post('timestamp_create');
$model->is_url_strict_parsing_disabled = Yii::$app->request->post('is_url_strict_parsing_disabled');
// make sure the currently provided informations are valid (like title);
if (!$model->validate()) {
return $this->sendModelError($model);
}
$this->menuFlush();
if ($model->nav_item_type == $navItemType) {
$typeModel = $model->getType();
// lets just update the type data
switch ($navItemType) {
case 1:
$this->setPostAttribute($model, 'nav_item_type_id');
break;
case 2:
$this->setPostAttribute($typeModel, 'module_name');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->update();
break;
case 3:
$this->setPostAttribute($typeModel, 'type');
$this->setPostAttribute($typeModel, 'value');
$this->setPostAttribute($typeModel, 'target');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->update();
break;
default:
throw new Exception("Invalid nav item type.");
break;
}
} else {
// set the new type
$model->nav_item_type = $navItemType;
switch ($navItemType) {
case 1:
// check for existent version, if not available create "First version"
if (!NavItemPage::find()->where(['nav_item_id' => $navItemId])->exists()) {
$pageModel = new NavItemPage();
$pageModel->attributes = [
'nav_item_id' => $navItemId,
'timestamp_create' => time(),
'create_user_id' => Yii::$app->adminuser->getId(),
'version_alias' => Module::t('Initial'),
'layout_id' => Yii::$app->request->post('layout_id'),
];
if (!$pageModel->save()) {
return $this->sendModelError($pageModel);
}
$model->nav_item_type_id = $navItemId;
} else {
$this->setPostAttribute($model, 'nav_item_type_id');
}
break;
case 2:
$typeModel = new NavItemModule();
$this->setPostAttribute($typeModel, 'module_name');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->insert();
$model->nav_item_type_id = $typeModel->id;
break;
case 3:
$typeModel = new NavItemRedirect();
$this->setPostAttribute($typeModel, 'type');
$this->setPostAttribute($typeModel, 'value');
$this->setPostAttribute($typeModel, 'target');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->insert();
$model->nav_item_type_id = $typeModel->id;
break;
default:
throw new Exception("Invalid nav item type.");
break;
}
}
if ($model->update()) {
return [
'item' => $model,
'typeData' => ($model->nav_item_type == 1) ? NavItemPage::getVersionList($model->id) : $model->getType()->toArray()
];
}
return false;
} | php | public function actionUpdatePageItem($navItemId, $navItemType)
{
$model = NavItem::findOne($navItemId);
if (!$model) {
throw new Exception('Unable to find the requested nav item object.');
}
$model->setParentFromModel();
$model->title = Yii::$app->request->post('title', false);
$model->alias = Yii::$app->request->post('alias', false);
$model->description = Yii::$app->request->post('description', null);
$model->keywords = Yii::$app->request->post('keywords');
$model->title_tag = Yii::$app->request->post('title_tag');
$model->image_id = Yii::$app->request->post('image_id');
$model->timestamp_create = Yii::$app->request->post('timestamp_create');
$model->is_url_strict_parsing_disabled = Yii::$app->request->post('is_url_strict_parsing_disabled');
// make sure the currently provided informations are valid (like title);
if (!$model->validate()) {
return $this->sendModelError($model);
}
$this->menuFlush();
if ($model->nav_item_type == $navItemType) {
$typeModel = $model->getType();
// lets just update the type data
switch ($navItemType) {
case 1:
$this->setPostAttribute($model, 'nav_item_type_id');
break;
case 2:
$this->setPostAttribute($typeModel, 'module_name');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->update();
break;
case 3:
$this->setPostAttribute($typeModel, 'type');
$this->setPostAttribute($typeModel, 'value');
$this->setPostAttribute($typeModel, 'target');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->update();
break;
default:
throw new Exception("Invalid nav item type.");
break;
}
} else {
// set the new type
$model->nav_item_type = $navItemType;
switch ($navItemType) {
case 1:
// check for existent version, if not available create "First version"
if (!NavItemPage::find()->where(['nav_item_id' => $navItemId])->exists()) {
$pageModel = new NavItemPage();
$pageModel->attributes = [
'nav_item_id' => $navItemId,
'timestamp_create' => time(),
'create_user_id' => Yii::$app->adminuser->getId(),
'version_alias' => Module::t('Initial'),
'layout_id' => Yii::$app->request->post('layout_id'),
];
if (!$pageModel->save()) {
return $this->sendModelError($pageModel);
}
$model->nav_item_type_id = $navItemId;
} else {
$this->setPostAttribute($model, 'nav_item_type_id');
}
break;
case 2:
$typeModel = new NavItemModule();
$this->setPostAttribute($typeModel, 'module_name');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->insert();
$model->nav_item_type_id = $typeModel->id;
break;
case 3:
$typeModel = new NavItemRedirect();
$this->setPostAttribute($typeModel, 'type');
$this->setPostAttribute($typeModel, 'value');
$this->setPostAttribute($typeModel, 'target');
if (!$typeModel->validate()) {
return $this->sendModelError($typeModel);
}
$typeModel->insert();
$model->nav_item_type_id = $typeModel->id;
break;
default:
throw new Exception("Invalid nav item type.");
break;
}
}
if ($model->update()) {
return [
'item' => $model,
'typeData' => ($model->nav_item_type == 1) ? NavItemPage::getVersionList($model->id) : $model->getType()->toArray()
];
}
return false;
} | [
"public",
"function",
"actionUpdatePageItem",
"(",
"$",
"navItemId",
",",
"$",
"navItemType",
")",
"{",
"$",
"model",
"=",
"NavItem",
"::",
"findOne",
"(",
"$",
"navItemId",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"throw",
"new",
"Exception",
... | check old entries - delete if obsolete (changed type) and add new entry to the appropriate cms_nav_item_(page/module/redirect).
@param integer $navItemId The id of the nav_item item which should be changed
@param integer $navItemType The NEW type of content for the above nav_item.id
@return array|bool
@throws Exception | [
"check",
"old",
"entries",
"-",
"delete",
"if",
"obsolete",
"(",
"changed",
"type",
")",
"and",
"add",
"new",
"entry",
"to",
"the",
"appropriate",
"cms_nav_item_",
"(",
"page",
"/",
"module",
"/",
"redirect",
")",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L284-L392 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionTypePageContainer | public function actionTypePageContainer($navItemId)
{
$navItem = NavItem::findOne($navItemId);
$type = $navItem->getType();
$layout = Layout::findOne($type->layout_id);
if (!empty($layout)) {
$layout->json_config = json_decode($layout->json_config, true);
}
return [
//'nav_item' => $navItem,
'layout' => $layout,
'type_container' => $type,
];
} | php | public function actionTypePageContainer($navItemId)
{
$navItem = NavItem::findOne($navItemId);
$type = $navItem->getType();
$layout = Layout::findOne($type->layout_id);
if (!empty($layout)) {
$layout->json_config = json_decode($layout->json_config, true);
}
return [
//'nav_item' => $navItem,
'layout' => $layout,
'type_container' => $type,
];
} | [
"public",
"function",
"actionTypePageContainer",
"(",
"$",
"navItemId",
")",
"{",
"$",
"navItem",
"=",
"NavItem",
"::",
"findOne",
"(",
"$",
"navItemId",
")",
";",
"$",
"type",
"=",
"$",
"navItem",
"->",
"getType",
"(",
")",
";",
"$",
"layout",
"=",
"L... | returns all the PAGE type specific informations.
@return array | [
"returns",
"all",
"the",
"PAGE",
"type",
"specific",
"informations",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L399-L413 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionMoveBefore | public function actionMoveBefore($moveItemId, $droppedBeforeItemId)
{
$result = Nav::moveToBefore($moveItemId, $droppedBeforeItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | php | public function actionMoveBefore($moveItemId, $droppedBeforeItemId)
{
$result = Nav::moveToBefore($moveItemId, $droppedBeforeItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | [
"public",
"function",
"actionMoveBefore",
"(",
"$",
"moveItemId",
",",
"$",
"droppedBeforeItemId",
")",
"{",
"$",
"result",
"=",
"Nav",
"::",
"moveToBefore",
"(",
"$",
"moveItemId",
",",
"$",
"droppedBeforeItemId",
")",
";",
"if",
"(",
"$",
"result",
"!==",
... | Move an item before an existing item.
@param integer $moveItemId
@param integer $droppedBeforeItemId
@return array | [
"Move",
"an",
"item",
"before",
"an",
"existing",
"item",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L434-L443 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionMoveAfter | public function actionMoveAfter($moveItemId, $droppedAfterItemId)
{
$result = Nav::moveToAfter($moveItemId, $droppedAfterItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | php | public function actionMoveAfter($moveItemId, $droppedAfterItemId)
{
$result = Nav::moveToAfter($moveItemId, $droppedAfterItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | [
"public",
"function",
"actionMoveAfter",
"(",
"$",
"moveItemId",
",",
"$",
"droppedAfterItemId",
")",
"{",
"$",
"result",
"=",
"Nav",
"::",
"moveToAfter",
"(",
"$",
"moveItemId",
",",
"$",
"droppedAfterItemId",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"t... | Move an item after an existing item.
@param integer $moveItemId
@param integer $droppedAfterItemId
@return array | [
"Move",
"an",
"item",
"after",
"an",
"existing",
"item",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L452-L461 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionMoveToChild | public function actionMoveToChild($moveItemId, $droppedOnItemId)
{
$result = Nav::moveToChild($moveItemId, $droppedOnItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | php | public function actionMoveToChild($moveItemId, $droppedOnItemId)
{
$result = Nav::moveToChild($moveItemId, $droppedOnItemId);
if ($result !== true) {
Yii::$app->response->setStatusCode(422, 'Found URL alias duplication in drop target "'.$result['title'].'".');
}
return ['success' => $result];
} | [
"public",
"function",
"actionMoveToChild",
"(",
"$",
"moveItemId",
",",
"$",
"droppedOnItemId",
")",
"{",
"$",
"result",
"=",
"Nav",
"::",
"moveToChild",
"(",
"$",
"moveItemId",
",",
"$",
"droppedOnItemId",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true"... | Move an item to a child item (make the parent of).
@param integer $moveItemId
@param integer $droppedOnItemId
@return array | [
"Move",
"an",
"item",
"to",
"a",
"child",
"item",
"(",
"make",
"the",
"parent",
"of",
")",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L470-L479 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionToggleBlockHidden | public function actionToggleBlockHidden($blockId, $hiddenState)
{
$block = NavItemPageBlockItem::findOne($blockId);
if ($block) {
$block->is_hidden = $hiddenState;
return $block->update(false);
}
return false;
} | php | public function actionToggleBlockHidden($blockId, $hiddenState)
{
$block = NavItemPageBlockItem::findOne($blockId);
if ($block) {
$block->is_hidden = $hiddenState;
return $block->update(false);
}
return false;
} | [
"public",
"function",
"actionToggleBlockHidden",
"(",
"$",
"blockId",
",",
"$",
"hiddenState",
")",
"{",
"$",
"block",
"=",
"NavItemPageBlockItem",
"::",
"findOne",
"(",
"$",
"blockId",
")",
";",
"if",
"(",
"$",
"block",
")",
"{",
"$",
"block",
"->",
"is... | Toggle visibilty of a block.
@param integer $blockId
@param integer $hiddenState
@return array | [
"Toggle",
"visibilty",
"of",
"a",
"block",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L488-L497 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionGetNavItemPath | public function actionGetNavItemPath($navId)
{
$data = "";
$node = NavItem::find()->where(['nav_id' => $navId])->one();
if ($node) {
$data .= $node->title;
$parentNavId = $navId;
while ($parentNavId != 0) {
$parentNavIdModel = Nav::findOne($parentNavId);
if ($parentNavIdModel) {
$parentNavId = $parentNavIdModel->parent_nav_id;
if ($parentNavId != 0) {
$node = NavItem::find()->where(['nav_id' => $parentNavId])->one();
if ($parentNavId) {
$data = $node->title . '/' . $data;
}
}
}
}
}
return $data;
} | php | public function actionGetNavItemPath($navId)
{
$data = "";
$node = NavItem::find()->where(['nav_id' => $navId])->one();
if ($node) {
$data .= $node->title;
$parentNavId = $navId;
while ($parentNavId != 0) {
$parentNavIdModel = Nav::findOne($parentNavId);
if ($parentNavIdModel) {
$parentNavId = $parentNavIdModel->parent_nav_id;
if ($parentNavId != 0) {
$node = NavItem::find()->where(['nav_id' => $parentNavId])->one();
if ($parentNavId) {
$data = $node->title . '/' . $data;
}
}
}
}
}
return $data;
} | [
"public",
"function",
"actionGetNavItemPath",
"(",
"$",
"navId",
")",
"{",
"$",
"data",
"=",
"\"\"",
";",
"$",
"node",
"=",
"NavItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'nav_id'",
"=>",
"$",
"navId",
"]",
")",
"->",
"one",
"(",
")",... | Get full constructed path of a nav item.
@param $navId
@return string Path | [
"Get",
"full",
"constructed",
"path",
"of",
"a",
"nav",
"item",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L505-L527 |
luyadev/luya-module-cms | src/admin/apis/NavItemController.php | NavItemController.actionGetNavContainerName | public function actionGetNavContainerName($navId)
{
$nav = Nav::findOne($navId);
if ($nav) {
$navCoontainer = NavContainer::findOne($nav->nav_container_id);
if ($navCoontainer) {
return $navCoontainer->name;
}
}
return "";
} | php | public function actionGetNavContainerName($navId)
{
$nav = Nav::findOne($navId);
if ($nav) {
$navCoontainer = NavContainer::findOne($nav->nav_container_id);
if ($navCoontainer) {
return $navCoontainer->name;
}
}
return "";
} | [
"public",
"function",
"actionGetNavContainerName",
"(",
"$",
"navId",
")",
"{",
"$",
"nav",
"=",
"Nav",
"::",
"findOne",
"(",
"$",
"navId",
")",
";",
"if",
"(",
"$",
"nav",
")",
"{",
"$",
"navCoontainer",
"=",
"NavContainer",
"::",
"findOne",
"(",
"$",... | Get Container name for a nav item.
@param $navId
@return string Container name | [
"Get",
"Container",
"name",
"for",
"a",
"nav",
"item",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/apis/NavItemController.php#L535-L545 |
luyadev/luya-module-cms | src/admin/importers/BlockImporter.php | BlockImporter.handleBlockDefinitions | protected function handleBlockDefinitions(array $definitions)
{
$ids = [];
foreach ($definitions as $blockDefinition) {
$block = Yii::getAlias($blockDefinition, false);
// if there is no alias, or not found, switch back to original name
if ($block === false) {
$block = $blockDefinition;
}
if (is_file($block)) {
$ids[] = $this->saveBlockByPath($block);
} elseif (is_dir($block)) {
$ids = array_merge($ids, $this->saveBlocksFromFolder($block));
} else {
$this->addLog("Unable to process block definition '{$block}'");
}
}
return $ids;
} | php | protected function handleBlockDefinitions(array $definitions)
{
$ids = [];
foreach ($definitions as $blockDefinition) {
$block = Yii::getAlias($blockDefinition, false);
// if there is no alias, or not found, switch back to original name
if ($block === false) {
$block = $blockDefinition;
}
if (is_file($block)) {
$ids[] = $this->saveBlockByPath($block);
} elseif (is_dir($block)) {
$ids = array_merge($ids, $this->saveBlocksFromFolder($block));
} else {
$this->addLog("Unable to process block definition '{$block}'");
}
}
return $ids;
} | [
"protected",
"function",
"handleBlockDefinitions",
"(",
"array",
"$",
"definitions",
")",
"{",
"$",
"ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"definitions",
"as",
"$",
"blockDefinition",
")",
"{",
"$",
"block",
"=",
"Yii",
"::",
"getAlias",
"(",
"$... | Handle an array with defintions whether they are files or folders.
@param array $definitions
@return array
@since 1.0.8 | [
"Handle",
"an",
"array",
"with",
"defintions",
"whether",
"they",
"are",
"files",
"or",
"folders",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/BlockImporter.php#L77-L96 |
luyadev/luya-module-cms | src/admin/importers/BlockImporter.php | BlockImporter.saveBlocksFromFolder | protected function saveBlocksFromFolder($folder)
{
$ids = [];
if (is_dir($folder)) {
foreach (FileHelper::findFiles($folder) as $blockItem) {
$ids[] = $this->saveBlockByPath($blockItem);
}
}
return $ids;
} | php | protected function saveBlocksFromFolder($folder)
{
$ids = [];
if (is_dir($folder)) {
foreach (FileHelper::findFiles($folder) as $blockItem) {
$ids[] = $this->saveBlockByPath($blockItem);
}
}
return $ids;
} | [
"protected",
"function",
"saveBlocksFromFolder",
"(",
"$",
"folder",
")",
"{",
"$",
"ids",
"=",
"[",
"]",
";",
"if",
"(",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"foreach",
"(",
"FileHelper",
"::",
"findFiles",
"(",
"$",
"folder",
")",
"as",
"$"... | Save all blocks from a given folder.
@param string $folder
@return number[]|boolean[]
@since 1.0.8 | [
"Save",
"all",
"blocks",
"from",
"a",
"given",
"folder",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/BlockImporter.php#L105-L115 |
luyadev/luya-module-cms | src/admin/importers/BlockImporter.php | BlockImporter.saveBlock | protected function saveBlock($fullClassName)
{
// ensure all classes start with trailing slash class name definition like `\foo\bar\Class`
$fullClassName = '\\' . ltrim($fullClassName, '\\');
$model = Block::find()->where(['class' => $fullClassName])->one();
$blockObject = $this->createBlockObject($fullClassName);
$blockGroupId = $this->getBlockGroupId($blockObject);
if (!in_array($blockGroupId, $this->blockGroupIds)) {
$this->blockGroupIds[] = $blockGroupId;
}
$log = "block {$fullClassName}: ";
if (!$model) {
$model = new Block();
$model->group_id = $blockGroupId;
$model->class = $fullClassName;
if ($model->save()) {
$log .= "Added to database";
} else {
$log .= "Error while saving";
}
} elseif ($model->group_id != $blockGroupId) {
$log .= 'Updated group id"';
$model->updateAttributes(['group_id' => $blockGroupId]);
} else {
$log .= 'remains the same, nothing to update';
}
$this->addLog($log);
return $model->id;
} | php | protected function saveBlock($fullClassName)
{
// ensure all classes start with trailing slash class name definition like `\foo\bar\Class`
$fullClassName = '\\' . ltrim($fullClassName, '\\');
$model = Block::find()->where(['class' => $fullClassName])->one();
$blockObject = $this->createBlockObject($fullClassName);
$blockGroupId = $this->getBlockGroupId($blockObject);
if (!in_array($blockGroupId, $this->blockGroupIds)) {
$this->blockGroupIds[] = $blockGroupId;
}
$log = "block {$fullClassName}: ";
if (!$model) {
$model = new Block();
$model->group_id = $blockGroupId;
$model->class = $fullClassName;
if ($model->save()) {
$log .= "Added to database";
} else {
$log .= "Error while saving";
}
} elseif ($model->group_id != $blockGroupId) {
$log .= 'Updated group id"';
$model->updateAttributes(['group_id' => $blockGroupId]);
} else {
$log .= 'remains the same, nothing to update';
}
$this->addLog($log);
return $model->id;
} | [
"protected",
"function",
"saveBlock",
"(",
"$",
"fullClassName",
")",
"{",
"// ensure all classes start with trailing slash class name definition like `\\foo\\bar\\Class`",
"$",
"fullClassName",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"$",
"fullClassName",
",",
"'\\\\'",
")",
";"... | Save a block by its given full class name.
Example full class name: luya\cms\blocks\ModuleBlock
@param string $fullClassName
@return number | [
"Save",
"a",
"block",
"by",
"its",
"given",
"full",
"class",
"name",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/BlockImporter.php#L125-L158 |
luyadev/luya-module-cms | src/admin/importers/BlockImporter.php | BlockImporter.saveBlockByPath | protected function saveBlockByPath($path)
{
$info = FileHelper::classInfo($path);
if ($info) {
$className = $info['namespace'] . '\\' . $info['class'];
return $this->saveBlock($className);
}
$this->addLog('Unable to find block namespace for file ' . $path);
return false;
} | php | protected function saveBlockByPath($path)
{
$info = FileHelper::classInfo($path);
if ($info) {
$className = $info['namespace'] . '\\' . $info['class'];
return $this->saveBlock($className);
}
$this->addLog('Unable to find block namespace for file ' . $path);
return false;
} | [
"protected",
"function",
"saveBlockByPath",
"(",
"$",
"path",
")",
"{",
"$",
"info",
"=",
"FileHelper",
"::",
"classInfo",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"info",
")",
"{",
"$",
"className",
"=",
"$",
"info",
"[",
"'namespace'",
"]",
".",... | Save a block by its path, this will extract the namespace of the block in order to save it.
Example path: /apps/myblocks/ExampleBlock.php
Example path: `
@param string $path
@return number|boolean | [
"Save",
"a",
"block",
"by",
"its",
"path",
"this",
"will",
"extract",
"the",
"namespace",
"of",
"the",
"block",
"in",
"order",
"to",
"save",
"it",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/BlockImporter.php#L169-L182 |
luyadev/luya-module-cms | src/admin/importers/BlockImporter.php | BlockImporter.getBlockGroupId | protected function getBlockGroupId(BlockInterface $blockObject)
{
$groupClassName = $blockObject->blockGroup();
$groupClassName = '\\' . ltrim($groupClassName, '\\');
$groupObject = Yii::createObject(['class' => $groupClassName]);
$group = BlockGroup::findOne(['identifier' => $groupObject->identifier()]);
if ($group) {
$group->updateAttributes([
'name' => $groupObject->label(),
'class' => $groupClassName,
'is_deleted' => false,
]);
return $group->id;
} else {
$model = new BlockGroup();
$model->name = $groupObject->label();
$model->identifier = $groupObject->identifier();
$model->created_timestamp = time();
$model->class = $groupClassName;
if ($model->save()) {
$this->addLog("Insert new block group {$model->name}.");
return $model->id;
}
}
return 0;
} | php | protected function getBlockGroupId(BlockInterface $blockObject)
{
$groupClassName = $blockObject->blockGroup();
$groupClassName = '\\' . ltrim($groupClassName, '\\');
$groupObject = Yii::createObject(['class' => $groupClassName]);
$group = BlockGroup::findOne(['identifier' => $groupObject->identifier()]);
if ($group) {
$group->updateAttributes([
'name' => $groupObject->label(),
'class' => $groupClassName,
'is_deleted' => false,
]);
return $group->id;
} else {
$model = new BlockGroup();
$model->name = $groupObject->label();
$model->identifier = $groupObject->identifier();
$model->created_timestamp = time();
$model->class = $groupClassName;
if ($model->save()) {
$this->addLog("Insert new block group {$model->name}.");
return $model->id;
}
}
return 0;
} | [
"protected",
"function",
"getBlockGroupId",
"(",
"BlockInterface",
"$",
"blockObject",
")",
"{",
"$",
"groupClassName",
"=",
"$",
"blockObject",
"->",
"blockGroup",
"(",
")",
";",
"$",
"groupClassName",
"=",
"'\\\\'",
".",
"ltrim",
"(",
"$",
"groupClassName",
... | The the group of a block based on the block object.
@param BlockInterface $blockObject
@return integer | [
"The",
"the",
"group",
"of",
"a",
"block",
"based",
"on",
"the",
"block",
"object",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/admin/importers/BlockImporter.php#L201-L232 |
luyadev/luya-module-cms | src/injectors/TagInjector.php | TagInjector.getAssignedTags | public function getAssignedTags()
{
if ($this->_assignedTags === null) {
$ids = ArrayHelper::getColumn($this->getContextConfigValue($this->varName, []), 'value');
$this->_assignedTags = Tag::find()->where(['in','id', $ids])->indexBy('name')->all();
}
return $this->_assignedTags;
} | php | public function getAssignedTags()
{
if ($this->_assignedTags === null) {
$ids = ArrayHelper::getColumn($this->getContextConfigValue($this->varName, []), 'value');
$this->_assignedTags = Tag::find()->where(['in','id', $ids])->indexBy('name')->all();
}
return $this->_assignedTags;
} | [
"public",
"function",
"getAssignedTags",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_assignedTags",
"===",
"null",
")",
"{",
"$",
"ids",
"=",
"ArrayHelper",
"::",
"getColumn",
"(",
"$",
"this",
"->",
"getContextConfigValue",
"(",
"$",
"this",
"->",
"v... | Get assigned models for the current Block.
@return \luya\admin\models\Tag All selected tags within the tag model. | [
"Get",
"assigned",
"models",
"for",
"the",
"current",
"Block",
"."
] | train | https://github.com/luyadev/luya-module-cms/blob/9a74bc5869c365e50bc455c4860e3af8c6145d34/src/injectors/TagInjector.php#L41-L49 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.