static function GetObject($tablename, $id, $pkname = "id") { $single = !is_array($id); settype($id, 'array'); $k = array(); foreach ($id as $oid) { $k[] = self::GetObjectKey($tablename, $oid, $pkname); } $r = Util_Array::AssColumn(self::Get($k), $pkname); return $single ? array_pop($r) : $r; }
public function buildArrayTreeNodes() { $datas = Util_Array::AssColumn($this->data, $this->keyName); $nodes = array(); foreach ($datas as $data) { $key = $data[$this->keyName]; $parentKey = $data[$this->parentName]; $node = $nodes[$key]; if (!$node) { $nodes[$key] = $node = new UtilArrayTreeNode(); } $node->data = $data; if ($parentKey && $datas[$parentKey]) { $parentNode = $nodes[$parentKey]; if (!$parentNode) { $nodes[$parentKey] = $parentNode = new UtilArrayTreeNode(); } $parentNode->subNode[$key] = $node; } } return $nodes; }
public function fetch($id, $key = null) { if (!$id) { return false; } $key = $key ? $key : $this->primaryKey; if (Util_Array::IsArrayValue($id)) { $id = array_values($id); $one = false; } else { $one = true; } $condition = array($key => $id); $option = array('one' => $one); $result = DB::LimitQuery($this->tableName, $condition, $option, $this->readDB); if (!$result) { $this->error = DB::$error; } if (is_array($id) && $this->primaryKey) { $result = Util_Array::AssColumn($result, $this->primaryKey); } return $result; }