예제 #1
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);
 }
 /**
  * Performs custom process on hard delete of content.
  *
  * @param  AbstractClassContent $content
  * @return self
  */
 protected function cleanUpContentHardDelete(AbstractClassContent $content)
 {
     $this->_em->getConnection()->executeQuery('DELETE FROM bb_indexation WHERE owner_uid = :uid', ['uid' => $content->getUid()])->execute();
     $this->_em->getConnection()->executeQuery('DELETE FROM bb_revision WHERE content_uid = :uid', ['uid' => $content->getUid()])->execute();
     return $this;
 }
 /**
  * Unsets a subcontent to the current collection.
  *
  * @param \BackBee\CoreDomain\ClassContent\AbstractClassContent $subContent
  *
  * @return \BackBee\CoreDomain\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;
 }
 /**
  * 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);
 }
예제 #5
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\\CoreDomain\\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();
     }
 }
예제 #6
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;
         }
     }
 }
예제 #7
0
 /**
  * Adds a subcontent to the colection.
  *
  * @param  \BackBee\CoreDomain\ClassContent\AbstractClassContent $value
  * @return string  the unique identifier of the add subcontent
  * @codeCoverageIgnore
  */
 protected function _addSubcontent(AbstractClassContent $value)
 {
     return $value->getUid();
 }