/** * Wrap module with inline admin controls. * * @param string $content * @param Curry_PageModuleWrapper $pageModuleWrapper * @return string */ protected function adminModule($content, Curry_PageModuleWrapper $pageModuleWrapper) { $user = User::getUser(); $pageId = $pageModuleWrapper->getPageRevision()->getPageId(); $page = $pageModuleWrapper->getPageRevision()->getPage(); $pageModuleId = $pageModuleWrapper->getPageModuleId(); $commands = array(); $templatePermission = $user->hasAccess('Curry_Backend_Template'); $contentPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT); $modulePermission = $user->hasPagePermission($page, PageAccessPeer::PERM_MODULES); $createPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CREATE_MODULE); if (!$user->hasModuleAccess($pageModuleWrapper)) { return $content; } if ($contentPermission || $modulePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'Module', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); if ($user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT)) { $commands['edit'] = array('Name' => 'Edit', 'Url' => $url, 'Class' => 'iframe'); } } if ($pageModuleWrapper->getTemplate() && $templatePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Template', 'view' => 'Edit', 'file' => $pageModuleWrapper->getTemplate())); $commands['template'] = array('Name' => 'Edit template', 'Url' => $url, 'Class' => 'iframe'); } if ($modulePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'ModuleProperties', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); $commands['properties'] = array('Name' => 'Properties', 'Url' => $url, 'Class' => 'iframe'); } if ($createPermission && ($contentPermission && !$pageModuleWrapper->isInherited() || $modulePermission)) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'DeleteModule', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); $commands['delete'] = array('Name' => 'Delete', 'Url' => $url, 'Class' => 'iframe'); } $module = $pageModuleWrapper->createObject(); $module->setPageGenerator($this); $commands = $module->getInlineCommands($commands); if (!count($commands)) { return $content; } $tpl = Curry_Twig_Template::loadTemplateString(Curry_InlineAdmin::getAdminModuleTpl()); return $tpl->render(array('Id' => $pageModuleId, 'Name' => $pageModuleWrapper->getName(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Content' => $content, 'commands' => $commands)); }
public function getInfo(Curry_PageModuleWrapper $wrapper) { $icons = ''; $pageModule = $wrapper->getPageModule(); if ($wrapper->isInherited()) { $pageUrl = url('', array('module', 'view', 'page_id' => $pageModule->getPageId())); $icons .= '<a href="' . $pageUrl . '" title="Inherited from ' . $pageModule->getPage() . '"><i class="icon-double-angle-up"></i></a>'; } else { $icons .= '<i class="icon-double-angle-down" title="Content is inherited to subpages"></i>'; } $langContent = ModuleDataQuery::create()->filterByPageModule($wrapper->getPageModule())->filterByPageRevision($wrapper->getPageRevision())->filterByLangcode("", Criteria::NOT_EQUAL)->select('Langcode')->find()->getArrayCopy(); if (!$wrapper->getEnabled()) { $icons .= ' <i class="icon-eye-close"></i>'; } if ($wrapper->hasData()) { $icons .= ' <i class="icon-picture" title="Page content"></i>'; } if (count($langContent)) { $icons .= ' <i class="icon-flag" title="Language specific content: ' . htmlspecialchars(join(', ', $langContent)) . '"></i>'; } return $icons; }
/** * Get "copy code" for module. * * @param Curry_PageModuleWrapper $module * @return array */ public static function getModuleCode(Curry_PageModuleWrapper $module) { $datas = array(); $moduleDatas = ModuleDataQuery::create()->filterByPageModule($module->getPageModule())->filterByPageRevision($module->getPageRevision())->orderByLangcode()->find(); foreach ($moduleDatas as $moduleData) { $datas[] = self::getModuleDataCode($moduleData); } return array("is_inherited" => $module->isInherited(), "uid" => $module->getPageModule()->getUid(), "name" => $module->getName(), "module_class" => $module->getClassName(), "inherit" => true, "target" => $module->getTarget(), "content_visibility" => $module->getPageModule()->getContentVisibility(), "search_visibility" => $module->getPageModule()->getSearchVisibility(), "datas" => $datas); }
/** * Save module properties. * * @param Curry_PageModuleWrapper $pageModuleWrapper * @param array $values */ public static function saveModuleProperties(Curry_PageModuleWrapper $pageModuleWrapper, array $values) { $modified = false; // PageModule $pageModule = $pageModuleWrapper->getPageModule(); $pageModule->setName($values['name']); $pageModule->setTarget($values['target']); $pageModule->setContentVisibility($values['content_visibility']); $pageModule->setSearchVisibility($values['search_visibility']); $modified |= $pageModule->isModified(); $pageModule->save(); // ModuleData $moduleData = $pageModuleWrapper->getModuleData(); $moduleData->setTemplate($values['local']['template'] === '' ? null : $values['local']['template']); $moduleData->setEnabled(self::str2bool($values['local']['show'])); $modified |= $moduleData->isModified(); $moduleData->save(); if ($modified) { $pageRevision = $pageModuleWrapper->getPageRevision(); $pageRevision->setUpdatedAt(time()); $pageRevision->save(); } }