protected function doSave($con) { if (null === $con) { $con = $this->getConnection(); } $pollid = $this->getValue('poll_id'); // creating a new answer $answer = new aPollAnswer(); $answer->setPollId($pollid); $answer->setRemoteAddress($this->getValue('remote_address')); $answer->setCulture($this->getValue('culture')); $answer->setIsNew(true); $answer->save(); $aid = $answer->getId(); // recovering all fields that must be saved in the DB $answer_fields = new Doctrine_Collection('aPollAnswerField'); $fields_to_save = $this->getFieldsToSave(); if (null === $fields_to_save) { throw new sfException('To save this form, you must define which fields must be saved using setFieldsToSave()'); } // for each field, we create a new aPollAnswerField, which is linked to a aPollAnswer // (and obviously to the poll) foreach ($fields_to_save as $field) { $v = $this->getValue($field); if (is_null($v) || '' === $v) { continue; } $af = new aPollAnswerField(); $af->setPollId($pollid); $af->setAnswerId($aid); $af->setName($field); if (is_array($v)) { $v = serialize($v); } $af->setValue($v); $answer_fields->add($af); } try { // Once all fields set, we save all of them if (count($answer_fields)) { $answer_fields->save(); } } catch (Exception $e) { $answer->delete(); throw $e; } return $answer; }
static function sendNotificationEmail($name, sfMailer $mailer, aPollPoll $poll, aPollAnswer $answer) { if (!self::getSendNotification($name)) { return false; } sfContext::getInstance()->getConfiguration()->loadHelpers('Partial'); $from = self::isUserOrEmail(self::getNotificationEmailFrom($name), true); $to = self::isUserOrEmail(self::getNotificationEmailTo($name), true); if (is_null($to)) { throw new sfException('No destination email defined. Cannot send a notification.'); } $form_name = aPollToolkit::getPollFormName($poll->getType()); $arguments = array('poll' => $poll, 'poll_form' => new $form_name($answer->getFieldsAsArray()), 'answer' => $answer); $message = $mailer->compose($from, $to); //$message->setContentType("text/html"); $message->setSubject(get_partial(self::getNotificationEmailTitlePartial($name), $arguments)); $body = get_partial(self::getNotificationEmailBodyPartial($name), $arguments); $message->addPart(self::createPlainTextBody($body), 'text/plain'); $message->addPart(self::createHtmlBody($poll->getType(), $body), 'text/html'); $mailer->send($message); return true; }