Exemplo n.º 1
0
 /**
  * @param string $slug
  * @param ContentEntity $parent
  * @return null|ContentEntity
  */
 public function getContentBySlug($slug, $parent = null, $contentTypes = array())
 {
     $qb = $this->cm()->getContentRepository()->createQueryBuilder('node');
     if (!empty($contentTypes)) {
         $condition = array();
         foreach ($contentTypes as $cInfo) {
             $condition[] = " (node.type = '" . $cInfo['type'] . "' AND node.schema = '" . $cInfo['schema'] . "' )";
         }
         if (!empty($condition)) {
             $qb->andWhere(' ( ' . implode(' OR ', $condition) . ' ) ');
         }
     }
     $qb->andWhere(" node.slug = '{$slug}' ");
     if (!empty($parent)) {
         $qb->andWhere(" node.treeParent = '" . $parent->getId() . "' ");
     }
     $qb->andWhere(" node.status ='" . ContentPublishType::Published . "' ");
     $qb->setMaxResults(1);
     try {
         return $qb->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
Exemplo n.º 2
0
 /**
  * @param ContentEntity $content
  * @return ContentEntity|void
  */
 public function save(ContentEntity $content = null)
 {
     if (null === $content) {
         return;
     }
     $currentUser = $this->getUser();
     $newRecord = false;
     if ($content->getId() == null) {
         $content->setCreatedDate(new \DateTime());
         if ($content->getAuthor() == null) {
             $content->setAuthor($currentUser);
         }
         $newRecord = true;
     } else {
         $content->setLastModifiedAuthor($currentUser);
         $content->setModifiedDate(new \DateTime());
     }
     if ($content->getPublishDate() == null && $content->getStatus() == ContentPublishType::Published) {
         $content->setPublishDate(new \DateTime());
     }
     if ($content->getExpireDate() == null && $content->getStatus() == ContentPublishType::Expired) {
         $content->setExpireDate(new \DateTime());
     }
     $this->em()->persist($content);
     $this->em()->flush();
     if ($newRecord) {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Add, $content->getId(), 'Added: ' . $content->getTitle());
     } else {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Edit, $content->getId(), 'Edit: ' . $content->getTitle());
     }
     return $content;
 }