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