public static getElementByPath ( string $type, string $path ) : Pimcore\Model\Element\ElementInterface | ||
$type | string | |
$path | string | |
return | Pimcore\Model\Element\ElementInterface |
/** * Takes data from editmode and convert it to internal objects * * @param mixed $data * @return void */ public function setDataFromEditmode($data) { // IMPORTANT: if you use this method be sure that the type of the property is already set if (in_array($this->getType(), array("document", "asset", "object"))) { $el = Element\Service::getElementByPath($this->getType(), $data); $this->data = null; if ($el) { $this->data = $el->getId(); } } else { if ($this->type == "date") { $this->data = new \Zend_Date($data); } else { if ($this->type == "bool") { $this->data = false; if (!empty($data)) { $this->data = true; } } else { // plain text $this->data = $data; } } } return $this; }
private function installUserRole() { $userRole = new \Pimcore\Model\User\Role(); $customerRole = $userRole->getByName('kunde'); if ($customerRole !== FALSE) { return $customerRole; } $user = \Pimcore\Model\User\Role::create(array('parentId' => 0, 'name' => 'kunde', 'active' => 1)); $permissions = array('assets' => TRUE, 'plugin_coreshop' => TRUE, 'coreshop_country' => TRUE, 'coreshop_currency' => TRUE, 'coreshop_zone' => TRUE, 'coreshop_user' => TRUE, 'dashboards' => TRUE, 'documents' => TRUE, 'notes_events' => TRUE, 'objects' => TRUE, 'recyclebin' => TRUE, 'redirects' => TRUE, 'seemode' => TRUE, 'users' => TRUE, 'website_settings' => TRUE); $classes = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); $workspaces = array('document' => array(array('path' => '/', 'list' => TRUE, 'save' => TRUE, 'unpublish' => TRUE, 'view' => TRUE, 'publish' => TRUE, 'delete' => TRUE, 'rename' => TRUE, 'create' => TRUE, 'settings' => TRUE, 'versions' => TRUE, 'properties' => TRUE), array('path' => '/demo')), 'object' => array(array('path' => '/', 'list' => TRUE, 'save' => TRUE, 'unpublish' => TRUE, 'view' => TRUE, 'publish' => TRUE, 'delete' => TRUE, 'rename' => TRUE, 'create' => TRUE, 'settings' => TRUE, 'versions' => TRUE, 'properties' => TRUE)), 'asset' => array(array('path' => '/', 'list' => TRUE, 'save' => TRUE, 'unpublish' => TRUE, 'view' => TRUE, 'publish' => TRUE, 'delete' => TRUE, 'rename' => TRUE, 'create' => TRUE, 'settings' => TRUE, 'versions' => TRUE, 'properties' => TRUE))); foreach ($workspaces as $type => $spaces) { $newWorkspaces = array(); foreach ($spaces as $space) { $element = \Pimcore\Model\Element\Service::getElementByPath($type, $space['path']); if ($element) { $className = '\\Pimcore\\Model\\User\\Workspace\\' . ucfirst($type); $workspace = new $className(); $workspace->setValues($space); $workspace->setCid($element->getId()); $workspace->setCpath($element->getFullPath()); $workspace->setUserId($user->getId()); $newWorkspaces[] = $workspace; } } $user->{'setWorkspaces' . ucfirst($type)}($newWorkspaces); } foreach ($permissions as $permName => $permAccess) { $user->setPermission($permName, $permAccess); } $user->setDocTypes(implode(',', array(1))); $user->setClasses(implode(',', $classes)); $user->save(); //var_dump($user); return $user; }
/** * @see Document\Tag\TagInterface::setDataFromEditmode * @param mixed $data * @return void */ public function setDataFromEditmode($data) { $pdf = Asset::getById($data["id"]); if ($pdf instanceof Asset\Document) { $this->id = $pdf->getId(); if (array_key_exists("hotspots", $data) && !empty($data["hotspots"])) { $rewritePath = function ($data) { if (!is_array($data)) { return array(); } foreach ($data as &$page) { foreach ($page as &$element) { if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) { foreach ($element["data"] as &$metaData) { if (in_array($metaData["type"], array("object", "asset", "document", "link"))) { $elTtype = $metaData["type"]; if ($metaData["type"] == "link") { $elTtype = "document"; } $el = Element\Service::getElementByPath($elTtype, $metaData["value"]); if (!$el && $metaData["type"] == "link") { $metaData["value"] = $metaData["value"]; } else { $metaData["value"] = $el; } } } } } } return $data; }; if (array_key_exists("hotspots", $data) && is_array($data["hotspots"]) && count($data["hotspots"]) > 0) { $data["hotspots"] = $rewritePath($data["hotspots"]); } $this->hotspots = $data["hotspots"]; } $this->texts = $data['texts']; $this->chapters = $data['chapters']; } return $this; }
public function updateAction() { $this->protectCSRF(); $user = User\AbstractUser::getById(intval($this->getParam("id"))); if ($user instanceof User && $user->isAdmin() && !$this->getUser()->isAdmin()) { throw new \Exception("Only admin users are allowed to modify admin users"); } if ($this->getParam("data")) { $values = \Zend_Json::decode($this->getParam("data")); if (!empty($values["password"])) { $values["password"] = Tool\Authentication::getPasswordHash($user->getName(), $values["password"]); } // check if there are permissions transmitted, if so reset them all to false (they will be set later) foreach ($values as $key => $value) { if (strpos($key, "permission_") === 0) { if (method_exists($user, "setAllAclToFalse")) { $user->setAllAclToFalse(); } break; } } $user->setValues($values); // only admins are allowed to create admin users // if the logged in user isn't an admin, set admin always to false if (!$this->getUser()->isAdmin() && $user instanceof User) { if ($user instanceof User) { $user->setAdmin(false); } } // check for permissions $availableUserPermissionsList = new User\Permission\Definition\Listing(); $availableUserPermissions = $availableUserPermissionsList->load(); foreach ($availableUserPermissions as $permission) { if (isset($values["permission_" . $permission->getKey()])) { $user->setPermission($permission->getKey(), (bool) $values["permission_" . $permission->getKey()]); } } // check for workspaces if ($this->getParam("workspaces")) { $workspaces = \Zend_Json::decode($this->getParam("workspaces")); foreach ($workspaces as $type => $spaces) { $newWorkspaces = []; foreach ($spaces as $space) { $element = Element\Service::getElementByPath($type, $space["path"]); if ($element) { $className = "\\Pimcore\\Model\\User\\Workspace\\" . ucfirst($type); $workspace = new $className(); $workspace->setValues($space); $workspace->setCid($element->getId()); $workspace->setCpath($element->getRealFullPath()); $workspace->setUserId($user->getId()); $newWorkspaces[] = $workspace; } } $user->{"setWorkspaces" . ucfirst($type)}($newWorkspaces); } } } $user->save(); $this->_helper->json(["success" => true]); }
/** * */ public function minimize() { switch ($this->type) { case "document": case "asset": case "object": $element = Element\Service::getElementByPath($this->type, $this->data); if ($element) { $this->data = $element->getId(); } else { $this->data = ""; } break; case "date": if ($this->data && !is_numeric($this->data)) { $this->data = strtotime($this->data); } default: //nothing to do } }
/** * @param $importValue * @return mixed|null|Asset|Document|Element\ElementInterface */ public function getFromCsvImport($importValue) { $value = null; $values = explode(":", $importValue); if (count($values) == 2) { $type = $values[0]; $path = $values[1]; $value = Element\Service::getElementByPath($type, $path); } else { //fallback for old export files if ($el = Asset::getByPath($importValue)) { $value = $el; } else { if ($el = Document::getByPath($importValue)) { $value = $el; } else { if ($el = Object::getByPath($importValue)) { $value = $el; } } } } return $value; }
public function findUsagesAction() { if ($this->getParam("id")) { $element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id")); } elseif ($this->getParam("path")) { $element = Element\Service::getElementByPath($this->getParam("type"), $this->getParam("path")); } $results = []; $success = false; if ($element) { $elements = $element->getDependencies()->getRequiredBy(); foreach ($elements as $el) { $item = Element\Service::getElementById($el["type"], $el["id"]); if ($item instanceof Element\ElementInterface) { $el["path"] = $item->getRealFullPath(); $results[] = $el; } } $success = true; } $this->_helper->json(["data" => $results, "success" => $success]); }
/** * @see Model\Object\ClassDefinition\Data::getDataFromEditmode * @param Object\Data\Hotspotimage $data * @param null|Model\Object\AbstractObject $object * @return Asset */ public function getDataFromEditmode($data, $object = null) { $rewritePath = function ($data) { if (!is_array($data)) { return array(); } foreach ($data as &$element) { if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) { foreach ($element["data"] as &$metaData) { if (in_array($metaData["type"], array("object", "asset", "document"))) { $el = Element\Service::getElementByPath($metaData["type"], $metaData["value"]); $metaData["value"] = $el; } } } } return $data; }; if (array_key_exists("marker", $data) && is_array($data["marker"]) && count($data["marker"]) > 0) { $data["marker"] = $rewritePath($data["marker"]); } if (array_key_exists("hotspots", $data) && is_array($data["hotspots"]) && count($data["hotspots"]) > 0) { $data["hotspots"] = $rewritePath($data["hotspots"]); } return new Object\Data\Hotspotimage($data["image"], $data["hotspots"], $data["marker"], $data["crop"]); }
public function websiteSettingsAction() { try { if ($this->getParam("data")) { $this->checkPermission("website_settings"); $data = \Zend_Json::decode($this->getParam("data")); if (is_array($data)) { foreach ($data as &$value) { $value = trim($value); } } if ($this->getParam("xaction") == "destroy") { if (\Pimcore\Tool\Admin::isExtJS6()) { $id = $data["id"]; } else { $id = $data; } $setting = WebsiteSetting::getById($id); $setting->delete(); $this->_helper->json(array("success" => true, "data" => array())); } else { if ($this->getParam("xaction") == "update") { // save routes $setting = WebsiteSetting::getById($data["id"]); switch ($setting->getType()) { case "document": case "asset": case "object": if (isset($data["data"])) { $path = $data["data"]; $element = Element\Service::getElementByPath($setting->getType(), $path); $data["data"] = $element ? $element->getId() : null; } break; } $setting->setValues($data); $setting->save(); $data = $this->getWebsiteSettingForEditMode($setting); $this->_helper->json(array("data" => $data, "success" => true)); } else { if ($this->getParam("xaction") == "create") { unset($data["id"]); // save route $setting = new WebsiteSetting(); $setting->setValues($data); $setting->save(); $this->_helper->json(array("data" => $setting, "success" => true)); } } } } else { // get list of routes $list = new WebsiteSetting\Listing(); $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams()); if ($sortingSettings['orderKey']) { $list->setOrderKey($sortingSettings['orderKey']); $list->setOrder($sortingSettings['order']); } else { $list->setOrderKey("name"); $list->setOrder("asc"); } if ($this->getParam("filter")) { $list->setCondition("`name` LIKE " . $list->quote("%" . $this->getParam("filter") . "%")); } $totalCount = $list->getTotalCount(); $list = $list->load(); $settings = array(); foreach ($list as $item) { $resultItem = $this->getWebsiteSettingForEditMode($item); $settings[] = $resultItem; } $this->_helper->json(array("data" => $settings, "success" => true, "total" => $totalCount)); } } catch (\Exception $e) { throw $e; $this->_helper->json(false); } $this->_helper->json(false); }
/** * @param mixed $data * @return $this */ public function setDataFromEditmode($data) { $rewritePath = function ($data) { if (!is_array($data)) { return array(); } foreach ($data as &$element) { if (array_key_exists("data", $element) && is_array($element["data"]) && count($element["data"]) > 0) { foreach ($element["data"] as &$metaData) { $metaData = new Element\Data\MarkerHotspotItem($metaData); if (in_array($metaData["type"], array("object", "asset", "document"))) { $el = Element\Service::getElementByPath($metaData["type"], $metaData->getValue()); $metaData["value"] = $el; } } } } return $data; }; if (is_array($data)) { if (array_key_exists("marker", $data) && is_array($data["marker"]) && count($data["marker"]) > 0) { $data["marker"] = $rewritePath($data["marker"]); } if (array_key_exists("hotspots", $data) && is_array($data["hotspots"]) && count($data["hotspots"]) > 0) { $data["hotspots"] = $rewritePath($data["hotspots"]); } $this->id = $data["id"]; $this->alt = $data["alt"]; $this->cropPercent = $data["cropPercent"]; $this->cropWidth = $data["cropWidth"]; $this->cropHeight = $data["cropHeight"]; $this->cropTop = $data["cropTop"]; $this->cropLeft = $data["cropLeft"]; $this->marker = $data["marker"]; $this->hotspots = $data["hotspots"]; } return $this; }
/** * fills object field data values from CSV Import String * @abstract * @param string $importValue * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return Object\ClassDefinition\Data */ public function getFromCsvImport($importValue, $object = null, $params = []) { $values = explode(",", $importValue); $value = []; foreach ($values as $element) { $tokens = explode(":", $element); if (count($tokens) == 2) { $type = $tokens[0]; $path = $tokens[1]; $value[] = Element\Service::getElementByPath($type, $path); } else { //fallback for old export files if ($el = Asset::getByPath($element)) { $value[] = $el; } elseif ($el = Document::getByPath($element)) { $value[] = $el; } elseif ($el = Object::getByPath($element)) { $value[] = $el; } } } return $value; }
/** * @param $metadata * @return array */ public static function minimizeMetadata($metadata) { if (!is_array($metadata)) { return $metadata; } $result = []; foreach ($metadata as $item) { $type = $item["type"]; switch ($type) { case "document": case "asset": case "object": $element = Element\Service::getElementByPath($type, $item["data"]); if ($element) { $item["data"] = $element->getId(); } else { $item["data"] = ""; } break; default: //nothing to do } $result[] = $item; } return $result; }
public function indexAction() { // clear open edit locks for this session (in the case of a reload, ...) \Pimcore\Model\Element\Editlock::clearSession(session_id()); // check maintenance $maintenance_enabled = false; $manager = Model\Schedule\Manager\Factory::getManager("maintenance.pid"); $lastExecution = $manager->getLastExecution(); if ($lastExecution) { if (time() - $lastExecution < 610) { // maintenance script should run at least every 10 minutes + a little tolerance $maintenance_enabled = true; } } $this->view->maintenance_enabled = \Zend_Json::encode($maintenance_enabled); // configuration $sysConfig = Config::getSystemConfig(); $this->view->config = $sysConfig; //mail settings $mailIncomplete = false; if ($sysConfig->email) { if (!$sysConfig->email->debug->emailaddresses) { $mailIncomplete = true; } if (!$sysConfig->email->sender->email) { $mailIncomplete = true; } if ($sysConfig->email->method == "smtp" && !$sysConfig->email->smtp->host) { $mailIncomplete = true; } } $this->view->mail_settings_complete = \Zend_Json::encode(!$mailIncomplete); // report configuration $this->view->report_config = Config::getReportConfig(); $cvData = []; // still needed when publishing objects $cvConfig = Tool::getCustomViewConfig(); if ($cvConfig) { foreach ($cvConfig as $node) { $tmpData = $node; // backwards compatibility $treeType = $tmpData["treetype"] ? $tmpData["treetype"] : "object"; $rootNode = Model\Element\Service::getElementByPath($treeType, $tmpData["rootfolder"]); if ($rootNode) { $tmpData["rootId"] = $rootNode->getId(); $tmpData["allowedClasses"] = $tmpData["classes"] ? explode(",", $tmpData["classes"]) : null; $tmpData["showroot"] = (bool) $tmpData["showroot"]; // Check if a user has privileges to that node if ($rootNode->isAllowed("list")) { $cvData[] = $tmpData; } } } } $this->view->customview_config = $cvData; // upload limit $max_upload = filesize2bytes(ini_get("upload_max_filesize") . "B"); $max_post = filesize2bytes(ini_get("post_max_size") . "B"); $upload_mb = min($max_upload, $max_post); $this->view->upload_max_filesize = $upload_mb; // session lifetime (gc) $session_gc_maxlifetime = ini_get("session.gc_maxlifetime"); if (empty($session_gc_maxlifetime)) { $session_gc_maxlifetime = 120; } $this->view->session_gc_maxlifetime = $session_gc_maxlifetime; // csrf token $user = $this->getUser(); $this->view->csrfToken = Tool\Session::useSession(function ($adminSession) use($user) { if (!isset($adminSession->csrfToken) && !$adminSession->csrfToken) { $adminSession->csrfToken = sha1(microtime() . $user->getName() . uniqid()); } return $adminSession->csrfToken; }); if (\Pimcore\Tool\Admin::isExtJS6()) { $this->forward("index6"); } }
/** Returns the element tree config for the given config name * @param $name * @return array */ protected static function getRuntimeElementTreeConfig($name) { $masterConfig = self::getPerspectivesConfig()->toArray(); $config = $masterConfig[$name]; if (!$config) { $config = []; } $tmpResult = $config["elementTree"]; if (is_null($tmpResult)) { $tmpResult = []; } $result = []; $cfConfigMapping = []; $cvConfigs = Tool::getCustomViewConfig(); if ($cvConfigs) { foreach ($cvConfigs as $node) { $tmpData = $node; if (!isset($tmpData["id"])) { Logger::error("custom view ID is missing " . var_export($tmpData, true)); continue; } if ($tmpData["hidden"]) { continue; } // backwards compatibility $treeType = $tmpData["treetype"] ? $tmpData["treetype"] : "object"; $rootNode = Model\Element\Service::getElementByPath($treeType, $tmpData["rootfolder"]); if ($rootNode) { $tmpData["type"] = "customview"; $tmpData["rootId"] = $rootNode->getId(); $tmpData["allowedClasses"] = $tmpData["classes"] ? explode(",", $tmpData["classes"]) : null; $tmpData["showroot"] = (bool) $tmpData["showroot"]; $customViewId = $tmpData["id"]; $cfConfigMapping[$customViewId] = $tmpData; } } } foreach ($tmpResult as $resultItem) { if ($resultItem["hidden"]) { continue; } if ($resultItem["type"] == "customview") { $customViewId = $resultItem["id"]; if (!$customViewId) { Logger::error("custom view id missing " . var_export($resultItem, true)); continue; } $customViewCfg = $cfConfigMapping[$customViewId]; if (!$customViewId) { Logger::error("no custom view config for id " . $customViewId); continue; } foreach ($resultItem as $specificConfigKey => $specificConfigValue) { $customViewCfg[$specificConfigKey] = $specificConfigValue; } $result[] = $customViewCfg; } else { $result[] = $resultItem; } } usort($result, function ($treeA, $treeB) { $a = $treeA["sort"] ? $treeA["sort"] : 0; $b = $treeB["sort"] ? $treeB["sort"] : 0; if ($a > $b) { return 1; } elseif ($a < $b) { return -1; } else { return 0; } }); return $result; }
/** * @param $importValue * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return array|mixed */ public function getFromCsvImport($importValue, $object = null, $params = []) { $values = explode(",", $importValue); $value = []; foreach ($values as $element) { $tokens = explode(":", $element); $type = $tokens[0]; $path = $tokens[1]; $el = Element\Service::getElementByPath($type, $path); if ($el) { $metaObject = \Pimcore::getDiContainer()->make('Pimcore\\Model\\Object\\Data\\ElementMetadata', ["fieldname" => $this->getName(), "columns" => $this->getColumnKeys(), "element" => $el]); $value[] = $metaObject; } } return $value; }
/** * @param $importValue * @return array|mixed */ public function getFromCsvImport($importValue) { $values = explode(",", $importValue); $value = array(); foreach ($values as $element) { $tokens = explode(":", $element); $type = $tokens[0]; $path = $tokens[1]; $el = Element\Service::getElementByPath($type, $path); if ($el) { $className = Tool::getModelClassMapping('\\Pimcore\\Model\\Object\\Data\\ElementMetadata'); $metaObject = new $className($this->getName(), $this->getColumnKeys(), $el); $value[] = $metaObject; } } return $value; }