Rev 1269 | Rev 1323 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1269 | Rev 1271 | ||
---|---|---|---|
Line 526... | Line 526... | ||
526 | * @throws OIDplusException |
526 | * @throws OIDplusException |
527 | */ |
527 | */ |
528 | public function getParent()/*: ?OIDplusObject*/ { |
528 | public function getParent()/*: ?OIDplusObject*/ { |
529 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
529 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
530 | $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId())); |
530 | $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId())); |
531 | if (!$res->any()) return null; |
531 | if ($res->any()) { |
532 | $row = $res->fetch_array(); |
532 | $row = $res->fetch_array(); |
533 | $parent = $row['parent']; |
533 | $parent = $row['parent']; |
534 | $obj = OIDplusObject::parse($parent); |
534 | $obj = OIDplusObject::parse($parent); |
535 | if ($obj) return $obj; |
535 | if ($obj) return $obj; |
536 | // TODO: Also implement one_up() like below |
536 | } |
537 | } else { |
537 | } else { |
538 | self::buildObjectInformationCache(); |
538 | self::buildObjectInformationCache(); |
539 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
539 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
540 | $parent = self::$object_info_cache[$this->nodeId()][self::CACHE_PARENT]; |
540 | $parent = self::$object_info_cache[$this->nodeId()][self::CACHE_PARENT]; |
541 | $obj = OIDplusObject::parse($parent); |
541 | $obj = OIDplusObject::parse($parent); |
542 | if ($obj) return $obj; |
542 | if ($obj) return $obj; |
543 | } |
543 | } |
- | 544 | } |
|
544 | 545 | ||
545 | // If this OID does not exist, the SQL query "select parent from ..." does not work. So we try to find the next possible parent using one_up() |
546 | // If this OID does not exist, the SQL query "select parent from ..." does not work. So we try to find the next possible parent using one_up() |
546 | $cur = $this->one_up(); |
547 | $cur = $this->one_up(); |
547 | if (!$cur) return null; |
548 | if (!$cur) return null; |
548 | do { |
549 | do { |
Line 551... | Line 552... | ||
551 | 552 | ||
552 | $prev = $cur; |
553 | $prev = $cur; |
553 | $cur = $cur->one_up(); |
554 | $cur = $cur->one_up(); |
554 | if (!$cur) return null; |
555 | if (!$cur) return null; |
555 | } while ($prev->nodeId() !== $cur->nodeId()); |
556 | } while ($prev->nodeId() !== $cur->nodeId()); |
556 | } |
557 | |
557 | return null; |
558 | return null; |
558 | } |
559 | } |
559 | 560 | ||
560 | /** |
561 | /** |
561 | * @return string|null |
562 | * @return string|null |