root/trunk/lib/model/Answer.php

Revision 88, 1.9 kB (checked in by fabien, 2 years ago)

updated to symfony 1.0 beta 1

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 require_once 'lib/model/om/BaseAnswer.php';
4
5
6 /**
7  * Skeleton subclass for representing a row from the 'ask_answer' table.
8  *
9  *
10  *
11  * You should add additional methods to this class to meet the
12  * application requirements.  This class will only be generated as
13  * long as it does not already exist in the output directory.
14  *
15  * @package model
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     // strip all HTML tags
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 ?>
Note: See TracBrowser for help on using the browser.