public function fetchAll()
 {
     $this->buildStart();
     $this->build();
     $this->buildStat();
     $results = array();
     while ($data = $this->stat->fetch()) {
         $area = new EventCustomFieldDefinitionModel();
         $area->setFromDataBaseRow($data);
         $results[] = $area;
     }
     return $results;
 }
 function testCustomFieldChange1()
 {
     TimeSource::mock(2012, 7, 1, 7, 0, 0);
     $customFieldDefinition1 = new EventCustomFieldDefinitionModel();
     $customFieldDefinition1->setId(1);
     $customFieldDefinition1->setExtensionId('org.openacalendar');
     $customFieldDefinition1->setType('TextSingleLine');
     $customFieldDefinition1->setKey('cats');
     $customFieldDefinition1->setLabel('cats');
     $event = new EventModel();
     $event->setStartAt(getUTCDateTime(2012, 6, 13, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2012, 6, 13, 21, 0, 0));
     $event->setSummary("Event Please");
     $event->setCustomField($customFieldDefinition1, "MANY");
     $eventSet = new EventRecurSetModel();
     $eventSet->setTimeZoneName('Europe/London');
     $eventSet->setCustomFields(array($customFieldDefinition1));
     $newEvents = $eventSet->getNewMonthlyEventsOnSetDayInWeek($event, 6 * 31);
     $this->assertTrue(count($newEvents) >= 6);
     $this->assertTrue($newEvents[0]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[0]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[1]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[1]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[2]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[2]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[3]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[3]->getCustomField($customFieldDefinition1));
     // DST shift happens here! The cats do not care.
     $this->assertTrue($newEvents[4]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[4]->getCustomField($customFieldDefinition1));
     $this->assertTrue($newEvents[5]->hasCustomField($customFieldDefinition1));
     $this->assertEquals("MANY", $newEvents[5]->getCustomField($customFieldDefinition1));
 }
 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);
 }
 /**
  * @dataProvider testData
  */
 function testBooleanParam($in, $out)
 {
     $this->assertEquals($out, EventCustomFieldDefinitionModel::isKeyValid($in));
 }
 public function getSymfonyFormOptions(\models\EventCustomFieldDefinitionModel $eventCustomFieldDefinitionModel)
 {
     return array('label' => $eventCustomFieldDefinitionModel->getLabel(), 'mapped' => false, 'required' => false);
 }
 /**
  * @return mixed
  */
 public function getCachedEventCustomFieldDefinitionsAsModels()
 {
     $out = array();
     if ($this->cached_event_custom_field_definitions) {
         foreach (json_decode($this->cached_event_custom_field_definitions) as $def) {
             $m = new EventCustomFieldDefinitionModel();
             $m->setId($def->id);
             $m->setExtensionId($def->extension_id);
             $m->setType($def->type);
             $m->setKey($def->key);
             $m->setLabel($def->label);
             $m->setIsActive($def->is_active);
             $out[] = $m;
         }
     }
     return $out;
 }
 function testChangCustomField1()
 {
     TimeSource::mock(2014, 1, 1, 9, 0, 0);
     $customFieldDefinition1 = new EventCustomFieldDefinitionModel();
     $customFieldDefinition1->setId(1);
     $customFieldDefinition1->setExtensionId('org.openacalendar');
     $customFieldDefinition1->setType('TextSingleLine');
     $customFieldDefinition1->setKey('cats');
     $customFieldDefinition1->setLabel('cats');
     $eventSet = new EventRecurSetModel();
     $eventSet->setTimeZoneName('Europe/London');
     $eventSet->setCustomFields(array($customFieldDefinition1));
     $initialEvent = new EventModel();
     $initialEvent->setSlug(1);
     $initialEvent->setCustomField($customFieldDefinition1, "Dogs go miaow");
     // this is the inital wrong value
     $initialEvent->setStartAt(getUTCDateTime(2014, 1, 7, 19, 0, 0));
     $initialEvent->setEndAt(getUTCDateTime(2014, 1, 7, 21, 0, 0));
     $eventSet->setInitialEventJustBeforeLastChange($initialEvent);
     $initialEventEdited = clone $initialEvent;
     $initialEventEdited->setCustomField($customFieldDefinition1, "Dogs go woof");
     // this is the later corrected value
     $eventSet->setInitalEvent($initialEventEdited);
     $futureEvent1 = new EventModel();
     $futureEvent1->setSlug(2);
     $futureEvent1->setCustomField($customFieldDefinition1, "Dogs go miaow");
     // this is the earlier wrong value that we will want to overwrite
     $futureEvent1->setStartAt(getUTCDateTime(2014, 1, 14, 19, 0, 0));
     $futureEvent1->setEndAt(getUTCDateTime(2014, 1, 14, 21, 0, 0));
     $futureEvent2 = new EventModel();
     $futureEvent2->setSlug(3);
     $futureEvent2->setCustomField($customFieldDefinition1, "Dogs go woof");
     // this value has already been corrected
     $futureEvent2->setStartAt(getUTCDateTime(2014, 1, 21, 19, 0, 0));
     $futureEvent2->setEndAt(getUTCDateTime(2014, 1, 21, 21, 0, 0));
     $futureEvent3 = new EventModel();
     $futureEvent3->setSlug(4);
     $futureEvent3->setCustomField($customFieldDefinition1, "Dogs go miaowwwwwwww");
     // this value has already been edited. Possible to overwrite but not recommended
     $futureEvent3->setStartAt(getUTCDateTime(2014, 1, 21, 19, 0, 0));
     $futureEvent3->setEndAt(getUTCDateTime(2014, 1, 21, 21, 0, 0));
     $eventSet->setFutureEvents(array($futureEvent1, $futureEvent2, $futureEvent3));
     $eventHistory = new \models\EventHistoryModel();
     $eventHistory->setFromDataBaseRow(array('event_id' => null, 'summary' => null, 'description' => null, 'start_at' => null, 'end_at' => null, 'created_at' => null, 'is_deleted' => null, 'is_cancelled' => null, 'country_id' => null, 'timezone' => null, 'venue_id' => null, 'url' => null, 'ticket_url' => null, 'is_virtual' => null, 'is_physical' => null, 'area_id' => null, 'user_account_id' => null, 'summary_changed' => '-1', 'description_changed' => '-1', 'start_at_changed' => '-1', 'end_at_changed' => '-1', 'is_deleted_changed' => '-1', 'country_id_changed' => '-1', 'timezone_changed' => '-1', 'venue_id_changed' => '-1', 'url_changed' => '-1', 'is_virtual_changed' => '-1', 'is_physical_changed' => '-1', 'area_id_changed' => '-1', 'is_new' => '-1', 'custom_fields' => json_encode(array('1' => 'Dogs go woof')), 'custom_fields_changed' => json_encode(array('1' => 1))));
     $eventSet->setInitalEventLastChange($eventHistory);
     ## Detect !!!
     $eventSet->applyChangeToFutureEvents();
     ## Test Changes Picked Up
     $proposedChanges1 = $eventSet->getFutureEventsProposedChangesForEventSlug($futureEvent1->getSlug());
     $this->assertEquals(false, $proposedChanges1->getSummaryChangePossible());
     $this->assertEquals(false, $proposedChanges1->getSummaryChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getDescriptionChangePossible());
     $this->assertEquals(false, $proposedChanges1->getDescriptionChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getTimezoneChangePossible());
     $this->assertEquals(false, $proposedChanges1->getTimezoneChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getCountryAreaVenueIdChangePossible());
     $this->assertEquals(false, $proposedChanges1->getCountryAreaVenueIdChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getUrlChangePossible());
     $this->assertEquals(false, $proposedChanges1->getUrlChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getIsVirtualChangePossible());
     $this->assertEquals(false, $proposedChanges1->getIsVirtualChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getIsPhysicalChangePossible());
     $this->assertEquals(false, $proposedChanges1->getIsPhysicalChangeSelected());
     $this->assertEquals(false, $proposedChanges1->getStartEndAtChangePossible());
     $this->assertEquals(false, $proposedChanges1->getStartEndAtChangeSelected());
     $this->assertEquals(true, $proposedChanges1->getCustomFieldChangePossible($customFieldDefinition1));
     $this->assertEquals(true, $proposedChanges1->getCustomFieldChangeSelected($customFieldDefinition1));
     $proposedChanges2 = $eventSet->getFutureEventsProposedChangesForEventSlug($futureEvent2->getSlug());
     $this->assertEquals(false, $proposedChanges2->getSummaryChangePossible());
     $this->assertEquals(false, $proposedChanges2->getSummaryChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getDescriptionChangePossible());
     $this->assertEquals(false, $proposedChanges2->getDescriptionChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getTimezoneChangePossible());
     $this->assertEquals(false, $proposedChanges2->getTimezoneChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getCountryAreaVenueIdChangePossible());
     $this->assertEquals(false, $proposedChanges2->getCountryAreaVenueIdChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getUrlChangePossible());
     $this->assertEquals(false, $proposedChanges2->getUrlChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getIsVirtualChangePossible());
     $this->assertEquals(false, $proposedChanges2->getIsVirtualChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getIsPhysicalChangePossible());
     $this->assertEquals(false, $proposedChanges2->getIsPhysicalChangeSelected());
     $this->assertEquals(false, $proposedChanges2->getStartEndAtChangePossible());
     $this->assertEquals(false, $proposedChanges2->getStartEndAtChangeSelected());
     $this->assertEquals(false, $proposedChanges2->isAnyChangesPossible());
     $this->assertEquals(false, $proposedChanges2->getCustomFieldChangePossible($customFieldDefinition1));
     $this->assertEquals(false, $proposedChanges2->getCustomFieldChangeSelected($customFieldDefinition1));
     $proposedChanges3 = $eventSet->getFutureEventsProposedChangesForEventSlug($futureEvent3->getSlug());
     $this->assertEquals(false, $proposedChanges3->getSummaryChangePossible());
     $this->assertEquals(false, $proposedChanges3->getSummaryChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getDescriptionChangePossible());
     $this->assertEquals(false, $proposedChanges3->getDescriptionChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getTimezoneChangePossible());
     $this->assertEquals(false, $proposedChanges3->getTimezoneChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getCountryAreaVenueIdChangePossible());
     $this->assertEquals(false, $proposedChanges3->getCountryAreaVenueIdChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getUrlChangePossible());
     $this->assertEquals(false, $proposedChanges3->getUrlChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getIsVirtualChangePossible());
     $this->assertEquals(false, $proposedChanges3->getIsVirtualChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getIsPhysicalChangePossible());
     $this->assertEquals(false, $proposedChanges3->getIsPhysicalChangeSelected());
     $this->assertEquals(false, $proposedChanges3->getStartEndAtChangePossible());
     $this->assertEquals(false, $proposedChanges3->getStartEndAtChangeSelected());
     $this->assertEquals(true, $proposedChanges3->isAnyChangesPossible());
     $this->assertEquals(true, $proposedChanges3->getCustomFieldChangePossible($customFieldDefinition1));
     $this->assertEquals(false, $proposedChanges3->getCustomFieldChangeSelected($customFieldDefinition1));
     ## Now Set to don't update and run and test
     $proposedChanges1->setCustomFieldChangeSelected($customFieldDefinition1, false);
     $this->assertEquals(false, $proposedChanges1->applyToEvent($futureEvent1, $initialEventEdited));
     $this->assertEquals("Dogs go miaow", $futureEvent1->getCustomField($customFieldDefinition1));
     ## Now Set to do update and run and test
     $proposedChanges1->setCustomFieldChangeSelected($customFieldDefinition1, true);
     $this->assertEquals(true, $proposedChanges1->applyToEvent($futureEvent1, $initialEventEdited));
     $this->assertEquals("Dogs go woof", $futureEvent1->getCustomField($customFieldDefinition1));
 }
 public function hasDetailsValueForCustomField(EventCustomFieldDefinitionModel $customField)
 {
     $key = 'event.custom.' . $customField->getKey();
     return isset($this->details[$key]) && $this->details[$key];
 }
 public function updateSiteCache($site)
 {
     global $DB;
     $stat = $DB->prepare("SELECT * FROM event_custom_field_definition_information WHERE site_id=:site_id ORDER BY id ASC");
     $stat->execute(array('site_id' => $site instanceof SiteModel ? $site->getId() : $site));
     $out = array();
     while ($data = $stat->fetch()) {
         $ecfd = new EventCustomFieldDefinitionModel();
         $ecfd->setFromDataBaseRow($data);
         $out[] = array('id' => $ecfd->getId(), 'extension_id' => $ecfd->getExtensionId(), 'type' => $ecfd->getType(), 'key' => $ecfd->getKey(), 'label' => $ecfd->getLabel(), 'is_active' => $ecfd->getIsActive());
     }
     $stat = $DB->prepare("UPDATE site_information SET cached_event_custom_field_definitions=:cached_event_custom_field_definitions WHERE id=:id");
     $stat->execute(array('id' => $site instanceof SiteModel ? $site->getId() : $site, 'cached_event_custom_field_definitions' => json_encode($out)));
 }
 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));
 }