Exemple #1
0
 /**
  * @covers ByJG\AnyDataset\Repository\SingleRow::getFieldArray
  * @todo   Implement testGetFieldArray().
  */
 public function testGetFieldArray()
 {
     $this->fill();
     $this->assertEquals(array(10, 20, 30), $this->object->getFieldArray('field1'));
     $this->assertEquals(array(40), $this->object->getFieldArray('field2'));
     $this->object->addField('field3', '');
     $this->object->acceptChanges();
     $this->assertEquals(array(), $this->object->getFieldArray('field3'));
 }
Exemple #2
0
 /**
  * @access public
  * @return SingleRow
  * @throws IteratorException
  */
 public function moveNext()
 {
     if (!$this->hasNext()) {
         throw new IteratorException("No more records. Did you used hasNext() before moveNext()?");
     }
     $node = $this->_nodeList->item($this->_current++);
     $sr = new SingleRow();
     foreach ($this->_colNodes as $key => $colxpath) {
         $nodecol = XmlUtil::selectNodes($node, $colxpath, $this->_registerNS);
         if (is_null($nodecol)) {
             $sr->addField(strtolower($key), "");
         } else {
             foreach ($nodecol as $col) {
                 $sr->addField(strtolower($key), $col->nodeValue);
             }
         }
     }
     return $sr;
 }
Exemple #3
0
 /**
  * @return bool
  */
 public function hasNext()
 {
     if (count($this->_rowBuffer) >= SQLRelayIterator::RECORD_BUFFER) {
         return true;
     } else {
         if (is_null($this->_cursor)) {
             return count($this->_rowBuffer) > 0;
         } else {
             if ($this->_currentRow < $this->count()) {
                 $sr = new SingleRow();
                 $colCount = sqlrcur_colCount($this->_cursor);
                 for ($col = 0; $col < $colCount; $col++) {
                     $fieldName = strtolower(sqlrcur_getColumnName($this->_cursor, $col));
                     $value = sqlrcur_getField($this->_cursor, $this->_currentRow, $col);
                     if (is_null($value)) {
                         $sr->addField($fieldName, "");
                     } elseif (is_object($value)) {
                         $sr->addField($fieldName, "[OBJECT]");
                     } else {
                         $value = AnyDataset::fixUTF8($value);
                         $sr->addField($fieldName, $value);
                     }
                 }
                 $this->_currentRow++;
                 // Enfileira o registo
                 array_push($this->_rowBuffer, $sr);
                 // Traz novos até encher o Buffer
                 if (count($this->_rowBuffer) < DBIterator::RECORD_BUFFER) {
                     $this->hasNext();
                 }
                 return true;
             } else {
                 sqlrcur_free($this->_cursor);
                 $this->_cursor = null;
                 return count($this->_rowBuffer) > 0;
             }
         }
     }
 }
Exemple #4
0
 /**
  * Private method used to read and populate anydataset class from specified file
  * @param string $filepath Path and Filename to be read
  * @return null
  */
 private function createFrom($filepath)
 {
     if (file_exists($filepath)) {
         $anyDataSet = XmlUtil::createXmlDocumentFromFile($filepath);
         $this->_collection = array();
         $rows = $anyDataSet->getElementsByTagName("row");
         foreach ($rows as $row) {
             $sr = new SingleRow();
             $fields = $row->getElementsByTagName("field");
             foreach ($fields as $field) {
                 $attr = $field->attributes->getNamedItem("name");
                 if (!is_null($attr)) {
                     $sr->addField($attr->nodeValue, $field->nodeValue);
                 } else {
                     throw new \InvalidArgumentException('Malformed anydataset file ' . basename($filepath));
                 }
             }
             $sr->acceptChanges();
             $this->_collection[] = $sr;
         }
         $this->_currentRow = sizeof($this->_collection) - 1;
     }
 }
Exemple #5
0
 /**
  * Return all custom's fields from this user
  *
  * @param SingleRow $userRow
  */
 protected function setCustomFieldsInUser($userRow)
 {
     if ($this->getCustomTable()->table == "") {
         return;
     }
     $userId = $userRow->getField($this->getUserTable()->id);
     $sql = $this->_sqlHelper->createSafeSQL($this->sqlSetCustomFieldsInUser(), array("@@Table" => $this->getCustomTable()->table, "@@Id" => $this->getUserTable()->id));
     $param = array('id' => $userId);
     $it = $this->_db->getIterator($sql, $param);
     while ($it->hasNext()) {
         $sr = $it->moveNext();
         $userRow->addField($sr->getField($this->getCustomTable()->name), $sr->getField($this->getCustomTable()->value));
     }
 }