Rev 969 | Rev 977 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 969 | Rev 975 | ||
---|---|---|---|
Line 157... | Line 157... | ||
157 | self::buildObjectInformationCache(); |
157 | self::buildObjectInformationCache(); |
158 | 158 | ||
159 | foreach ($ra_mails_to_check as $check_ra_mail) { |
159 | foreach ($ra_mails_to_check as $check_ra_mail) { |
160 | $out_part = array(); |
160 | $out_part = array(); |
161 | 161 | ||
162 | foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) { |
162 | foreach (self::$object_info_cache as $id => $cacheitem) { |
163 | // If the OID RA is the RA we are searching, then add the object to the choice list |
163 | // If the OID RA is the RA we are searching, then add the object to the choice list |
- | 164 | $ra_email = $cacheitem[self::CACHE_RA_EMAIL]; |
|
164 | if ($ra_email == $check_ra_mail) $out_part[] = $id; |
165 | if ($ra_email == $check_ra_mail) $out_part[] = $id; |
165 | } |
166 | } |
166 | 167 | ||
167 | foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) { |
168 | foreach (self::$object_info_cache as $id => $cacheitem) { |
- | 169 | $parent = $cacheitem[self::CACHE_PARENT]; |
|
168 | if (isset(self::$object_info_cache[$parent])) { |
170 | if (isset(self::$object_info_cache[$parent])) { |
169 | if (self::$object_info_cache[$parent][self::CACHE_RA_EMAIL] == $ra_email) { |
171 | if (self::$object_info_cache[$parent][self::CACHE_RA_EMAIL] == $ra_email) { |
170 | // if the parent has the same RA, then this OID cannot be a root => remove the element from the choice list |
172 | // if the parent has the same RA, then this OID cannot be a root => remove the element from the choice list |
171 | foreach (array_keys($out_part, $id) as $key) unset($out_part[$key]); |
173 | foreach (array_keys($out_part, $id) as $key) unset($out_part[$key]); |
172 | } |
174 | } |
Line 198... | Line 200... | ||
198 | } |
200 | } |
199 | } |
201 | } |
200 | } else { |
202 | } else { |
201 | self::buildObjectInformationCache(); |
203 | self::buildObjectInformationCache(); |
202 | 204 | ||
203 | foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) { |
205 | foreach (self::$object_info_cache as $id => $cacheitem) { |
- | 206 | $confidential = $cacheitem[self::CACHE_CONFIDENTIAL]; |
|
204 | if (!$confidential) { |
207 | if (!$confidential) { |
205 | $obj = self::parse($id); // will be NULL if the object type is not registered |
208 | $obj = self::parse($id); // will be NULL if the object type is not registered |
206 | if ($obj && (!$obj->isConfidential())) { |
209 | if ($obj && (!$obj->isConfidential())) { |
207 | $out[] = $id; |
210 | $out[] = $id; |
208 | } |
211 | } |
Line 282... | Line 285... | ||
282 | $out[] = $obj; |
285 | $out[] = $obj; |
283 | } |
286 | } |
284 | } else { |
287 | } else { |
285 | self::buildObjectInformationCache(); |
288 | self::buildObjectInformationCache(); |
286 | 289 | ||
287 | foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) { |
290 | foreach (self::$object_info_cache as $id => $cacheitem) { |
- | 291 | $parent = $cacheitem[self::CACHE_PARENT]; |
|
288 | if ($parent == $this->nodeId()) { |
292 | if ($parent == $this->nodeId()) { |
289 | $obj = self::parse($id); |
293 | $obj = self::parse($id); |
290 | if (!$obj) continue; |
294 | if (!$obj) continue; |
291 | $out[] = $obj; |
295 | $out[] = $obj; |
292 | } |
296 | } |
Line 429... | Line 433... | ||
429 | } |
433 | } |
430 | return false; |
434 | return false; |
431 | } |
435 | } |
432 | } |
436 | } |
433 | 437 | ||
- | 438 | public function getDescription() { |
|
- | 439 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
|
- | 440 | $res = OIDplus::db()->query("select description from ###objects where id = ?", array($this->nodeId())); |
|
- | 441 | if (!$res->any()) return null; |
|
- | 442 | $row = $res->fetch_array(); |
|
- | 443 | return $row['description']; |
|
- | 444 | } else { |
|
- | 445 | self::buildObjectInformationCache(); |
|
- | 446 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
|
- | 447 | return self::$object_info_cache[$this->nodeId()][self::CACHE_DESCRIPTION]; |
|
- | 448 | } |
|
- | 449 | return false; |
|
- | 450 | } |
|
- | 451 | } |
|
- | 452 | ||
- | 453 | public function getComment() { |
|
- | 454 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
|
- | 455 | $res = OIDplus::db()->query("select comment from ###objects where id = ?", array($this->nodeId())); |
|
- | 456 | if (!$res->any()) return null; |
|
- | 457 | $row = $res->fetch_array(); |
|
- | 458 | return $row['comment']; |
|
- | 459 | } else { |
|
- | 460 | self::buildObjectInformationCache(); |
|
- | 461 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
|
- | 462 | return self::$object_info_cache[$this->nodeId()][self::CACHE_COMMENT]; |
|
- | 463 | } |
|
- | 464 | return false; |
|
- | 465 | } |
|
- | 466 | } |
|
- | 467 | ||
- | 468 | public function getCreatedTime() { |
|
- | 469 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
|
- | 470 | $res = OIDplus::db()->query("select created from ###objects where id = ?", array($this->nodeId())); |
|
- | 471 | if (!$res->any()) return null; |
|
- | 472 | $row = $res->fetch_array(); |
|
- | 473 | return $row['created']; |
|
- | 474 | } else { |
|
- | 475 | self::buildObjectInformationCache(); |
|
- | 476 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
|
- | 477 | return self::$object_info_cache[$this->nodeId()][self::CACHE_CREATED]; |
|
- | 478 | } |
|
- | 479 | return false; |
|
- | 480 | } |
|
- | 481 | } |
|
- | 482 | ||
- | 483 | public function getUpdatedTime() { |
|
- | 484 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
|
- | 485 | $res = OIDplus::db()->query("select updated from ###objects where id = ?", array($this->nodeId())); |
|
- | 486 | if (!$res->any()) return null; |
|
- | 487 | $row = $res->fetch_array(); |
|
- | 488 | return $row['updated']; |
|
- | 489 | } else { |
|
- | 490 | self::buildObjectInformationCache(); |
|
- | 491 | if (isset(self::$object_info_cache[$this->nodeId()])) { |
|
- | 492 | return self::$object_info_cache[$this->nodeId()][self::CACHE_UPDATED]; |
|
- | 493 | } |
|
- | 494 | return false; |
|
- | 495 | } |
|
- | 496 | } |
|
- | 497 | ||
434 | public function userHasParentalWriteRights($ra_email=null) { |
498 | public function userHasParentalWriteRights($ra_email=null) { |
435 | if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail(); |
499 | if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail(); |
436 | 500 | ||
437 | if (is_null($ra_email)) { |
501 | if (is_null($ra_email)) { |
438 | if (OIDplus::authUtils()->isAdminLoggedIn()) return true; |
502 | if (OIDplus::authUtils()->isAdminLoggedIn()) return true; |
Line 479... | Line 543... | ||
479 | if ($obj->equals($test)) return $test; |
543 | if ($obj->equals($test)) return $test; |
480 | } |
544 | } |
481 | return false; |
545 | return false; |
482 | } else { |
546 | } else { |
483 | self::buildObjectInformationCache(); |
547 | self::buildObjectInformationCache(); |
484 | foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) { |
548 | foreach (self::$object_info_cache as $id => $cacheitem) { |
485 | if (strpos($id, $obj->ns().':') === 0) { |
549 | if (strpos($id, $obj->ns().':') === 0) { |
486 | $test = OIDplusObject::parse($id); |
550 | $test = OIDplusObject::parse($id); |
487 | if ($obj->equals($test)) return $test; |
551 | if ($obj->equals($test)) return $test; |
488 | } |
552 | } |
489 | } |
553 | } |
Line 501... | Line 565... | ||
501 | 565 | ||
502 | public static function resetObjectInformationCache() { |
566 | public static function resetObjectInformationCache() { |
503 | self::$object_info_cache = null; |
567 | self::$object_info_cache = null; |
504 | } |
568 | } |
505 | 569 | ||
506 | const CACHE_CONFIDENTIAL = 0; // TODO: An object would be better so you can use $cacheitem->isConfidential() etc. |
570 | const CACHE_ID = 'id'; |
507 | const CACHE_PARENT = 1; |
571 | const CACHE_PARENT = 'parent'; |
- | 572 | const CACHE_TITLE = 'title'; |
|
- | 573 | const CACHE_DESCRIPTION = 'description'; |
|
508 | const CACHE_RA_EMAIL = 2; |
574 | const CACHE_RA_EMAIL = 'ra_email'; |
- | 575 | const CACHE_CONFIDENTIAL = 'confidential'; |
|
- | 576 | const CACHE_CREATED = 'created'; |
|
- | 577 | const CACHE_UPDATED = 'updated'; |
|
509 | const CACHE_TITLE = 3; |
578 | const CACHE_COMMENT = 'comment'; |
510 | 579 | ||
511 | private static function buildObjectInformationCache() { |
580 | private static function buildObjectInformationCache() { |
512 | if (is_null(self::$object_info_cache)) { |
581 | if (is_null(self::$object_info_cache)) { |
513 | self::$object_info_cache = array(); |
582 | self::$object_info_cache = array(); |
514 | $res = OIDplus::db()->query("select id, parent, confidential, ra_email, title from ###objects"); |
583 | $res = OIDplus::db()->query("select * from ###objects"); |
515 | while ($row = $res->fetch_array()) { |
584 | while ($row = $res->fetch_array()) { |
516 | self::$object_info_cache[$row['id']] = array($row['confidential'], $row['parent'], $row['ra_email'], $row['title']); |
585 | self::$object_info_cache[$row['id']] = $row; |
517 | } |
586 | } |
518 | } |
587 | } |
519 | } |
588 | } |
520 | 589 | ||
521 | // override this function if you want your object type to save |
590 | // override this function if you want your object type to save |