public function addTool($tool)
 {
     // Define a new object and try to add and save new value passed
     $newTool = new CollectingTools();
     $newTool->setTool($tool);
     try {
         $newTool->save();
     } catch (Doctrine_Exception $ne) {
         // Return database error if occurs
         $e = new DarwinPgErrorParser($ne);
         return $e->getMessage();
     }
     // Return id of new record saved
     return $newTool->getId();
 }
Example #2
0
 /**
  * Action executed when trying to add a new tool in collecting tools table
  * Returns id if successfull and error message if not
  * @param sfWebRequest $request Request coming from browser
  */
 public function executeAddTool(sfWebRequest $request)
 {
     if ($this->getUser()->isA(Users::REGISTERED_USER)) {
         $this->forwardToSecureAction();
     }
     // Test well action is Ajaxly called and that value parameter exist
     $this->forward404Unless($request->isMethod(sfRequest::POST) && $request->isXmlHttpRequest() && $request->hasParameter('value'));
     try {
         // Define a new object and try to add and save new value passed
         $newTool = new CollectingTools();
         $newTool->setTool($request->getParameter('value'));
         $newTool->save();
         // Return id of new record saved
         $response = $newTool->getId();
     } catch (Doctrine_Exception $ne) {
         // Return database error if occurs
         $e = new DarwinPgErrorParser($ne);
         $response = $e->getMessage();
     }
     return $this->renderText($response);
 }
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(4, new lime_output_color());
$tools = Doctrine::getTable('CollectingTools')->fetchTools();
$t->is(count($tools), 2, '"2" Tools defined by default');
$t->info('Insert a new value');
$newVal = new CollectingTools();
$newVal->setTool('Bourouche');
$newVal->save();
$newValIndex = $newVal->getId();
$tools = Doctrine::getTable('CollectingTools')->fetchTools();
$t->is(count($tools), 3, '"3" Tools defined now');
$t->is($tools[$newValIndex], 'Bourouche', 'The new value inserted is well "Bourouche"');
$iteration = 1;
foreach ($tools as $value) {
    if ($iteration == 2) {
        $t->is($value, 'Bourouche', 'The new value ("Bourouche") is well the "second" one to be in the list brought by "fetchTools"');
        break;
    }
    $iteration++;
}