作者:yonetic
项目:pimcore-coreshop-dem
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")));
}
Element\Editlock::lock($this->getParam("id"), "document");
$page = Document\Page::getById($this->getParam("id"));
$page = $this->getLatestVersion($page);
$page->setVersions(array_splice($page->getVersions(), 0, 1));
$page->getScheduledTasks();
$page->idPath = Element\Service::getIdPath($page);
$page->userPermissions = $page->getUserPermissions();
$page->setLocked($page->isLocked());
$page->setParent(null);
if ($page->getContentMasterDocument()) {
$page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath();
}
// get depending redirects
$redirectList = new Redirect\Listing();
$redirectList->setCondition("target = ?", $page->getId());
$page->redirects = $redirectList->load();
// unset useless data
$page->setElements(null);
$page->childs = null;
// cleanup properties
$this->minimizeProperties($page);
if ($page->isAllowed("view")) {
$this->_helper->json($page);
}
$this->_helper->json(false);
}
作者:emanuel-londo
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")));
}
Element\Editlock::lock($this->getParam("id"), "document");
$snippet = Document\Snippet::getById($this->getParam("id"));
$modificationDate = $snippet->getModificationDate();
$snippet = $this->getLatestVersion($snippet);
$snippet->setVersions(array_splice($snippet->getVersions(), 0, 1));
$snippet->getScheduledTasks();
$snippet->idPath = Element\Service::getIdPath($snippet);
$snippet->userPermissions = $snippet->getUserPermissions();
$snippet->setLocked($snippet->isLocked());
$snippet->setParent(null);
if ($snippet->getContentMasterDocument()) {
$snippet->contentMasterDocumentPath = $snippet->getContentMasterDocument()->getRealFullPath();
}
$this->minimizeProperties($snippet);
// unset useless data
$snippet->setElements(null);
if ($snippet->isAllowed("view")) {
$this->_helper->json($snippet);
}
$this->_helper->json(false);
}
作者:solvera
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]);
}
Element\Editlock::lock($this->getParam("id"), "document");
$link = Document\Hardlink::getById($this->getParam("id"));
$link = clone $link;
$link->idPath = Element\Service::getIdPath($link);
$link->userPermissions = $link->getUserPermissions();
$link->setLocked($link->isLocked());
$link->setParent(null);
if ($link->getSourceDocument()) {
$link->sourcePath = $link->getSourceDocument()->getRealFullPath();
}
$this->addTranslationsData($link);
$this->minimizeProperties($link);
//Hook for modifying return value - e.g. for changing permissions based on object data
//data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values
$returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($link));
\Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $link, "returnValueContainer" => $returnValueContainer]);
if ($link->isAllowed("view")) {
$this->_helper->json($returnValueContainer->getData());
}
$this->_helper->json(false);
}
作者:solvera
项目:pimcor
public function extractRelations($element, $apiElementKeys, $recursive, $includeRelations)
{
$foundRelations = [];
if ($includeRelations) {
$dependency = $element->getDependencies();
if ($dependency) {
foreach ($dependency->getRequires() as $r) {
if ($e = Element\Service::getDependedElement($r)) {
if ($element->getId() != $e->getId() and !in_array(Element\Service::getElementType($e) . "_" . $e->getId(), $apiElementKeys)) {
$foundRelations[Element\Service::getElementType($e) . "_" . $e->getId()] = ["elementType" => Element\Service::getType($e), "element" => $e->getId(), "recursive" => false];
}
}
}
}
}
$childs = $element->getChilds();
if ($recursive and $childs) {
foreach ($childs as $child) {
if (!in_array(Element\Service::getType($child) . "_" . $child->getId(), $apiElementKeys)) {
$foundRelations[Element\Service::getType($child) . "_" . $child->getId()] = ["elementType" => Element\Service::getType($child), "element" => $child->getId(), "recursive" => $recursive];
}
}
}
return $foundRelations;
}
作者:pimcor
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]);
}
Element\Editlock::lock($this->getParam("id"), "document");
$email = Document\Newsletter::getById($this->getParam("id"));
$email = clone $email;
$email = $this->getLatestVersion($email);
$versions = Element\Service::getSafeVersionInfo($email->getVersions());
$email->setVersions(array_splice($versions, 0, 1));
$email->idPath = Element\Service::getIdPath($email);
$email->userPermissions = $email->getUserPermissions();
$email->setLocked($email->isLocked());
$email->setParent(null);
// unset useless data
$email->setElements(null);
$email->childs = null;
$this->addTranslationsData($email);
$this->minimizeProperties($email);
//Hook for modifying return value - e.g. for changing permissions based on object data
//data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values
$returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($email));
\Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $email, "returnValueContainer" => $returnValueContainer]);
if ($email->isAllowed("view")) {
$this->_helper->json($returnValueContainer->getData());
}
$this->_helper->json(false);
}
作者:pimcor
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]);
}
\Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document");
$page = Document\Printpage::getById($this->getParam("id"));
$page = $this->getLatestVersion($page);
$page->getVersions();
$page->getScheduledTasks();
$page->idPath = Service::getIdPath($page);
$page->userPermissions = $page->getUserPermissions();
$page->setLocked($page->isLocked());
if ($page->getContentMasterDocument()) {
$page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath();
}
$this->addTranslationsData($page);
// unset useless data
$page->setElements(null);
$page->childs = null;
// cleanup properties
$this->minimizeProperties($page);
//Hook for modifying return value - e.g. for changing permissions based on object data
//data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values
$returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($page));
\Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $page, "returnValueContainer" => $returnValueContainer]);
if ($page->isAllowed("view")) {
$this->_helper->json($returnValueContainer->getData());
}
$this->_helper->json(false);
}
作者:Gerhard1
项目:pimcor
/**
* @param $webResource
*/
public function __construct($webResource)
{
$this->id = $webResource->getId();
if ($webResource instanceof Element\ElementInterface) {
$this->type = Element\Service::getType($webResource);
} else {
$this->type = "unknown";
}
}
作者:solvera
项目:pimcor
/**
* gets workflow config for element. always returns first valid workflow config
*
* @param Asset|Document|ConcreteObject $element
* @return array
*/
public static function getElementWorkflowConfig(AbstractElement $element)
{
$config = self::getWorkflowManagementConfig();
if (!is_array($config)) {
return null;
}
$elementType = Service::getElementType($element);
$elementSubType = $element->getType();
foreach ($config['workflows'] as $workflow) {
//workflow is not enabled, continue with next
if (isset($workflow['enabled']) && !$workflow['enabled']) {
continue;
}
if (isset($workflow['workflowSubject']) && in_array($elementType, $workflow['workflowSubject']['types'])) {
switch ($elementType) {
case 'asset':
if (isset($workflow['workflowSubject']['assetTypes']) && is_array($workflow['workflowSubject']['assetTypes'])) {
if (in_array($elementSubType, $workflow['workflowSubject']['assetTypes'])) {
return $workflow;
}
} else {
\Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available asset types');
}
break;
case 'document':
if (isset($workflow['workflowSubject']['documentTypes']) && is_array($workflow['workflowSubject']['documentTypes'])) {
if (in_array($elementSubType, $workflow['workflowSubject']['documentTypes'])) {
return $workflow;
}
} else {
\Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available document types');
}
break;
case 'object':
if ($element instanceof ConcreteObject) {
if (isset($workflow['workflowSubject']['classes']) && is_array($workflow['workflowSubject']['classes'])) {
$classId = $element->getClassId();
if (in_array($classId, $workflow['workflowSubject']['classes'])) {
return $workflow;
}
} else {
\Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available class ID\'s');
}
}
break;
default:
//unknown element type, return null
return null;
}
}
}
return null;
}
作者:pimcor
项目:pimcor
/**
* @param string $name
* @return $this|void
* @throws DAV\Exception\Forbidden
* @throws \Exception
*/
public function setName($name)
{
if ($this->asset->isAllowed("rename")) {
$user = AdminTool::getCurrentUser();
$this->asset->setUserModification($user->getId());
$this->asset->setFilename(Element\Service::getValidKey($name), "asset");
$this->asset->save();
} else {
throw new DAV\Exception\Forbidden();
}
return $this;
}
作者:rolandstol
项目:pimcor
/**
* @param $cid
* @param $ctype
* @throws \Exception
*/
public function getByElement($cid, $ctype)
{
$data = $this->db->fetchRow("SELECT * FROM edit_lock WHERE cid = ? AND ctype = ?", array($cid, $ctype));
if (!$data["id"]) {
throw new \Exception("Lock with cid " . $cid . " and ctype " . $ctype . " not found");
}
$this->assignVariablesToModel($data);
// add elements path
$element = Model\Element\Service::getElementById($ctype, $cid);
if ($element) {
$this->model->setCpath($element->getFullpath());
}
}
作者:ascertai
项目:NGsho
public static function interpret($value, $config = null)
{
$result = array();
if (is_array($value)) {
foreach ($value as $v) {
$result[] = array("dest" => $v->getId(), "type" => \Pimcore\Model\Element\Service::getElementType($v));
}
} else {
if ($value instanceof \Pimcore\Model\Element\AbstractElement) {
$result[] = array("dest" => $value->getId(), "type" => \Pimcore\Model\Element\Service::getElementType($value));
}
}
return $result;
}
作者:pawansgi9
项目:pimcore
/**
* @static
* @return mixed|\Zend_Config
*/
public static function getWebsiteConfig()
{
if (\Zend_Registry::isRegistered("pimcore_config_website")) {
$config = \Zend_Registry::get("pimcore_config_website");
} else {
$cacheKey = "website_config";
$siteId = null;
if (Model\Site::isSiteRequest()) {
$siteId = Model\Site::getCurrentSite()->getId();
$cacheKey = $cacheKey . "_site_" . $siteId;
}
if (!($config = Cache::load($cacheKey))) {
$settingsArray = array();
$cacheTags = array("website_config", "system", "config", "output");
$list = new Model\WebsiteSetting\Listing();
$list = $list->load();
foreach ($list as $item) {
$key = $item->getName();
$itemSiteId = $item->getSiteId();
if ($itemSiteId != 0 && $itemSiteId != $siteId) {
continue;
}
$s = null;
switch ($item->getType()) {
case "document":
case "asset":
case "object":
$s = Model\Element\Service::getElementById($item->getType(), $item->getData());
break;
case "bool":
$s = (bool) $item->getData();
break;
case "text":
$s = (string) $item->getData();
break;
}
if ($s instanceof Model\Element\ElementInterface) {
$cacheTags = $s->getCacheTags($cacheTags);
}
if (isset($s)) {
$settingsArray[$key] = $s;
}
}
$config = new \Zend_Config($settingsArray, true);
Cache::save($config, $cacheKey, $cacheTags, null, 998);
}
self::setWebsiteConfig($config);
}
return $config;
}
作者:ChristophWurs
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")));
}
Element\Editlock::lock($this->getParam("id"), "document");
$folder = Document\Folder::getById($this->getParam("id"));
$folder->idPath = Element\Service::getIdPath($folder);
$folder->userPermissions = $folder->getUserPermissions();
$folder->setLocked($folder->isLocked());
$folder->setParent(null);
$this->minimizeProperties($folder);
if ($folder->isAllowed("view")) {
$this->_helper->json($folder);
}
$this->_helper->json(false);
}
作者:pimcor
项目:pimcor
/**
* Moves a file/directory
*
* @param string $sourcePath
* @param string $destinationPath
* @return void
*/
public function move($sourcePath, $destinationPath)
{
$nameParts = explode("/", $sourcePath);
$nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
$sourcePath = implode("/", $nameParts);
$nameParts = explode("/", $destinationPath);
$nameParts[count($nameParts) - 1] = Element\Service::getValidKey($nameParts[count($nameParts) - 1], "asset");
$destinationPath = implode("/", $nameParts);
try {
if (dirname($sourcePath) == dirname($destinationPath)) {
$asset = null;
if ($asset = Asset::getByPath("/" . $destinationPath)) {
// If we got here, this means the destination exists, and needs to be overwritten
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
// see: Asset\WebDAV\File::delete() why this is necessary
$log = Asset\WebDAV\Service::getDeleteLog();
if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
$asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
if ($asset) {
$sourceAsset = Asset::getByPath("/" . $sourcePath);
$asset->setData($sourceAsset->getData());
$sourceAsset->delete();
}
}
if (!$asset) {
$asset = Asset::getByPath("/" . $sourcePath);
}
$asset->setFilename(basename($destinationPath));
} else {
$asset = Asset::getByPath("/" . $sourcePath);
$parent = Asset::getByPath("/" . dirname($destinationPath));
$asset->setPath($parent->getRealFullPath() . "/");
$asset->setParentId($parent->getId());
}
$user = \Pimcore\Tool\Admin::getCurrentUser();
$asset->setUserModification($user->getId());
$asset->save();
} catch (\Exception $e) {
Logger::error($e);
}
}
作者:solvera
项目:pimcor
public function treeGetChildsByIdAction()
{
$document = Document::getById($this->getParam("node"));
$documents = [];
$cv = false;
if ($document->hasChilds()) {
$limit = intval($this->getParam("limit"));
if (!$this->getParam("limit")) {
$limit = 100000000;
}
$offset = intval($this->getParam("start"));
if ($this->getParam("view")) {
$cv = \Pimcore\Model\Element\Service::getCustomViewById($this->getParam("view"));
}
$list = new Document\Listing();
if ($this->getUser()->isAdmin()) {
$list->setCondition("parentId = ? ", $document->getId());
} else {
$userIds = $this->getUser()->getRoles();
$userIds[] = $this->getUser()->getId();
$list->setCondition("parentId = ? and\n (\n (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(CONCAT(path,`key`),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n or\n (select list from users_workspaces_document where userId in (" . implode(',', $userIds) . ") and LOCATE(cpath,CONCAT(path,`key`))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n )", $document->getId());
}
$list->setOrderKey(["index", "id"]);
$list->setOrder(["asc", "asc"]);
$list->setLimit($limit);
$list->setOffset($offset);
\Pimcore\Model\Element\Service::addTreeFilterJoins($cv, $list);
$childsList = $list->load();
foreach ($childsList as $childDocument) {
// only display document if listing is allowed for the current user
if ($childDocument->isAllowed("list")) {
$documents[] = $this->getTreeNodeConfig($childDocument);
}
}
}
if ($this->getParam("limit")) {
$this->_helper->json(["offset" => $offset, "limit" => $limit, "total" => $document->getChildAmount($this->getUser()), "nodes" => $documents]);
} else {
$this->_helper->json($documents);
}
$this->_helper->json(false);
}
作者:Gerhard1
项目:pimcor
/**
* Clear all relations in the database
* @param Element\ElementInterface $element
*/
public function cleanAllForElement($element)
{
try {
$id = $element->getId();
$type = Element\Service::getElementType($element);
//schedule for sanity check
$data = $this->db->fetchAll("SELECT * FROM dependencies WHERE targetid = ? AND targettype = ?", array($id, $type));
if (is_array($data)) {
foreach ($data as $row) {
$sanityCheck = new Element\Sanitycheck();
$sanityCheck->setId($row['sourceid']);
$sanityCheck->setType($row['sourcetype']);
$sanityCheck->save();
}
}
$this->db->delete("dependencies", $this->db->quoteInto("sourceid = ?", $id) . " AND " . $this->db->quoteInto("sourcetype = ?", $type));
$this->db->delete("dependencies", $this->db->quoteInto("targetid = ?", $id) . " AND " . $this->db->quoteInto("targettype = ?", $type));
} catch (\Exception $e) {
\Logger::error($e);
}
}
作者:ascertai
项目:NGsho
public function getRelationAttribute($attributeName)
{
$relationObjectArray = array();
if ($this->relations[$attributeName]) {
foreach ($this->relations[$attributeName] as $relation) {
$relationObject = \Pimcore\Model\Element\Service::getElementById($relation['type'], $relation['id']);
if ($relationObject) {
$relationObjectArray[] = $relationObject;
}
}
}
if (count($relationObjectArray) == 1) {
return $relationObjectArray[0];
} else {
if (count($relationObjectArray) > 1) {
return $relationObjectArray;
} else {
return null;
}
}
}
作者:emanuel-londo
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(array("editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")));
}
Element\Editlock::lock($this->getParam("id"), "document");
$email = Document\Email::getById($this->getParam("id"));
$email = $this->getLatestVersion($email);
$email->setVersions(array_splice($email->getVersions(), 0, 1));
$email->idPath = Element\Service::getIdPath($email);
$email->userPermissions = $email->getUserPermissions();
$email->setLocked($email->isLocked());
$email->setParent(null);
// unset useless data
$email->setElements(null);
$email->childs = null;
// cleanup properties
$this->minimizeProperties($email);
if ($email->isAllowed("view")) {
$this->_helper->json($email);
}
$this->_helper->json(false);
}
作者:dachcom-digita
项目:pimcore-toolbo
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;
}
作者:solvera
项目:pimcor
public function getDataByIdAction()
{
// check for lock
if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) {
$this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]);
}
\Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document");
$page = Document\Printpage::getById($this->getParam("id"));
$page = $this->getLatestVersion($page);
$page->getVersions();
$page->getScheduledTasks();
$page->idPath = Service::getIdPath($page);
$page->userPermissions = $page->getUserPermissions();
$page->setLocked($page->isLocked());
// unset useless data
$page->setElements(null);
$page->childs = null;
// cleanup properties
$this->minimizeProperties($page);
if ($page->isAllowed("view")) {
$this->_helper->json($page);
}
$this->_helper->json(false);
}