Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * 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')));
 }
Exemplo n.º 3
0
 /**
  *
  */
 private function removeMenuItem()
 {
     $menuId = intval($this->request->gp('menu_id'));
     $menu = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId);
     $this->db->remove($menu);
     $this->db->flush();
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * @param $classAnnotation
  * @return $this
  */
 private function removeEntities($classAnnotation)
 {
     $classAnnotation = (object) $classAnnotation;
     if (count($classAnnotation->entity)) {
         foreach ($classAnnotation->entity as $className => $entries) {
             foreach ($entries as $entryData) {
                 if ($entry = $this->getEntity($className, $entryData)) {
                     $this->db->remove($entry);
                 }
             }
         }
     }
     if (count($classAnnotation->config)) {
         $className = '\\Fraym\\Registry\\Entity\\Config';
         foreach ($classAnnotation->config as $configName => $data) {
             if (!isset($data['deletable']) || $data['deletable'] === true) {
                 $entry = $this->db->getRepository($className)->findOneByName($configName);
                 if ($entry) {
                     $this->db->remove($entry);
                 }
             }
         }
     }
     $this->db->flush();
     return $this;
 }
Exemplo n.º 6
0
 /**
  * @return bool|mixed
  */
 public function getContent()
 {
     if ($this->user->isAdmin() === false) {
         return false;
     }
     $currentEntity = false;
     $errors = false;
     $data = array();
     $formFields = array();
     $entities = array();
     $modelClass = false;
     $model = false;
     $modelName = $this->request->gp('model', false);
     $groupedModels = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Group')->findAll();
     if ($modelName) {
         $model = $this->entityManager->getEntityByStringOrId($modelName);
         if ($model) {
             $modelClass = $model->className;
         }
     }
     if ($this->request->isXmlHttpRequest()) {
         return $this->createEntityFromSingleField($modelClass);
     }
     if ($modelClass && $this->request->isPost()) {
         $data = $this->request->getGPAsArray();
         $validation = $this->validation->setData($data)->getFormFieldValidation($modelClass);
         if ($id = $this->request->post('id')) {
             $currentEntity = $this->db->getRepository($modelClass)->findOneById($id);
             if (isset($data['cmd']) && $data['cmd'] == 'update' && $currentEntity && ($errors = $validation->check()) === true) {
                 $currentEntity->updateEntity($data);
             } elseif (isset($data['cmd']) && $data['cmd'] == 'remove' && $currentEntity) {
                 $this->db->remove($currentEntity);
                 $this->db->flush();
                 $data = array();
                 $currentEntity = false;
             } elseif (isset($data['cmd']) && $data['cmd'] == 'update') {
                 $currentEntity->updateEntity($data, false);
             }
         } else {
             if (isset($data['cmd']) && $data['cmd'] == 'new' && ($errors = $validation->check()) === true) {
                 $currentEntity = new $modelClass();
                 $currentEntity->updateEntity($data);
             }
         }
     }
     if ($modelClass && $model) {
         $entities = $this->db->getRepository($modelClass)->findAll();
         $formFields = $this->formField->setClassName($modelClass)->getFields();
     }
     $this->view->assign('locales', $this->locale->getLocales());
     $this->view->assign('data', $data);
     $this->view->assign('errors', $errors);
     $this->view->assign('currentEntity', $currentEntity);
     $this->view->assign('entities', $entities);
     $this->view->assign('groupedModels', $groupedModels);
     $this->view->assign('model', $model);
     $this->view->assign('formFields', $formFields);
     return $this->siteManagerController->getIframeContent($this->template->fetch('EntityView'));
 }
Exemplo n.º 7
0
 /**
  * @param $block
  * @return bool
  */
 public function undoBlock($block)
 {
     foreach ($block->changeSets as $change) {
         $this->db->remove($change);
     }
     if (get_class($block) === 'Fraym\\Block\\Entity\\ChangeSet') {
         $this->db->remove($block);
     }
     $this->db->flush();
     return true;
 }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
 /**
  * @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;
 }
Exemplo n.º 10
0
 /**
  * @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;
 }
Exemplo n.º 11
0
 /**
  * Paste copied block
  */
 protected 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))) {
         $menuItem = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuId);
         $blocks = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findBy(['menuItem' => $menuItem, 'contentId' => $contentId], ['position' => 'asc']);
         // Re-Order other blocks
         foreach ($blocks as $k => $b) {
             $b->position = $k + 1;
         }
         if ($op === 'copy') {
             $block = $block->changeSets->count() ? $block->changeSets->last() : $block;
             $copiedBlock = clone $block;
             $copiedBlock->id = null;
             $copiedBlock->position = 0;
             $copiedBlock->contentId = $contentId;
             $copiedBlock->menuItem = $menuItem;
             if ($byRef === true) {
                 $copiedBlock->config = null;
                 if ($block->byRef) {
                     $block = $block->byRef;
                     $copiedBlock->byRef = $block;
                 }
                 $copiedBlock->byRef = $block;
             }
             $changedBlock = $this->createChangeSet($copiedBlock, null, \Fraym\Block\Entity\ChangeSet::ADDED);
         } else {
             $changedBlock = $block->changeSets->count() ? $block->changeSets->last() : $block;
             $changedBlock->position = 0;
             $changedBlock->menuItem = $menuItem;
             $changedBlock->contentId = $contentId;
             $this->createChangeSet($changedBlock, $block, \Fraym\Block\Entity\ChangeSet::MOVED);
         }
         $this->db->flush();
         $this->response->sendAsJson(['success' => true, 'data' => $this->prepareBlockOutput($changedBlock)]);
     }
     $this->response->sendAsJson(['success' => false, 'message' => $this->translation->getTranslation('Paste error, please reload the page and copy again.')]);
 }
Exemplo n.º 12
0
 /**
  * @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;
 }
Exemplo n.º 13
0
 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;
 }