CMS  Version 3.9
taxonomy.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2014 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 class Taxonomy extends DataItem
40 {
41  var $table = "taxonomy";
42  var $primary_key = "taxonomy_id";
43  var $cacheLocal = true;
44 
45  var $_termCache = array();
46 
47  var $fields = array("taxonomy_id" => Number,
48  "identifier" => String,
49  "taxonomy_name" => String,
50  "description" => HTML,
51  "associated_classes" => String,
52  "published" => Boolean,
53  "enable_facet_filter" => Boolean);
54 
55  var $relations = array("Terms" => TaxonomyTerm);
56 
57  static function fromIdentifier($identifier)
58  {
59  return Query::create(Taxonomy, "WHERE identifier=:i")
60  ->bind(":i", $identifier)
61  ->executeSingle();
62  }
63 
64  function Associations($constraint = "")
65  {
66  return $this->getRelatedList(TaxonomyAssociation, "", $constraint);
67  }
68 
69  function Terms($constraint = "")
70  {
71  return $this->getRelatedList(TaxonomyTerm, "", $constraint);
72  }
73 
74  function getTerm($term)
75  {
76  return Query::create(TaxonomyTerm, "WHERE taxonomy_id=:taxonomy AND term=:term")
77  ->bind(":taxonomy", $this->taxonomy_id,
78  ":term", $term)
79  ->executeSingle();
80  }
81 
82  function countTerms()
83  {
84  return Query::create(TaxonomyTerm, "WHERE taxonomy_id=:taxonomy")
85  ->bind(":taxonomy", $this->taxonomy_id)
86  ->executeValue("COUNT(1)");
87  }
88 
90  {
91  $item = new $class;
92  $pk = $item->getPrimaryKey();
93 
94  return Query::create($class, "WHERE $pk in (SELECT id FROM taxonomy_term_association WHERE taxonomy_id=:t AND class=:c)")
95  ->bind(":t", $this->taxonomy_id,
96  ":c", $class)
97  ->execute();
98  }
99 
100  function getAssociatedTerms($item)
101  {
102  return Query::create(TaxonomyTerm, "WHERE term_id IN (SELECT term_id FROM taxonomy_term_association where taxonomy_id=:t and class=:c and id=:i)")
103  ->bind(":t", $this->taxonomy_id,
104  ":c", get_class($item),
105  ":i", $item->get($item->getPrimaryKey()))
106  ->execute();
107  }
108 
109  function getAssociatedTermIds($item)
110  {
111  $cl = get_class($item);
112 
113  if (!isset($this->_termCache[$cl]))
114  {
115  $this->_termCache[$cl] = IndexedQuery::create(TaxonomyTermAssociationSummary, "WHERE taxonomy_id=:t and class=:c", "id")
116  ->bind(":t", $this->taxonomy_id,
117  ":c", get_class($item))
118  ->execute();
119  }
120 
121  return $this->_termCache[$cl][$item->get($item->getPrimaryKey())]->term_ids;
122  }
123 
125  {
126  return Query::create(TaxonomyTerm, "WHERE term_id in (SELECT term_id FROM taxonomy_term_association where taxonomy_id=:id AND class=:cl) ORDER BY sort_order, term")
127  ->bind(":id", $this->taxonomy_id, ":cl", $class)
128  ->execute();
129  }
130 }
131 ?>
$constraint
getTerm($term)
Definition: taxonomy.inc:74
$primary_key
Definition: taxonomy.inc:42
getAssociatedTermsByClass($class)
Definition: taxonomy.inc:124
getAssociatedTermIds($item)
Definition: taxonomy.inc:109
countTerms()
Definition: taxonomy.inc:82
Associations($constraint="")
Definition: taxonomy.inc:64
getAssociatedTerms($item)
Definition: taxonomy.inc:100
Terms($constraint="")
Definition: taxonomy.inc:69
static fromIdentifier($identifier)
Definition: taxonomy.inc:57
getAssociatedItems($class)
Definition: taxonomy.inc:89
$identifier
Definition: rss.inc:37
$term
Definition: term_dialog.inc:46