00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 include_once('TranslationProject.php');
00022
00030 class ProjectIterator implements Iterator, RecursiveIterator
00031 {
00032 private $LocaleID;
00033 private $ParentID;
00035 private $CurrentProject;
00037 public static $ProjectList;
00038 public static $ProjectChildren;
00046 public function __construct($parentID, $localeID)
00047 {
00048 $DB =& GetDbConn();
00049 $Tables =& GetTables();
00050
00051 $this->LocaleID = $localeID;
00052 $this->ParentID = $parentID;
00053
00054
00055 if(empty(self::$ProjectList[$this->LocaleID]))
00056 {
00057 $rs = $DB->Execute("SELECT ID, ParentID, Name, LocaleID, Skeleton, OrigDoc, TIMESTAMP(LastSeen) as LastSeen FROM ".$Tables["Projects"]." WHERE LocaleID = ? ORDER BY Name", $this->LocaleID);
00058 $haveMore = true;
00059
00060 while($haveMore)
00061 {
00062 $proj = new TranslationProject();
00063
00064 if(($haveMore = $proj->LoadFromRecordSet($rs)))
00065 {
00066 self::$ProjectList[$this->LocaleID][$proj->GetID()] = $proj;
00067 self::$ProjectChildren[$this->LocaleID][$proj->GetParentID()][] = $proj->GetID();
00068 }
00069 }
00070 $rs->Close();
00071 }
00072
00073 if(empty(self::$ProjectList[$this->LocaleID]))
00074 {
00075 throw new Exception("There are no projects for Language ID: ".$this->LocaleID.". Please import before using.");
00076 }
00077
00078
00079 $this->rewind();
00080 }
00081
00082
00083
00087 public function rewind()
00088 {
00089
00090 if(!empty(self::$ProjectChildren[$this->LocaleID][$this->ParentID][0]))
00091 {
00092 $this->CurrentID = self::$ProjectChildren[$this->LocaleID][$this->ParentID][0];
00093 }
00094 else
00095 {
00096 $this->CurrentID = 0;
00097 }
00098 }
00102 public function hasMore()
00103 {
00104
00105 $siblings = self::$ProjectChildren[$this->LocaleID][
00106 self::$ProjectList[$this->LocaleID][$this->CurrentID]->GetParentID()
00107 ];
00108
00109
00110 $takeNext = false;
00111 $foundMore = false;
00112 foreach($siblings as $pid)
00113 {
00114
00115 if($takeNext)
00116 {
00117 $foundMore = true;
00118 break;
00119 }
00120
00121
00122 if($pid == $this->CurrentID)
00123 {
00124 $takeNext = true;
00125 }
00126 }
00127 return $foundMore;
00128 }
00132 public function key()
00133 {
00134 return $this->CurrentID;
00135 }
00139 public function current()
00140 {
00141 return self::$ProjectList[$this->LocaleID][$this->CurrentID];
00142 }
00146 public function next()
00147 {
00148
00149 $siblings = self::$ProjectChildren[$this->LocaleID][
00150 self::$ProjectList[$this->LocaleID][$this->CurrentID]->GetParentID()
00151 ];
00152
00153
00154 $lastID = $this->CurrentID;
00155 $this->CurrentID = 0;
00156
00157
00158 $takeNext = false;
00159 foreach($siblings as $pid)
00160 {
00161
00162 if($takeNext)
00163 {
00164 $this->CurrentID = $pid;
00165 break;
00166 }
00167
00168
00169 if($pid == $lastID)
00170 {
00171 $takeNext = true;
00172 }
00173 }
00174 }
00178 public function valid()
00179 {
00180 return $this->CurrentID != 0;
00181 }
00182
00183
00184
00188 public function hasChildren()
00189 {
00190
00191 return !empty(self::$ProjectChildren[$this->LocaleID][$this->CurrentID]);
00192 }
00193
00197 public function getChildren()
00198 {
00199
00200 return new ProjectIterator($this->CurrentID, $this->LocaleID);
00201 }
00202 }
00203 ?>