]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/Entity/Contribution.php
Parents can display their children transactions
[galette.git] / galette / lib / Galette / Entity / Contribution.php
index bfa80bc423b54444f68b7bb017f47c1773941c89..99b929296ab6c5b7a3608dae9ddce62a1eac88da 100644 (file)
@@ -1413,4 +1413,31 @@ class Contribution
             'montant_cotis'     => $this->isFee() ? 1 : 0
         ];
     }
+
+    /**
+     * Can current logged-in user display contribution
+     *
+     * @param Login $login Login instance
+     *
+     * @return boolean
+     */
+    public function canShow(Login $login): bool
+    {
+        //admin and staff users can edit, as well as member itself
+        if ($this->id && $login->id == $this->id || $login->isAdmin() || $login->isStaff()) {
+            return true;
+        }
+
+        //parent can see their children contributions
+        $parent = new Adherent($this->zdb);
+        $parent
+            ->disableAllDeps()
+            ->enableDep('children')
+            ->load($this->login->id);
+        if ($parent->hasChildren()) {
+            return true;
+        }
+
+        return false;
+    }
 }