public function __construct($view, \Admin\Core\Helper $helper, \TYPO3\FLOW3\Object\ObjectManagerInterface $objectManager) { $this->helper = $helper; $this->view = $view; $this->objectManager = $objectManager; $partial = $this->getName(); $replacements = array("@partial" => $partial, "@package" => $this->helper->getPackageByClassName(get_class($this)), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => $partial); $template = $this->helper->getPathByPatternFallbacks("DashboardWidgets", $replacements); $this->view->setTemplatePathAndFilename($template); $this->initializeWidget(); }
/** * * @param string $file * @param string $dependencies * @return string */ public function render($add = null, $render = null) { if ($add !== null) { \Admin\Core\API::add("WidgetResources", $add, $this->renderChildren()); return ""; } if ($render !== null && $render == true) { $resources = \Admin\Core\API::get("WidgetResources"); if (is_array($resources)) { return implode("\n", $resources); } } }
/** * Iterates through elements of $each and renders child nodes * * @param string $get * @param string $as * @return string Rendered string * @author Marc Neuhaus <*****@*****.**> * @api */ public function render($get, $as = null) { if ($as == null) { $as = $get; } if (\Admin\Core\API::has($get)) { $this->templateVariableContainer->add($as, \Admin\Core\API::get($get)); } elseif (is_callable("\\Admin\\Core\\Api::get" . ucfirst($get))) { $function = "get" . ucfirst($get); $result = call_user_func("\\Admin\\Core\\Api::get" . ucfirst($get)); $this->templateVariableContainer->add($as, $result); } $output = $this->renderChildren(); $this->templateVariableContainer->remove($as); return $output; }
/** * Create objects * * @param string $being * @param array $ids * @author Marc Neuhaus <*****@*****.**> * */ public function execute($being, $ids = null) { $object = $this->adapter->getBeing($being); if ($this->request->hasArgument("create")) { $result = $this->adapter->createObject($being, $this->request->getArgument("item")); if (is_a($result, $being)) { $this->controller->addLog(); $arguments = array("being" => \Admin\Core\API::get("classShortNames", $being)); $this->controller->redirect('list', NULL, NULL, $arguments); } else { $object->setErrors($result); $object->setObject($this->request->getArgument("item")); } } $this->view->assign("being", $object); }
public function renderPartial($variant = "Default") { $replacements = array("@partial" => "Field", "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => "Field", "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks("Partials", $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); return $this->view->render(); }
/** * Delete objects * * @param string $being * @param array $ids * @author Marc Neuhaus <*****@*****.**> * */ public function execute($being, $ids = null) { $this->being = $being; $this->view->assign('className', $being); $this->settings = $this->getSettings(); $this->handleBulkActions(); $this->adapter->initQuery($being); $results = $this->adapter->getQuery()->execute(); $this->view->assign("objects", $results); // Redirect to creating a new Object if there aren't any (Clean Slate) if ($results->count() < 1) { $arguments = array("being" => \Admin\Core\API::get("classShortNames", $being)); $this->controller->redirect("create", NULL, NULL, $arguments); } $listActions = $this->controller->getActions("list", $being, true); $this->view->assign('listActions', $listActions); }
/** * Delete objects * * @param string $being * @param array $ids * @author Marc Neuhaus <*****@*****.**> * */ public function execute($being, $ids = null) { if (is_array($ids)) { if ($this->request->hasArgument("confirm")) { foreach ($ids as $id) { $this->adapter->deleteObject($being, $id); } $this->controller->addLog(); $arguments = array("being" => \Admin\Core\API::get("classShortNames", $being)); $this->controller->redirect('list', NULL, NULL, $arguments); } else { $arguments = $this->request->getArguments(); $arguments["id"] = implode(",", $ids); $this->controller->redirect('confirm', NULL, NULL, $arguments); } } }
/** * Edit objects * * @param string $being * @param array $ids * @author Marc Neuhaus <*****@*****.**> * */ public function execute($being, $ids = null) { if ($this->request->hasArgument("update")) { $result = $this->adapter->updateObject($being, current($ids), $this->request->getArgument("item")); if (is_a($result, $being)) { $arguments = array("being" => \Admin\Core\API::get("classShortNames", $being)); $this->controller->addLog(); $this->controller->redirect('list', NULL, NULL, $arguments); } else { # foreach ($attributeSets as $set => $attributes) { # foreach ($attributes as $key => $attribute) { # if(array_key_exists($attribute["name"],$errors)){ # $attributeSets[$set][$key]["error"] = $errors[$attribute["name"]]; # } # } # } } } $object = $this->adapter->getBeing($being, current($ids)); $this->view->assign("being", $object); }
/** * * @param object $value * @param string $partial * @param string $fallbacks * @param array $vars * @param string $section * @param mixed $optional * @param string $variant * @return string Rendered string * @author Marc Neuhaus <*****@*****.**> * @api */ public function render($value = '', $partial = '', $fallbacks = '', $vars = array(), $section = null, $optional = false, $variant = "Default") { if ($value !== '') { return $value; } if ($partial !== '') { if ($fallbacks !== '') { $replacements = array("@partial" => $partial, "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => $partial, "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); $identifier = str_replace("/", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks($fallbacks, $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } if (empty($vars)) { $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); if (!empty($template)) { return $this->view->render(); } } else { $partial = $this->parseTemplate($template); $variableContainer = $this->objectManager->create('TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $vars); $renderingContext = $this->buildRenderingContext($variableContainer); return $partial->render($renderingContext); } } } if ($section !== null) { $output = $this->viewHelperVariableContainer->getView()->renderSection($section, $vars, $optional); if (strlen($output) < 1) { $output = $this->renderChildren(); } return $output; } }
/** * Render the link. * * @param string $action Target action * @param array $arguments Arguments * @param string $being * @param string $shortcut * @param string $selectionShortcut * @param string $controller Target controller. If NULL current controllerName is used * @param string $package Target package. if NULL current package is used * @param string $subpackage Target subpackage. if NULL current subpackage is used * @param string $section The anchor to be added to the URI * @param string $format The requested format, e.g. ".html" * @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments) * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE * @return string The rendered link * @api */ public function render($action = NULL, $arguments = array(), $being = NULL, $selectionShortcut = false, $shortcut = false, $controller = NULL, $package = NULL, $subpackage = NULL, $section = '', $format = '', array $additionalParams = array(), $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $overrule = array()) { $uriBuilder = $this->controllerContext->getUriBuilder(); if ($being !== NULL) { $arguments["being"] = \Admin\Core\API::get("classShortNames", $being); } try { $uri = $uriBuilder->reset()->setSection($section)->setCreateAbsoluteUri(TRUE)->setArguments($additionalParams)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setFormat($format)->uriFor($action, $arguments, $controller, $package, $subpackage); $this->tag->addAttribute('href', $uri); if ($shortcut) { $this->tag->addAttribute("data-klove-shortcut", $shortcut); } if ($selectionShortcut) { $this->tag->addAttribute("data-klove-row-shortcut", $selectionShortcut); } } catch (\TYPO3\FLOW3\Exception $exception) { throw new \TYPO3\Fluid\Core\ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception); } $this->tag->setContent($this->renderChildren()); $this->tag->forceClosingTag(TRUE); return $this->tag->render(); }
public function createBeing($being, $id = null) { $realAction = \Admin\Core\API::get("action"); \Admin\Core\API::set("action", "inline"); $b = $this->adapter->getBeing($this->being, $id); \Admin\Core\API::set("action", $realAction); $b->prefix = $this->getPrefix(); if (!empty($id)) { # $identity = array( $this->getPrefix() . "[__identity]" => $id ); $b->addHiddenProperty($this->getPrefix() . "[__identity]", $id); } return $b; }
public function getArguments() { return array("id" => $this->getIdentity(), "being" => get_class($this), "adapter" => \Admin\Core\API::get("adapter")); }
private function prepare($action) { $this->start = microtime(); $this->adapters = $this->helper->getAdapters(); $this->settings = $this->helper->getSettings(); \Admin\Core\API::set("classShortNames", $this->compileShortNames()); \Admin\Core\API::set("action", $action); if ($this->request->hasArgument("being")) { $this->being = $this->request->getArgument("being"); if (!stristr($this->being, "\\")) { $this->being = \Admin\Core\API::get("classShortNames", $this->being); } \Admin\Core\API::set("being", $this->being); $this->adapter = $this->helper->getAdapterByBeing($this->being); \Admin\Core\API::set("adapter", $this->adapter); $this->group = $this->helper->getGroupByBeing($this->being); \Admin\Core\API::set("group", $this->group); } if ($this->request->hasArgument("id")) { $this->id = $this->request->getArgument("id"); if (is_array($this->id)) { $this->id = implode(",", $this->id); } } $user = $this->securityManager->getUser(); if (!isset($user) || !is_object($user)) { $this->securityManager->redirectToLogin(); } else { $allowedBeings = array("view" => array()); try { foreach ($user->getRoles() as $role) { foreach ($role->getGrant() as $policy) { $allowedBeings[$policy->getAction()][] = $policy->getBeing(); } } } catch (\Doctrine\ORM\EntityNotFoundException $e) { unset($user); $this->securityManager->redirectToLogin(); } $this->user = $user; } $groups = $this->helper->getGroups(); ksort($groups); foreach ($groups as $package => $group) { foreach ($group["beings"] as $key => $being) { if (!in_array($being["being"], $allowedBeings["view"])) { if (!$user->isAdmin()) { unset($groups[$package]["beings"][$key]); } } if (!empty($this->adapter)) { if ($being["being"] == $this->being && $being["adapter"] == $this->adapter) { $groups[$package]["beings"][$key]["active"] = true; } else { $groups[$package]["beings"][$key]["active"] = false; } } } if (empty($groups[$package]["beings"])) { unset($groups[$package]); } } $this->view = $this->resolveView(); \Admin\Core\API::set("user", $user); if ($this->view !== NULL) { $this->view->assign('settings', $this->settings); $this->initializeView($this->view); } $this->view->assign('groups', $groups); $this->setTemplate($action); $context = getenv("FLOW3_CONTEXT") ? getenv("FLOW3_CONTEXT") : "Production"; $this->view->assign("context", $context); $hasId = isset($this->id) ? true : false; $topBarActions = $this->getActions($action, $this->being, $hasId); $this->view->assign('topBarActions', $topBarActions); }
/** * checks the conf if the element should be ignored * * @param string $conf * @return void * @author Marc Neuhaus */ public function shouldBeIgnored($annotations, $property) { if (in_array($property, explode(",", $this->ignoredProperties))) { return true; } if (isset($annotations["inject"])) { return true; } if (!isset($annotations["ignore"])) { return false; } else { $ignore = current($annotations["ignore"]); if (empty($ignore->views) || $ignore->views === true) { return true; } else { $actions = explode(",", $ignore->views); $action = \Admin\Core\API::get("action"); return in_array($action, $actions); } } return false; }
public function getArguments() { return array("id" => $this->getIdentity(), "being" => "Admin\\Security\\User", "adapter" => \Admin\Core\API::get("adapter")); }