Skip to content

Instantly share code, notes, and snippets.

@ksn135
Last active May 18, 2017 21:14
Show Gist options
  • Save ksn135/0818a550d93925a551872390111ee506 to your computer and use it in GitHub Desktop.
Save ksn135/0818a550d93925a551872390111ee506 to your computer and use it in GitHub Desktop.
Shop categories routing for Symfony 1.4 with Propel 1.2
<?php
class mainActions extends sfActions
{
public function executeShow( sfWebRequest $request )
{
$this->section = $this->getRoute()->getSection();
$this->addMeta($this->section);
$c = new Criteria();
$c->add( SectionPeer::IS_VISIBLE, true );
$c->addAscendingOrderByColumn( SectionPeer::SORT_POSITION );
$this->sections = ($this->section->getType()!='showcase3') ?
$this->section->getSectionsRelatedByIdJoinsfAsset($c) :
$this->section->getSectionsRelatedById($c);
$this->qty = count($this->sections);
$c2 = new Criteria();
$c2->add( PriceItemPeer::IS_VISIBLE, true);
$c2->addAscendingOrderByColumn( PriceItemPeer::SORT_POSITION );
$query = PriceItemQuery::create(null, $c2);
if ($this->section->getType() != 'showcase3') {
$query = $query->joinWith('sfAsset', Criteria::LEFT_JOIN);
}
$this->price_items = $query
->filterBySection($this->section)
->find();
$this->gallery = $this->section->getGallery();
$this->setTemplate($this->section->getType());
}
}
shop:
url: /:category1/:category2/:category3/:category4/:category5/:category6/:category7/:category8/:category9
class: sfPropelORMRoute
options:
model: Section
type: object
query_methods:
- filterVisible
- leftJoinWithsfAsset
param:
module: main
action: show
category1: ~
category2: ~
category3: ~
category4: ~
category5: ~
category6: ~
category7: ~
category8: ~
category9: ~
requirements:
sf_method: [get]
<php
class SectionQuery extends BaseSectionQuery
{
private $categories = null;
public function filterVisible()
{
return $this->filterByIsVisible(true);
}
private function filterByCategory($pos, $category, $apply = false)
{
if (!$this->categories) $this->categories = array();
if (!empty($category)) $this->categories[$pos] = $category;
if (!$apply) return $this;
$rez = $this;
foreach( array_reverse($this->categories) as $lev => $slug )
{
if (!$lev) $rez->filterBySlug($slug);
else
{
$alias = 'Section';
for($k=1;$k<=$lev;$k++)
{
$alias2 = 'Section' . $k;
$rez->join("$alias.SectionRelatedByParentId $alias2");
$alias = $alias2;
}
$rez = $rez->useQuery("$alias2")
->filterBySlug($slug)->endUse();
}
}
return $rez;
}
public function filterByCategory1($category) { return $this->filterByCategory(0, $category); }
public function filterByCategory2($category) { return $this->filterByCategory(1, $category); }
public function filterByCategory3($category) { return $this->filterByCategory(2, $category); }
public function filterByCategory4($category) { return $this->filterByCategory(3, $category); }
public function filterByCategory5($category) { return $this->filterByCategory(4, $category); }
public function filterByCategory6($category) { return $this->filterByCategory(5, $category); }
public function filterByCategory7($category) { return $this->filterByCategory(6, $category); }
public function filterByCategory8($category) { return $this->filterByCategory(7, $category); }
public function filterByCategory9($category) { return $this->filterByCategory(8, $category, true ); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment