Subversion Repositories oidplus

Rev

Rev 228 | Rev 239 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 228 Rev 236
Line 86... Line 86...
86
                if (!OIDPLUS_OBJECT_CACHING) {
86
                if (!OIDPLUS_OBJECT_CACHING) {
87
                        if (is_null($ra_email)) {
87
                        if (is_null($ra_email)) {
88
                                $res = OIDplus::db()->query("select oChild.id as id, oChild.ra_email as child_mail, oParent.ra_email as parent_mail from ".OIDPLUS_TABLENAME_PREFIX."objects as oChild ".
88
                                $res = OIDplus::db()->query("select oChild.id as id, oChild.ra_email as child_mail, oParent.ra_email as parent_mail from ".OIDPLUS_TABLENAME_PREFIX."objects as oChild ".
89
                                                            "left join ".OIDPLUS_TABLENAME_PREFIX."objects as oParent on oChild.parent = oParent.id ".
89
                                                            "left join ".OIDPLUS_TABLENAME_PREFIX."objects as oParent on oChild.parent = oParent.id ".
90
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'));
90
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'));
91
                                while ($row = OIDplus::db()->fetch_array($res)) {
91
                                while ($row = $res->fetch_array()) {
92
                                        if (!OIDplus::authUtils()::isRaLoggedIn($row['parent_mail']) && OIDplus::authUtils()::isRaLoggedIn($row['child_mail'])) {
92
                                        if (!OIDplus::authUtils()::isRaLoggedIn($row['parent_mail']) && OIDplus::authUtils()::isRaLoggedIn($row['child_mail'])) {
93
                                                $x = self::parse($row['id']); // can be FALSE if namespace was disabled
93
                                                $x = self::parse($row['id']); // can be FALSE if namespace was disabled
94
                                                if ($x) $out[] = $x;
94
                                                if ($x) $out[] = $x;
95
                                        }
95
                                        }
96
                                }
96
                                }
Line 98... Line 98...
98
                                $res = OIDplus::db()->query("select oChild.id as id from ".OIDPLUS_TABLENAME_PREFIX."objects as oChild ".
98
                                $res = OIDplus::db()->query("select oChild.id as id from ".OIDPLUS_TABLENAME_PREFIX."objects as oChild ".
99
                                                            "left join ".OIDPLUS_TABLENAME_PREFIX."objects as oParent on oChild.parent = oParent.id ".
99
                                                            "left join ".OIDPLUS_TABLENAME_PREFIX."objects as oParent on oChild.parent = oParent.id ".
100
                                                            "where (ifnull(oParent.ra_email,'') <> ? and ifnull(oChild.ra_email,'') = ?) or ".
100
                                                            "where (ifnull(oParent.ra_email,'') <> ? and ifnull(oChild.ra_email,'') = ?) or ".
101
                                                            "      (oParent.ra_email is null and ifnull(oChild.ra_email,'') = ?) ".
101
                                                            "      (oParent.ra_email is null and ifnull(oChild.ra_email,'') = ?) ".
102
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'), array($ra_email, $ra_email, $ra_email));
102
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'), array($ra_email, $ra_email, $ra_email));
103
                                while ($row = OIDplus::db()->fetch_array($res)) {
103
                                while ($row = $res->fetch_array()) {
104
                                        $x = self::parse($row['id']); // can be FALSE if namespace was disabled
104
                                        $x = self::parse($row['id']); // can be FALSE if namespace was disabled
105
                                        if ($x) $out[] = self::parse($row['id']);
105
                                        if ($x) $out[] = self::parse($row['id']);
106
                                }
106
                                }
107
                        }
107
                        }
108
                } else {
108
                } else {
Line 148... Line 148...
148
                $out = array();
148
                $out = array();
149
 
149
 
150
                if (!OIDPLUS_OBJECT_CACHING) {
150
                if (!OIDPLUS_OBJECT_CACHING) {
151
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = 0 order by ".OIDplus::db()->natOrder('id'));
151
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where confidential = 0 order by ".OIDplus::db()->natOrder('id'));
152
 
152
 
153
                        while ($row = OIDplus::db()->fetch_array($res)) {
153
                        while ($row = $res->fetch_array()) {
154
                                $obj = self::parse($row['id']); // will be NULL if the object type is not registered
154
                                $obj = self::parse($row['id']); // will be NULL if the object type is not registered
155
                                if ($obj && (!$obj->isConfidential())) {
155
                                if ($obj && (!$obj->isConfidential())) {
156
                                        $out[] = $row['id'];
156
                                        $out[] = $row['id'];
157
                                }
157
                                }
158
                        }
158
                        }
Line 176... Line 176...
176
                if (!OIDPLUS_OBJECT_CACHING) {
176
                if (!OIDPLUS_OBJECT_CACHING) {
177
                        $curid = $this->nodeId();
177
                        $curid = $this->nodeId();
178
                        $orig_curid = $curid;
178
                        $orig_curid = $curid;
179
                        if (isset(self::$object_info_cache[$curid])) return self::$object_info_cache[$curid];
179
                        if (isset(self::$object_info_cache[$curid])) return self::$object_info_cache[$curid];
180
                        // Recursively search for the confidential flag in the parents
180
                        // Recursively search for the confidential flag in the parents
181
                        while (OIDplus::db()->num_rows($res = OIDplus::db()->query("select parent, confidential from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($curid))) > 0) {
181
                        while (($res = OIDplus::db()->query("select parent, confidential from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($curid)))->num_rows() > 0) {
182
                                $row = OIDplus::db()->fetch_array($res);
182
                                $row = $res->fetch_array();
183
                                if ($row['confidential']) {
183
                                if ($row['confidential']) {
184
                                        self::$object_info_cache[$curid] = true;
184
                                        self::$object_info_cache[$curid] = true;
185
                                        self::$object_info_cache[$orig_curid] = true;
185
                                        self::$object_info_cache[$orig_curid] = true;
186
                                        return true;
186
                                        return true;
187
                                } else {
187
                                } else {
Line 210... Line 210...
210
        }
210
        }
211
 
211
 
212
        public function isChildOf(OIDplusObject $obj) {
212
        public function isChildOf(OIDplusObject $obj) {
213
                if (!OIDPLUS_OBJECT_CACHING) {
213
                if (!OIDPLUS_OBJECT_CACHING) {
214
                        $curid = $this->nodeId();
214
                        $curid = $this->nodeId();
215
                        while (OIDplus::db()->num_rows($res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($curid))) > 0) {
215
                        while (($res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($curid)))->num_rows() > 0) {
216
                                $row = OIDplus::db()->fetch_array($res);
216
                                $row = $res->fetch_array();
217
                                if ($curid == $obj->nodeId()) return true;
217
                                if ($curid == $obj->nodeId()) return true;
218
                                $curid = $row['parent'];
218
                                $curid = $row['parent'];
219
                        }
219
                        }
220
                        return false;
220
                        return false;
221
                } else {
221
                } else {
Line 232... Line 232...
232
 
232
 
233
        public function getChildren() {
233
        public function getChildren() {
234
                $out = array();
234
                $out = array();
235
                if (!OIDPLUS_OBJECT_CACHING) {
235
                if (!OIDPLUS_OBJECT_CACHING) {
236
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ?", array($this->nodeId()));
236
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ?", array($this->nodeId()));
237
                        while ($row = OIDplus::db()->fetch_array($res)) {
237
                        while ($row = $res->fetch_array()) {
238
                                $obj = self::parse($row['id']);
238
                                $obj = self::parse($row['id']);
239
                                if (!$obj) continue;
239
                                if (!$obj) continue;
240
                                $out[] = $obj;
240
                                $out[] = $obj;
241
                        }
241
                        }
242
                } else {
242
                } else {
Line 303... Line 303...
303
        }
303
        }
304
 
304
 
305
        public static function exists($id) {
305
        public static function exists($id) {
306
                if (!OIDPLUS_OBJECT_CACHING) {
306
                if (!OIDPLUS_OBJECT_CACHING) {
307
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($id));
307
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($id));
308
                        return OIDplus::db()->num_rows($res) > 0;
308
                        return $res->num_rows() > 0;
309
                } else {
309
                } else {
310
                        self::buildObjectInformationCache();
310
                        self::buildObjectInformationCache();
311
                        return isset(self::$object_info_cache[$id]);
311
                        return isset(self::$object_info_cache[$id]);
312
                }
312
                }
313
        }
313
        }
314
 
314
 
315
        public function getParent() {
315
        public function getParent() {
316
                if (!OIDPLUS_OBJECT_CACHING) {
316
                if (!OIDPLUS_OBJECT_CACHING) {
317
                        $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
317
                        $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
318
                        $row = OIDplus::db()->fetch_array($res);
318
                        $row = $res->fetch_array();
319
                        $parent = $row['parent'];
319
                        $parent = $row['parent'];
320
                        $obj = OIDplusObject::parse($parent);
320
                        $obj = OIDplusObject::parse($parent);
321
                        if ($obj) return $obj;
321
                        if ($obj) return $obj;
322
                } else {
322
                } else {
323
                        self::buildObjectInformationCache();
323
                        self::buildObjectInformationCache();
Line 343... Line 343...
343
        }
343
        }
344
 
344
 
345
        public function getRaMail() {
345
        public function getRaMail() {
346
                if (!OIDPLUS_OBJECT_CACHING) {
346
                if (!OIDPLUS_OBJECT_CACHING) {
347
                        $res = OIDplus::db()->query("select ra_email from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
347
                        $res = OIDplus::db()->query("select ra_email from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
348
                        $row = OIDplus::db()->fetch_array($res);
348
                        $row = $res->fetch_array();
349
                        return $row['ra_email'];
349
                        return $row['ra_email'];
350
                } else {
350
                } else {
351
                        self::buildObjectInformationCache();
351
                        self::buildObjectInformationCache();
352
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
352
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
353
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_RA_EMAIL];
353
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_RA_EMAIL];
Line 357... Line 357...
357
        }
357
        }
358
 
358
 
359
        public function getTitle() {
359
        public function getTitle() {
360
                if (!OIDPLUS_OBJECT_CACHING) {
360
                if (!OIDPLUS_OBJECT_CACHING) {
361
                        $res = OIDplus::db()->query("select title from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
361
                        $res = OIDplus::db()->query("select title from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($this->nodeId()));
362
                        $row = OIDplus::db()->fetch_array($res);
362
                        $row = $res->fetch_array();
363
                        return $row['title'];
363
                        return $row['title'];
364
                } else {
364
                } else {
365
                        self::buildObjectInformationCache();
365
                        self::buildObjectInformationCache();
366
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
366
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
367
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_TITLE];
367
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_TITLE];
Line 411... Line 411...
411
                $obj = OIDplusObject::parse($id);
411
                $obj = OIDplusObject::parse($id);
412
                if (!$obj) throw new Exception("findFitting: Parse failed\n");
412
                if (!$obj) throw new Exception("findFitting: Parse failed\n");
413
 
413
 
414
                if (!OIDPLUS_OBJECT_CACHING) {
414
                if (!OIDPLUS_OBJECT_CACHING) {
415
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id like ?", array($obj->ns().':%'));
415
                        $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where id like ?", array($obj->ns().':%'));
416
                        while ($row = OIDplus::db()->fetch_object($res)) {
416
                        while ($row = $res->fetch_object()) {
417
                                $test = OIDplusObject::parse($row->id);
417
                                $test = OIDplusObject::parse($row->id);
418
                                if ($obj->equals($test)) return $test;
418
                                if ($obj->equals($test)) return $test;
419
                        }
419
                        }
420
                        return false;
420
                        return false;
421
                } else {
421
                } else {
Line 449... Line 449...
449
 
449
 
450
        private static function buildObjectInformationCache() {
450
        private static function buildObjectInformationCache() {
451
                if (is_null(self::$object_info_cache)) {
451
                if (is_null(self::$object_info_cache)) {
452
                        self::$object_info_cache = array();
452
                        self::$object_info_cache = array();
453
                        $res = OIDplus::db()->query("select id, parent, confidential, ra_email, title from ".OIDPLUS_TABLENAME_PREFIX."objects");
453
                        $res = OIDplus::db()->query("select id, parent, confidential, ra_email, title from ".OIDPLUS_TABLENAME_PREFIX."objects");
454
                        while ($row = OIDplus::db()->fetch_array($res)) {
454
                        while ($row = $res->fetch_array()) {
455
                                if ($row['confidential'] == chr(0)) $row['confidential'] = false; // ODBC...
455
                                if ($row['confidential'] == chr(0)) $row['confidential'] = false; // ODBC...
456
                                if ($row['confidential'] == chr(1)) $row['confidential'] = true; // ODBC...
456
                                if ($row['confidential'] == chr(1)) $row['confidential'] = true; // ODBC...
457
                                self::$object_info_cache[$row['id']] = array($row['confidential'], $row['parent'], $row['ra_email'], $row['title']);
457
                                self::$object_info_cache[$row['id']] = array($row['confidential'], $row['parent'], $row['ra_email'], $row['title']);
458
                        }
458
                        }
459
                }
459
                }