1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\I18n;
13
14 use ICanBoogie\I18n;
15
16 use Brickrouge\Element;
17 use Brickrouge\Form;
18
19 use Icybee\Modules\Pages\Model as PagesModel;
20
21 22 23
24 class NodeNativeElement extends Element
25 {
26 const CONSTRUCTOR = '#node-native-constructor';
27
28 public function __construct(array $attributes=array())
29 {
30 global $core;
31
32 $site = $core->site;
33 $native = $site->native->language;
34
35 parent::__construct
36 (
37 'select', $attributes + array
38 (
39 Form::LABEL => 'nativeid',
40 Element::GROUP => 'i18n',
41 Element::DESCRIPTION => I18n\t('nativeid', array('native' => $native, 'language' => $site->language), array('scope' => 'element.description'))
42 )
43 );
44 }
45
46 protected function render_inner_html_for_select()
47 {
48 global $core;
49
50 $native = $core->site->native->language;
51 $constructor = $this[self::CONSTRUCTOR];
52 $options = array();
53
54 if ($constructor == 'pages')
55 {
56 $nodes = $core->models['pages']
57 ->select('nid, parentid, title')
58 ->filter_by_language($native)
59 ->order('weight, created')
60 ->all(\PDO::FETCH_OBJ);
61
62 $tree = PagesModel::nestNodes($nodes);
63
64 if ($tree)
65 {
66 PagesModel::setNodesDepth($tree);
67 $records = PagesModel::levelNodesById($tree);
68
69 foreach ($records as $record)
70 {
71 $options[$record->nid] = str_repeat("\xC2\xA0", $record->depth * 4) . $record->title;
72 }
73 }
74 }
75 else
76 {
77 $options = $core->models['nodes']
78 ->select('nid, title')
79 ->filter_by_constructor_and_language($constructor, $native)
80 ->order('title')
81 ->pairs;
82
83 foreach ($options as &$label)
84 {
85 $label = \ICanBoogie\shorten($label);
86 }
87
88 unset($label);
89 }
90
91 $this[self::OPTIONS] = array(null => 'none') + $options;
92
93 return parent::render_inner_html_for_select();
94 }
95 }