root/trunk/lib/model/SnippetVote.php

Revision 2, 1.1 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/BaseSnippetVote.php';
4
5
6 /**
7  * Skeleton subclass for representing a row from the 'sn_vote' 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 SnippetVote extends BaseSnippetVote
18 {
19   public function save($con = null)
20   {
21
22     $con = Propel::getConnection();
23     try
24     {
25       $con->begin();
26
27       $ret = parent::save($con);
28
29       // update average_vote in snippet table
30       $c = new Criteria();
31       $c->add(SnippetVotePeer::SNIPPET_ID, $this->getSnippetId());
32       $votes = SnippetVotePeer::doSelect($c);
33
34       $sum_of_votes = 0;
35       foreach($votes as $vote)
36       {
37         $sum_of_votes += $vote->getVote();
38       }
39
40       $this->getSnippetSnippet()->setAverageVote($sum_of_votes / count($votes));
41       $this->getSnippetSnippet()->save($con);
42
43       $con->commit();
44
45       return $ret;
46     }
47     catch (Exception $e)
48     {
49       $con->rollback();
50       throw $e;
51     }
52   }
53 }
54
Note: See TracBrowser for help on using the browser.