function index($siteid, Request $request, Application $app) { $this->build($siteid, $request, $app); $form = $app['form.factory']->create(new ActionForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $action = new ActionParser($data['action']); if ($action->getCommand() == 'addtextsingleline') { $ecfdm = new EventCustomFieldDefinitionModel(); if ($ecfdm->isKeyValid($action->getParam(0))) { $ecfdm->setSiteId($this->parameters['site']->getId()); $ecfdm->setExtensionId('org.openacalendar'); $ecfdm->setType('TextSingleLine'); $ecfdm->setKey($action->getParam(0)); $ecfdm->setLabel($action->getParam(0)); $repo = new EventCustomFieldDefinitionRepository(); $repo->create($ecfdm, $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/eventcustomfielddefinition/' . $ecfdm->getId()); } else { $app['flashmessages']->addError("Key Not Allowed"); } } else { if ($action->getCommand() == 'addtextmultiline') { $ecfdm = new EventCustomFieldDefinitionModel(); if ($ecfdm->isKeyValid($action->getParam(0))) { $ecfdm->setSiteId($this->parameters['site']->getId()); $ecfdm->setExtensionId('org.openacalendar'); $ecfdm->setType('TextMultiLine'); $ecfdm->setKey($action->getParam(0)); $ecfdm->setLabel($action->getParam(0)); $repo = new EventCustomFieldDefinitionRepository(); $repo->create($ecfdm, $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/eventcustomfielddefinition/' . $ecfdm->getId()); } else { $app['flashmessages']->addError("Key Not Allowed"); } } } } } $this->parameters['form'] = $form->createView(); $rb = new EventCustomFieldDefinitionRepositoryBuilder(); $rb->setSite($this->parameters['site']); $this->parameters['fields'] = $rb->fetchAll(); return $app['twig']->render('sysadmin/eventcustomfielddefinitionlist/index.html.twig', $this->parameters); }
public function testAddCustomFieldThenCreateEventWithContent() { TimeSource::mock(2014, 5, 1, 7, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $customFieldDefinition1 = new EventCustomFieldDefinitionModel(); $customFieldDefinition1->setSiteId($site->getId()); $customFieldDefinition1->setExtensionId('org.openacalendar'); $customFieldDefinition1->setType('TextSingleLine'); $customFieldDefinition1->setKey('cats'); $customFieldDefinition1->setLabel('cats'); $customFieldDefinition2 = new EventCustomFieldDefinitionModel(); $customFieldDefinition2->setSiteId($site->getId()); $customFieldDefinition2->setExtensionId('org.openacalendar'); $customFieldDefinition2->setType('TextSingleLine'); $customFieldDefinition2->setKey('dogs'); $customFieldDefinition2->setLabel('dogs'); $ecfRepo = new EventCustomFieldDefinitionRepository(); $ecfRepo->create($customFieldDefinition1, $user); $ecfRepo->create($customFieldDefinition2, $user); $event = new EventModel(); $event->setSummary("test"); $event->setDescription("test test"); $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0)); $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0)); $event->setUrl("http://www.info.com"); $event->setTicketUrl("http://www.tickets.com"); $event->setCustomField($customFieldDefinition1, "CATS"); // CREATE WITH TimeSource::mock(2014, 5, 1, 7, 1, 0); $eventRepository = new EventRepository(); $eventRepository->create($event, $site, $user); $event = $eventRepository->loadByID($event->getId()); $this->assertEquals(true, $event->hasCustomField($customFieldDefinition1)); $this->assertEquals(false, $event->hasCustomField($customFieldDefinition2)); $this->assertFalse($event->getIsDeleted()); // LET's CHECK HISTORY $eventHistoryRepo = new EventHistoryRepository(); $stat = $this->app['db']->prepare("SELECT * FROM event_history"); $stat->execute(); while ($data = $stat->fetch()) { $eventHistory = new EventHistoryModel(); $eventHistory->setFromDataBaseRow($data); $eventHistoryRepo->ensureChangedFlagsAreSet($eventHistory); } $eventHistoryRepoBuilder = new EventHistoryRepositoryBuilder(); $eventHistoryRepoBuilder->setEvent($event); $histories = $eventHistoryRepoBuilder->fetchAll(); $this->assertEquals(1, count($histories)); $historyCreate = $histories[0]; $this->assertTrue($historyCreate->getCustomFieldChangedKnown($customFieldDefinition1)); $this->assertTrue($historyCreate->getCustomFieldChanged($customFieldDefinition1)); $this->assertFalse($historyCreate->getCustomFieldChanged($customFieldDefinition2)); }