Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

TranslationProject.php

Go to the documentation of this file.
00001 <?
00002 /***************************************************************************
00003  *   Copyright (C) 2005 by Ferenc Veres   *
00004  *   lion@netngine.hu   *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00020  ***************************************************************************/
00021 
00032 class TranslationProject
00033 {
00034         private $ProjectID;     
00035         private $ParentID;      
00036         private $Name;          
00037         private $LocaleID;      
00038         private $Skeleton;      
00039         private $Document;      
00040         private $LastSeen;      
00042         public static $LocaleIDCache; 
00050         public function __construct($loadByID = 0)
00051         {
00052                 if($loadByID != 0)
00053                 {
00054                         $this->LoadByID($loadByID);
00055                 }
00056         }
00057 
00064         public static function InitLocaleIDCache()
00065         {
00066                 $DB =& GetDbConn();
00067                 $Tables =& GetTables();
00068                 
00069                 $rs = $DB->Execute("SELECT ID, Name FROM ".$Tables["Locales"]." ORDER BY Name");
00070                 while($row = $rs->FetchRow()) 
00071                 {
00072                         TranslationProject::$LocaleIDCache[$row["Name"]] = $row["ID"];
00073                 }
00074         }
00075         
00076         private function Clear()
00077         {
00078                 unset($this->ProjectID);
00079                 unset($this->ParentID);
00080                 unset($this->Name);
00081                 unset($this->LocaleID);
00082                 unset($this->Skeleton);
00083                 unset($this->Document);
00084                 unset($this->lastSeen);
00085         }
00086 
00087         private function NameCollision()
00088         {
00089                 $DB =& GetDbConn();
00090                 $Tables =& GetTables();
00091 
00092                 $old = $DB->GetOne("SELECT ID FROM ".$Tables["Projects"]." WHERE ParentID = ? AND Name = ? AND LocaleID = ?", array($this->ParentID, $this->Name, $this->LocaleID));
00093                 if($old)
00094                 {
00095                         return true;
00096                 }
00097                 else
00098                 {
00099                         return false;
00100                 }
00101 
00102         }
00103 
00115         public function CreateRootProject($name, $localeID)
00116         {
00117                 return $this->CreateProject(0, $name, $localeID);
00118         }
00119 
00135         public function CreateProject($parentID, $name, $localeID, $document = '', $skeleton = '')
00136         {
00137                 $this->Clear();
00138                 
00139                 $this->ParentID = $parentID;
00140                 $this->Name = $name;
00141                 $this->LocaleID = $localeID;
00142                 $this->Document = $document;
00143                 $this->Skeleton = $skeleton;
00144                 $this->LastSeen = time();
00145                 
00146                 // Project with this name already exists in this Parent?
00147                 if($this->NameCollision())
00148                 {
00149                         $this->Clear();
00150                         throw new Exception("Project with this name already exists, same location.");
00151                 }
00152         }
00153 
00163         public function Save()
00164         {
00165                 $DB =& GetDbConn();
00166                 $Tables =& GetTables();
00167                 
00168                 // Is this an already saved project?
00169                 if(isset($this->ProjectID))
00170                 {
00171                         // Already saved (or a loaded) project, UPDATE in database
00172                         
00173                         $ok = $DB->Execute("UPDATE ".$Tables["Projects"]." SET ParentID = ?, Name = ?, LocaleID = ?, OrigDoc = ?, Skeleton = ?, LastSeen = now() WHERE ID = ?", array($this->ParentID, $this->Name, $this->LocaleID, $this->Document, $this->Skeleton, $this->ProjectID));
00174                 }
00175                 else
00176                 {
00177                         // New project, INSERT into database
00178                         
00179                         // Project with this name already exists in this Parent?
00180                         if($this->NameCollision())
00181                         {
00182                                 throw new Exception("Project with this name already exists, same location.");
00183                         }
00184                         
00185                         $ok = $DB->Execute("INSERT INTO ".$Tables["Projects"]." (ParentID, Name, LocaleID, OrigDoc, Skeleton, LastSeen) VALUES (?,?,?,?,?, now())", array($this->ParentID, $this->Name, $this->LocaleID, $this->Document, $this->Skeleton));
00186 
00187                         // Get new ID
00188                         if(!$DB->Insert_ID())
00189                         {
00190                                 throw new Exception("DB Error: Insert_ID not supported.");
00191                         }
00192                         $this->ProjectID = $DB->Insert_ID();
00193                 }
00194 
00195                 return $this->ProjectID;
00196         }
00197 
00206         public function LoadRoot($name, $localeID)
00207         {
00208                 return $this->Load(0, $name, $localeID);
00209         }
00210 
00220         public function Load($parentID, $name, $localeID)
00221         {
00222                 $DB =& GetDbConn();
00223                 $Tables =& GetTables();
00224                 
00225                 $rs = $DB->Execute("SELECT ID, ParentID, Name, LocaleID, Skeleton, OrigDoc, TIMESTAMP(LastSeen) as LastSeen FROM ".$Tables["Projects"]." WHERE ParentID = ? AND Name = ? AND LocaleID = ?", array($parentID, $name, $localeID));
00226 
00227                 $retVal = $this->LoadRecordSetEntry($rs);
00228                 $rs->Close();
00229 
00230                 return $retVal;
00231         }
00232 
00243         public function LoadFromRecordset($recordSet)
00244         {
00245                 return $this->LoadRecordSetEntry($recordSet);
00246         }
00247 
00255         public function LoadByID($projectID)
00256         {
00257                 $DB =& GetDbConn();
00258                 $Tables =& GetTables();
00259 
00260                 $rs = $DB->Execute("SELECT ID, ParentID, Name, LocaleID, Skeleton, OrigDoc, TIMESTAMP(LastSeen) as LastSeen FROM ".$Tables["Projects"]." WHERE ID = ?", array($projectID));
00261                 
00262                 $retVal = $this->LoadRecordSetEntry($rs);
00263                 $rs->Close();
00264                 
00265                 return $retVal;
00266 
00267         }
00268 
00277         private function LoadRecordSetEntry($rs)
00278         {
00279                 $this->Clear();
00280                 
00281                 if($row = $rs->FetchRow())
00282                 {
00283                         $this->ProjectID = $row["ID"];
00284                         $this->ParentID = $row["ParentID"];
00285                         $this->Name = $row["Name"];
00286                         $this->LocaleID = $row["LocaleID"];
00287                         $this->Skeleton = $row["Skeleton"];
00288                         $this->Document = $row["OrigDoc"];
00289                         $this->LastSeen = $row["LastSeen"];
00290                         return true;
00291                 }
00292                 else
00293                 {
00294                         return false;
00295                 }
00296         }
00297 
00298         /* SET METHODS */
00299 
00306         public function SetName($name)
00307         {
00308                 if(!$name)
00309                 {
00310                         throw new Exception("Cannot set Project Name to emtpy.");
00311                 }
00312                 $this->Name = $name;
00313         }
00314         
00321         public function SetSkeleton($skeleton)
00322         {
00323                 $this->Skeleton = $skeleton;
00324         }
00325 
00332         public function SetDocument($document)
00333         {
00334                 $this->Document = $document;
00335         }
00336 
00337 
00338         /* GET METHODS */
00339         
00345         public function GetName()
00346         {
00347                 if(!isset($this->Name))
00348                 {
00349                         throw new Exception("Uninitialized project, cannot get Name.");
00350                 }
00351                 return $this->Name;
00352         }
00353         
00359         public function GetID()
00360         {
00361                 if(!isset($this->Name))
00362                 {
00363                         throw new Exception("Uninitialized project, cannot get ID.");
00364                 }
00365                 return $this->ProjectID;
00366         }
00367 
00373         public function GetParentID()
00374         {
00375                 if(!isset($this->Name))
00376                 {
00377                         throw new Exception("Uninitialized project, cannot get Parent ID.");
00378                 }
00379                 return $this->ParentID;
00380         }
00381 
00387         public function GetLocaleID()
00388         {
00389                 if(!isset($this->Name))
00390                 {
00391                         throw new Exception("Uninitialized project, cannot get Locale ID.");
00392                 }
00393                 return $this->LocaleID;
00394         }
00395 
00401         public function GetSkeleton()
00402         {
00403                 if(!isset($this->Name))
00404                 {
00405                         throw new Exception("Uninitialized project, cannot get Skeleton.");
00406                 }
00407                 return $this->Skeleton;
00408         }
00409         
00415         public function GetDocument()
00416         {
00417                 if(!isset($this->Name))
00418                 {
00419                         throw new Exception("Uninitialized project, cannot get Document.");
00420                 }
00421                 return $this->Document;
00422         }
00423 
00431         public function GetLastSeen()
00432         {
00433                 if(!isset($this->Name))
00434                 {
00435                         throw new Exception("Uninitialized project, cannot get LastSeen.");
00436                 }
00437                 return $this->LastSeen;
00438         }
00439 
00440 }
00441 
00442 ?>

Generated on Sat Apr 22 16:49:53 2006 for XarayaTranslationMemory by  doxygen 1.4.4