function getValue($filtered = true) { $values = explode($this->separator, $this->_value); $tags = array(); foreach ($values as &$value) { $value = trim($value); if ($value != '') { if ($this->_filter && $filtered) { $value = call_user_func($this->_filter, $value, $this->getName()); } $tags[] = $value; } } $ids = array(); foreach ($tags as $tag) { $ds = new TableReader('blog_tag'); $id = $ds->select('blog_tag_id')->where('tag', $tag)->fetchScalar(); if (!$id) { $writer = new TableWriter('blog_tag'); $id = $writer->insert(array('tag' => $tag, 'url_tag' => TextHelper::urlize($tag))); } $ids[] = $id; } return $ids; }
protected function deleteRows($conditions, &$files_to_delete = array()) { if (!$conditions) { return true; } $rows = $this->getAllRows($conditions); $files_to_delete = $this->getFilesToDelete($rows, $files_to_delete); /** * Creates an array with all the the primary_key => value pairs of all the rows that have to be deleted. */ $row_conditions = array(); foreach ($rows as $row) { $values = array(); foreach ($this->primary as $primary) { $values[$primary] = $row[$primary]; } $row_conditions[] = $values; } $children = $this->schema->getChildren($this->name); foreach ($children as $child) { if (!isset($child['key'][2]) || is_null($child['key'][2])) { } elseif ($child['key'][2] == self::ON_DELETE_RESTRICT) { $reader = new TableReader($child['table']->getName()); foreach ($row_conditions as $row_condition) { foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $reader->where($column, $value); } } } if ($reader->count()) { return false; } } elseif ($child['key'][2] == self::ON_DELETE_CASCADE) { foreach ($row_conditions as $row_condition) { $child_conditions = array(); foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $child_conditions[$column] = $value; } } if (!$child['table']->deleteRows($child_conditions, $files_to_delete)) { return false; } } } elseif ($child['key'][2] == self::ON_DELETE_SET_NULL) { //Not implemented yet } } foreach ($this->getKeys() as $column => $key) { if ($key[2] == AdminTable::ON_DELETE_CASCADE_REVERSED) { $table = $this->schema->getTable($key[0]); foreach ($rows as $row) { if (!$table->deleteRows(array($key[1] => $row[$key[1]]), $files_to_delete)) { return false; } } } } $ds = new TableWriter($this->name); foreach ($conditions as $column => $value) { $ds->where($column, $value); } return $ds->delete(); }