/** * @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; }
/** * @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; } } } }
/** * Render Column * * @param DOMNode $column * @param SingleRow $row * @param EditListField $field */ public function renderColumn($column, $row, $field) { switch ($field->fieldType) { case EditListFieldType::TEXT: XmlUtil::AddTextNode($column, $row->getField($field->fieldData)); break; case EditListFieldType::IMAGE: // XmlnukeImage $xmi $xmi = new XmlnukeImage($row->getField($field->fieldData)); $xmi->generateObject($column); break; case EditListFieldType::LOOKUP: $value = $row->getField($field->fieldData); if ($value == "") { $value = "---"; } else { $value = isset($field->arrayLookup[$value]) ? $field->arrayLookup[$value] : "[{$value} ?]"; } XmlUtil::AddTextNode($column, $value); break; case EditListFieldType::FORMATTER: $obj = $field->formatter; if (is_null($obj) || !$obj instanceof IEditListFormatter) { throw new InvalidArgumentException("The EditListFieldType::FORMATTER requires a valid IEditListFormatter class"); } else { XmlUtil::AddTextNode($column, $obj->Format($row, $field->fieldData, $row->getField($field->fieldData))); } break; default: XmlUtil::AddTextNode($column, $row->getField($field->fieldData)); break; } }
/** * * @param SingleRow $sr */ function assertSingleRow($sr, $count) { $this->assertEquals($sr->getField("category"), $this->arrTest[$count]["category"]); $this->assertEquals($sr->getField("title"), $this->arrTest[$count]["title"]); $this->assertEquals($sr->getField("lang"), $this->arrTest[$count]["lang"]); }
/** * Override Specific implementation of setPropValue to SingleRow * * @param SingleRow $obj * @param string $propName * @param string $value */ protected function setPropValue($obj, $propName, $value) { $obj->setField($propName, $value); }
/** * Append one row to AnyDataset. * @param SingleRow $sr * @return void */ public function appendRow($sr = null) { if (!is_null($sr)) { if ($sr instanceof SingleRow) { $this->_collection[] = $sr; $sr->acceptChanges(); } elseif (is_array($sr)) { $this->_collection[] = new SingleRow($sr); } else { throw new InvalidArgumentException("You must pass an array or a SingleRow object"); } } else { $sr = new SingleRow(); $this->_collection[] = $sr; $sr->acceptChanges(); } $this->_currentRow = count($this->_collection) - 1; }
/** * * @param SingleRow $singleRow * @return string */ private function evalString(SingleRow $singleRow) { $result = array(); $finalResult = false; $pos = 0; $result[0] = true; foreach ($this->_filters as $filter) { if ($filter[0] == ")" || $filter[0] == " or ") { $finalResult |= $result[$pos]; $result[++$pos] = true; } $name = $filter[1]; $relation = $filter[2]; $value = $filter[3]; $field = $singleRow->getField($name); if (!is_array($field)) { $field = array($field); } foreach ($field as $valueparam) { switch ($relation) { case Relation::EQUAL: $result[$pos] &= $valueparam == $value; break; case Relation::GREATER_THAN: $result[$pos] &= $valueparam > $value; break; case Relation::LESS_THAN: $result[$pos] &= $valueparam < $value; break; case Relation::GREATER_OR_EQUAL_THAN: $result[$pos] &= $valueparam >= $value; break; case Relation::LESS_OR_EQUAL_THAN: $result[$pos] &= $valueparam <= $value; break; case Relation::NOT_EQUAL: $result[$pos] &= $valueparam != $value; break; case Relation::STARTS_WITH: $result[$pos] &= strpos($valueparam, $value) === 0; break; case Relation::CONTAINS: $result[$pos] &= strpos($valueparam, $value) !== false; break; } } } $finalResult |= $result[$pos]; return $finalResult; }
/** * * @param SingleRow $sr */ function assertSingleRow($sr, $count) { $this->assertEquals($sr->getField("name"), $this->arrTest[$count]["name"]); $this->assertEquals($sr->getField("surname"), $this->arrTest[$count]["surname"]); $this->assertEquals($sr->getField("age"), $this->arrTest[$count]["age"]); }
/** * @todo Fix Property Pattern */ public function testConstructor_PropertyPattern() { $model = new \AnyDataSet\Tests\Sample\ModelPropertyPattern(); $model->setIdModel(10); $model->setClientName("Testing"); $sr = new SingleRow($model); // Important to note: // The property is _Id_Model, but is changed to "set/get IdModel" throught PropertyName // Because this, the field is Id_Model instead IdModel $this->assertEquals(10, $sr->getField("IdModel")); $this->assertEquals("Testing", $sr->getField("ClientName")); }
/** * 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)); } }
/** * * @param SingleRow $sr */ function assertSingleRow($sr, $count) { $this->assertEquals($sr->getField("field1"), $count); $this->assertEquals($sr->getField("field2"), "STRING{$count}"); $this->assertEquals($sr->getField("field3"), "VALUE{$count}"); }
/** * * @param SingleRow $sr */ function assertField($sr, $line, $field, $value) { $this->assertEquals($sr->getField($field), $value); //, "At line $line field '$field' I expected '" . $value . "' but I got '" . $sr->getField($field) . "'"); }