extend('classMapper', function ($classMapper, $c) { $classMapper->setClassMapping('organisation', 'UserFrosting\Sprinkle\Organisations\Database\Models\Organisation'); $classMapper->setClassMapping('organisation_approval', 'UserFrosting\Sprinkle\Organisations\Database\Models\OrganisationApproval'); $classMapper->setClassMapping('organisation_sprunje', 'UserFrosting\Sprinkle\Organisations\Sprunje\OrganisationSprunje'); $classMapper->setClassMapping('organisation_member', 'UserFrosting\Sprinkle\Organisations\Database\Models\OrganisationMember'); $classMapper->setClassMapping('organisation_membership_approval', 'UserFrosting\Sprinkle\Organisations\Database\Models\OrganisationMembershipApproval'); $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; }); /* * Extends the 'view' service with the OrganisationsExtension for Twig. * * @return \Slim\Views\Twig */ $container->extend('view', function ($view, $c) { $twig = $view->getEnvironment(); $extension = new OrganisationsExtension($c); $twig->addExtension($extension); return $view; }); /* * Token logging with Monolog. * * Extend this service to push additional handlers onto the 'tokens' log stack. * * @return \Monolog\Logger */ $container['tokenLogger'] = function ($c) { $logger = new Logger('tokens'); $logFile = $c->locator->findResource('log://userfrosting.log', true, true); $handler = new StreamHandler($logFile); $formatter = new MixedFormatter(null, null, true); $handler->setFormatter($formatter); $logger->pushHandler($handler); return $logger; }; /* * 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 deleted * * 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) { }; }; /* * Repository for organisation registration approval requests. * * @return \UserFrosting\Sprinkle\Organisations\Repository\OrganisationApprovalRepository */ $container['repoOrganisationApproval'] = function ($c) { $classMapper = $c->classMapper; $config = $c->config; $repo = new OrganisationApprovalRepository($classMapper, $config['verification.algorithm'], $c['tokenLogger'], $config['debug.tokens']); return $repo; }; /* * Repository for membership approval requests. * * @return \UserFrosting\Sprinkle\Organisations\Repository\OrganisationMembershipApprovalRepository */ $container['repoOrganisationMembershipApproval'] = function ($c) { $classMapper = $c->classMapper; $config = $c->config; $repo = new OrganisationMembershipApprovalRepository($classMapper, $config['verification.algorithm'], $c['tokenLogger'], $config['debug.tokens']); return $repo; }; } }