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);
 }
Пример #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);
     }
 }
Пример #3
0
 public function buildArray()
 {
     $id = $this->getFolder();
     $visible = $this->getVisible();
     $search = FolderQuery::create();
     $this->configureI18nProcessing($search, array('TITLE'));
     $search->filterById($id);
     if ($visible !== BooleanOrBothType::ANY) {
         $search->filterByVisible($visible);
     }
     $results = array();
     $ids = array();
     do {
         $folder = $search->findOne();
         if ($folder != null) {
             $results[] = array("ID" => $folder->getId(), "TITLE" => $folder->getVirtualColumn('i18n_TITLE'), "URL" => $folder->getUrl($this->locale), "LOCALE" => $this->locale);
             $parent = $folder->getParent();
             if ($parent > 0) {
                 // Prevent circular refererences
                 if (in_array($parent, $ids)) {
                     throw new \LogicException(sprintf("Circular reference detected in folder ID=%d hierarchy (folder ID=%d appears more than one times in path)", $id, $parent));
                 }
                 $ids[] = $parent;
                 $search = FolderQuery::create();
                 $this->configureI18nProcessing($search, array('TITLE'));
                 $search->filterById($parent);
                 if ($visible != BooleanOrBothType::ANY) {
                     $search->filterByVisible($visible);
                 }
             }
         }
     } while ($folder != null && $parent > 0);
     // Reverse list and build the final result
     return array_reverse($results);
 }
Пример #4
0
 /**
  * Get the root folder
  * @param  int   $folderId
  * @return mixed
  */
 public function getRoot($folderId)
 {
     $folder = FolderQuery::create()->findPk($folderId);
     if (0 !== $folder->getParent()) {
         $parentFolder = FolderQuery::create()->findPk($folder->getParent());
         if (null !== $parentFolder) {
             $folderId = $this->getRoot($parentFolder->getId());
         }
     }
     return $folderId;
 }
Пример #5
0
 public function testSearchById()
 {
     $folder = FolderQuery::create()->findOne();
     if (null === $folder) {
         $folder = new \Thelia\Model\Folder();
         $folder->setParent(0);
         $folder->setVisible(1);
         $folder->setTitle('foo');
         $folder->save();
     }
     $otherParameters = array("visible" => "*");
     $this->baseTestSearchById($folder->getId(), $otherParameters);
 }
Пример #6
0
 public function updatePosition(UpdatePositionEvent $event)
 {
     if (null !== ($folder = FolderQuery::create()->findPk($event->getObjectId()))) {
         $folder->setDispatcher($event->getDispatcher());
         switch ($event->getMode()) {
             case UpdatePositionEvent::POSITION_ABSOLUTE:
                 $folder->changeAbsolutePosition($event->getPosition());
                 break;
             case UpdatePositionEvent::POSITION_DOWN:
                 $folder->movePositionDown();
                 break;
             case UpdatePositionEvent::POSITION_UP:
                 $folder->movePositionUp();
                 break;
         }
     }
 }
Пример #7
0
 /**
  * Create and save the id of the pop-in images folder if necessary.
  *
  * @throws \Exception
  * @throws PropelException
  */
 protected function createPopInImageFolder()
 {
     $imageFolderIdConfig = ConfigQuery::create()->findOneByName(static::CONF_KEY_IMAGE_FOLDER_ID);
     if (null !== $imageFolderIdConfig && null !== FolderQuery::create()->findPk($imageFolderIdConfig->getValue())) {
         // we already have and know our images folder
         return;
     }
     Propel::getConnection()->beginTransaction();
     try {
         // create the folder
         $folder = new Folder();
         $folder->setVisible(true);
         /** @var Lang $lang */
         foreach (LangQuery::create()->find() as $lang) {
             $localizedTitle = Translator::getInstance()->trans("Pop-in images", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
             if ($localizedTitle == "") {
                 continue;
             }
             $folder->setLocale($lang->getLocale())->setTitle($localizedTitle);
         }
         $folder->save();
         // save the folder id in configuration
         if ($folder->getId() !== null) {
             $config = new Config();
             $config->setName(static::CONF_KEY_IMAGE_FOLDER_ID)->setValue($folder->getId())->setHidden(false);
             /** @var Lang $lang */
             foreach (LangQuery::create()->find() as $lang) {
                 $localizedTitle = Translator::getInstance()->trans("Pop-in images folder id", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
                 if ($localizedTitle == "") {
                     continue;
                 }
                 $config->setLocale($lang->getLocale())->setTitle($localizedTitle);
             }
             $config->save();
         }
     } catch (\Exception $e) {
         Propel::getConnection()->rollBack();
         throw $e;
     }
     Propel::getConnection()->commit();
 }
Пример #8
0
 protected function buildFolderTree($parent, $visible, $level, $maxLevel, $exclude, &$resultsList)
 {
     if ($level > $maxLevel) {
         return;
     }
     $search = FolderQuery::create();
     $this->configureI18nProcessing($search, array('TITLE'));
     $search->filterByParent($parent);
     if ($visible != BooleanOrBothType::ANY) {
         $search->filterByVisible($visible);
     }
     if ($exclude != null) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $search->orderByPosition(Criteria::ASC);
     $results = $search->find();
     foreach ($results as $result) {
         $resultsList[] = array("ID" => $result->getId(), "TITLE" => $result->getVirtualColumn('i18n_TITLE'), "PARENT" => $result->getParent(), "URL" => $this->getReturnUrl() ? $result->getUrl($this->locale) : null, "VISIBLE" => $result->getVisible() ? "1" : "0", "LEVEL" => $level, 'CHILD_COUNT' => $result->countChild());
         $this->buildFolderTree($result->getId(), $visible, 1 + $level, $maxLevel, $exclude, $resultsList);
     }
 }
Пример #9
0
 public function folderDataAccess($params, &$smarty)
 {
     $folderId = $this->request->get('folder_id');
     if ($folderId !== null) {
         $search = FolderQuery::create()->filterById($folderId);
         return $this->dataAccessWithI18n("Folder", $params, $search);
     }
 }
Пример #10
0
 Model\AttributeCombinationQuery::create()->deleteAll();
 Model\FeatureQuery::create()->deleteAll();
 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();
Пример #11
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);
     }
     $folder = $this->getFolder();
     $folderDefault = $this->getFolderDefault();
     if (!is_null($folder) || !is_null($folderDefault)) {
         $foldersIds = array();
         if (!is_array($folder)) {
             $folder = array();
         }
         if (!is_array($folderDefault)) {
             $folderDefault = array();
         }
         $foldersIds = array_merge($foldersIds, $folder, $folderDefault);
         $folders = FolderQuery::create()->filterById($foldersIds, Criteria::IN)->find();
         $depth = $this->getDepth();
         if (null !== $depth) {
             foreach (FolderQuery::findAllChild($folder, $depth) as $subFolder) {
                 $folders->prepend($subFolder);
             }
         }
         $search->filterByFolder($folders, Criteria::IN);
     }
     $current = $this->getCurrent();
     if ($current === true) {
         $search->filterById($this->request->get("content_id"));
     } elseif ($current === false) {
         $search->filterById($this->request->get("content_id"), Criteria::NOT_IN);
     }
     $current_folder = $this->getCurrentFolder();
     if ($current_folder === true) {
         $current = ContentQuery::create()->findPk($this->request->get("content_id"));
         $search->filterByFolder($current->getFolders(), Criteria::IN);
     } elseif ($current_folder === false) {
         $current = ContentQuery::create()->findPk($this->request->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)) {
         $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);
     }
     $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 (null === $foldersIds || count($foldersIds) != 1) {
                     throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
                 }
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "manual_reverse":
                 if (null === $foldersIds || count($foldersIds) != 1) {
                     throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
                 }
                 $search->orderByPosition(Criteria::DESC);
                 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->orderByPosition(Criteria::ASC);
                 break;
             case "position_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     $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);
     }
     return $search;
 }
Пример #12
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));
 }
Пример #13
0
 /**
  * @return \Thelia\Model\Folder
  */
 protected function getRandomFolder()
 {
     $folder = FolderQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
     if (null === $folder) {
         $this->fail('use fixtures before launching test, there is no folder in database');
     }
     return $folder;
 }
Пример #14
0
 /**
  * Performs an INSERT on the database, given a Folder or Criteria object.
  *
  * @param mixed               $criteria Criteria or Folder 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(FolderTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Folder object
     }
     if ($criteria->containsKey(FolderTableMap::ID) && $criteria->keyContainsValue(FolderTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . FolderTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = FolderQuery::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;
 }
Пример #15
0
 public function parseResults(LoopResult $loopResult)
 {
     /** @var \Thelia\Model\Folder $folder */
     foreach ($loopResult->getResultDataCollection() as $folder) {
         $loopResultRow = new LoopResultRow($folder);
         $loopResultRow->set("ID", $folder->getId())->set("IS_TRANSLATED", $folder->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $folder->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("PARENT", $folder->getParent())->set("ROOT", $folder->getRoot($folder->getId()))->set("URL", $this->getReturnUrl() ? $folder->getUrl($this->locale) : null)->set("META_TITLE", $folder->getVirtualColumn('i18n_META_TITLE'))->set("META_DESCRIPTION", $folder->getVirtualColumn('i18n_META_DESCRIPTION'))->set("META_KEYWORDS", $folder->getVirtualColumn('i18n_META_KEYWORDS'))->set("CHILD_COUNT", $folder->countChild())->set("CONTENT_COUNT", $folder->countAllContents())->set("VISIBLE", $folder->getVisible() ? "1" : "0")->set("POSITION", $folder->getPosition());
         $isBackendContext = $this->getBackendContext();
         if ($this->getWithPrevNextInfo()) {
             // Find previous and next folder
             $previousQuery = FolderQuery::create()->filterByParent($folder->getParent())->filterByPosition($folder->getPosition(), Criteria::LESS_THAN);
             if (!$isBackendContext) {
                 $previousQuery->filterByVisible(true);
             }
             $previous = $previousQuery->orderByPosition(Criteria::DESC)->findOne();
             $nextQuery = FolderQuery::create()->filterByParent($folder->getParent())->filterByPosition($folder->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);
         }
         $this->addOutputFields($loopResultRow, $folder);
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
Пример #16
0
 /**
  * Check if the element exists and is visible
  *
  * @param $context string   catalog or content
  * @param $id string        id of the element
  * @return bool
  */
 private function checkId($context, $id)
 {
     $ret = false;
     if (is_numeric($id)) {
         if ("catalog" === $context) {
             $cat = CategoryQuery::create()->findPk($id);
             $ret = null !== $cat && $cat->getVisible();
         } elseif ("brand" === $context) {
             $brand = BrandQuery::create()->findPk($id);
             $ret = null !== $brand && $brand->getVisible();
         } else {
             $folder = FolderQuery::create()->findPk($id);
             $ret = null !== $folder && $folder->getVisible();
         }
     }
     return $ret;
 }
Пример #17
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 (ChildFolderQuery::isVersioningEnabled() && ($this->isNew() || $this->isModified()) || $this->isDeleted()) {
         return true;
     }
     return false;
 }
Пример #18
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;
 }
Пример #19
0
 /**
  * Returns a new ChildFolderQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildFolderQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof \Thelia\Model\FolderQuery) {
         return $criteria;
     }
     $query = new \Thelia\Model\FolderQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  * @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;
     }
 }
Пример #21
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 '';
 }
Пример #22
0
 public function testDeleteFileFolderImage()
 {
     $this->doTestDeleteFile(new FolderImage(), FolderQuery::create()->findOne(), 'images', 'folder');
 }
Пример #23
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;
 }
Пример #24
0
 public function postImport()
 {
     // Fix parent IDs for each object, which are still T1 parent IDs
     $obj_list = FolderQuery::create()->orderById()->find();
     foreach ($obj_list as $obj) {
         $t1_parent = $obj->getParent() - 1000000;
         Tlog::getInstance()->addInfo("Searching T1 parent {$t1_parent}");
         if ($t1_parent > 0) {
             try {
                 $obj->setParent($this->fld_corresp->getT2($t1_parent))->save();
             } catch (\Exception $ex) {
                 // Parent does not exists -> delete the T2 folder.
                 $obj->delete();
                 Tlog::getInstance()->addWarning("Deleted folder T2 ID=" . $obj->getId() . ", which has an invalid parent T1 ID={$t1_parent}.");
             }
         }
     }
 }
Пример #25
0
 /**
  * Get the associated ChildFolder object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildFolder The associated ChildFolder object.
  * @throws PropelException
  */
 public function getFolder(ConnectionInterface $con = null)
 {
     if ($this->aFolder === null && $this->id !== null) {
         $this->aFolder = ChildFolderQuery::create()->findPk($this->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->aFolder->addFolderVersions($this);
            */
     }
     return $this->aFolder;
 }
Пример #26
0
 /**
  * @param $event \Thelia\Core\Event\UpdatePositionEvent
  * @return null|Response
  */
 protected function performAdditionalUpdatePositionAction($event)
 {
     $folder = FolderQuery::create()->findPk($event->getObjectId());
     if ($folder != null) {
         return $this->generateRedirectFromRoute('admin.folders.default', ['parent' => $folder->getParent()]);
     } else {
         return null;
     }
 }
Пример #27
0
 /**
  * Gets the number of ChildFolder 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 ChildFolder objects
  */
 public function countFolders($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collFolders || null !== $criteria) {
         if ($this->isNew() && null === $this->collFolders) {
             return 0;
         } else {
             $query = ChildFolderQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByContent($this)->count($con);
         }
     } else {
         return count($this->collFolders);
     }
 }
Пример #28
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;
 }