]> git.agnieray.net Git - galette.git/commitdiff
Simplify some code
authorJohan Cwiklinski <johan@x-tnd.be>
Sun, 14 Nov 2021 17:36:35 +0000 (18:36 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 14 Nov 2021 17:53:44 +0000 (18:53 +0100)
galette/lib/Galette/Entity/Contribution.php
galette/lib/Galette/Entity/Transaction.php

index c1fb4de13e6f65954e98739685276733ce4f7b23..50e763f0dbc617e4544a7e4dd8740382a89e0c06 100644 (file)
@@ -291,6 +291,14 @@ class Contribution
      */
     public function load($id)
     {
+        if (!$this->login->isLogged()) {
+            Analog::log(
+                'Non-logged-in users cannot load contribution id `' . $id,
+                Analog::ERROR
+            );
+            return false;
+        }
+
         try {
             $select = $this->zdb->select(self::TABLE, 'c');
             $select->join(
@@ -300,29 +308,15 @@ class Contribution
             );
             //restrict query on current member id if he's not admin nor staff member
             if (!$this->login->isAdmin() && !$this->login->isStaff()) {
-                if (!$this->login->isLogged()) {
-                    Analog::log(
-                        'Non-logged-in users cannot load contribution id `' . $id,
-                        Analog::ERROR
-                    );
-                    return false;
-                }
-                if (!$this->login->isGroupManager()) {
-                    $select->where
-                        ->nest()
-                            ->equalTo('a.' . Adherent::PK, $this->login->id)
-                            ->or
-                            ->equalTo('a.parent_id', $this->login->id)
-                        ->unnest()
-                        ->and
-                        ->equalTo('c.' . self::PK, $id)
-                    ;
-                } else {
-                    $select->where([
-                        Adherent::PK    => $this->login->id,
-                        self::PK        => $id
-                    ]);
-                }
+                $select->where
+                    ->nest()
+                        ->equalTo('a.' . Adherent::PK, $this->login->id)
+                        ->or
+                        ->equalTo('a.parent_id', $this->login->id)
+                    ->unnest()
+                    ->and
+                    ->equalTo('c.' . self::PK, $id)
+                ;
             } else {
                 $select->where->equalTo(self::PK, $id);
             }
index 799d5e91af87891ff235b523489821fb31a382f5..35d4c50c5082e531a5154f8a26df6391090062f1 100644 (file)
@@ -152,6 +152,14 @@ class Transaction
      */
     public function load($id)
     {
+        if (!$this->login->isLogged()) {
+            Analog::log(
+                'Non-logged-in users cannot load transaction id `' . $id,
+                Analog::ERROR
+            );
+            return false;
+        }
+
         try {
             $select = $this->zdb->select(self::TABLE, 't');
             $select->where([self::PK => $id]);
@@ -162,14 +170,7 @@ class Transaction
             );
 
             //restrict query on current member id if he's not admin nor staff member
-            if (!$this->login->isAdmin() && !$this->login->isStaff() && !$this->login->isGroupManager()) {
-                if (!$this->login->isLogged()) {
-                    Analog::log(
-                        'Non-logged-in users cannot load transaction id `' . $id,
-                        Analog::ERROR
-                    );
-                    return false;
-                }
+            if (!$this->login->isAdmin() && !$this->login->isStaff()) {
                 $select->where
                     ->nest()
                         ->equalTo('a.' . Adherent::PK, $this->login->id)