Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * richieste actions.
- *
- * @subpackage richieste
- * @version SVN: $Id: actions.class.php 131 2011-09-05 16:12:27Z Claudio $
- */
- class richiesteActions extends sfActions
- {
- public function executeIndex(sfWebRequest $request)
- {
- // Filtri!!
- if (null === $this->filters){
- $this->filters = new Richiesta_preventivoFormFilter($this->getFilters());
- }
- $this->filters->setTableMethod('addQueryListaRichiesta');
- $q = $this->filters->buildQuery($this->getFilters());
- $aliasRichiesta = $q->getRootAlias();
- if($request->getParameter('cliente')){
- $q->addWhere($aliasRichiesta.'.id_cliente = ?', $request->getParameter('cliente'));
- }
- elseif($request->getParameter('sessione')){
- $q->addWhere($aliasRichiesta.'.id_sessione_vendita = ?', $request->getParameter('sessione'));
- }
- // Controllo dell'ordinamento
- if ($request->getParameter('ordinamento')){
- $this->setSort(array(
- $request->getParameter('ordinamento'),
- $request->getParameter('tipo_ordinamento'))
- );
- }
- $this->addSortQuery($q);
- $this->sort = $this->getSort();
- // Pager...
- $this->pgRichieste = new sfDoctrinePager(
- 'Richiesta_preventivo',
- sfConfig::get('app_numero_righe_per_lista')
- );
- if ($request->getParameter('pag')){
- $this->setPage($request->getParameter('pag', $this->getPage()));
- }
- }
- public function executeShow(sfWebRequest $request)
- {
- $this->richiesta_preventivo = Doctrine_Core::getTable('Richiesta_preventivo')
- ->find(array($request->getParameter('id')));
- $this->forward404Unless($this->richiesta_preventivo);
- }
- public function executeNew(sfWebRequest $request)
- {
- $this->form = new Richiesta_preventivoForm();
- }
- public function executeCreate(sfWebRequest $request)
- {
- $this->forward404Unless($request->isMethod(sfRequest::POST));
- $this->form = new Richiesta_preventivoForm();
- $this->processForm($request, $this->form);
- $this->setTemplate('new');
- }
- public function executeEdit(sfWebRequest $request)
- {
- $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')));
- $this->form = new Richiesta_preventivoForm($richiesta_preventivo);
- }
- public function executeUpdate(sfWebRequest $request)
- {
- $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
- $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')));
- $this->form = new Richiesta_preventivoForm($richiesta_preventivo);
- $this->processForm($request, $this->form);
- $this->setTemplate('edit');
- }
- public function executeDelete(sfWebRequest $request)
- {
- $request->checkCSRFProtection();
- $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')));
- $richiesta_preventivo->delete();
- $this->redirect('richieste/index');
- }
- protected function processForm(sfWebRequest $request, sfForm $form)
- {
- $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
- if ($form->isValid())
- {
- $richiesta_preventivo = $form->save();
- $this->redirect('richieste/edit?id='.$richiesta_preventivo->getId());
- }
- }
- // wToDo: Da qui in poi vorrei generalizzare a tutti gli altri moduli...
- public function executeBatch(sfWebRequest $request){
- $request->checkCSRFProtection();
- if (!$ids = $request->getParameter('ids')){
- $this->getUser()
- ->setFlash('error', 'Devi selezionare almeno una richiesta.');
- $this->redirect(array(
- 'module' => 'richieste',
- 'action' => 'index'
- )); // wToDo: Serve ASSOLUTAMENTE un modo per passare a ->redirect()
- // l'indirizzo da cui si fa la request... Sennò non posso
- // integrare i batch all'interno del minibox!!
- }
- if (!$action = $request->getParameter('batch_action')){
- $this->getUser()
- ->setFlash('error', 'Devi selezionare un\'azione da compiere.');
- $this->redirect(array(
- 'module' => 'richieste',
- 'action' => 'index'
- )); // Vedi sopra
- }
- if (!method_exists($this, $method = 'execute'.ucfirst($action))){
- throw new InvalidArgumentException(
- sprintf(
- 'Claudio e Roberto devono ancora creare il metodo "%s" per l\'azione "%s!!"',
- $method,
- $action
- )
- );
- }
- $validatore = new sfValidatorDoctrineChoice(array(
- 'multiple' => true,
- 'model' => 'Richiesta_preventivo'
- ));
- try{
- // valido gli ids
- $ids = $validatore->clean($ids);
- // execute batch
- $this->$method($request);
- }
- catch (sfValidatorError $e){
- $this->getUser()
- ->setFlash(
- 'error',
- 'Errore (generato probabilmente dal fatto che alcune richieste selezionate nel frattempo sono state cancellate.)'
- );
- }
- $this->redirect(array(
- 'module' => 'richieste',
- 'action' => 'index'
- )); // Vedi sopra
- }
- // Sorting
- protected function addSortQuery($query){
- if (array(null, null) == ($sort = $this->getSort()))
- {
- return;
- }
- if (!in_array(strtolower($sort[1]), array('asc', 'desc')))
- {
- $sort[1] = 'asc';
- }
- if (isset($sort[0])){
- $query->addOrderBy($sort[0] . ' ' . $sort[1]);
- }
- }
- protected function getSort(){
- if (null !== $sort = $this->getUser()->getAttribute('richieste.sort', null))
- {
- return $sort;
- }
- return array('', 'asc');
- }
- protected function setSort(array $sort){
- if (null !== $sort[0] && null === $sort[1])
- {
- $sort[1] = 'asc';
- }
- $this->getUser()->setAttribute('richieste.sort', $sort);
- }
- // Paging
- protected function setPage($pag){
- $this->getUser()->setAttribute('richieste.pag', $pag);
- }
- protected function getPage(){
- return $this->getUser()->getAttribute('richieste.pag', 1);
- }
- // Filtri
- protected function getFilters(){
- return $this->getUser()->getAttribute('richieste.filters', array());
- }
- protected function setFilters(array $filters){
- return $this->getUser()->setAttribute('richieste.filters', $filters);
- }
- }
Add Comment
Please, Sign In to add comment