XarayaTranslationMemory  1.6
StringIterator.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************************
3  * Copyright (C) 2005-2020 by Ferenc Veres *
4  * lion@netngine.hu *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18  ***************************************************************************/
19  include_once('TranslationString.php');
20 
28 class StringIterator implements Iterator
29 {
30  private $ProjectID;
31  private $ProjectStrings = [];
33  private $Current;
34  private $IsValid;
41  public function __construct($projectID)
42  {
43  $DB =& GetDbConn();
44  $Tables =& GetTables();
45 
46  $this->ProjectID = $projectID;
47 
48  // Fetch all strings of the project from the DB.
49  $rs = $DB->Execute("SELECT ID, Original, LocaleID, Translation, SentenceID, LastSeen, RowOrder FROM ".$Tables["Strings"]." WHERE ProjectID=? ORDER BY RowOrder", array($this->ProjectID));
50 
51  while($row = $rs->FetchRow())
52  {
53  // Add fully initializes strings to the array.
54  $this->ProjectStrings[] = new TranslationString(
55  $row["ID"],
56  $this->ProjectID,
57  $row["Original"],
58  $row["LocaleID"],
59  $row["Translation"],
60  $row["SentenceID"],
61  $row["LastSeen"],
62  $row["RowOrder"]);
63  }
64  $this->rewind();
65  }
66 
67  /* Iterator interface */
68 
72  public function rewind()
73  {
74  $this->Current = 0;
75  }
76 
80  public function hasMore()
81  {
82  return (count($this->ProjectStrings) > $this->Current);
83  }
84 
88  public function key()
89  {
90  return $this->Current;
91  }
92 
96  public function current()
97  {
98  return $this->ProjectStrings[$this->Current];
99  }
100 
104  public function next()
105  {
106  $this->Current++;
107  }
108 
112  public function valid()
113  {
114  return (count($this->ProjectStrings) > $this->Current);
115  }
116 }
& GetTables()
Definition: Common.php:71
& GetDbConn()
Definition: Common.php:61
__construct($projectID)
$DB
Definition: export.php:28