OutputTranslations.php
[Pman.Cms] / OutputTranslations.php
1 <?php
2
3 require_once 'Pman.php'; /// needed as we might not be included from pman..
4
5 class Pman_Cms_OutputTranslations extends Pman
6 {
7     var $lang = 'en';
8     
9     function get($lang)
10     {
11         $this->getTranslations($lang);
12     }
13     
14     function getTranslations($lang)
15     {
16         if(!empty($lang)){
17             $this->lang = $lang;
18         }
19         
20         $ret = array();
21         $template = DB_DataObject::factory('cms_template');
22         $template_ids = $template->fetchAll('id');
23         
24         print_R($template_ids);exit;
25         
26         foreach ($template->fetchAll() as $tmpl){
27             $base = DB_DataObject::factory('cms_templatestr');
28             $base->setFrom(array(
29                 'template_id' => $tmpl->id,
30                 'lang' => '',
31                 'active' => 1
32             ));
33             $base = $base->fetchAll('id');
34             
35             $translation = DB_DataObject::factory('cms_templatestr');
36             $translation->autoJoin();
37             $translation->setFrom(array(
38                 'template_id' => $tmpl->id,
39                 'lang' => $this->lang,
40                 'active' => 1
41             ));
42             $translation->whereAddIn('cms_templatestr.src_id', $base, 'int');
43             
44             foreach ($translation->fetchAll() as $t){
45                 if(!isset($ret[$tmpl->template])){
46                     $ret[$tmpl->template] = array();
47                 }
48                 
49                 $ret[$tmpl->template][$t->src_id_mdsum] = (empty($t->txt)) ? $t->src_id_txt : $t->txt;
50             }
51         }
52         
53         $ret = array();
54         $template = DB_DataObject::factory('cms_template');
55     
56         foreach ($template->fetchAll() as $tmpl){
57             $base = DB_DataObject::factory('cms_templatestr');
58             $base->setFrom(array(
59                 'template_id' => $tmpl->id,
60                 'lang' => '',
61                 'active' => 1
62             ));
63             $base = $base->fetchAll('id');
64             
65             $translation = DB_DataObject::factory('cms_templatestr');
66             $translation->autoJoin();
67             $translation->setFrom(array(
68                 'template_id' => $tmpl->id,
69                 'lang' => $this->lang,
70                 'active' => 1
71             ));
72             $translation->whereAddIn('cms_templatestr.src_id', $base, 'int');
73             
74             foreach ($translation->fetchAll() as $t){
75                 if(!isset($ret[$tmpl->template])){
76                     $ret[$tmpl->template] = array();
77                 }
78                 
79                 $ret[$tmpl->template][$t->src_id_mdsum] = (empty($t->txt)) ? $t->src_id_txt : $t->txt;
80             }
81         }
82         
83         return $ret;
84     }
85     
86 }