/apps/backend/modules/mineralogy/actions/actions.class.php

https://github.com/eMerzh/Darwin · PHP · 178 lines · 150 code · 16 blank · 12 comment · 14 complexity · 0b463ba8d06cac51c4b2d54992688f47 MD5 · raw file

  1. <?php
  2. /**
  3. * mineralogy actions.
  4. *
  5. * @package darwin
  6. * @subpackage mineralogy
  7. * @author DB team <darwin-ict@naturalsciences.be>
  8. * @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
  9. */
  10. class mineralogyActions extends DarwinActions
  11. {
  12. protected $widgetCategory = 'catalogue_mineralogy_widget';
  13. protected $table = 'mineralogy';
  14. public function preExecute()
  15. {
  16. if (! strstr('view',$this->getActionName()) && ! strstr('index',$this->getActionName()) && ! strstr('searchForLimited',$this->getActionName()) && ! strstr('search',$this->getActionName()) )
  17. {
  18. if(! $this->getUser()->isAtLeast(Users::ENCODER))
  19. {
  20. $this->forwardToSecureAction();
  21. }
  22. }
  23. }
  24. public function executeChoose(sfWebRequest $request)
  25. {
  26. $name = $request->hasParameter('name')?$request->getParameter('name'):'' ;
  27. $this->setLevelAndCaller($request);
  28. $this->searchForm = new MineralogyFormFilter(array('table' => $this->table, 'level' => $this->level, 'caller_id' => $this->caller_id, 'name' => $name));
  29. $this->setLayout(false);
  30. }
  31. public function executeDelete(sfWebRequest $request)
  32. {
  33. $unit = Doctrine::getTable('Mineralogy')->find($request->getParameter('id'));
  34. $this->forward404Unless(
  35. $unit,
  36. sprintf('Object mineralogy does not exist (%s).', $request->getParameter('id'))
  37. );
  38. if(! $request->hasParameter('confirm'))
  39. {
  40. $this->number_child = Doctrine::getTable('Mineralogy')->hasChildrens('Mineralogy',$unit->getId());
  41. if($this->number_child)
  42. {
  43. $this->link_delete = 'mineralogy/delete?confirm=1&id='.$unit->getId();
  44. $this->link_cancel = 'mineralogy/edit?id='.$unit->getId();
  45. $this->setTemplate('warndelete', 'catalogue');
  46. return;
  47. }
  48. }
  49. try
  50. {
  51. $unit->delete();
  52. $this->redirect('mineralogy/index');
  53. }
  54. catch(Doctrine_Exception $ne)
  55. {
  56. $e = new DarwinPgErrorParser($ne);
  57. $error = new sfValidatorError(new savedValidator(),$e->getMessage());
  58. $this->form = new MineralogyForm($unit);
  59. $this->form->getErrorSchema()->addError($error);
  60. $this->loadWidgets();
  61. $this->no_right_col = Doctrine::getTable('Mineralogy')->testNoRightsCollections('mineral_ref',$request->getParameter('id'), $this->getUser()->getId());
  62. $this->setTemplate('edit');
  63. }
  64. }
  65. public function executeNew(sfWebRequest $request)
  66. {
  67. $mineral = new Mineralogy() ;
  68. $mineral = $this->getRecordIfDuplicate($request->getParameter('duplicate_id','0'), $mineral);
  69. if($request->hasParameter('mineralogy')) $mineral->fromArray($request->getParameter('mineralogy'));
  70. $this->form = new MineralogyForm($mineral);
  71. }
  72. public function executeCreate(sfWebRequest $request)
  73. {
  74. $this->form = new MineralogyForm();
  75. $this->processForm($request,$this->form);
  76. $this->setTemplate('new');
  77. }
  78. public function executeEdit(sfWebRequest $request)
  79. {
  80. $unit = Doctrine::getTable('Mineralogy')->find($request->getParameter('id'));
  81. $this->forward404Unless($unit,'Unit not Found');
  82. $this->no_right_col = Doctrine::getTable('Mineralogy')->testNoRightsCollections('mineral_ref',$request->getParameter('id'), $this->getUser()->getId());
  83. $this->form = new MineralogyForm($unit);
  84. $this->loadWidgets();
  85. }
  86. public function executeUpdate(sfWebRequest $request)
  87. {
  88. $unit = Doctrine::getTable('Mineralogy')->find($request->getParameter('id'));
  89. $this->forward404Unless($unit,'Unit not Found');
  90. $this->no_right_col = Doctrine::getTable('Mineralogy')->testNoRightsCollections('mineral_ref',$request->getParameter('id'), $this->getUser()->getId());
  91. $this->form = new MineralogyForm($unit);
  92. $this->processForm($request,$this->form);
  93. $this->loadWidgets();
  94. $this->setTemplate('edit');
  95. }
  96. public function executeIndex(sfWebRequest $request)
  97. {
  98. $this->setLevelAndCaller($request);
  99. $this->searchForm = new MineralogyFormFilter(array('table' => $this->table, 'level' => $this->level, 'caller_id' => $this->caller_id));
  100. }
  101. protected function processForm(sfWebRequest $request, sfForm $form)
  102. {
  103. $form->bind( $request->getParameter($form->getName()),$request->getFiles($form->getName()) );
  104. if ($form->isValid())
  105. {
  106. try{
  107. $form->save();
  108. $this->redirect('mineralogy/edit?id='.$form->getObject()->getId());
  109. }
  110. catch(Doctrine_Exception $ne)
  111. {
  112. $e = new DarwinPgErrorParser($ne);
  113. $error = new sfValidatorError(new savedValidator(),$e->getMessage());
  114. $form->getErrorSchema()->addError($error);
  115. }
  116. }
  117. }
  118. public function executeSearchFor(sfWebRequest $request)
  119. {
  120. // Forward to a 404 page if the method used is not a post
  121. $this->forward404Unless($request->isMethod('get'));
  122. // Triggers the search ID function
  123. if($request->getParameter('searchedCrit', '') !== '')
  124. {
  125. $unitId = Doctrine::getTable('Mineralogy')->findOneByCode($request->getParameter('searchedCrit'));
  126. if ($unitId)
  127. return $this->renderText($unitId->getCode());
  128. else
  129. return $this->renderText('not found');
  130. }
  131. return $this->renderText('');
  132. }
  133. public function executeSearchForLimited(sfWebRequest $request)
  134. {
  135. // Forward to a 404 page if the method used is not a post
  136. $this->forward404Unless($request->isMethod('get'));
  137. // Triggers the search ID function
  138. if($request->getParameter('q', '') !== '' && $request->getParameter('limit', '') !== '')
  139. {
  140. $codes = Doctrine::getTable('Mineralogy')->fetchByCodeLimited($request->getParameter('q'), $request->getParameter('limit'));
  141. if ($codes)
  142. {
  143. $values=array();
  144. foreach($codes as $key=>$value)
  145. {
  146. $values[$key]=$value->getCode();
  147. }
  148. return $this->renderText(implode("\n",$values));
  149. }
  150. else
  151. return $this->renderText(array(''));
  152. }
  153. return $this->renderText(array(''));
  154. }
  155. public function executeView(sfWebRequest $request)
  156. {
  157. $this->mineral = Doctrine::getTable('Mineralogy')->find($request->getParameter('id'));
  158. $this->forward404Unless($this->mineral,'Mineralogic unit not Found');
  159. $this->form = new MineralogyForm($this->mineral);
  160. $this->loadWidgets();
  161. }
  162. }