From 22db0f11e4b11ad6b84a34d9fb7b61c15aa539a3 Mon Sep 17 00:00:00 2001 From: edward Date: Wed, 30 Mar 2016 18:51:45 +0800 Subject: [PATCH] RooTrait.php RooGetTrait.php --- RooGetTrait.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ RooTrait.php | 59 ------------------------------------------ 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/RooGetTrait.php b/RooGetTrait.php index c4d30861..c3cbdb8d 100644 --- a/RooGetTrait.php +++ b/RooGetTrait.php @@ -291,5 +291,73 @@ trait Pman_Core_RooGetTrait { $this->jdata($ret, max(count($ret), $total), $extra ); + } + + function checkDebugPost() + { + return (!empty($_GET['_post']) || !empty($_GET['_debug_post'])) && + $this->authUser && + method_exists($this->authUser,'groups') && + in_array('Administrators', $this->authUser->groups('name')); + + } + + function selectSingle($x, $id, $req=false) + { + $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false; + + if (!is_array($id) && empty($id)) { + + if (method_exists($x, 'toRooSingleArray')) { + $this->jok($x->toRooSingleArray($this->getAuthUser(), $req)); + } + + if (method_exists($x, 'toRooArray')) { + $this->jok($x->toRooArray($req)); + } + + $this->jok($x->toArray()); + } + + + $this->loadMap($x, array( + 'columns' => $_columns, + + )); + if ($req !== false) { + $this->setFilters($x, $req); + } + + if (is_array($id)) { + // lookup... + $x->setFrom($req['lookup'] ); + $x->limit(1); + if (!$x->find(true)) { + if (!empty($id['_id'])) { + // standardize this? + $this->jok($x->toArray()); + } + $this->jok(false); + } + + } else if (!$x->get($id)) { + $this->jerr("selectSingle: no such record ($id)"); + } + + // ignore perms if comming from update/insert - as it's already done... + if ($req !== false && !$this->checkPerm($x,'S')) { + $this->jerr("PERMISSION DENIED - si"); + } + // different symantics on all these calls?? + if (method_exists($x, 'toRooSingleArray')) { + $this->jok($x->toRooSingleArray($this->authUser, $req)); + } + if (method_exists($x, 'toRooArray')) { + $this->jok($x->toRooArray($req)); + } + + $this->jok($x->toArray()); + + } } diff --git a/RooTrait.php b/RooTrait.php index 1c3a34a4..bb94e16c 100644 --- a/RooTrait.php +++ b/RooTrait.php @@ -85,65 +85,6 @@ trait Pman_Core_RooTrait { return $x; } - function selectSingle($x, $id, $req=false) - { - $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false; - - if (!is_array($id) && empty($id)) { - - if (method_exists($x, 'toRooSingleArray')) { - $this->jok($x->toRooSingleArray($this->getAuthUser(), $req)); - } - - if (method_exists($x, 'toRooArray')) { - $this->jok($x->toRooArray($req)); - } - - $this->jok($x->toArray()); - } - - - $this->loadMap($x, array( - 'columns' => $_columns, - - )); - if ($req !== false) { - $this->setFilters($x, $req); - } - - // DB_DataObject::DebugLevel(1); - if (is_array($id)) { - // lookup... - $x->setFrom($req['lookup'] ); - $x->limit(1); - if (!$x->find(true)) { - if (!empty($id['_id'])) { - // standardize this? - $this->jok($x->toArray()); - } - $this->jok(false); - } - - } else if (!$x->get($id)) { - $this->jerr("selectSingle: no such record ($id)"); - } - - // ignore perms if comming from update/insert - as it's already done... - if ($req !== false && !$this->checkPerm($x,'S')) { - $this->jerr("PERMISSION DENIED - si"); - } - // different symantics on all these calls?? - if (method_exists($x, 'toRooSingleArray')) { - $this->jok($x->toRooSingleArray($this->authUser, $req)); - } - if (method_exists($x, 'toRooArray')) { - $this->jok($x->toRooArray($req)); - } - - $this->jok($x->toArray()); - - - } /* * From Pman.php -- 2.39.2