| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
require_once 'lib/model/om/BaseAnswer.php'; |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
class Answer extends BaseAnswer |
|---|
| 18 |
{ |
|---|
| 19 |
public function getRelevancyUpPercent() |
|---|
| 20 |
{ |
|---|
| 21 |
$total = $this->getRelevancyUp() + $this->getRelevancyDown(); |
|---|
| 22 |
|
|---|
| 23 |
return $total ? sprintf('%.0f', $this->getRelevancyUp() * 100 / $total) : 0; |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
public function getRelevancyDownPercent() |
|---|
| 27 |
{ |
|---|
| 28 |
$total = $this->getRelevancyUp() + $this->getRelevancyDown(); |
|---|
| 29 |
|
|---|
| 30 |
return $total ? sprintf('%.0f', $this->getRelevancyDown() * 100 / $total) : 0; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
public function setBody($v) |
|---|
| 34 |
{ |
|---|
| 35 |
parent::setBody($v); |
|---|
| 36 |
|
|---|
| 37 |
require_once('markdown.php'); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$v = htmlentities($v, ENT_QUOTES, 'UTF-8'); |
|---|
| 41 |
|
|---|
| 42 |
$this->setHtmlBody(markdown($v)); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
public function deleteReports() |
|---|
| 46 |
{ |
|---|
| 47 |
$reports = $this->getReportAnswers(); |
|---|
| 48 |
foreach ($reports as $report) |
|---|
| 49 |
{ |
|---|
| 50 |
$report->delete(); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
$this->setReports(0); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
public function deleteSpam($moderator) |
|---|
| 57 |
{ |
|---|
| 58 |
$con = Propel::getConnection(); |
|---|
| 59 |
try |
|---|
| 60 |
{ |
|---|
| 61 |
$con->begin(); |
|---|
| 62 |
|
|---|
| 63 |
$user = $this->getUser(); |
|---|
| 64 |
if ($user->getNickname() != 'anonymous') |
|---|
| 65 |
{ |
|---|
| 66 |
$user->setDeletions($user->getDeletions() + 1); |
|---|
| 67 |
$user->save(); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
$this->delete(); |
|---|
| 71 |
|
|---|
| 72 |
$con->commit(); |
|---|
| 73 |
|
|---|
| 74 |
$log = 'moderator "%s" deleted answer "%s" for question "%s" (%s)'; |
|---|
| 75 |
$log = sprintf($log, $moderator->getNickname(), $this->getId(), $this->getQuestion()->getTitle(), substr($this->getBody(), 0, 50)); |
|---|
| 76 |
sfContext::getInstance()->getLogger()->warning($log); |
|---|
| 77 |
} |
|---|
| 78 |
catch (PropelException $e) |
|---|
| 79 |
{ |
|---|
| 80 |
$con->rollback(); |
|---|
| 81 |
throw $e; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
public function getFeedAuthorEmail() |
|---|
| 86 |
{ |
|---|
| 87 |
return ''; |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
?> |
|---|