Пример #1
0
 /**
  * Calculate next position relative to our parent
  *
  * @param ContentQuery $query
  * @deprecated since 2.3, and will be removed in 2.4
  */
 protected function addCriteriaToPositionQuery($query)
 {
     $contents = ContentFolderQuery::create()->filterByFolderId($this->getDefaultFolderId())->filterByDefaultFolder(true)->select('content_id')->find();
     // Filtrer la requete sur ces produits
     if ($contents != null) {
         $query->filterById($contents, Criteria::IN);
     }
 }
Пример #2
0
 public function testQuery()
 {
     $data = $this->handler->buildData($this->lang)->getData();
     $max = count($data);
     if ($max > 50) {
         $max = 50;
     }
     for ($i = 0; $i < $max;) {
         $content = ContentQuery::create()->findPk($data[$i]["id"]);
         $this->assertNotNull($content);
         $content->setLocale($this->lang->getLocale());
         $this->assertEquals($content->getTitle(), $data[$i]["title"]);
         $this->assertEquals($content->getDescription(), $data[$i]["description"]);
         $this->assertEquals($content->getChapo(), $data[$i]["chapo"]);
         $this->assertEquals($content->getPostscriptum(), $data[$i]["conclusion"]);
         $this->assertEquals($content->getMetaTitle(), $data[$i]["seo_title"]);
         $this->assertEquals($content->getMetaDescription(), $data[$i]["seo_description"]);
         $this->assertEquals($content->getMetaKeywords(), $data[$i]["seo_keywords"]);
         do {
             if (null !== $data[$i]["folder_id"]) {
                 $folder = FolderQuery::create()->findPk($data[$i]["folder_id"]);
                 $this->assertNotNull($folder);
                 $contentFolder = ContentFolderQuery::create()->filterByContent($content)->filterByFolder($folder)->findOne();
                 $this->assertNotNull($contentFolder);
                 $folder->setLocale($this->lang->getLocale());
                 $this->assertEquals($folder->getTitle(), $data[$i]["folder_title"]);
                 $this->assertEquals($contentFolder->getDefaultFolder(), (bool) (int) $data[$i]["is_default_folder"]);
             }
         } while (isset($data[++$i]["id"]) && $data[$i - 1]["id"] === $data[$i]["id"] && ++$max);
     }
 }
 public function find(FindViewEvent $event)
 {
     $objectType = $event->getObjectType();
     $objectId = $event->getObjectId();
     // Try to find a direct match. A view is defined for the object.
     if (null !== ($viewObj = ViewQuery::create()->filterBySourceId($objectId)->findOneBySource($objectType))) {
         $viewName = $viewObj->getView();
         if (!empty($viewName)) {
             $event->setView($viewName)->setViewObject($viewObj);
             return;
         }
     }
     $foundView = $sourceView = null;
     if ($objectType == 'category') {
         $foundView = $this->searchInParents($objectId, $objectType, CategoryQuery::create(), false, $sourceView);
     } elseif ($objectType == 'folder') {
         $foundView = $this->searchInParents($objectId, $objectType, FolderQuery::create(), false, $sourceView);
     } elseif ($objectType == 'product') {
         if (null !== ($product = ProductQuery::create()->findPk($objectId))) {
             $foundView = $this->searchInParents($product->getDefaultCategoryId(), 'category', CategoryQuery::create(), true, $sourceView);
         }
     } elseif ($objectType == 'content') {
         if (null !== ($content = ContentQuery::create()->findPk($objectId))) {
             $foundView = $this->searchInParents($content->getDefaultFolderId(), 'folder', FolderQuery::create(), true, $sourceView);
         }
     }
     $event->setView($foundView)->setViewObject($sourceView);
 }
Пример #4
0
 public function preImport()
 {
     // Delete table before proceeding
     ContentQuery::create()->deleteAll();
     ContentImageQuery::create()->deleteAll();
     ContentDocumentQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->content_corresp->reset();
 }
Пример #5
0
 public function delete(ContentDeleteEvent $event)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getContentId()))) {
         $defaultFolderId = $content->getDefaultFolderId();
         $content->setDispatcher($event->getDispatcher())->delete();
         $event->setDefaultFolderId($defaultFolderId);
         $event->setContent($content);
     }
 }
Пример #6
0
 /**
  * @return ContentQuery
  */
 public function getQuery(Lang $lang)
 {
     $locale = $lang->getLocale();
     $contentI18nJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
     $folderI18nJoin = new Join(FolderTableMap::ID, FolderI18nTableMap::ID, Criteria::LEFT_JOIN);
     $urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
     $query = ContentQuery::create()->select([ContentTableMap::ID, ContentTableMap::VISIBLE, "content_TITLE", "content_CHAPO", "content_DESCRIPTION", "content_CONCLUSION", "content_seo_TITLE", "content_seo_DESCRIPTION", "content_seo_KEYWORDS", "url_URL", "folder_TITLE", "folder_ID", "folder_IS_DEFAULT"])->_if($this->isImageExport())->useContentImageQuery("content_image_join", Criteria::LEFT_JOIN)->addAsColumn("content_IMAGES", "GROUP_CONCAT(DISTINCT `content_image_join`.FILE)")->addSelectColumn("content_IMAGES")->groupByContentId()->endUse()->_endif()->_if($this->isDocumentExport())->useContentDocumentQuery("content_document_join", Criteria::LEFT_JOIN)->addAsColumn("content_DOCUMENTS", "GROUP_CONCAT(DISTINCT `content_document_join`.FILE)")->addSelectColumn("content_DOCUMENTS")->groupByContentId()->endUse()->_endif()->useContentFolderQuery(null, Criteria::LEFT_JOIN)->useFolderQuery(null, Criteria::LEFT_JOIN)->_if($this->isDocumentExport())->useFolderDocumentQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_DOCUMENTS", "GROUP_CONCAT(DISTINCT " . FolderDocumentTableMap::FILE . ")")->addSelectColumn("folder_DOCUMENTS")->endUse()->_endif()->_if($this->isImageExport())->useFolderImageQuery(null, Criteria::LEFT_JOIN)->addAsColumn("folder_IMAGES", "GROUP_CONCAT(DISTINCT " . FolderImageTableMap::FILE . ")")->addSelectColumn("folder_IMAGES")->endUse()->_endif()->addJoinObject($folderI18nJoin, "folder_i18n_join")->addJoinCondition("folder_i18n_join", FolderI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("folder_TITLE", FolderI18nTableMap::TITLE)->addAsColumn("folder_ID", FolderTableMap::ID)->endUse()->addAsColumn("folder_IS_DEFAULT", ContentFolderTableMap::DEFAULT_FOLDER)->endUse()->addJoinObject($contentI18nJoin, "content_i18n_join")->addJoinCondition("content_i18n_join", ContentI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)->addAsColumn("content_CHAPO", ContentI18nTableMap::CHAPO)->addAsColumn("content_DESCRIPTION", ContentI18nTableMap::DESCRIPTION)->addAsColumn("content_CONCLUSION", ContentI18nTableMap::POSTSCRIPTUM)->addAsColumn("content_seo_TITLE", ContentI18nTableMap::META_TITLE)->addAsColumn("content_seo_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)->addAsColumn("content_seo_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)->addJoinObject($urlJoin, "url_rewriting_join")->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW . " = ?", (new Content())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("url_URL", RewritingUrlTableMap::URL)->groupBy(ContentTableMap::ID)->groupBy("folder_ID")->orderById();
     return $query;
 }
Пример #7
0
 public function getData()
 {
     $locale = $this->language->getLocale();
     $contentI18nJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
     $folderI18nJoin = new Join(FolderTableMap::ID, FolderI18nTableMap::ID, Criteria::LEFT_JOIN);
     $urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
     $query = ContentQuery::create()->addSelfSelectColumns()->useContentFolderQuery(null, Criteria::LEFT_JOIN)->useFolderQuery(null, Criteria::LEFT_JOIN)->addJoinObject($folderI18nJoin, "folder_i18n_join")->addJoinCondition("folder_i18n_join", FolderI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("folder_TITLE", FolderI18nTableMap::TITLE)->addAsColumn("folder_ID", FolderTableMap::ID)->endUse()->addAsColumn("folder_IS_DEFAULT", ContentFolderTableMap::DEFAULT_FOLDER)->endUse()->addJoinObject($contentI18nJoin, "content_i18n_join")->addJoinCondition("content_i18n_join", ContentI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)->addAsColumn("content_CHAPO", ContentI18nTableMap::CHAPO)->addAsColumn("content_DESCRIPTION", ContentI18nTableMap::DESCRIPTION)->addAsColumn("content_CONCLUSION", ContentI18nTableMap::POSTSCRIPTUM)->addAsColumn("content_seo_TITLE", ContentI18nTableMap::META_TITLE)->addAsColumn("content_seo_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)->addAsColumn("content_seo_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)->addJoinObject($urlJoin, "url_rewriting_join")->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW . " = ?", (new Content())->getRewrittenUrlViewName(), null, \PDO::PARAM_STR)->addJoinCondition("url_rewriting_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)->addAsColumn("url_URL", RewritingUrlTableMap::URL)->groupBy(ContentTableMap::ID)->groupBy("folder_ID")->orderById();
     return $query;
 }
Пример #8
0
 /**
  * Check that a pop-campaign content source is valid.
  * @param $contentSourceType
  * @param $contentSourceId
  * @throws \InvalidArgumentException
  */
 protected function validateContentSource($contentSourceType, $contentSourceId)
 {
     switch ($contentSourceType) {
         case 'content':
             if (null === ContentQuery::create()->findPk($contentSourceId)) {
                 throw new \InvalidArgumentException('No content with id ' . $contentSourceId);
             }
             break;
     }
 }
Пример #9
0
 /**
  *
  * count all products for current category and sub categories
  *
  * @return int
  */
 public function countAllContents()
 {
     $children = FolderQuery::findAllChild($this->getId());
     array_push($children, $this);
     $contentsCount = 0;
     foreach ($children as $child) {
         $contentsCount += ContentQuery::create()->filterByFolder($child)->count();
     }
     return $contentsCount;
 }
Пример #10
0
 public function testSearchById()
 {
     $content = ContentQuery::create()->findOne();
     if (null === $content) {
         $content = new \Thelia\Model\Content();
         $content->setVisible(1);
         $content->setTitle('foo');
         $content->save();
     }
     $otherParameters = array("visible" => "*");
     $this->baseTestSearchById($content->getId(), $otherParameters);
 }
Пример #11
0
 /**
  * Provides access to an attribute of the current folder
  *
  * @param  array $params
  * @param  \Smarty $smarty
  * @return string the value of the requested attribute
  */
 public function folderDataAccess($params, &$smarty)
 {
     $folderId = $this->getRequest()->get('folder_id');
     if ($folderId === null) {
         $contentId = $this->getRequest()->get('content_id');
         if ($contentId !== null) {
             if (null !== ($content = ContentQuery::create()->findPk($contentId))) {
                 $folderId = $content->getDefaultFolderId();
             }
         }
     }
     if ($folderId !== null) {
         return $this->dataAccessWithI18n("Folder", $params, FolderQuery::create()->filterByPrimaryKey($folderId));
     }
     return '';
 }
Пример #12
0
 public function contentDataAccess($params, &$smarty)
 {
     $contentId = $this->request->get('content_id');
     if ($contentId !== null) {
         $search = ContentQuery::create()->filterById($contentId);
         return $this->dataAccessWithI18n("Content", $params, $search);
     }
 }
Пример #13
0
 /**
  * Returns a new ChildContentQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildContentQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof \Thelia\Model\ContentQuery) {
         return $criteria;
     }
     $query = new \Thelia\Model\ContentQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Пример #14
0
 public function delete(ContentDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getContentId()))) {
         $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $fileList = ['images' => [], 'documentList' => []];
             $defaultFolderId = $content->getDefaultFolderId();
             // Get content's files to delete after content deletion
             $fileList['images']['list'] = ContentImageQuery::create()->findByContentId($event->getContentId());
             $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;
             $fileList['documentList']['list'] = ContentDocumentQuery::create()->findByContentId($event->getContentId());
             $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;
             // Delete content
             $content->setDispatcher($dispatcher)->delete($con);
             $event->setDefaultFolderId($defaultFolderId);
             $event->setContent($content);
             // Dispatch delete content's files event
             foreach ($fileList as $fileTypeList) {
                 foreach ($fileTypeList['list'] as $fileToDelete) {
                     $fileDeleteEvent = new FileDeleteEvent($fileToDelete);
                     $dispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
                 }
             }
             $con->commit();
         } catch (\Exception $e) {
             $con->rollback();
             throw $e;
         }
     }
 }
 /**
  * @param string $view
  * @param int $id
  * @return bool
  */
 private function textExist($view, $id)
 {
     $test = null;
     if ($view == 'product') {
         $test = ProductQuery::create()->findPk($id);
     } else {
         if ($view == 'brand') {
             $test = BrandQuery::create()->findPk($id);
         } else {
             if ($view == 'category') {
                 $test = CategoryQuery::create()->findPk($id);
             } else {
                 if ($view == 'folder') {
                     $test = FolderQuery::create()->findPk($id);
                 } else {
                     if ($view == 'content') {
                         $test = ContentQuery::create()->findPk($id);
                     }
                 }
             }
         }
     }
     if ($test !== null) {
         return true;
     } else {
         return false;
     }
 }
Пример #16
0
 /**
  * Gets the number of ChildContent objects related by a many-to-many relationship
  * to the current object by way of the content_folder cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      ConnectionInterface $con Optional connection object
  *
  * @return int the number of related ChildContent objects
  */
 public function countContents($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collContents || null !== $criteria) {
         if ($this->isNew() && null === $this->collContents) {
             return 0;
         } else {
             $query = ChildContentQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByFolder($this)->count($con);
         }
     } else {
         return count($this->collContents);
     }
 }
Пример #17
0
 /**
  * @param $event \Thelia\Core\Event\UpdatePositionEvent
  * @return null|Response
  */
 protected function performAdditionalUpdatePositionAction($event)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getObjectId()))) {
         // Redirect to parent category list
         return $this->generateRedirectFromRoute('admin.folders.default', ['parent' => $content->getDefaultFolderId()]);
     } else {
         return null;
     }
 }
Пример #18
0
 /**
  * Get the associated ChildContent object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildContent The associated ChildContent object.
  * @throws PropelException
  */
 public function getContent(ConnectionInterface $con = null)
 {
     if ($this->aContent === null && $this->content_id !== null) {
         $this->aContent = ChildContentQuery::create()->findPk($this->content_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aContent->addProductAssociatedContents($this);
            */
     }
     return $this->aContent;
 }
Пример #19
0
 /**
  * @param  LoopResultRow         $loopResultRow
  * @param  \Thelia\Model\Content $content
  * @param $defaultFolderId
  * @return LoopResultRow
  */
 private function findNextPrev(LoopResultRow $loopResultRow, ContentModel $content, $defaultFolderId)
 {
     $isBackendContext = $this->getBackendContext();
     if ($this->getWithPrevNextInfo()) {
         // Find previous and next category
         $previousQuery = ContentQuery::create()->joinContentFolder()->where('ContentFolder.folder_id = ?', $defaultFolderId)->filterByPosition($content->getPosition(), Criteria::LESS_THAN);
         if (!$isBackendContext) {
             $previousQuery->filterByVisible(true);
         }
         $previous = $previousQuery->orderByPosition(Criteria::DESC)->findOne();
         $nextQuery = ContentQuery::create()->joinContentFolder()->where('ContentFolder.folder_id = ?', $defaultFolderId)->filterByPosition($content->getPosition(), Criteria::GREATER_THAN);
         if (!$isBackendContext) {
             $nextQuery->filterByVisible(true);
         }
         $next = $nextQuery->orderByPosition(Criteria::ASC)->findOne();
         $loopResultRow->set("HAS_PREVIOUS", $previous != null ? 1 : 0)->set("HAS_NEXT", $next != null ? 1 : 0)->set("PREVIOUS", $previous != null ? $previous->getId() : -1)->set("NEXT", $next != null ? $next->getId() : -1);
     }
     return $loopResultRow;
 }
Пример #20
0
 public function getRefrence(CommentReferenceGetterEvent $event)
 {
     if ('product' === $event->getRef()) {
         $product = ProductQuery::create()->findPk($event->getRefId());
         if (null !== $product) {
             $event->setTypeTitle($this->translator->trans('Product', [], 'core', $event->getLocale()));
             $event->setTitle($product->getTitle());
             $event->setViewUrl($product->getUrl($event->getLocale()));
             $event->setEditUrl(URL::getInstance()->absoluteUrl('/admin/products/update', ['product_id' => $product->getId()]));
             $event->setObject($product);
         }
     } elseif ('content' === $event->getRef()) {
         $content = ContentQuery::create()->findPk($event->getRefId());
         if (null !== $content) {
             $event->setTypeTitle($this->translator->trans('Content', [], 'core', $event->getLocale()));
             $event->setTitle($content->getTitle());
             $event->setViewUrl($content->getUrl($event->getLocale()));
             $event->setEditUrl(URL::getInstance()->absoluteUrl('/admin/contents/update', ['product_id' => $content->getId()]));
             $event->setObject($content);
         }
     }
 }
Пример #21
0
 /**
  * @depends testToggleVisibility
  */
 public function testAddContent(ProductModel $product)
 {
     $contents = $product->getProductAssociatedContents();
     $this->assertEquals(0, count($contents));
     $content = ContentQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     $event = new ProductAddContentEvent($product, $content->getId());
     $event->setDispatcher($this->getDispatcher());
     $action = new Product();
     $action->addContent($event);
     $product->clearProductAssociatedContents();
     $newContents = $product->getProductAssociatedContents();
     $this->assertEquals(1, count($newContents));
     return $product;
 }
Пример #22
0
 public function testDeleteFileContentImage()
 {
     $this->doTestDeleteFile(new ContentImage(), ContentQuery::create()->findOne(), 'images', 'content');
 }
Пример #23
0
 public function buildModelCriteria()
 {
     $search = ContentQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'));
     $id = $this->getId();
     if (!is_null($id)) {
         $search->filterById($id, Criteria::IN);
     }
     $manualOrderAllowed = false;
     if (null !== ($folderDefault = $this->getFolderDefault())) {
         // Select the contents which have $folderDefault as the default folder.
         $search->useContentFolderQuery('FolderSelect')->filterByDefaultFolder(true)->filterByFolderId($folderDefault, Criteria::IN)->endUse();
         // We can only sort by position if we have a single folder ID
         $manualOrderAllowed = 1 == count($folderDefault);
     } elseif (null !== ($folderIdList = $this->getFolder())) {
         // Select all content which have one of the required folders as the default one, or an associated one
         $depth = $this->getDepth();
         $allFolderIDs = FolderQuery::getFolderTreeIds($folderIdList, $depth);
         $search->useContentFolderQuery('FolderSelect')->filterByFolderId($allFolderIDs, Criteria::IN)->endUse();
         // We can only sort by position if we have a single folder ID, with a depth of 1
         $manualOrderAllowed = 1 == $depth && 1 == count($folderIdList);
     } else {
         $search->leftJoinContentFolder('FolderSelect')->addJoinCondition('FolderSelect', '`FolderSelect`.DEFAULT_FOLDER = 1');
     }
     $search->withColumn('CAST(CASE WHEN ISNULL(`FolderSelect`.POSITION) THEN \'' . PHP_INT_MAX . '\' ELSE `FolderSelect`.POSITION END AS SIGNED)', 'position_delegate');
     $search->withColumn('`FolderSelect`.FOLDER_ID', 'default_folder_id');
     $search->withColumn('`FolderSelect`.DEFAULT_FOLDER', 'is_default_folder');
     $current = $this->getCurrent();
     if ($current === true) {
         $search->filterById($this->getCurrentRequest()->get("content_id"));
     } elseif ($current === false) {
         $search->filterById($this->getCurrentRequest()->get("content_id"), Criteria::NOT_IN);
     }
     $current_folder = $this->getCurrentFolder();
     if ($current_folder === true) {
         $current = ContentQuery::create()->findPk($this->getCurrentRequest()->get("content_id"));
         $search->filterByFolder($current->getFolders(), Criteria::IN);
     } elseif ($current_folder === false) {
         $current = ContentQuery::create()->findPk($this->getCurrentRequest()->get("content_id"));
         $search->filterByFolder($current->getFolders(), Criteria::NOT_IN);
     }
     $visible = $this->getVisible();
     if ($visible !== BooleanOrBothType::ANY) {
         $search->filterByVisible($visible ? 1 : 0);
     }
     $title = $this->getTitle();
     if (!is_null($title)) {
         $this->addSearchInI18nColumn($search, 'TITLE', Criteria::LIKE, "%" . $title . "%");
     }
     $exclude = $this->getExclude();
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $exclude_folder = $this->getExcludeFolder();
     if (!is_null($exclude_folder)) {
         $search->filterByFolder(FolderQuery::create()->filterById($exclude_folder, Criteria::IN)->find(), Criteria::NOT_IN);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha-reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual":
                 if (!$manualOrderAllowed) {
                     throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
                 }
                 $search->addAscendingOrderByColumn('position_delegate');
                 break;
             case "manual_reverse":
                 if (!$manualOrderAllowed) {
                     throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
                 }
                 $search->addDescendingOrderByColumn('position_delegate');
                 break;
             case "given_id":
                 if (null === $id) {
                     throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
                 }
                 foreach ($id as $singleId) {
                     $givenIdMatched = 'given_id_matched_' . $singleId;
                     $search->withColumn(ContentTableMap::ID . "='{$singleId}'", $givenIdMatched);
                     $search->orderBy($givenIdMatched, Criteria::DESC);
                 }
                 break;
             case "random":
                 $search->clearOrderByColumns();
                 $search->addAscendingOrderByColumn('RAND()');
                 break 2;
             case "created":
                 $search->addAscendingOrderByColumn('created_at');
                 break;
             case "created_reverse":
                 $search->addDescendingOrderByColumn('created_at');
                 break;
             case "updated":
                 $search->addAscendingOrderByColumn('updated_at');
                 break;
             case "updated_reverse":
                 $search->addDescendingOrderByColumn('updated_at');
                 break;
             case "position":
                 $search->addAscendingOrderByColumn('position_delegate');
                 break;
             case "position_reverse":
                 $search->addDescendingOrderByColumn('position_delegate');
                 break;
         }
     }
     $search->groupById();
     return $search;
 }
Пример #24
0
 public function buildModelCriteria()
 {
     $search = FolderQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS']);
     $id = $this->getId();
     if (!is_null($id)) {
         $search->filterById($id, Criteria::IN);
     }
     $parent = $this->getParent();
     if (!is_null($parent)) {
         $search->filterByParent($parent);
     }
     $current = $this->getCurrent();
     if ($current === true) {
         $search->filterById($this->request->get("folder_id"));
     } elseif ($current === false) {
         $search->filterById($this->request->get("folder_id"), Criteria::NOT_IN);
     }
     $exclude = $this->getExclude();
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $content = $this->getContent();
     if (null !== $content) {
         $obj = ContentQuery::create()->findPk($content);
         if ($obj) {
             $search->filterByContent($obj, Criteria::IN);
         }
     }
     $title = $this->getTitle();
     if (!is_null($title)) {
         $this->addTitleSearchWhereClause($search, Criteria::LIKE, '%' . $title . '%');
     }
     $visible = $this->getVisible();
     if ($visible !== BooleanOrBothType::ANY) {
         $search->filterByVisible($visible ? 1 : 0);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
             case "manual":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "random":
                 $search->clearOrderByColumns();
                 $search->addAscendingOrderByColumn('RAND()');
                 break 2;
                 break;
             case "created":
                 $search->addAscendingOrderByColumn('created_at');
                 break;
             case "created_reverse":
                 $search->addDescendingOrderByColumn('created_at');
                 break;
             case "updated":
                 $search->addAscendingOrderByColumn('updated_at');
                 break;
             case "updated_reverse":
                 $search->addDescendingOrderByColumn('updated_at');
                 break;
         }
     }
     return $search;
 }
Пример #25
0
 public function getAvailableRelatedContentAction($categoryId, $folderId)
 {
     $result = array();
     $folders = FolderQuery::create()->filterById($folderId)->find();
     if ($folders !== null) {
         $list = ContentQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->filterByFolder($folders, Criteria::IN)->filterById(CategoryAssociatedContentQuery::create()->select('content_id')->findByCategoryId($categoryId), Criteria::NOT_IN)->find();
         if ($list !== null) {
             foreach ($list as $item) {
                 $result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
             }
         }
     }
     return $this->jsonResponse(json_encode($result));
 }
Пример #26
0
 Model\FeatureI18nQuery::create()->deleteAll();
 Model\FeatureAvQuery::create()->deleteAll();
 Model\FeatureAvI18nQuery::create()->deleteAll();
 Model\AttributeQuery::create()->deleteAll();
 Model\AttributeI18nQuery::create()->deleteAll();
 Model\AttributeAvQuery::create()->deleteAll();
 Model\AttributeAvI18nQuery::create()->deleteAll();
 Model\CategoryQuery::create()->deleteAll();
 Model\CategoryI18nQuery::create()->deleteAll();
 Model\ProductQuery::create()->deleteAll();
 Model\ProductI18nQuery::create()->deleteAll();
 Model\CustomerQuery::create()->deleteAll();
 Model\AdminQuery::create()->deleteAll();
 Model\FolderQuery::create()->deleteAll();
 Model\FolderI18nQuery::create()->deleteAll();
 Model\ContentQuery::create()->deleteAll();
 Model\ContentI18nQuery::create()->deleteAll();
 Model\AccessoryQuery::create()->deleteAll();
 Model\ProductSaleElementsQuery::create()->deleteAll();
 Model\ProductPriceQuery::create()->deleteAll();
 Model\BrandQuery::create()->deleteAll();
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 Model\BrandImageQuery::create()->deleteAll();
 Model\ProductDocumentQuery::create()->deleteAll();
 Model\CategoryDocumentQuery::create()->deleteAll();
 Model\FolderDocumentQuery::create()->deleteAll();
 Model\ContentDocumentQuery::create()->deleteAll();
Пример #27
0
 /**
  * @return \Thelia\Model\Content
  */
 protected function getRandomContent()
 {
     $content = ContentQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     if (null === $content) {
         $this->fail('use fixtures before launching test, there is no content in database');
     }
     return $content;
 }
Пример #28
0
 public function buildModelCriteria()
 {
     $search = FolderQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM', 'META_TITLE', 'META_DESCRIPTION', 'META_KEYWORDS'));
     $id = $this->getId();
     if (!is_null($id)) {
         $search->filterById($id, Criteria::IN);
     }
     $parent = $this->getParent();
     if (!is_null($parent)) {
         $search->filterByParent($parent);
     }
     $current = $this->getCurrent();
     if ($current === true) {
         $search->filterById($this->request->get("folder_id"));
     } elseif ($current === false) {
         $search->filterById($this->request->get("folder_id"), Criteria::NOT_IN);
     }
     $exclude = $this->getExclude();
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $content = $this->getContent();
     if (null !== $content) {
         $obj = ContentQuery::create()->findPk($content);
         if ($obj) {
             $search->filterByContent($obj, Criteria::IN);
         }
     }
     $title = $this->getTitle();
     if (!is_null($title)) {
         $search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END " . Criteria::LIKE . " ?", "%" . $title . "%", \PDO::PARAM_STR);
     }
     $visible = $this->getVisible();
     if ($visible !== BooleanOrBothType::ANY) {
         $search->filterByVisible($visible ? 1 : 0);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
             case "manual_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
             case "manual":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "random":
                 $search->clearOrderByColumns();
                 $search->addAscendingOrderByColumn('RAND()');
                 break 2;
                 break;
         }
     }
     return $search;
 }
Пример #29
0
 /**
  * Checks whether the current state must be recorded as a version
  *
  * @return  boolean
  */
 public function isVersioningNecessary($con = null)
 {
     if ($this->alreadyInSave) {
         return false;
     }
     if ($this->enforceVersion) {
         return true;
     }
     if (ChildContentQuery::isVersioningEnabled() && ($this->isNew() || $this->isModified()) || $this->isDeleted()) {
         return true;
     }
     return false;
 }
Пример #30
0
 /**
  * Performs an INSERT on the database, given a Content or Criteria object.
  *
  * @param mixed               $criteria Criteria or Content object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(ContentTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Content object
     }
     if ($criteria->containsKey(ContentTableMap::ID) && $criteria->keyContainsValue(ContentTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ContentTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = ContentQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }