Exemplo n.º 1
0
 public function testLoadSpecificUrl()
 {
     $searchResult = new RewritingUrl();
     $searchResult->setUrl('foo.html');
     $retrieverQuery = $this->getMock('\\Thelia\\Model\\RewritingUrlQuery', array('getSpecificUrlQuery'));
     $retrieverQuery->expects($this->any())->method('getSpecificUrlQuery')->with('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'))->will($this->returnValue($searchResult));
     $retriever = new RewritingRetriever();
     $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
     $rewritingUrlQuery->setValue($retriever, $retrieverQuery);
     $retriever->loadSpecificUrl('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'));
     $this->assertEquals('foo.html', $retriever->rewrittenUrl);
     $this->assertEquals(URL::getInstance()->viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'lang' => 'fr_FR', 'view_id' => 1)), $retriever->url);
 }
Exemplo n.º 2
0
 /**
  * @param RewritingUrl $rewritingUrl
  */
 public function __construct(RewritingUrl $rewritingUrl)
 {
     $this->id = $rewritingUrl->getId();
     $this->url = $rewritingUrl->getUrl();
     $this->view = $rewritingUrl->getView();
     $this->viewLocale = $rewritingUrl->getViewLocale();
     $this->redirected = $rewritingUrl->getRedirected();
     $this->rewritingUrl = $rewritingUrl;
 }
Exemplo n.º 3
0
 /**
  * Set the rewritten URL for the given locale
  *
  * @param  string                                  $locale a valid locale (e.g. en_US)
  * @param $url
  * @return $this
  * @throws UrlRewritingException
  * @throws \Thelia\Exception\UrlRewritingException
  */
 public function setRewrittenUrl($locale, $url)
 {
     $currentUrl = $this->getRewrittenUrl($locale);
     if ($currentUrl == $url || null === $url) {
         /* no url update */
         return $this;
     }
     try {
         $resolver = new RewritingResolver($url);
         /* we can reassign old url */
         if (null === $resolver->redirectedToUrl) {
             /* else ... */
             if ($resolver->view == $this->getRewrittenUrlViewName() && $resolver->viewId == $this->getId()) {
                 /* it's an url related to the current object */
                 if ($resolver->locale != $locale) {
                     /* it is an url related to this product for another locale */
                     throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
                 }
                 if (count($resolver->otherParameters) > 0) {
                     /* it is an url related to this product but with more arguments */
                     throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
                 }
                 /* here it must be a deprecated url */
             } else {
                 /* already related to another object */
                 throw new UrlRewritingException(Translator::getInstance()->trans('URL_ALREADY_EXISTS'), UrlRewritingException::URL_ALREADY_EXISTS);
             }
         }
     } catch (UrlRewritingException $e) {
         /* It's all good if URL is not found */
         if ($e->getCode() !== UrlRewritingException::URL_NOT_FOUND) {
             throw $e;
         }
     }
     /* set the new URL */
     if (isset($resolver)) {
         /* erase the old one */
         $rewritingUrl = RewritingUrlQuery::create()->findOneByUrl($url);
         $rewritingUrl->setView($this->getRewrittenUrlViewName())->setViewId($this->getId())->setViewLocale($locale)->setRedirected(null)->save();
         /* erase additional arguments if any : only happens in case it erases a deprecated url */
         RewritingArgumentQuery::create()->filterByRewritingUrl($rewritingUrl)->deleteAll();
     } else {
         /* just create it */
         $rewritingUrl = new RewritingUrl();
         $rewritingUrl->setUrl($url)->setView($this->getRewrittenUrlViewName())->setViewId($this->getId())->setViewLocale($locale)->save();
     }
     /* deprecate the old one if needed */
     if (null !== ($oldRewritingUrl = RewritingUrlQuery::create()->findOneByUrl($currentUrl))) {
         $oldRewritingUrl->setRedirected($rewritingUrl->getId())->save();
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Filter the query by a related \Thelia\Model\RewritingUrl object
  *
  * @param \Thelia\Model\RewritingUrl|ObjectCollection $rewritingUrl The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildRewritingArgumentQuery The current query, for fluid interface
  */
 public function filterByRewritingUrl($rewritingUrl, $comparison = null)
 {
     if ($rewritingUrl instanceof \Thelia\Model\RewritingUrl) {
         return $this->addUsingAlias(RewritingArgumentTableMap::REWRITING_URL_ID, $rewritingUrl->getId(), $comparison);
     } elseif ($rewritingUrl instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(RewritingArgumentTableMap::REWRITING_URL_ID, $rewritingUrl->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByRewritingUrl() only accepts arguments of type \\Thelia\\Model\\RewritingUrl or Collection');
     }
 }
Exemplo n.º 5
0
 /**
  * Declares an association between this object and a ChildRewritingUrl object.
  *
  * @param                  ChildRewritingUrl $v
  * @return                 \Thelia\Model\RewritingUrl The current object (for fluent API support)
  * @throws PropelException
  */
 public function setRewritingUrlRelatedByRedirected(ChildRewritingUrl $v = null)
 {
     if ($v === null) {
         $this->setRedirected(NULL);
     } else {
         $this->setRedirected($v->getId());
     }
     $this->aRewritingUrlRelatedByRedirected = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildRewritingUrl object, it will not be re-added.
     if ($v !== null) {
         $v->addRewritingUrlRelatedById($this);
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Exclude object from result
  *
  * @param   ChildRewritingUrl $rewritingUrl Object to remove from the list of results
  *
  * @return ChildRewritingUrlQuery The current query, for fluid interface
  */
 public function prune($rewritingUrl = null)
 {
     if ($rewritingUrl) {
         $this->addUsingAlias(RewritingUrlTableMap::ID, $rewritingUrl->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * @param RewritingUrl $url
  * @param string $name
  * @param string $value
  * @return RewritingArgument
  */
 private function insertUrlArgument(RewritingUrl $url, $name, $value)
 {
     $insert = new RewritingArgument();
     $insert->setRewritingUrlId($url->getId())->setParameter($name)->setValue($value)->save();
     return $insert;
 }
Exemplo n.º 8
0
 /**
  * @param $type
  * @param RewritingUrl $result
  * @param $configValues
  * @param $sitemap
  */
 protected function generateSitemapImage($type, $result, $configValues, &$sitemap)
 {
     $event = new ImageEvent();
     $event->setWidth($configValues['width'])->setHeight($configValues['height'])->setQuality($configValues['quality'])->setRotation($configValues['rotation'])->setResizeMode($configValues['resizeMode'])->setBackgroundColor($configValues['bgColor'])->setAllowZoom($configValues['allowZoom']);
     // Put source image file path
     $source_filepath = sprintf("%s%s/%s/%s", THELIA_ROOT, ConfigQuery::read('images_library_path', 'local/media/images'), $type, $result->getVirtualColumn('PRODUCT_FILE'));
     $event->setSourceFilepath($source_filepath);
     $event->setCacheSubdirectory($type);
     try {
         // Dispatch image processing event
         $this->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
         // New sitemap image entry
         $sitemap[] = '
         <url>
             <loc>' . URL::getInstance()->absoluteUrl($result->getUrl()) . '</loc>
             <image:image>
                 <image:loc>' . $event->getFileUrl() . '</image:loc>
                 <image:title>' . htmlspecialchars($result->getVirtualColumn('PRODUCT_TITLE')) . '</image:title>
             </image:image>
         </url>';
     } catch (\Exception $ex) {
     }
 }