Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class shopprodActions extends sfActions
- {
- public function getDefaultPage()
- {
- return 1;
- }
- /*
- *
- * sorting stuff
- *
- */
- protected function getValidSortColumns() {
- return array('id', 'name', 'country_id');
- }
- protected function getValidSortTypes() {
- return array('asc', 'desc');
- }
- protected function getDefaultSortColumn() {
- return 'name';
- }
- protected function getDefaultSortType() {
- return 'asc';
- }
- protected function getSortColumn() {
- return $this->getUser()->getAttribute('element_shopprod.sort_column',
- $this->getDefaultSortColumn(),
- 'aquis_namespace');
- }
- protected function setSortColumn($column = null) {
- if (!(is_string($column) &&
- in_array($column, $this->getValidSortColumns()))) {
- $sort_column = null;
- }
- $this->getUser()->setAttribute('element_shopprod.sort_column',
- ($column === null ?
- $this->getDefaultSortColumn() :
- $column),
- 'aquis_namespace');
- return $this->getSortColumn();
- }
- protected function getSortType() {
- return $this->getUser()->getAttribute('element_shopprod.sort_type',
- $this->getDefaultSortType(),
- 'aquis_namespace');
- }
- protected function setSortType($type = null) {
- if (!(is_string($type) && in_array($type, $this->getValidSortTypes()))) {
- $type = null;
- }
- $this->getUser()->setAttribute('element_shopprod.sort_type',
- ($type === null ?
- $this->getDefaultSortType() :
- $type),
- 'aquis_namespace');
- return $this->getSortType();
- }
- protected function addSortToQuery($query, $sort_column, $sort_type)
- {
- $query->addOrderBy($sort_column . ' ' . $sort_type);
- }
- public function getMaxPerPage()
- {
- return $this->maxPerPage;
- }
- protected function setPage($page)
- {
- $this->getUser()->setAttribute('element_shopprod.page', $page);
- return $page;
- }
- protected function getPage()
- {
- return $this->getUser()->getAttribute('element_shopprod.page', 1);
- }
- public function executeFilter(sfWebRequest $request) {
- $values = $this->getFilterValues();
- $this->form = new ElementFormFilter($values);
- }
- protected function getDefaultFilterValues() {
- return array();
- }
- protected function setFilterValues($filter_values = null) {
- if (!is_array($filter_values)) {
- $filter_values = null;
- }
- $this->getUser()->setAttribute('element_shopprod.filter_values',
- ($filter_values === null ?
- $this->getDefaultFilterValues() :
- $filter_values),
- 'aquis_namespace');
- return $this->getFilterValues();
- }
- protected function getFilterValues() {
- return $this->getUser()->getAttribute('element_shopprod.filter_values',
- $this->getDefaultFilterValues(),
- 'aquis_namespace');
- }
- public function executeIndex(sfWebRequest $request) {
- // session variables
- $perpage = sfConfig::get('app_max_shopprod_per_page', 2);
- $page = $request->getParameter('page', null);
- $max_per_page = $request->getParameter('max_per_page', null);
- $sort_column = $request->getParameter('sort_column', null);
- $sort_type = $request->getParameter('sort_type', null);
- //modify here too
- $filter_values = $request->getParameter('shopprod_filters', null);
- $filter_reset = $request->getParameter('filter_reset', null);
- if ($_POST){
- $this->setPage(1);
- }
- (!$page) ?
- $page = $this->getPage():
- $page = $this->setPage($page);
- (!$max_per_page) ?
- $max_per_page = $this->getMaxPerPage():
- ($max_per_page = $this->setMaxPerPage($max_per_page)) &&
- ($page = 1);
- (!$sort_column) ?
- $sort_column = $this->getSortColumn():
- $sort_column = $this->setSortColumn($sort_column);
- (!$sort_type) ?
- $sort_type = $this->getSortType():
- $sort_type = $this->setSortType($sort_type);
- (!$filter_values) ?
- $filter_values = $this->getFilterValues():
- $filter_values = $this->setFilterValues($filter_values);
- //$filter_values = $this->setFiltervalues(array(), array('price'=>93));
- //var_dump($filter_values);
- if ($filter_reset == 1) {
- $filter_values = null;
- $this->setFilterValues();
- }
- $this->sort_column =
- $this->getUser()->getAttribute('element_shopprod.sort_column',
- $this->getDefaultSortColumn(),
- 'aquis_namespace');
- $this->sort_type =
- $this->getUser()->getAttribute('element_shopprod.sort_type',
- $this->getDefaultSortType(),
- 'aquis_namespace');
- $this->page =
- $this->getUser()->getAttribute('element_shopprod.page',
- $this->getDefaultPage(),
- 'aquis_namespace');
- $filter_values =
- $this->getUser()->getAttribute('element_shopprod.filter_values',
- $this->getDefaultFilterValues(),
- 'aquis_namespace');
- // base query
- $query = Doctrine::getTable('shopprod')
- ->createQuery('p')
- ->select()
- ->from('shopprod r')
- ->orderBy('updated_at DESC')
- ;
- //Ceva care se adauga daca sunt credentiale
- //$query = Doctrine::getTable('Element')
- // ->createQuery('e');
- //if (!$this->getUser()->hasCredential('validate')) {
- // $query = $query->where('e.is_validate = 1');
- //}
- // Handling filtering
- $this->filterform = new shopprodFormFilter($filter_values,
- array(
- 'isadmingroup' => $this->getUser()->hasGroup('admin'),
- )
- );
- if ($filter_values) {
- $this->filterform->setQuery($query);
- $this->filterform->bind($filter_values);
- //echo $this->filterform->renderGlobalErrors();
- //echo $this->filterform->hasErrors();
- //die;
- if ($this->filterform->isValid()) {
- // aici trebuie sa incepem sa creem un nou QUERY
- //$query = $this->filterform->getQuery();
- $query = Doctrine_Core::getTable('shopprod')->createQuery('a')
- ->select('')
- ->from('shopprod p')
- ->orderBy('updated_at DESC')
- ;
- if (isset($filter_values["shopcar_id"]) && ($filter_values["shopcar_id"]!=="")){
- $query->andWhere('shopcar_id = ?' , $filter_values["shopcar_id"]);
- }
- if (isset($filter_values["shopcat_id"]) && ($filter_values["shopcat_id"]!=="")){
- //echo $query; die;
- //var_dump($filter_values["shopcat_id"]); die;
- //Aflam obiectul categorie
- $shopcat = Doctrine_Core::getTable('shopcat')->find(array($filter_values["shopcat_id"]));
- $shopcatlist = Doctrine_Core::getTable('shopcat')->getInList($shopcat);
- $shopcarslist = Doctrine_Core::getTable('shopcar')->getCarListInCategory($shopcatlist);
- $query->andWhere('shopcar_id IN (' . $shopcarslist . ')');
- }
- if (isset($filter_values["shoppartname_id"]) && ($filter_values["shoppartname_id"]!=="")){
- $shoppartname = Doctrine_Core::getTable('shoppartname')->find(array($filter_values["shoppartname_id"]));
- $list = Doctrine_Core::getTable('shoppartname')->getInList($shoppartname);
- //echo $list; die;
- //actualizare in caz de filtrare
- //Doctrine_Core::getTable('shoppartname')->filtratplus($filter_values["shoppartname_id"]);
- $filtrat = $shoppartname->getFiltrat()+1;
- $shoppartname->set('filtrat', $filtrat);
- $shoppartname->save();
- $query->andWhere('shoppartname_id IN (' . $list . ')');
- }
- if (isset($filter_values["shoplocation_id"]) && ($filter_values["shoplocation_id"]!=="")){
- //echo "<pre>"; var_dump($filter_values["shoplocation_id"]); die;
- $shoplocation = Doctrine_Core::getTable('shoplocation')->find(array($filter_values["shoplocation_id"]));
- $list = Doctrine_Core::getTable('shoplocation')->getInList($shoplocation);
- //echo $list; die;
- $query->andWhere('shoplocation_id IN (' . $list . ')');
- }
- //echo $query; die;
- } else {
- $this->getUser()->setFlash('error',
- "Filtering is not possible due " .
- "to some errors.".
- " Previous filters, if any were resetted !");
- $this->redirect('shopprod/index?filter_reset=1');
- //$this->setTemplate('filter');
- //$this->redirect('@element_filter');
- }
- }
- // Applying sorting to filtered query
- if ($sort_column !== 'shopcat_id'){
- $this->addSortToQuery($query, $sort_column, $sort_type);
- }
- //echo $query;
- // Handling pager
- if (!$this->shopprods) {
- $this->shopprods = new sfDoctrinePager('shopprod', $perpage);
- }
- $this->shopprods->setQuery($query);
- $this->shopprods->setPage($page, 1);
- $this->shopprods->init();
- }
- ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement