예제 #1
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;
 }
예제 #2
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;
 }
예제 #3
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');
     }
 }
예제 #4
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;
 }
예제 #5
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;
 }