1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Taxonomy\Vocabulary;
13
14 class ManageBlock extends \Icybee\ManageBlock
15 {
16 17 18 19 20 21
22 protected function get_available_columns()
23 {
24 return array_merge(parent::get_available_columns(), array
25 (
26 Vocabulary::VOCABULARY => __CLASS__ . '\VocabularyColumn',
27 Vocabulary::SCOPE => __CLASS__ . '\ScopeColumn'
28 ));
29 }
30 }
31
32 namespace Icybee\Modules\Taxonomy\Vocabulary\ManageBlock;
33
34 use ICanBoogie\I18n;
35 use ICanBoogie\Module;
36
37 use Icybee\ManageBlock\Column;
38 use Icybee\ManageBlock\EditDecorator;
39
40 41 42
43 class VocabularyColumn extends Column
44 {
45 public function render_cell($record)
46 {
47 global $core;
48
49 $vid = $record->vid;
50 $terms = $core->models['taxonomy.terms']
51 ->select('term')
52 ->filter_by_vid($vid)
53 ->order('term.weight, term')
54 ->all(\PDO::FETCH_COLUMN);
55
56 $order_link = null;
57
58 if ($terms)
59 {
60 $last = array_pop($terms);
61
62 $includes = $terms
63 ? I18n\t('Including: !list and !last', array('!list' => \ICanBoogie\shorten(implode(', ', $terms), 128, 1), '!last' => $last))
64 : I18n\t('Including: !entry', array('!entry' => $last));
65
66 $order_url = \ICanBoogie\Routing\contextualize("/admin/{$this->manager->module->id}/$vid/order");
67
68 $order_link = <<<EOT
69 <a href="$order_url">Order the terms</a>
70 EOT;
71 }
72 else
73 {
74 $includes = '<em class="light">The vocabulary is empty</em>';
75 }
76
77 if ($order_link)
78 {
79 $order_link = " – {$order_link}";
80 }
81
82 return new EditDecorator($record->vocabulary, $record) . <<<EOT
83 <br /><span class="small">{$includes}{$order_link}</span>
84 EOT;
85 }
86 }
87
88 89 90
91 class ScopeColumn extends Column
92 {
93 public function render_cell($record)
94 {
95 global $core;
96
97 $scope = $this->manager->module->model('scopes')
98 ->select('constructor')
99 ->where('vid = ?', $record->vid)
100 ->all(\PDO::FETCH_COLUMN);
101
102 if ($scope)
103 {
104 $context = $core->site->path;
105
106 foreach ($scope as &$constructor)
107 {
108 $constructor = '<a href="' . $context . '/admin/' . $constructor . '">' . I18n\t($core->modules->descriptors[$constructor][Module::T_TITLE]) . '</a>';
109 }
110
111 $last = array_pop($scope);
112
113 $includes = $scope
114 ? I18n\t(':list and :last', array(':list' => \ICanBoogie\shorten(implode(', ', $scope), 128, 1), ':last' => $last))
115 : I18n\t(':one', array(':one' => $last));
116 }
117 else
118 {
119 $includes = '<em>Aucune portée</em>';
120 }
121
122 return '<span class="small">' . $includes . '</span>';
123 }
124 }