Exemplo n.º 1
0
 /**
  * Action executed when trying to add a new method in collecting methods table
  * Returns id if successfull and error message if not
  * @param sfWebRequest $request Request coming from browser
  */
 public function executeAddMethod(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
         $newMethod = new CollectingMethods();
         $newMethod->setMethod($request->getParameter('value'));
         $newMethod->save();
         // Return id of new record saved
         $response = $newMethod->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());
$methods = Doctrine::getTable('CollectingMethods')->fetchMethods();
$t->is(count($methods), 2, '"2" Methods defined by default');
$t->info('Insert a new value');
$newVal = new CollectingMethods();
$newVal->setMethod('Intuition');
$newVal->save();
$newValIndex = $newVal->getId();
$methods = Doctrine::getTable('CollectingMethods')->fetchMethods();
$t->is(count($methods), 3, '"3" Methods defined now');
$t->is($methods[$newValIndex], 'Intuition', 'The new value inserted is well "Intuition"');
foreach ($methods as $value) {
    $t->is($value, 'Intuition', 'The new value ("Intuition") is well the "first" one to be in the list brought by "fetchMethods"');
    break;
}
Exemplo n.º 3
0
 public function addMethod($data, $staging_id)
 {
     $method = Doctrine::getTable('CollectingMethods')->checkIfMethod($data);
     if ($method) {
         $ref = $method->getId();
     } else {
         $object = new CollectingMethods();
         $object->setMethod($data);
         $object->save();
         $ref = $object->getId();
     }
     $object = new StagingMethods();
     $object->fromArray(array("staging_ref" => $staging_id, "collecting_method_ref" => $ref));
     return $object;
 }