Entities/Administrators/Model/Administrator.php
public function isDeletable(): bool
    {
        if (is_null($this->authorization)) {
            throw new \Exception("Authorization must be set");
        }
        
        $id = $this->getId();

        // make sure the current administrator is not deleting her/himself
        if ($this->isLoggedIn()) {
            $this->notDeletableReason = "Administrator cannot delete own account: id $id";
            return false;
        }

        // non-top dogs cannot delete top dogs
        if (!$this->getAuthorization()->hasTopRole() && $this->hasTopRole()) {
            $this->notDeletableReason = "Not authorized to delete administrator: id $id";
            return false;
        }

        // make sure there are no events for administrator being deleted
        if ((EventsTableMapper::getInstance())->existForAdministrator($id)) {
            $this->notDeletableReason = "Events exist for administrator: id $id";
            return false;
        }

        return true;
    }
public function isDeletable(): bool
    {
        if (is_null($this->authorization)) {
            throw new \Exception("Authorization must be set");
        }
        
        $id = $this->getId();

        // make sure the current administrator is not deleting her/himself
        if ($this->isLoggedIn()) {
            $this->notDeletableReason = "Administrator cannot delete own account: id $id";
            return false;
        }

        // non-top dogs cannot delete top dogs
        if (!$this->getAuthorization()->hasTopRole() && $this->hasTopRole()) {
            $this->notDeletableReason = "Not authorized to delete administrator: id $id";
            return false;
        }

        // make sure there are no events for administrator being deleted
        if ((EventsTableMapper::getInstance())->existForAdministrator($id)) {
            $this->notDeletableReason = "Events exist for administrator: id $id";
            return false;
        }

        return true;
    }
public function isDeletable ( ) : bool { if ( is_null ( $ this -> authorization ) ) { throw new \ Exception ( "Authorization must be set" ) ; } $ id = $ this -> getId ( ) ; // make sure the current administrator is not deleting her/himself if ( $ this -> isLoggedIn ( ) ) { $ this -> notDeletableReason = "Administrator cannot delete own account: id $id" ; return false ; } // non-top dogs cannot delete top dogs if ( ! $ this -> getAuthorization ( ) -> hasTopRole ( ) && $ this -> hasTopRole ( ) ) { $ this -> notDeletableReason = "Not authorized to delete administrator: id $id" ; return false ; } // make sure there are no events for administrator being deleted if ( ( EventsTableMapper :: getInstance ( ) ) -> existForAdministrator ( $ id ) ) { $ this -> notDeletableReason = "Events exist for administrator: id $id" ; return false ; } return true ; }
whether this model is allowed to be deleted
do not allow admin to delete themself or non-owners to delete owners
whether this model is allowed to be deleted do not allow admin to delete themself or non - owners to delete owners