Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • Hooks
  • ManageBlock
  • Model
  • Module
  • SaveOperation
  • Term
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Taxonomy\Terms;
 13 
 14 use ICanBoogie\ActiveRecord;
 15 use ICanBoogie\Event;
 16 use ICanBoogie\Exception;
 17 
 18 class Hooks
 19 {
 20     static public function on_nodes_delete(Event $event)
 21     {
 22         global $core;
 23 
 24         $core->models['taxonomy.terms/nodes']->filter_by_nid($event->rc)->delete();
 25     }
 26 
 27     static public function markup_terms(array $args, \Patron\Engine $patron, $template)
 28     {
 29         global $core;
 30 
 31         if (isset($args['scope']))
 32         {
 33             throw new Exception('The "scope" parameter is deprecated, use "construtor" instead.');
 34 
 35             $args['constructor'] = $args['scope'];
 36         }
 37 
 38         $conditions = array();
 39         $conditions_args = array();
 40 
 41         $inner = ' INNER JOIN {prefix}taxonomy_terms term USING(vid)';
 42 
 43         $constructor = $args['constructor'];
 44 
 45         if ($constructor)
 46         {
 47             $inner .= ' INNER JOIN {prefix}taxonomy_vocabulary__scopes USING(vid)';
 48 
 49             $conditions[] = 'constructor = ?';
 50             $conditions_args[] = $constructor;
 51         }
 52 
 53         $vocabulary = $args['vocabulary'];
 54 
 55         if ($vocabulary)
 56         {
 57             if (is_numeric($vocabulary))
 58             {
 59                 $conditions[] = 'vid = ?';
 60                 $conditions_args[] = $vocabulary;
 61             }
 62             else
 63             {
 64                 $conditions[] = '(vocabulary = ? OR vocabularyslug = ?)';
 65                 $conditions_args[] = $vocabulary;
 66                 $conditions_args[] = $vocabulary;
 67             }
 68         }
 69 
 70         $conditions[] = '(SELECT GROUP_CONCAT(nid) FROM {prefix}taxonomy_terms__nodes tnode
 71             INNER JOIN {prefix}nodes node USING(nid)
 72             WHERE is_online = 1 AND tnode.vtid = term.vtid) IS NOT NULL';
 73 
 74 
 75         $where = $conditions ? ' WHERE ' . implode(' AND ', $conditions) : null;
 76 
 77         $model = $core->models['taxonomy.terms'];
 78 
 79         $entries = $model->query
 80         (
 81             'SELECT voc.*, term.*,
 82 
 83             (SELECT GROUP_CONCAT(nid) FROM {prefix}taxonomy_terms__nodes tnode
 84             INNER JOIN {prefix}nodes node USING(nid)
 85             WHERE is_online = 1 AND tnode.vtid = term.vtid
 86             ORDER BY tnode.weight) AS nodes_ids
 87 
 88             FROM {prefix}taxonomy_vocabulary voc' . $inner . $where . ' ORDER BY term.weight, term',
 89 
 90             $conditions_args
 91         )
 92         ->fetchAll(\PDO::FETCH_CLASS, 'Icybee\Modules\Taxonomy\Terms\Term', array($model));
 93 
 94         if ($constructor)
 95         {
 96             foreach ($entries as $entry)
 97             {
 98                 $entry->nodes_constructor = $constructor;
 99             }
100         }
101 
102         return $patron($template, $entries);
103     }
104 
105     /*
106 
107     Charge des noeuds 'complets' selon un _vocabulaire_ et/ou une _portée_.
108 
109     Parce qu'un même vocabulaire peut-être utilisé sur plusieurs modules, si 'scope' est
110     définit le constructeur du noeud doit être connu et égal à 'scope'. Pour cela il nous faut
111     joindre la table du module `system.nodes`.
112 
113     Si scope est défini c'est plus simple, parce que toutes les entrées sont chargées depuis un
114     même module.
115 
116     Si scope est défini, il faudrait peut-être modifier 'self' pour qu'il contienne les données du
117     terme. Ou alors utiliser un autre marqueur pour l'occasion... hmm ce serait peut-être le mieux.
118     <p:taxonomy:term select="" vacabulary="" scope="" />
119 
120     Les options de 'range' ne doivent pas être appliquée aux termes mais au noeud chargés dans un
121     second temps. Notamment les options d'ordre.
122 
123     */
124     static public function markup_nodes(array $args, \Patron\Engine $patron, $template)
125     {
126         global $core;
127 
128         $term = $patron->context['this'];
129         $order = $args['order'];
130 
131         if ($term instanceof \Icybee\Modules\Taxonomy\Terms\Term)
132         {
133             $constructor = $term->nodes_constructor;
134             $order = $args['order'] ? strtr($args['order'], ':', ' ') : 'FIELD (nid, ' . $term->nodes_ids . ')';
135 
136             $entries = $core->models[$constructor]->where('is_online = 1 AND nid IN(' . $term->nodes_ids . ')')->order($order)->all;
137 
138             $taxonomy_property = $term->vocabularyslug;
139             $taxonomy_property_slug = $taxonomy_property . 'slug';
140 
141             foreach ($entries as $entry)
142             {
143                 $entry->$taxonomy_property = $term;
144                 $entry->$taxonomy_property_slug = $term->termslug;
145             }
146         }
147         else
148         {
149             $term = $args['term'];
150             $vocabulary = $args['vocabulary'];
151             $constructor = $args['constructor'];
152 
153             $vocabulary = $core->models['taxonomy.vocabulary']
154             ->joins('INNER JOIN {self}__scopes USING(vid)')
155             ->joins('INNER JOIN {prefix}taxonomy_terms USING(vid)')
156             ->where('vocabularyslug = ? AND constructor = ? AND termslug = ?', $vocabulary, $constructor, $term)
157             ->one;
158 
159             $patron->context['self']['vocabulary'] = $vocabulary;
160 
161             $ids = $core->db->query
162             (
163                 'SELECT nid FROM {prefix}taxonomy_vocabulary voc
164                 INNER JOIN {prefix}taxonomy_vocabulary__scopes scopes USING(vid)
165                 INNER JOIN {prefix}taxonomy_terms term USING(vid)
166                 INNER JOIN {prefix}taxonomy_terms__nodes tnode USING(vtid)
167                 WHERE constructor = ? AND term.termslug = ?', array
168                 (
169                     $constructor, $term
170                 )
171             )
172             ->fetchAll(\PDO::FETCH_COLUMN);
173 
174             if (!$ids)
175             {
176                 return;
177             }
178 
179             $limit = $args['limit'];
180             $offset = (isset($args['page']) ? $args['page'] : 0) * $limit;
181 
182             $arr = $core->models[$constructor]
183             ->where(array('is_online' => true, 'nid' => $ids))
184             ->order($order);
185 
186             $count = $arr->count;
187             $entries = $arr->limit($offset, $limit)->all;
188 
189             $patron->context['self']['range'] = array
190             (
191                 'count' => $count,
192                 'limit' => $limit,
193                 'page' => isset($args['page']) ? $args['page'] : 0
194             );
195         }
196 
197         return $patron($template, $entries);
198     }
199 }
Autodoc API documentation generated by ApiGen 2.8.0