Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function getRepositoryName(array $criteria = null)
 {
     if (isset($criteria['node.nodeType']) && $criteria['node.nodeType'] instanceof NodeType) {
         $rep = NodeType::getGeneratedEntitiesNamespace() . "\\" . $criteria['node.nodeType']->getSourceEntityClassName();
         unset($criteria['node.nodeType']);
     } else {
         $rep = "RZ\\Roadiz\\Core\\Entities\\NodesSources";
     }
     $this->repository = $rep;
     return $rep;
 }
Exemplo n.º 2
0
 protected function handleNodeForm($form, NodeType $nodetype)
 {
     if ($form->isValid()) {
         $data = [];
         foreach ($form->getData() as $key => $value) {
             if (!is_array($value) && $this->notBlank($value) || is_array($value) && isset($value["compareDatetime"]) || is_array($value) && isset($value["compareDate"]) || is_array($value) && $value != [] && !isset($value["compareOp"])) {
                 if (strstr($key, "__node__") == 0) {
                     $data[str_replace("__node__", "node.", $key)] = $value;
                 } else {
                     $data[$key] = $value;
                 }
             }
         }
         $data = $this->processCriteria($data, "node.");
         $data = $this->processCriteriaNodetype($data, $nodetype);
         $listManager = $this->createEntityListManager(NodeType::getGeneratedEntitiesNamespace() . '\\' . $nodetype->getSourceEntityClassName(), $data);
         if ($this->pagination === false) {
             $listManager->setItemPerPage($this->itemPerPage);
             $listManager->disablePagination();
         }
         $listManager->handle();
         $entities = $listManager->getEntities();
         $nodes = [];
         foreach ($entities as $nodesSource) {
             if (!in_array($nodesSource->getNode(), $nodes)) {
                 $nodes[] = $nodesSource->getNode();
             }
         }
         if ($form->get('exportNodesSources')->isClicked()) {
             $response = new Response($this->getXlsxResults($nodetype, $entities), Response::HTTP_OK, []);
             $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'search.xlsx'));
             return $response;
         }
         $this->assignation['filters'] = $listManager->getAssignation();
         $this->assignation['nodesSources'] = $entities;
         $this->assignation['nodes'] = $nodes;
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * Get NodesSources class metadata.
  *
  * @return Doctrine\ORM\Mapping\ClassMetadata
  */
 public static function getNodesSourcesMetadata()
 {
     $metadata = new ClassMetadata('RZ\\Roadiz\\Core\\Entities\\NodesSources');
     try {
         /**
          *  List node types
          */
         $nodeTypes = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\NodeType')->findAll();
         $map = [];
         foreach ($nodeTypes as $type) {
             $map[strtolower($type->getName())] = NodeType::getGeneratedEntitiesNamespace() . '\\' . $type->getSourceEntityClassName();
         }
         $metadata->setDiscriminatorMap($map);
         return $metadata;
     } catch (\PDOException $e) {
         /*
          * Database tables don't exist yet
          * Need Install
          */
         return null;
     }
 }
Exemplo n.º 4
0
 protected function makeNodeRec($data)
 {
     $nodetype = $this->em->getRepository('RZ\\Roadiz\\Core\\Entities\\NodeType')->findOneByName($data["node_type"]);
     $node = new Node($nodetype);
     $node->setNodeName($data['node_name']);
     $node->setHome($data['home']);
     $node->setVisible($data['visible']);
     $node->setStatus($data['status']);
     $node->setLocked($data['locked']);
     $node->setPriority($data['priority']);
     $node->setHidingChildren($data['hiding_children']);
     $node->setArchived($data['archived']);
     $node->setSterile($data['sterile']);
     $node->setChildrenOrder($data['children_order']);
     $node->setChildrenOrderDirection($data['children_order_direction']);
     foreach ($data["nodes_sources"] as $source) {
         $trans = new Translation();
         $trans->setLocale($source['translation']);
         $trans->setName(Translation::$availableLocales[$source['translation']]);
         $namespace = NodeType::getGeneratedEntitiesNamespace();
         $classname = $nodetype->getSourceEntityClassName();
         $class = $namespace . "\\" . $classname;
         $nodeSource = new $class($node, $trans);
         $nodeSource->setTitle($source["title"]);
         $nodeSource->setMetaTitle($source["meta_title"]);
         $nodeSource->setMetaKeywords($source["meta_keywords"]);
         $nodeSource->setMetaDescription($source["meta_description"]);
         $fields = $nodetype->getFields();
         foreach ($fields as $field) {
             if (!$field->isVirtual() && isset($source[$field->getName()])) {
                 if ($field->getType() == NodeTypeField::DATETIME_T || $field->getType() == NodeTypeField::DATE_T) {
                     $date = new \DateTime($source[$field->getName()]['date'], new \DateTimeZone($source[$field->getName()]['timezone']));
                     $setter = $field->getSetterName();
                     $nodeSource->{$setter}($date);
                 } else {
                     $setter = $field->getSetterName();
                     $nodeSource->{$setter}($source[$field->getName()]);
                 }
             }
         }
         if (!empty($source['url_aliases'])) {
             foreach ($source['url_aliases'] as $url) {
                 $alias = new UrlAlias($nodeSource);
                 $alias->setAlias($url['alias']);
                 $nodeSource->addUrlAlias($alias);
             }
         }
         $node->getNodeSources()->add($nodeSource);
     }
     if (!empty($data['tags'])) {
         foreach ($data["tags"] as $tag) {
             $tmp = $this->em->getRepository('RZ\\Roadiz\\Core\\Entities\\Tag')->findOneBy(["tagName" => $tag]);
             $node->getTags()->add($tmp);
         }
     }
     if (!empty($data['children'])) {
         foreach ($data['children'] as $child) {
             $tmp = $this->makeNodeRec($child);
             $node->addChild($tmp);
         }
     }
     return $node;
 }
Exemplo n.º 5
0
    /**
     * Generate Doctrine entity class for current nodetype.
     *
     * @return string or false
     */
    public function generateSourceEntityClass()
    {
        $folder = ROADIZ_ROOT . '/gen-src/' . NodeType::getGeneratedEntitiesNamespace();
        $file = $folder . '/' . $this->nodeType->getSourceEntityClassName() . '.php';
        if (!file_exists($folder)) {
            mkdir($folder, 0755, true);
        }
        if (!file_exists($file)) {
            $fields = $this->nodeType->getFields();
            $fieldsArray = [];
            $indexes = [];
            foreach ($fields as $field) {
                $fieldsArray[] = $field->getHandler()->generateSourceField();
                if ($field->isIndexed()) {
                    $indexes[] = $field->getHandler()->generateSourceFieldIndex();
                }
            }
            $content = '<?php
/*
 * THIS IS A GENERATED FILE, DO NOT EDIT IT
 * IT WILL BE RECREATED AT EACH NODE-TYPE UPDATE
 */
namespace ' . NodeType::getGeneratedEntitiesNamespace() . ';

use RZ\\Roadiz\\Core\\Entities\\NodesSources;
use Doctrine\\ORM\\Mapping as ORM;

/**
 * Generated custom node-source type from RZ-CMS backoffice.
 *
 * @ORM\\Entity(repositoryClass="RZ\\Roadiz\\Core\\Repositories\\NodesSourcesRepository")
 * @ORM\\Table(name="' . $this->nodeType->getSourceEntityTableName() . '", indexes={' . implode(',', $indexes) . '})
 */
class ' . $this->nodeType->getSourceEntityClassName() . ' extends NodesSources
{
    ' . implode('', $fieldsArray) . '

    public function __toString()
    {
        return \'' . $this->nodeType->getSourceEntityClassName() . ' #\' . $this->getId() .
        \' <\' . $this->getTitle() . \'>[\' . $this->getTranslation()->getLocale() .
        \']\';
    }
}
';
            if (false === @file_put_contents($file, $content)) {
                throw new IOException("Impossible to write entity class file (" . $file . ").", 1);
            }
            /*
             * Force Zend OPcache to reset file
             */
            if (function_exists('opcache_invalidate')) {
                opcache_invalidate($file, true);
            }
            return "Source class “" . $this->nodeType->getSourceEntityClassName() . "” has been created." . PHP_EOL;
        } else {
            return "Source class “" . $this->nodeType->getSourceEntityClassName() . "” already exists." . PHP_EOL;
        }
        return false;
    }
 /**
  * {@inheritDoc}
  *
  * @param string                          $string
  * @param RZ\Roadiz\Core\Entities\NodeType $type
  *
  * @return RZ\Roadiz\Core\Entities\NodeSource
  */
 public function deserializeWithNodeType($string, NodeType $type)
 {
     $fields = $type->getFields();
     /*
      * Create source default values
      */
     $sourceDefaults = ["title", "meta_title", "meta_keywords", "meta_description"];
     foreach ($fields as $field) {
         if (!$field->isVirtual()) {
             $sourceDefaults[] = $field->getName();
         }
     }
     $encoder = new JsonEncoder();
     $nameConverter = new CamelCaseToSnakeCaseNameConverter($sourceDefaults);
     $normalizer = new GetSetMethodNormalizer(null, $nameConverter);
     $serializer = new Serializer([$normalizer], [$encoder]);
     $node = $serializer->deserialize($string, NodeType::getGeneratedEntitiesNamespace() . '\\' . $type->getSourceEntityClassName(), 'json');
     return $node;
 }