root/trunk/lib/model/SnippetTagPeer.php

Revision 2, 1.9 kB (checked in by fabien, 4 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   // include base peer class
4   require_once 'model/om/BaseSnippetTagPeer.php';
5  
6   // include object class
7   include_once 'model/SnippetTag.php';
8
9
10 /**
11  * Skeleton subclass for performing query and update operations on the 'sn_tag' table.
12  *
13  *
14  *
15  * You should add additional methods to this class to meet the
16  * application requirements.  This class will only be generated as
17  * long as it does not already exist in the output directory.
18  *
19  * @package model
20  */   
21 class SnippetTagPeer extends BaseSnippetTagPeer
22 {
23   public static function getAllWithCount($max = 100)
24   {
25     $tags = array();
26
27     $con = Propel::getConnection();
28     $query = '
29       SELECT t1.name AS tag,
30       COUNT(t1.name) AS count
31       FROM '.SnippetTagPeer::TABLE_NAME.' AS t1
32       GROUP BY t1.name
33       ORDER BY count DESC
34     ';
35
36     $stmt = $con->prepareStatement($query);
37     $stmt->setLimit($max);
38     $rs = $stmt->executeQuery();
39     $max_popularity = 0;
40     while ($rs->next())
41     {
42       $tags[$rs->getString('tag')] = $rs->getInt('count');
43     }
44
45     ksort($tags);
46
47     return $tags;
48   }
49
50   public static function getForSnippetsWithCount($snippets, $excluded_tags, $max = 100)
51   {
52     $snippet_ids = array();
53     foreach($snippets as $snippet)
54     {
55       $snippet_ids[] = $snippet->getId();
56     }
57
58     $con = Propel::getConnection();
59     $query = '
60       SELECT '.SnippetTagPeer::NAME.' AS tag,
61       COUNT('.SnippetTagPeer::NAME.') AS count
62       FROM '.SnippetTagPeer::TABLE_NAME.'
63       WHERE '.SnippetTagPeer::SNIPPET_ID.' IN ('.implode(' ,', $snippet_ids).')
64       GROUP BY '.SnippetTagPeer::NAME.'
65       ORDER BY '.SnippetTagPeer::NAME.' ASC
66     ';
67
68     $stmt = $con->prepareStatement($query);
69     $stmt->setLimit($max);
70     $rs = $stmt->executeQuery();
71
72     $tags = array();
73     while ($rs->next())
74     {
75       $tag = $rs->getString('tag');
76       if(array_search($tag, $excluded_tags) === false)
77       {
78         $tags[$tag] = $rs->getInt('count');
79       }
80     }
81
82     return $tags;
83   }
84 }
85
Note: See TracBrowser for help on using the browser.