extend('classMapper', function ($classMapper, $c) { $classMapper->setClassMapping('organisation', 'UserFrosting\Sprinkle\Organisations\Database\Models\Organisation'); $classMapper->setClassMapping('organisation_sprunje', 'UserFrosting\Sprinkle\Organisations\Sprunje\OrganisationSprunje'); $classMapper->setClassMapping('user', 'UserFrosting\Sprinkle\Organisations\Database\Models\User'); $classMapper->setClassMapping('user_sprunje', 'UserFrosting\Sprinkle\Organisations\Sprunje\UserSprunje'); return $classMapper; }); /* * Extend the 'authorizer' service to add extra access condition callbacks. * * @return \UserFrosting\Sprinkle\Core\Util\ClassMapper */ $container->extend('authorizer', function ($authorizer, $c) { $new_authorizer = new AuthorizationManager($c, $authorizer->getCallbacks()); /* * Check if all $user is a member of $organisation. * * @param int $user_id the id of the requesting user (normally currentUser->id). * @param int $organisation_id the id of the target organisation. * @return bool true if $user is a member of $organisation. */ $new_authorizer->addCallback('is_organisation_member', function ($user_id, $organisation_id) { return Capsule::table('organisation_members') ->where('user_id', $user_id) ->where('organisation_id', $organisation_id) ->count() > 0; }); /* * Check if all $user is an administrator of $organisation. * * @param int $user_id the id of the requesting user (normally currentUser->id). * @param int $organisation_id the id of the target organisation. * @return bool true if $user is an administrator of $organisation. */ $new_authorizer->addCallback('is_organisation_admin', function ($user_id, $organisation_id) { return Capsule::table('organisation_members') ->where('user_id', $user_id) ->where('organisation_id', $organisation_id) ->where('flag_admin', true) ->count() > 0; }); return $new_authorizer; }); /* * Returns a callback that handles merging any organisation objects. * * @return callable */ $container['organisation.beforeMerge'] = function ($c) { /* * This method is invoked when an organisation is about to be merged * * Returns a callback that handles re-owning any organisation objects. * Throwing exceptions is allowed but not recommended. This method is triggered within a Capsule context. * @param \UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationInterfaces $source Organisation merging from * @param \UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationInterfaces $target Organisation merging towards */ return function (OrganisationInterface $source, OrganisationInterface $target) use ($c) { }; }; /* * Returns a callback that handles hard deleting an organisation (clean up any associated objects). * * @return callable */ $container['organisation.beforeDelete'] = function ($c) { /* * This method is invoked when an organisation is about to be merged * * Returns a callback that handles re-owning any organisation objects. * Throwing exceptions is allowed but not recommended. This method is triggered within a Capsule context. * @param \UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationInterfaces $organisation Organisation about to be deleted */ return function (OrganisationInterface $organisation) use ($c) { }; }; } }