fix #7754 - download and upload for translations
[Pman.Core] / DataObjects / Core_templatestr.php
1 <?php
2 /**
3  * Table Definition for core_templatestr
4  *
5  *
6  * The idea here is that it contains all the strings in the templates with a language '' (empty)
7  * , it then generates a matching set of strings
8  * 
9  */
10 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
11
12 class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject 
13 {
14     ###START_AUTOCODE
15     /* the code below is auto generated do not remove the above tag */
16
17     public $__table = 'core_templatestr';         // table name
18     public $id;                              // int(11)  not_null primary_key auto_increment
19     public $template_id;                           // string(64)  not_null
20     public $txt;                    // datetime(19)  multiple_key binary
21     public $updated;                        // blob(65535)  blob
22     public $src_id;                          // int(11)  not_null
23     public $lang;    // text  NOT NULL;
24     public $mdsum;    // text  NOT NULL;
25     public $active;
26     public $on_table;
27     public $on_id;
28     public $on_col;
29  
30     /* the code above is auto generated do not remove the tag below */
31     ###END_AUTOCODE
32     
33     function beforeInsert($q,$roo)
34     {
35         if(!empty($q['_rescan'])){
36             $this->syncLang($q['_rescan']);
37             $roo->jok('OK');
38         }
39     }
40     
41     
42     function applyFilters($q, $au, $roo)
43     {
44         if (!empty($q['_tree'])) {
45             $this->applyFiltersTree($q,$roo);
46         }
47         
48         if(!empty($q['on_table']) && (empty($q['template_id']) || !is_numeric($q['template_id']))){
49             $this->template_id = 0;
50              $this->whereAdd("  join_src_id_id.txt != ''");
51         }
52         if (!empty($q['_search_txt'])) {
53             $str = $this->escape($q['_search_txt']);
54             $this->whereAdd("core_templatestr.txt like '%{$str}%' OR join_src_id_id.txt like '%{$str}%'");
55             
56         }
57     }
58     function translateTableCol($obj, $col, $lang)
59     {
60         $cts = DB_DataObject::factory('core_templatestr');
61         $cts->lang = $lang;
62         $cts->on_table = $obj->tableName();
63         $cts->on_id = $obj->pid();
64         $cc = clone($cts);
65         if(!$cts->find(true)){
66             return $obj->$col;
67         }
68         
69         
70         if(empty($cts->txt)){
71             return $obj->$col;
72         }
73             
74         return $cts->txt;
75     }
76     /**
77      *
78      * insert the origanal table text
79      * 
80      * @param type $roo
81      * @param type $obj
82      * @param type $chg
83      * @return type 
84      */
85     function onTableChange($roo, $obj, $chg)
86     {
87         
88         $ff = HTML_FlexyFramework::get()->Pman_Core;
89             
90         if(empty($ff['DataObjects_Core_templatestr']['tables'])){
91             return;
92         }
93         $tn = $obj->tableName();
94         if(empty($ff['DataObjects_Core_templatestr']['tables'][$tn])){
95             return;
96         }
97         $cols = $ff['DataObjects_Core_templatestr']['tables'][$tn];
98         
99         $deactive = array();
100         $active = array();
101
102         foreach($cols as $c) {
103             $x = $this->factory($this->tableName());
104             $x->on_id = $obj->pid();
105             $x->on_table = $tn;
106             $x->on_col = $c;
107             $x->lang = ''; /// eg. base language..
108             $up = $x->find(true);
109
110             if($up) {
111                 // deactivate empty words
112                 if(empty($obj->$c)) {
113                     $deactive[] = $x->id;
114                 }
115                 // activate non-empty words
116                 else {
117                     $active[] = $x->id;
118                 }
119
120                 if($x->txt == $obj->$c) {
121                     continue; // skip when no change
122                 }
123             }
124             else {
125                 // skip empty words
126                 if(empty($obj->$c)) {
127                     continue;
128                 }
129             }
130
131             $x->active = 1;
132             $x->src_id = 0;
133             $x->txt = $obj->$c;
134             $x->mdsum = md5($obj->$c);
135             $x->template_id = 0;
136             $x->updated = date('Y-m-d H:i:s', strtotime("NOW"));
137             $up ? $x->update() : $x->insert();
138         }
139
140         if(count($deactive)) {
141             $t = DB_DataObject::factory($this->tableName());
142             // deactivate the parent data
143             $t->query("UPDATE core_templatestr
144                       SET active = 0 WHERE id in (" . implode(',' ,$deactive) . ")
145                      ");
146
147             // deactivate the child data
148             $t->query("UPDATE  core_templatestr 
149             SET active = 0
150             WHERE
151                 src_id IN (". implode(',' ,$deactive) . ")
152                 AND
153                 lang != ''
154              ");
155         }
156
157         if(count($active)) {
158             $t = DB_DataObject::factory($this->tableName());
159             // activate the aprent data
160             $t->query("UPDATE core_templatestr
161                 SET active = 1 WHERE id in (" . implode(',' ,$active) . ")
162             ");
163             // deactivate the child data
164             $t->query("UPDATE  core_templatestr 
165             SET active = 1
166               WHERE
167                  src_id IN (". implode(',' ,$active) . ")
168                 AND
169                 lang != ''
170             ");
171         }
172         
173         
174     }
175     
176     
177     function applyFiltersTree($q,$roo)
178     {
179         if (empty($q['node'])) {
180             $roo->jerr("invalid node");
181         }
182         switch(true) {
183             
184             case ($q['node'] == 'transtree'):
185             case ($q['node'] == 'langlist'):
186                // DB_DataObject::debugLevel(1);
187                 $x = DB_Dataobject::Factory($this->tableName());
188                 $x->selectAdd();
189                 $x->selectAdd('distinct(lang) as lang');
190                 
191                 $x->selectAdd("i18n_translate('l', lang, 'en') as lang_name");
192                 $x->whereAdd("lang != ''");
193                 $ret= array();
194                 foreach( $x->fetchAll() as $l) {
195                     $ret[] = array(
196                         'text'=>$l->lang_name,
197                         'id' => $q['node'] == 'langlist' ? $l->lang : 'lang:'.$l->lang ,
198                         'language' => true
199                     );
200                 }
201                 if (empty($ret)) {
202                     $ret[] = array(
203                         'text'=>'English',
204                         'id' => 'lang:en',
205                         'language' => true
206                     );
207                 }
208                 $roo->jdata($ret);
209             
210             case  preg_match('/^lang:/', $q['node']):
211                 
212                 $lang = preg_replace('/^lang:/', '', $q['node']);
213                 $ret= array();  
214                 $x = DB_DataObject::factory('core_templatestr');
215                 $x->autoJoin();
216                 $x->selectAdd();
217                 $x->selectAdd('distinct(view_name) as view_name');
218                 $x->lang = $lang;
219                 $x->whereAdd('join_template_id_id.is_deleted = 0');
220                 $x->orderBy('view_name DESC');
221                 $x->find();
222                 while($x->fetch()) {
223                     $ret[] = array( 
224                         'text'=> $x->view_name,
225                         'id' => 'view:'. $lang .':'.  $x->view_name,
226                         'leaf' => false
227                     );
228                 }
229
230                 $ff = HTML_FlexyFramework::get()->Pman_Core;
231
232                 if(!empty($ff['DataObjects_Core_templatestr']['tables'])){
233                     foreach($ff['DataObjects_Core_templatestr']['tables'] as $table=>$v){
234                         $ret[] = array(
235                             'text'=> $table,
236                             'on_table' => $table,
237                             'id' => 'table:'. $lang .':'. $table,
238                             'leaf' => true
239                         );
240                     }
241                 }
242                 
243                  
244                 $roo->jdata($ret);
245                 
246                 break;
247                 
248                 
249             case  preg_match('/^view:/', $q['node']):
250                 
251                
252                 $bits= explode(":",preg_replace('/^view:/', '', $q['node']));
253                 
254                 $x = DB_DataObject::factory($this->tableName());
255                 $x->autoJoin();
256                 $x->selectAdd();
257                 $x->selectAdd('distinct(core_templatestr.template_id) as template_id');
258                 $x->whereAdd("join_template_id_id.view_name = '{$x->escape($bits[1])}'");
259                 $x->whereAdd('join_template_id_id.is_deleted = 0');
260                 $x->lang = $bits[0];
261                 $ids = $x->fetchAll('template_id');
262                 
263                 $ret= array();
264                 //add the table type lists
265                 /*
266                 $ff = HTML_FlexyFramework::get()->Pman_Core;
267                 
268                 
269 //                $x->orderBy('template ASC');
270 //                $x->whereAdd("lang != ''");
271                 */
272                 //below are old code
273                 $xx = DB_Dataobject::Factory('core_template');
274                 $xx->whereAddIn('id', $ids, 'int');
275                 $xx->selectAdd();
276                 $xx->selectAdd("
277                                
278                     id, concat(  template) as template_name
279                 ");
280                 $xx->orderBy('template_name ASC');
281                 
282                 foreach( $xx->fetchAll('id', 'template_name') as $l =>$n) {
283                     $ret[] = array(
284                         'text'=> $n,
285                         'id' => $l,
286                         'leaf' => true
287                     );
288                 }
289                 
290                 $roo->jdata($ret);
291                  break;
292         }
293                 
294         
295         
296     }
297     
298     
299     /**
300      *
301      * 
302      * @param object $tmpl core_template data object
303      * @param array $words array of words 
304      */ 
305     function syncTemplateWords($tmpl, $keyvalue = false)
306     {
307         
308         $words = $tmpl->words;
309         // mapping for template : 
310         //tablename => $n (templatename) 
311         //tableid => $k (key value)
312         //colname => $n (templatename) 
313         // mdsum => md5(sum)
314         //
315         //print_r($words);exit;
316         // grab original
317         $tt = DB_DataObject::factory($this->tableName());
318  
319         $t = clone($tt);
320         $t->template_id = $tmpl->id;
321         $t->whereAdd("lang = ''");
322         
323         
324         // we have a situation where old md sums where created..
325         
326         
327         
328         $cur = $t->fetchAll('mdsum', 'id'); 
329         
330         
331         
332         
333         
334         
335         
336         // now loop through current..
337         $cwords = array();// not in used??
338         $active = array();
339 //        echo "sync Template Words... \n";
340 //        print_r($words);
341         
342         foreach($words as $k=>$v) {
343             
344             
345             $v = trim($v);
346
347             // skip empty words
348             if(empty($v)) {
349                 continue;
350             }
351             
352             $md = $keyvalue ? $k : md5($v);
353             
354             // check to see if there are more that one versions of that md5
355             
356             
357             if (!isset($cur[$md])) {
358                 // create a record for it..
359                 $t = DB_DataObject::factory($this->tableName());
360                 $t->setFrom(array(
361                     'txt' => $v,
362                     'lang' => '',// by default should a english 
363                     'updated' => date('Y-m-d H:i:s', strtotime("YESTERDAY")),
364                     'template_id'=>$tmpl->id,
365                     'mdsum' => $md,
366                     'src_id' => 0,
367                     'active' => 1,
368                 ));
369                 $active[] =  $t->insert();
370                 continue;
371             }  
372             $cur[$md] = $this->checkDupes($tmpl->id, '',  $cur[$md] , $md);
373             
374             $active[] = $cur[$md];
375             
376             // we have it already? - 
377             $t = DB_DataObject::factory($this->tableName());
378             $t->query("UPDATE {$this->tableName()}
379                         SET active= 1
380                         WHERE
381                         id = ".$cur[$md]);
382             unset($cur[$md]);
383             
384         }
385         // delete unused.
386         
387         
388         
389
390         $deactive = array();
391         if (count(array_values($cur))) {// de-active unused
392
393             $t = DB_DataObject::factory($this->tableName());
394 //            echo "de-active current?? \n";
395 //            print_r($cur);
396 //            echo "\n";
397             $deactive = array_values($cur);
398             $t->query("UPDATE core_templatestr
399                       SET active = 0 WHERE id in (" . implode(',' ,$deactive) . ")
400                      ");
401         }
402         
403         // delete all the items that are not relivant.
404         // clear orphaned chidren - it just blanks out the src id, so they can be used as suggestions..?
405         // this does not help - as it just puts random strings in there.. - with no reference to the original text..
406         $t = DB_DataObject::factory($this->tableName());
407     
408         // this will active the child data
409         if (empty($active)) {// set the active array to empty
410             $active = array(-1);
411         }
412         $t->query("UPDATE  core_templatestr 
413                 SET active = 1
414                   WHERE
415                      src_id IN (". implode(',' ,$active) . ")
416                     AND
417                     template_id = {$tmpl->id}
418         ");
419         //deactive the child data
420         if (empty($deactive)) {
421             $deactive = array(-1);
422         }
423         $t->query("UPDATE  core_templatestr 
424                 SET active = 0
425                   WHERE
426                     src_id IN (". implode(',' ,$deactive) . ")
427                     AND
428                     template_id = {$tmpl->id}
429                     AND
430                     lang != ''
431         ");
432     }
433     
434     function checkDupes($tid, $lang, $id, $mdsum) {
435         
436         $t = DB_DataObject::factory($this->tableName());
437         $t->template_id = $tid;
438         $t->mdsum = $mdsum;
439         $t->whereAdd("lang = '{$lang}'");
440         if ($t->count() == 1) {
441             return $id; // only got one ... no issues..
442         }
443         
444         //echo "GOT DUPES : $id, $lang, $id , $mdsum\n";
445         
446         //DB_DataObject::debugLevel(1);
447         // find out if any of them have got translations.
448         $ids = $t->fetchAll('id');
449         
450         
451         $t = DB_DataObject::factory($this->tableName());
452         $t->whereAddIn('src_id', $ids, 'int');
453         $t->whereAdd("txt != ''");
454         $t->orderBy('updated DESC');
455         if ($t->count()) {
456             $t->limit(1);
457             // do any translations exist?
458             $t->find(true);
459             $id = $t->src_id;
460         }
461         
462         
463         // delete all the others...
464         $t = DB_DataObject::factory($this->tableName());
465         $t->whereAddIn('src_id', $ids, 'int');
466         $t->whereAdd("src_id != $id");
467         $t->find();
468         while($t->fetch()) {
469             $tt = clone($t);
470             $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
471             $tt->update($t);
472         }
473         $t = DB_DataObject::factory($this->tableName());
474         $t->whereAddIn('id', $ids, 'int');
475         $t->whereAdd("id != $id");
476         $t->find();
477         while($t->fetch()) {
478             $tt = clone($t);
479             $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
480             $tt->update($t);
481         }
482         // this is done by calling code 
483         //$t = DB_DataObject::factory($this->tableName());
484         //$t->query("update core_templatestr set active= 1 where src_id = $id");
485         
486         
487         
488        //exit;
489         return $id;
490     
491                
492          
493     }
494     
495     function syncLang($lang)
496     {
497         // bugs with our old code...
498 //        die('in?');
499         $tn = $this->tableName();
500         $t = DB_DataObject::factory($tn);
501         $t->query("DELETE FROM {$tn} WHERE lang !='' AND src_id = 0 AND on_table  = ''");
502         
503         // find all the id's from lang that have not been generated..
504         
505         
506         static $id_tmp = false;
507         
508         if ($id_tmp == false) {
509             //find the origanal 
510             $t = DB_DataObject::factory($tn);
511             $t->whereAdd("lang = ''");
512             $t->active = 1;
513             
514             //old code, this did not support the on_table
515     //        $id_tmp = $t->fetchAll('id','template_id');
516     //        $ids = array_keys($id_tmp);
517             $id_tmp = array();
518             //new code for support the sync tables 
519             foreach($t->fetchAll() as $ori){
520                 $id_tmp[$ori->id] = $ori;
521             }
522         }
523         $ids = array_keys($id_tmp);
524         
525         // matching by language:
526         $t = DB_DataObject::factory($tn);
527         $t->whereAddIn('src_id', $ids , 'int');
528         $t->lang = $lang;
529         //$t->active = 1;
530         $got = $t->fetchAll('src_id');
531         $missing = array_diff($ids, $got);
532         
533         if (empty($missing)) {
534             return;
535         }
536         $t = DB_DataObject::factory($tn);
537         $q = "CREATE TEMPORARY TABLE core_templatestr_insert SELECT
538             id as src_id,
539             '' as txt,
540             '$lang' as lang,
541             NOW() as updated,
542             template_id,
543             on_table,
544             on_id,
545             on_col,
546             1 as active
547             FROM core_templatestr
548             WHERE
549             id IN (". implode(',', $missing) . ")
550         ";
551         //echo $q; exit;
552         DB_DataObject::factory($tn)->query($q);
553         $q = "INSERT INTO $tn (src_id, txt, lang, updated, template_id, on_table,on_id, on_col, active) SELECT * FROM core_templatestr_insert";
554         DB_DataObject::factory($tn)->query($q);
555         $q = "DROP TEMPORARY TABLE core_templatestr_insert";
556         DB_DataObject::factory($tn)->query($q);
557             
558       
559         
560     }
561     
562     // called from flexy to translate a string.
563     
564     
565     function translateFlexyString($flexy, $string)
566     {
567          $debug = false;;
568         //if (!empty($_REQUEST['_debug'])) { $debug= true; }
569         
570         // using $flexy->currentTemplate -> find the template we are looking at..
571         // then find the string for $flexy->options['locale']
572         //DB_DataObject::debugLevel(1);
573         if ($debug) { var_dump($string); }
574         
575         static $cache = array(); // cache of templates..
576         
577         $ff = HTML_FlexyFramework::get();
578         $view_name = isset($ff->Pman_Core['view_name']) ? $ff->Pman_Core['view_name'] : false;
579         if (empty($view_name)) {
580             $pg = HTML_FlexyFramework::get()->page;
581             if (isset($pg->templateViewName)) {
582                 $view_name = $pg->templateViewName;
583             }
584             
585         }
586         
587         
588         
589         if ($debug) { var_dump(array('view_name'=> $view_name)); }
590         
591         $tempdir = '';
592         foreach($flexy->options['templateDir'] as $td) {
593             if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
594                 $tempdir = $td;
595                 break;
596             }
597         }
598         
599         
600         $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
601         
602          
603         if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
604             if ($debug) { echo "from cache no match - $string\n"; }
605             return $string;
606         }
607         
608         if (!isset($cache[$tmpname])) {
609                 
610             
611             
612             $tmpl = DB_DataObject::factory('core_template');
613             if ($view_name !== false) {
614                 $tmpl->view_name = $view_name;
615             }
616             if(!$tmpl->get('template', $tmpname)){
617                 // strip of site prefix if set...
618                  
619                 $tmpl = DB_DataObject::factory('core_template');
620                 if(!$tmpl->get('template', $tmpname)){
621                     //var_dump("no template? {$tmpname} or {$relpath}" );
622                     $cache[$tmpname] = false;
623                     if ($debug) { echo "no template found - no match - $string\n"; }
624                     return $string;
625                 }
626             }
627             $cache[$tmpname] = $tmpl;
628         } else {
629             $tmpl = $cache[$tmpname] ;
630         }
631         
632         
633     
634         //get original template id
635         /*
636         $orig = DB_DataObject::factory($this->tableName());
637         $orig->lang = '';
638         $orig->template_id = $tmpl->id;
639         $orig->active = 1;
640         
641         $cache[$tmpname]->words = 
642         
643         if(!$orig->get( 'mdsum' , md5(trim($string)))){
644              //var_dump('no text? '. $string);
645             if ($debug) { echo "no original string found tplid: {$tmpl->id}\n"; }
646             return false;
647         }
648         */
649         
650         if (empty($cache[$tmpname]->translations)) {
651         
652             //find out the text by language
653             //DB_DataObject::DebugLevel(1);
654             $x = DB_DataObject::factory($this->tableName());
655             $x->lang = $flexy->options['locale'];
656             $x->template_id = $tmpl->id;
657             $x->autoJoin();
658             $cache[$tmpname]->translations = $x->fetchAll('src_id_mdsum', 'txt');
659             if (empty($cache[$tmpname]->translations)) {
660                 $cache[$tmpname]->translations = true;
661             }
662             //var_Dump($cache[$tmpname]->translations);
663         }
664         
665         
666         if ($cache[$tmpname]->translations === true) {
667             return $string;
668         }
669         //var_dump("Checking: " . md5(trim($string)));
670         
671         if (!empty($cache[$tmpname]->translations [md5(trim($string))])){
672            // var_dump("RETURNING: ". $cache[$tmpname]->translations [md5(trim($string))]);
673             return $cache[$tmpname]->translations [md5(trim($string))];
674         }
675         return $string;
676         
677     }
678     
679     
680     function translateChanged($flexy)
681     {
682         
683         $date = $this->lastUpdated($flexy);
684         if ($date === false) {
685             return false;
686         }
687         $utime = file_exists($flexy->compiledTemplate) ?  filemtime( $flexy->compiledTemplate) : 0;
688         return strtotime($date) >  $utime;
689     }
690     
691     // determine if a complied template need recompling
692     
693     function lastUpdated($flexy)
694     {
695         //return true;
696         // var_dump('check changed?');
697         //DB_DataObject::debugLevel(1);
698         //var_Dump(array($flexy->options['templateDir'][0], $flexy->currentTemplate));
699         
700         //var_dump($flexy->compiledTemplate);
701         $utime = file_exists($flexy->compiledTemplate) ?  filemtime( $flexy->compiledTemplate) : 0;
702         
703        
704         static $cache = array(); // cache of templates..
705         
706         $ff = HTML_FlexyFramework::get();
707         $view_name = isset($ff->Pman_Core['view_name']) ? $ff->Pman_Core['view_name'] : false;
708         
709         // find which of the template directories was actually used for the template.
710         
711         $tempdir = '';
712         foreach($flexy->options['templateDir'] as $td) {
713             if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
714                 $tempdir = $td;
715                 break;
716             }
717         }
718         
719         
720         $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
721         
722         // we do not have any record of this template..
723         if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
724             return false;
725         }
726         
727         if (!isset($cache[$tmpname])) {
728                 
729             
730             
731             $tmpl = DB_DataObject::factory('core_template');
732             if ($view_name !== false) {
733                 $tmpl->view_name = $view_name;
734             }
735             if(!$tmpl->get('template', $tmpname)){
736                 // strip of site prefix if set...
737                  
738                 $tmpl = DB_DataObject::factory('core_template');
739                 if(!$tmpl->get('template', $tmpname)){
740                     //var_dump("no template? {$tmpname} or {$relpath}" );
741                     $cache[$tmpname] = false;
742                     return false;
743                 }
744             }
745             $cache[$tmpname] = $tmpl;
746         } else {
747             $tmpl = $cache[$tmpname] ;
748         }
749           
750          
751         
752         $x = DB_DataObject::factory($this->tableName());
753         $x->lang = $flexy->options['locale'];
754         $x->active = 1;
755         $x->template_id = $tmpl->id;
756         //$x->whereAdd("updated > '". date('Y-m-d H:i:s', $utime)."'");
757         if ($x->count() < 1) {
758             return false; // we don't have any record of it.
759         }
760         $x->selectAdd();
761         $x->selectAdd('max(updated) as max_updated');
762         $x->find(true);
763         return $x->max_updated;
764         
765         
766     }
767     
768     function toRooArray($req) {
769         $ret = $this->toArray();
770
771         if (empty($req['csvCols'])) {
772             return $ret;
773         }
774
775         // for download
776
777         // translations for table columns
778         if(!empty($ret['on_table']) && !empty($ret['on_id']) && !empty($ret['on_col'])) {
779             $ret['template_id_view_name'] = 'database';
780             $ret['template_id_template'] = $ret['on_table'] . ':' . $ret['on_col'];
781         }
782
783         return $ret;
784     }
785
786     function postListFilter($ar, $au, $req)
787     {
788         if (empty($req['csvCols'])) {
789             return $ar;
790         }
791
792         // for download
793
794         $ret = array();
795
796         foreach($ar as $v) {
797             if(empty($v['on_table']) || empty($v['on_id']) || empty($v['on_col'])) {
798                 $ret[] = $v;
799                 continue;
800             }
801
802             // translations for table columns
803             // avoid duplicate (same src_id_mdsum, same on_table, same on_col, but different on_id)
804
805             $key = $v['on_table'] . ':' . $v['on_col'] . ':' . $v['src_id_mdsum'];
806
807             if(!empty($ret[$key])) {
808                 continue;
809             }
810
811             $ret[$key] = $v;
812         }
813
814         $ret = array_values($ret);
815         
816         return $ret;
817
818     }
819 }