Ejemplo n.º 1
0
 public function computeRteAttribute()
 {
     $renderer = $this->getRenderer();
     $contentParent = $renderer->getClassContainer();
     if (null !== $contentParent) {
         if ($contentParent instanceof AbstractClassContent && !$contentParent instanceof ContentSet) {
             $elementName = $renderer->getCurrentElement();
             if (null !== $elementName) {
                 $contentData = $contentParent->{$elementName};
                 /* if it's the same content */
                 if (null !== $contentData && $contentData->getUid() === $this->content->getUid()) {
                     if ($this->content->isElementContent()) {
                         $defaultOptions = $contentParent->getDefaultOptions();
                         if (isset($defaultOptions[$elementName]['parameters']['rte'])) {
                             $this->attributes['data-rteconfig'] = $defaultOptions[$elementName]['parameters']['rte'];
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Adds a subcontent to the colection.
  *
  * @param  \BackBee\ClassContent\AbstractClassContent $value
  * @return string  the unique identifier of the add subcontent
  * @codeCoverageIgnore
  */
 protected function _addSubcontent(AbstractClassContent $value)
 {
     return $value->getUid();
 }
Ejemplo n.º 3
0
 /**
  * Returns the index of the content of $element
  *
  * @param AbstractClassContent $element
  * @param boolean              $useIntIndex
  *
  * @return integer|boolean
  */
 public function indexOfByUid($element, $useIntIndex = false)
 {
     if ($element instanceof AbstractClassContent) {
         /* find content */
         $index = 0;
         foreach ($this->getData() as $key => $content) {
             if ($content instanceof AbstractClassContent && $element->getUid() === $content->getUid()) {
                 $index = $useIntIndex ? (int) $key : $index;
                 return $index;
             }
             $index++;
         }
         return false;
     }
     return array_search($element, $this->_data, true);
 }
 /**
  * Removes stored site-content indexes for a content in a site.
  *
  * @param  Site                 $site
  * @param  AbstractClassContent $content
  *
  * @return IndexationRepository
  */
 public function removeIdxSiteContent(Site $site, AbstractClassContent $content)
 {
     $query = 'DELETE FROM idx_site_content WHERE site_uid = :site AND (content_uid IN ' . '(SELECT content_uid FROM content_has_subcontent WHERE parent_uid = :content)' . 'OR content_uid = :content)';
     $params = array('site' => $site->getUid(), 'content' => $content->getUid());
     return $this->_executeQuery($query, $params);
 }
Ejemplo n.º 5
0
 /**
  * Performs custom process on hard delete of content.
  *
  * @param  AbstractClassContent $content
  * @return self
  */
 protected function cleanUpContentHardDelete(AbstractClassContent $content)
 {
     $this->_em->getConnection()->executeQuery('DELETE FROM indexation WHERE owner_uid = :uid', ['uid' => $content->getUid()])->execute();
     $this->_em->getConnection()->executeQuery('DELETE FROM revision WHERE content_uid = :uid', ['uid' => $content->getUid()])->execute();
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Deletes outdated keyword content joins.
  *
  * @param AbstractClassContent $content
  * @param mixed                $keywords
  */
 public function cleanKeywordLinks(AbstractClassContent $content, $keywords)
 {
     if (!is_array($keywords)) {
         $keywords = [$keywords];
     }
     $keywordUids = [];
     foreach ($keywords as $keyword) {
         if ($keyword instanceof Keyword && !empty($keyword->value) && null !== ($realKeyword = $this->_em->find('BackBee\\NestedNode\\KeyWord', $keyword->value))) {
             $keywordUids[] = $realKeyword->getUid();
         }
     }
     $query = $this->_em->getConnection()->createQueryBuilder()->select('c.keyword_uid')->from('keywords_contents', 'c');
     $query->where($query->expr()->eq('c.content_uid', $query->expr()->literal($content->getUid())));
     $savedKeywords = $query->execute()->fetchAll(\PDO::FETCH_COLUMN);
     $linksToBeRemoved = array_diff($savedKeywords, $keywordUids);
     if (count($linksToBeRemoved)) {
         $query = $this->_em->getConnection()->createQueryBuilder()->delete('keywords_contents');
         array_walk($linksToBeRemoved, function (&$value, $key, $query) {
             $value = $query->expr()->literal($value);
         }, $query);
         $query->where($query->expr()->eq('content_uid', $query->expr()->literal($content->getUid())))->andWhere($query->expr()->in('keyword_uid', $linksToBeRemoved))->execute();
     }
 }
 /**
  * Unsets a subcontent to the current collection.
  *
  * @param \BackBee\ClassContent\AbstractClassContent $subContent
  *
  * @return \BackBee\ClassContent\AbstractClassContent
  */
 public function unsetSubContent(AbstractClassContent $subContent)
 {
     foreach ($this->_data as $key => $value) {
         if (is_array($value)) {
             $totalContent = count($value);
             foreach ($value as $cKey => $cValue) {
                 $contentUid = $cValue;
                 if (is_array($cValue)) {
                     $contentUid = array_values($cValue);
                     $contentUid = end($contentUid);
                 }
                 if ($subContent->getUid() == $contentUid) {
                     if (1 === $totalContent) {
                         $this->_data[$key] = [];
                         $this->_subcontent->removeElement($subContent);
                     } else {
                         unset($value[$cKey]);
                         $this->_data[$key] = $value;
                     }
                 }
             }
         }
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Find pages by Class content
  *
  * @param  \BackBee\ClassContent\AbstractClassContent $content
  *
  * @return Collection<Page>
  */
 public function findPagesByContent($content)
 {
     $contentUids = array_merge($this->getContentsParentUids($content->getUid()), [$content->getUid()]);
     $contentUids = implode(', ', array_unique(array_map(function ($uid) {
         return '"' . $uid . '"';
     }, $contentUids)));
     $pageUids = $this->_em->getConnection()->executeQuery(sprintf('SELECT uid FROM page WHERE contentset IN (%s)', $contentUids))->fetchAll(\PDO::FETCH_COLUMN);
     return $this->_em->createQueryBuilder('p')->select('p')->from('BackBee\\NestedNode\\Page', 'p')->where('p._uid IN (:uids)')->setParameter('uids', $pageUids)->getQuery()->getResult();
 }
Ejemplo n.º 9
0
 /**
  * Performs custom process on hard delete of content.
  *
  * @param  AbstractClassContent $content
  * @return self
  */
 protected function cleanUpContentHardDelete(AbstractClassContent $content)
 {
     $this->_em->getConnection()->executeUpdate('DELETE FROM indexation WHERE owner_uid = :uid', ['uid' => $content->getUid()]);
     $revisions = $this->_em->getRepository('BackBee\\ClassContent\\Revision')->findBy(['_content' => $content]);
     foreach ($revisions as $revision) {
         $this->_em->remove($revision);
     }
     return $this;
 }
Ejemplo n.º 10
0
 public function tryResolveParentObject(AbstractClassContent $parent, AbstractClassContent $element)
 {
     foreach ($parent->getData() as $key => $values) {
         if (!is_array($values)) {
             $values = array($values);
         }
         foreach ($values as $value) {
             if ($value instanceof AbstractClassContent) {
                 if (!$value->isLoaded()) {
                     // try to load subcontent
                     if (null !== ($subcontent = $this->getApplication()->getEntityManager()->getRepository(\Symfony\Component\Security\Core\Util\ClassUtils::getRealClass($value))->load($value, $this->getRenderer()->getApplication()->getBBUserToken()))) {
                         $value = $subcontent;
                     }
                 }
                 if ($element->equals($value)) {
                     $this->__currentelement = $key;
                     $this->__object = $parent;
                     $this->_parentuid = $parent->getUid();
                 } else {
                     $this->tryResolveParentObject($value, $element);
                 }
             }
             if (null !== $this->__currentelement) {
                 break;
             }
         }
         if (null !== $this->__currentelement) {
             break;
         }
     }
 }