root/trunk/lib/model/SnippetComment.php

Revision 2, 1.5 kB (checked in by fabien, 6 years ago)

initial import

  • 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 'model/om/BaseSnippetComment.php';
4
5
6 /**
7  * Skeleton subclass for representing a row from the 'sn_comment' 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 SnippetComment extends BaseSnippetComment
18 {
19   public function setBody($body)
20   {
21     parent::setBody($body);
22
23     $this->setHtmlBody(myToolkit::transformToHtml($body));
24   }
25
26   public function save($con = null)
27   {
28     $con = Propel::getConnection();
29     try
30     {
31       $con->begin();
32
33       $ret = parent::save($con);
34
35       $this->updateRelatedSnippet($con);
36
37       $con->commit();
38
39       return $ret;
40     }
41     catch (Exception $e)
42     {
43       $con->rollback();
44       throw $e;
45     }
46   }
47
48   public function delete($con = null)
49   {
50     $con = Propel::getConnection();
51     try
52     {
53       $con->begin();
54
55       $ret = parent::delete($con);
56
57       $this->updateRelatedSnippet($con);
58
59       $con->commit();
60
61       return $ret;
62     }
63     catch (Exception $e)
64     {
65       $con->rollback();
66       throw $e;
67     }
68   }
69
70   // update nb_comments in snippet table
71   private function updateRelatedSnippet($con)
72   {
73     $snippet = $this->getSnippetSnippet();
74     $c = new Criteria();
75     $c->add(SnippetCommentPeer::SNIPPET_ID, $snippet->getId());
76     $snippet->setNbComments(SnippetCommentPeer::doCount($c, $con));
77     $snippet->save($con);
78   }
79 }
80
Note: See TracBrowser for help on using the browser.