/** * Implementation for 'POST' method for Rest API * * @param mixed $trnCategory, $trnId, $trnLang Primary key * * @return array $result Returns array within multiple records or a single record depending if * a single selection was requested passing id(s) as param */ protected function post($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate) { try { $result = array(); $obj = new Translation(); $obj->setTrnCategory($trnCategory); $obj->setTrnId($trnId); $obj->setTrnLang($trnLang); $obj->setTrnValue($trnValue); $obj->setTrnUpdateDate($trnUpdateDate); $obj->save(); } catch (Exception $e) { throw new RestException(412, $e->getMessage()); } }
/** * returns an array with * codError 0 - no error, < 0 error * rowsAffected 0,1 the number of rows affected * message message error. */ function addTranslation($category, $id, $languageId, $value) { //if exists the row in the database propel will update it, otherwise will insert. $tr = TranslationPeer::retrieveByPK($category, $id, $languageId); if (!(is_object($tr) && get_class($tr) == 'Translation')) { $tr = new Translation(); } $tr->setTrnCategory($category); $tr->setTrnId($id); $tr->setTrnLang($languageId); $tr->setTrnValue($value); $tr->setTrnUpdateDate(date('Y-m-d')); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); } else { // Something went wrong. We can now get the validationFailures and handle them. $msg = ''; $validationFailuresArray = $tr->getValidationFailures(); foreach ($validationFailuresArray as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "\n"; } return array('codError' => -100, 'rowsAffected' => 0, 'message' => $msg); } return array('codError' => 0, 'rowsAffected' => $res, 'message' => ''); //to do: uniform coderror structures for all classes }