| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
require_once 'model/om/BaseSnippetTagPeer.php'; |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
include_once 'model/SnippetTag.php'; |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 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 |
|
|---|