Skip to content

Commit

Permalink
Merge pull request #573 from pmattmann/bugfix/camp-service
Browse files Browse the repository at this point in the history
Default ActivityCategory for CampType
  • Loading branch information
manuelmeister authored Nov 3, 2020
2 parents ab8f643 + 53e50d7 commit 141b17c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
9 changes: 5 additions & 4 deletions backend/module/eCampCore/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@
],

// Use lazy services (service proxies) for expensive constructors or in case circular dependencies are needed
// #572 please remember if we want to use lazy services we need to remove the final methods from AbstractEntityService
'lazy_services' => [
'class_map' => [
\eCamp\Core\EntityService\ActivityCategoryService::class => \eCamp\Core\EntityService\ActivityCategoryService::class,
//\eCamp\Core\EntityService\ActivityCategoryService::class => \eCamp\Core\EntityService\ActivityCategoryService::class,
],
],
'delegators' => [
\eCamp\Core\EntityService\ActivityCategoryService::class => [
Laminas\ServiceManager\Proxy\LazyServiceFactory::class,
],
//\eCamp\Core\EntityService\ActivityCategoryService::class => [
// Laminas\ServiceManager\Proxy\LazyServiceFactory::class,
//],
],
],

Expand Down
25 changes: 25 additions & 0 deletions backend/module/eCampCore/data/prod/CampTypeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function load(ObjectManager $manager) {
$campType->setOrganization($pbs);
$campType->setIsJS(true);
$campType->setIsCourse(false);
$campType->setJsonConfig($this->getJsonConfig());

$manager->persist($campType);
}
Expand All @@ -44,6 +45,7 @@ public function load(ObjectManager $manager) {
$campType->setOrganization($pbs);
$campType->setIsJS(true);
$campType->setIsCourse(false);
$campType->setJsonConfig($this->getJsonConfig());

$manager->persist($campType);
}
Expand All @@ -61,4 +63,27 @@ public function load(ObjectManager $manager) {
public function getDependencies() {
return [OrganizationData::class, ActivityTypeData::class];
}

private function getJsonConfig() {
$lagersport = $this->getReference(ActivityTypeData::$LAGERSPORT);
$lageraktivitaet = $this->getReference(ActivityTypeData::$LAGERAKTIVITAET);

return json_encode([
CampType::CNF_ACTIVITY_CATEGORIES => [
[
'activityTypeId' => $lagersport->getId(),
'short' => 'LS',
'name' => $lagersport->getName(),
'color' => $lagersport->getDefaultColor(),
'numberingStyle' => $lagersport->getDefaultNumberingStyle(),
], [
'activityTypeId' => $lageraktivitaet->getId(),
'short' => 'LA',
'name' => $lageraktivitaet->getName(),
'color' => $lageraktivitaet->getDefaultColor(),
'numberingStyle' => $lageraktivitaet->getDefaultNumberingStyle(),
],
],
]);
}
}
2 changes: 1 addition & 1 deletion backend/module/eCampCore/src/Entity/CampType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @ORM\Entity
*/
class CampType extends BaseEntity {
const CNF_EVENT_CATEGORIES = 'activityCategories';
const CNF_ACTIVITY_CATEGORIES = 'activityCategories';
const CNF_JOBS = 'jobs';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ protected function createEntity($data) {
$this->assertAllowed($campCollaboration, Acl::REST_PRIVILEGE_CREATE);

if ($data->userId === $authUser->getId()) {
// Create CampCollaboration for AuthUser
$campCollaboration->setStatus(CampCollaboration::STATUS_REQUESTED);
if ($data->userId === $camp->getCreator()->getId()) {
// Create CampCollaboration for Creator
$campCollaboration->setStatus(CampCollaboration::STATUS_ESTABLISHED);
$campCollaboration->setCollaborationAcceptedBy($authUser->getUsername());
} else {
// Create CampCollaboration for AuthUser
$campCollaboration->setStatus(CampCollaboration::STATUS_REQUESTED);
}
} else {
// Create CampCollaboration for other User
$campCollaboration->setStatus(CampCollaboration::STATUS_INVITED);
Expand Down
33 changes: 20 additions & 13 deletions backend/module/eCampCore/src/EntityService/CampService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\ORM\ORMException;
use eCamp\Core\Entity\AbstractCampOwner;
use eCamp\Core\Entity\Camp;
use eCamp\Core\Entity\CampCollaboration;
use eCamp\Core\Entity\CampType;
use eCamp\Core\Entity\User;
use eCamp\Core\Hydrator\CampHydrator;
Expand All @@ -22,11 +23,15 @@ class CampService extends AbstractEntityService {
/** @var ActivityCategoryService */
protected $activityCategoryService;

/** @var CampCollaborationService */
protected $campCollaboratorService;

public function __construct(
ActivityCategoryService $activityCategoryService,
PeriodService $periodService,
ServiceUtils $serviceUtils,
AuthenticationService $authenticationService
AuthenticationService $authenticationService,
CampCollaborationService $campCollaboratorService
) {
parent::__construct(
$serviceUtils,
Expand All @@ -37,6 +42,7 @@ public function __construct(

$this->periodService = $periodService;
$this->activityCategoryService = $activityCategoryService;
$this->campCollaboratorService = $campCollaboratorService;
}

/**
Expand Down Expand Up @@ -87,18 +93,26 @@ protected function createEntityPost(BaseEntity $entity, $data) {
$camp = $entity;
$campType = $camp->getCampType();

// Create CampCollaboration for Creator
$this->campCollaboratorService->create((object) [
'campId' => $camp->getId(),
'role' => CampCollaboration::ROLE_MANAGER,
]);

/** Create default Jobs */
/*
$jobConfigs = $campType->getConfig(CampType::CNF_JOBS) ?: [];
foreach ($jobConfigs as $jobConfig) {
$jobConfig->campId = $camp->getId();
$this->getJobService()->create($jobConfig);
}
*/

/** Create default ActivityCategories: */
$ecConfigs = $campType->getConfig(CampType::CNF_EVENT_CATEGORIES) ?: [];
foreach ($ecConfigs as $ecConfig) {
$ecConfig->campId = $camp->getId();
$this->getActivityCategoryService()->create($ecConfig);
// Create default ActivityCategories
$acConfigs = $campType->getConfig(CampType::CNF_ACTIVITY_CATEGORIES) ?: [];
foreach ($acConfigs as $acConfig) {
$acConfig->campId = $camp->getId();
$this->activityCategoryService->create($acConfig);
}

// Create Periods:
Expand All @@ -108,13 +122,6 @@ protected function createEntityPost(BaseEntity $entity, $data) {
$period->campId = $camp->getId();
$this->periodService->create($period);
}
} elseif (isset($data->start, $data->end)) {
$this->getPeriodService()->create((object) [
'campId' => $camp->getId(),
'description' => 'Main',
'start' => $data->start,
'end' => $data->end,
]);
}

return $camp;
Expand Down

0 comments on commit 141b17c

Please sign in to comment.