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