From 6632351bc0ab9dd46d998ccd9e6ffc80e320eeb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Skej=C3=B8?= Date: Mon, 25 Aug 2008 07:58:04 +0200 Subject: [PATCH] Added a getRowFromValue() --- AOOSModel.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/AOOSModel.php b/AOOSModel.php index 3e8abe4..8c83845 100644 --- a/AOOSModel.php +++ b/AOOSModel.php @@ -376,6 +376,20 @@ class AOOSModel extends AOOSModule } /** + * Is the given value a column index? + * @param string $name + * @return bool + */ + public function inColumnIndex($name) + { + if (!in_array($name, $this->columnIndex())) + { + return false; + } + return true; + } + + /** * Appends given values to the end of the model. The number of keys is the number of values added. * @param array $values Values to append. * @param auto|null $key If "auto" is given the column ids we be determined automatically. If not the function expects the array to be a hash which keys is used as column indexes(default). @@ -412,6 +426,39 @@ class AOOSModel extends AOOSModule } /** + * Returns the row index in which the given field has the given value. Returns false if none is found + * @param string $name Field name + * @param string $value Field value + * @return int|false + */ + public function getRowFromValue($name, $value) + { + if (!$this->inColumnIndex($name)) + { + throw new AOOSException($this->core(), $this->tr("not_in_column_index"), "", true, 2); + return false; + } + + $c = $this->getColumn($name); + $r = null; + for($i = 0; $i < count($c); $i++) + { + if ($c[$i] == $value) + { + $r = $i; + } + } + + if ($r === null) + { + throw new AOOSException($this->core(), $this->tr("value_not_in_row"), "", true, 2); + return false; + } + + return $r; + } + + /** * When set to true all data is escaped. Escaping is done in the data() call, which means *all* data is escaped, not only newly added data. * Default is true. * @param bool $state Should data be escaped or not? -- 2.11.4.GIT