forked from spapali/Blue-Economics
/
Responses.php
62 lines (54 loc) · 2.14 KB
/
Responses.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
use Base\Responses as BaseResponses;
class Responses extends BaseResponses
{
/**
* @param \Propel\Runtime\Connection\ConnectionInterface $conn
* @return bool|void
*/
public function preInsert(\Propel\Runtime\Connection\ConnectionInterface $conn = null)
{
$this->setCreated(time());
return true;
}
/**
* notify user who posted question about response
*/
public function postSave(\Propel\Runtime\Connection\ConnectionInterface $conn = null)
{
$this->updateQuestionState($conn);
$this->notifyUser($conn);
}
private function updateQuestionState($conn)
{
$state = new \ExpertQuestionState();
$state->setExperts(ExpertsQuery::create()->findOneByUsername($this->getExpert()));
$state->setQuestionId($this->getQuestionId());
$state->setIsResponded(true);
$state->setIsRead(true);
$state->save();
}
private function notifyUser($conn = null)
{
//TODO: Make this a more general function. For now only email supported.
//TODO: Complete/cleanup email setup and execution; This should probably be config driven
/*
$mailer = new PHPMailer();
$question = QuestionsQuery::create($conn)->findOneById($this->getQuestionId());
$mailer->addAddress($question->getSubmitter());
$mailer->Subject = 'Answer to your Question: ' . $question->getQuestion();
$mailer->setFrom($this->getExpert());
$loader = new Twig_Loader_Filesystem(__DIR__ . '/../templates/');
$twig = new Twig_Environment($loader, array(
'cache' => __DIR__ . '/../templates/cache/'
));
$context = array('expert' => $this->getExpert(), 'time' => $this->getCreated()->format(DateTime::RFC822));
$mailer->Body = $twig->loadTemplate('question-response-email.html')->render($context);
$mailer->send();
*/
$logger = \BlueEcons\FAQApi::getLogger(get_class($this));
$logger->info(sprintf("User notification will be generated for question %s. Answered by %s",
$this->getQuestionId(),
$this->getExpert()));
}
}