/** * @param $key * @param $val * @return $this */ public function set($key, $val) { $obj = null; if ($this->db->getEntityManager()) { $obj = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Config')->findOneByName(strtoupper($key)); if ($obj === null) { $obj = new \Fraym\Registry\Entity\Config(); $obj->name = strtoupper($key); $this->db->persist($obj); } $obj->value = $val; $this->db->flush(); } return $this; }
/** * Paste copied block */ private function pasteBlock() { $blockId = $this->request->gp('blockId'); $op = $this->request->gp('op', 'copy') == 'copy' ? 'copy' : 'cut'; $byRef = $this->request->gp('byRef', false) === 'true' ? true : false; $menuId = $this->request->gp('menuId', false); $contentId = $this->request->gp('contentId', false); if ($contentId && $blockId && ($block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId))) { if ($op === 'copy') { $copiedBlock = clone $block; $copiedBlock->id = null; $copiedBlock->contentId = $contentId; $copiedBlock->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); if ($byRef === true) { $copiedBlock->config = null; if ($block->byRef) { $block = $block->byRef; $copiedBlock->byRef = $block; } $copiedBlock->byRef = $block; } $this->db->persist($copiedBlock); $block = $copiedBlock; } else { $block->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); $block->contentId = $contentId; $this->db->persist($block); } $this->db->flush(); $this->response->sendAsJson(array('success' => true, 'data' => $this->prepareBlockOutput($block))); } $this->response->sendAsJson(array('success' => false, 'message' => $this->translation->getTranslation('Paste error, please copy again'))); }
/** * @return bool */ public function changeMenuItemPosition() { $parentId = intval($this->request->gp('parent_id')); $menuId = intval($this->request->gp('menu_id')); $position = intval($this->request->gp('position')); $menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId); if (!$menuItem) { return false; } $newPositions = 0; $menuItem->sorter = $position; $menuItem->parent = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($parentId); foreach ($menuItem->parent->children as $childMenuItem) { if ($menuId != $childMenuItem->id) { if ($newPositions == $position) { $newPositions++; } $childMenuItem->sorter = $newPositions; $newPositions++; $this->db->persist($childMenuItem); } } $this->db->flush(); return true; }
/** * @param $site * @return $this */ protected function addMenuItems($site) { $pageRoot = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById(1); /** * 404 Page */ $newPage = new \Fraym\Menu\Entity\MenuItem(); $newPage->site = $site; $newPage->caching = true; $newPage->https = false; $newPage->checkPermission = false; $newPage->is404 = true; $newPage->parent = $pageRoot; $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation(); $newPageTranslation->menuItem = $newPage; $newPageTranslation->visible = false; $newPageTranslation->active = true; $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale); $newPageTranslation->subtitle = ''; $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $this->locale->getLocale()->locale) . '-404'; $newPageTranslation->description = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale); $newPageTranslation->externalUrl = false; $this->db->persist($newPageTranslation); $this->db->flush(); $this->db->clear(); return $this; }
private function createBlock($contentId, $menuItemId, $extension, $config) { $block = new \Fraym\Block\Entity\Block(); $block->extension = $extension; $block->contentId = $contentId; $block->menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemId); $block->site = $this->site; $block->config = $config; $this->db->persist($block); $this->db->flush(); }
/** * @param $blockHistory * @param $block * @param $historyType * @return mixed */ public function setHistoryFrom($blockHistory, $block, $historyType) { if ($historyType != 'deleted') { $blockHistory->from = $block; } else { foreach ($block->histories as $historyBlock) { $historyBlock->from = null; $this->db->persist($historyBlock); } $this->db->flush(); } return $blockHistory; }
/** * @param Entity\Registry $registryEntry * @param $className * @param $classAnnotation * @return Entity\Registry */ private function updateRegistryEntry(Entity\Registry $registryEntry, $className, $classAnnotation) { $registryEntry->className = $className; $registryEntry->deletable = $classAnnotation->deletable; $registryEntry->name = $classAnnotation->name; $registryEntry->version = $classAnnotation->version; $registryEntry->author = $classAnnotation->author; $registryEntry->website = $classAnnotation->website; $registryEntry->repositoryKey = $classAnnotation->repositoryKey; $this->db->persist($registryEntry); $this->db->flush(); return $registryEntry; }
/** * @param Entity\Registry $registryEntry * @param $className * @param $classAnnotation * @return Entity\Registry */ protected function updateRegistryEntry(Entity\Registry $registryEntry, $className, $classAnnotation) { $registryEntry->className = $className; $registryEntry->deletable = $classAnnotation->deletable; $registryEntry->name = $classAnnotation->name; $registryEntry->repositoryKey = $classAnnotation->repositoryKey; $registryEntry->composerPackage = $classAnnotation->composerPackage; if ($classAnnotation->composerPackage === true && ($package = $this->getPackage($classAnnotation->repositoryKey))) { $package = $this->getLatestPackageVersion($package); $registryEntry->version = $package->getVersion(); } else { $registryEntry->version = '0.0.0'; } $this->db->persist($registryEntry); $this->db->flush(); return $registryEntry; }
/** * @param $block */ public function deploy($block) { if (count($block->changeSets)) { $lastChange = clone $block->changeSets->last(); } // New blocks if (get_class($block) === 'Fraym\\Block\\Entity\\ChangeSet') { if (count($block->changeSets) === 0) { $lastChange = clone $block; } if ($lastChange->type !== Entity\ChangeSet::DELETED) { $changeSetId = $block->id; $this->db->remove($block); $this->db->flush(); $block = new Entity\Block(); $block->id = $changeSetId; // Disable generator to keep current id $metadata = $this->db->getClassMetaData(get_class($block)); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE); } } foreach ($block->changeSets as $change) { $this->db->remove($change); } $this->db->flush(); if ($lastChange->type === Entity\ChangeSet::DELETED) { $this->db->remove($block); } else { $block->contentId = $lastChange->contentId; $block->name = $lastChange->name; $block->position = $lastChange->position; $block->menuItem = $lastChange->menuItem; $block->site = $lastChange->site; $block->user = $lastChange->user; $block->byRef = $lastChange->byRef; $block->menuItemTranslation = $lastChange->menuItemTranslation; $block->extension = $lastChange->extension; if (!$block->byRef) { $block->config = $lastChange->config; } $this->db->persist($block); } $this->db->flush(); $this->clearMenuCache($block); }
/** * @param $userId * @return $this */ public function setUserId($userId) { $this->user = $this->db->getRepository('\\Fraym\\User\\Entity\\User')->findOneById($userId); if (!$this->user) { $this->session->destroy(); return $this; } $this->userId = $userId; $this->session->set('userId', $this->userId); if ($this->user) { $this->isLoggedIn = true; $this->user->isOnline = true; $this->user->lastLogin = new \DateTime(); $this->db->persist($this->user); $this->db->flush(); } return $this; }
/** * @param $changedBlock * @param $parentBlock * @param $type * @return Entity\ChangeSet */ protected function createChangeSet($changedBlock, $parentBlock, $type) { $changeSet = new \Fraym\Block\Entity\ChangeSet(); $changeSet->contentId = $changedBlock->contentId; $changeSet->position = $changedBlock->position; $changeSet->menuItem = $changedBlock->menuItem; $changeSet->site = $changedBlock->site; $changeSet->menuItemTranslation = $changedBlock->menuItemTranslation; $changeSet->extension = $changedBlock->extension; $changeSet->user = $this->user->getUserEntity(); $changeSet->byRef = $changedBlock->byRef; $changeSet->block = $parentBlock; $changeSet->type = $type; if (!$changedBlock->byRef) { $changeSet->config = $changedBlock->config; } $this->db->persist($changeSet); $this->db->flush(); return $changeSet; }
/** * @param \Fraym\Block\Entity\Block $block * @param $config * @return \Fraym\Block\Entity\ChangeSet */ public function createChangeSet(\Fraym\Block\Entity\Block $block, $config) { if ($block->changeSets->count()) { $block = $block->changeSets->last(); } $changeSet = new \Fraym\Block\Entity\ChangeSet(); $changeSet->contentId = $block->contentId; $changeSet->name = $block->name; $changeSet->position = $block->position; $changeSet->byRef = $block->byRef; $changeSet->menuItem = $block->menuItem; $changeSet->site = $block->site; $changeSet->menuItemTranslation = $block->menuTranslation; $changeSet->extension = $block->extension; $changeSet->block = $block->block ?: $block; $changeSet->user = $block->user; $changeSet->config = $config; $changeSet->type = \Fraym\Block\Entity\ChangeSet::EDITED; $this->db->persist($changeSet); $this->db->flush(); return $changeSet; }
private function addMenuItems($site) { $gp = $this->request->getGPAsObject(); /** * Root Page */ $pageRoot = new \Fraym\Menu\Entity\MenuItem(); $pageRoot->site = $site; $pageRoot->caching = true; $pageRoot->visible = true; $pageRoot->active = true; $pageRoot->https = false; $pageRoot->checkPermission = false; $pageRoot->is404 = false; $pageRootTranslation = new \Fraym\Menu\Entity\MenuItemTranslation(); $pageRootTranslation->menuItem = $pageRoot; $pageRootTranslation->title = $this->translation->autoTranslation('Home', 'en', $gp->locale); $pageRootTranslation->subtitle = $this->translation->autoTranslation('Welcome to my website.', 'en', $gp->locale); $pageRootTranslation->url = ""; $pageRootTranslation->shortDescription = $this->translation->autoTranslation('My short website description', 'en', $gp->locale); $pageRootTranslation->longDescription = $this->translation->autoTranslation('My long website description', 'en', $gp->locale); $pageRootTranslation->externalUrl = false; $this->db->persist($pageRootTranslation); /** * 404 Page */ $newPage = new \Fraym\Menu\Entity\MenuItem(); $newPage->site = $site; $newPage->caching = true; $newPage->visible = false; $newPage->active = true; $newPage->https = false; $newPage->checkPermission = false; $newPage->is404 = true; $newPage->parent = $pageRoot; $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation(); $newPageTranslation->menuItem = $newPage; $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale); $newPageTranslation->subtitle = ''; $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $gp->locale) . '-404'; $newPageTranslation->shortDescription = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale); $newPageTranslation->longDescription = $this->translation->autoTranslation('404 Page not found', 'en', $gp->locale); $newPageTranslation->externalUrl = false; $this->db->persist($newPageTranslation); /** * Blog Page */ $newPage = new \Fraym\Menu\Entity\MenuItem(); $newPage->site = $site; $newPage->caching = true; $newPage->visible = true; $newPage->active = true; $newPage->https = false; $newPage->checkPermission = false; $newPage->is404 = false; $newPage->parent = $pageRoot; $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation(); $newPageTranslation->menuItem = $newPage; $newPageTranslation->title = $this->translation->autoTranslation('Blog', 'en', $gp->locale); $newPageTranslation->subtitle = $this->translation->autoTranslation('This is my blog.', 'en', $gp->locale); $newPageTranslation->url = "blog"; $newPageTranslation->shortDescription = $this->translation->autoTranslation('Check out my blog.', 'en', $gp->locale); $newPageTranslation->longDescription = $this->translation->autoTranslation('Check out my blog.', 'en', $gp->locale); $newPageTranslation->externalUrl = false; $this->db->persist($newPageTranslation); $this->db->flush(); $this->db->clear(); return $this; }