Guest User

Untitled

a guest
Oct 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.06 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * richieste actions.
  5.  *
  6.  * @subpackage richieste
  7.  * @version    SVN: $Id: actions.class.php 131 2011-09-05 16:12:27Z Claudio $
  8.  */
  9. class richiesteActions extends sfActions
  10. {
  11.   public function executeIndex(sfWebRequest $request)
  12.   {
  13.       // Filtri!!
  14.       if (null === $this->filters){
  15.           $this->filters = new Richiesta_preventivoFormFilter($this->getFilters());
  16.       }
  17.      
  18.       $this->filters->setTableMethod('addQueryListaRichiesta');
  19.       $q = $this->filters->buildQuery($this->getFilters());
  20.  
  21.       $aliasRichiesta = $q->getRootAlias();
  22.      
  23.       if($request->getParameter('cliente')){
  24.         $q->addWhere($aliasRichiesta.'.id_cliente = ?', $request->getParameter('cliente'));
  25.       }
  26.       elseif($request->getParameter('sessione')){
  27.         $q->addWhere($aliasRichiesta.'.id_sessione_vendita = ?', $request->getParameter('sessione'));
  28.       }
  29.  
  30.     // Controllo dell'ordinamento
  31.     if ($request->getParameter('ordinamento')){
  32.           $this->setSort(array(
  33.               $request->getParameter('ordinamento'),
  34.               $request->getParameter('tipo_ordinamento'))
  35.                   );
  36.     }
  37.     $this->addSortQuery($q);
  38.     $this->sort = $this->getSort();
  39.    
  40.     // Pager...
  41.     $this->pgRichieste = new sfDoctrinePager(
  42.             'Richiesta_preventivo',
  43.             sfConfig::get('app_numero_righe_per_lista')
  44.             );
  45.     if ($request->getParameter('pag')){
  46.       $this->setPage($request->getParameter('pag', $this->getPage()));
  47.     }
  48.   }
  49.  
  50.   public function executeShow(sfWebRequest $request)
  51.   {
  52.     $this->richiesta_preventivo = Doctrine_Core::getTable('Richiesta_preventivo')
  53.          ->find(array($request->getParameter('id')));
  54.     $this->forward404Unless($this->richiesta_preventivo);
  55.   }
  56.  
  57.   public function executeNew(sfWebRequest $request)
  58.   {
  59.     $this->form = new Richiesta_preventivoForm();
  60.   }
  61.  
  62.   public function executeCreate(sfWebRequest $request)
  63.   {
  64.     $this->forward404Unless($request->isMethod(sfRequest::POST));
  65.  
  66.     $this->form = new Richiesta_preventivoForm();
  67.  
  68.     $this->processForm($request, $this->form);
  69.  
  70.     $this->setTemplate('new');
  71.   }
  72.  
  73.   public function executeEdit(sfWebRequest $request)
  74.   {
  75.     $this->forward404Unless($richiesta_preventivo = Doctrine_Core::getTable('Richiesta_preventivo')->find(array($request->getParameter('id'))), sprintf('Object richiesta_preventivo does not exist (%s).', $request->getParameter('id')));
  76.     $this->form = new Richiesta_preventivoForm($richiesta_preventivo);
  77.   }
  78.  
  79.   public function executeUpdate(sfWebRequest $request)
  80.   {
  81.     $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
  82.     $this->forward404Unless($richiesta_preventivo = Doctrine_Core::getTable('Richiesta_preventivo')->find(array($request->getParameter('id'))), sprintf('Object richiesta_preventivo does not exist (%s).', $request->getParameter('id')));
  83.     $this->form = new Richiesta_preventivoForm($richiesta_preventivo);
  84.  
  85.     $this->processForm($request, $this->form);
  86.  
  87.     $this->setTemplate('edit');
  88.   }
  89.  
  90.   public function executeDelete(sfWebRequest $request)
  91.   {
  92.     $request->checkCSRFProtection();
  93.  
  94.     $this->forward404Unless($richiesta_preventivo = Doctrine_Core::getTable('Richiesta_preventivo')->find(array($request->getParameter('id'))), sprintf('Object richiesta_preventivo does not exist (%s).', $request->getParameter('id')));
  95.     $richiesta_preventivo->delete();
  96.  
  97.     $this->redirect('richieste/index');
  98.   }
  99.  
  100.   protected function processForm(sfWebRequest $request, sfForm $form)
  101.   {
  102.     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
  103.     if ($form->isValid())
  104.     {
  105.       $richiesta_preventivo = $form->save();
  106.  
  107.       $this->redirect('richieste/edit?id='.$richiesta_preventivo->getId());
  108.     }
  109.   }
  110.  
  111.   // wToDo: Da qui in poi vorrei generalizzare a tutti gli altri moduli...
  112.   public function executeBatch(sfWebRequest $request){
  113.       $request->checkCSRFProtection();
  114.       if (!$ids = $request->getParameter('ids')){
  115.           $this->getUser()
  116.                ->setFlash('error', 'Devi selezionare almeno una richiesta.');
  117.           $this->redirect(array(
  118.               'module' => 'richieste',
  119.               'action' => 'index'
  120.           )); // wToDo: Serve ASSOLUTAMENTE un modo per passare a ->redirect()
  121.               //        l'indirizzo da cui si fa la request... Sennò non posso
  122.               //        integrare i batch all'interno del minibox!!
  123.       }
  124.       if (!$action = $request->getParameter('batch_action')){
  125.           $this->getUser()
  126.                ->setFlash('error', 'Devi selezionare un\'azione da compiere.');
  127.           $this->redirect(array(
  128.               'module' => 'richieste',
  129.               'action' => 'index'
  130.           )); // Vedi sopra
  131.       }
  132.       if (!method_exists($this, $method = 'execute'.ucfirst($action))){
  133.           throw new InvalidArgumentException(
  134.               sprintf(
  135.                       'Claudio e Roberto devono ancora creare il metodo "%s" per l\'azione "%s!!"',
  136.                       $method,
  137.                       $action
  138.                       )
  139.               );
  140.       }
  141.       $validatore = new sfValidatorDoctrineChoice(array(
  142.           'multiple' => true,
  143.           'model'    => 'Richiesta_preventivo'
  144.           ));
  145.       try{
  146.           // valido gli ids
  147.           $ids = $validatore->clean($ids);
  148.           // execute batch
  149.           $this->$method($request);
  150.       }
  151.       catch (sfValidatorError $e){
  152.           $this->getUser()
  153.                ->setFlash(
  154.                        'error',
  155.                        'Errore (generato probabilmente dal fatto che alcune richieste selezionate nel frattempo sono state cancellate.)'
  156.                        );
  157.       }
  158.       $this->redirect(array(
  159.               'module' => 'richieste',
  160.               'action' => 'index'
  161.           )); // Vedi sopra
  162.     }
  163.   // Sorting
  164.   protected function addSortQuery($query){
  165.     if (array(null, null) == ($sort = $this->getSort()))
  166.     {
  167.       return;
  168.     }
  169.  
  170.     if (!in_array(strtolower($sort[1]), array('asc', 'desc')))
  171.     {
  172.       $sort[1] = 'asc';
  173.     }
  174.     if (isset($sort[0])){
  175.         $query->addOrderBy($sort[0] . ' ' . $sort[1]);
  176.     }
  177.   }
  178.   protected function getSort(){
  179.     if (null !== $sort = $this->getUser()->getAttribute('richieste.sort', null))
  180.     {
  181.       return $sort;
  182.     }
  183.     return array('', 'asc');
  184.   }
  185.   protected function setSort(array $sort){
  186.     if (null !== $sort[0] && null === $sort[1])
  187.     {
  188.       $sort[1] = 'asc';
  189.     }
  190.  
  191.     $this->getUser()->setAttribute('richieste.sort', $sort);
  192.   }
  193.   // Paging
  194.   protected function setPage($pag){
  195.     $this->getUser()->setAttribute('richieste.pag', $pag);
  196.   }
  197.   protected function getPage(){
  198.     return $this->getUser()->getAttribute('richieste.pag', 1);
  199.   }
  200.   // Filtri
  201.   protected function getFilters(){
  202.     return $this->getUser()->getAttribute('richieste.filters', array());
  203.   }
  204.   protected function setFilters(array $filters){
  205.     return $this->getUser()->setAttribute('richieste.filters', $filters);
  206.   }
  207. }
Add Comment
Please, Sign In to add comment