public function load(ObjectManager $manager) { $recurrence = $this->getReference("recurrence"); $category = $this->getReference("category"); $event = new Event(); $event->setStartdate(new \DateTime("2016-08-02 09:00:00")); $event->setEnddate(new \DateTime("2016-08-02 10:00:00")); }
/** * An event is modifiable if the current user is the author of the event or if he has the 'events.write' permission * * @return boolean */ public function isModifiable(Event $event) { $auth = $this->sm->get('zfcuser_auth_service'); if ($auth->hasIdentity()) { if ($this->getRbac()->isGranted('events.write') || $event->getAuthor() && $event->getAuthor()->getId() === $auth->getIdentity()->getId()) { return true; } } return false; }
/** * @return string */ public function getName() { $name = 'New Trial'; if ($this->event) { $name = $this->event->getName(); } $name .= ' ' . $this->getDateDisplay(); return $name; }
private function getFormBrouillage($idfreq, $event = null) { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); if (!$event) { $event = new Event(); $event->setCategory($em->getRepository('Application\\Entity\\BrouillageCategory')->findOneBy(array('defaultbrouillagecategory' => true))); } $builder = new AnnotationBuilder(); $form = $builder->createForm($event); $form->setHydrator(new DoctrineObject($em))->setObject($event); $form->bind($event); $form->setData($event->getArrayCopy()); $form->get('impact')->setValueOptions($em->getRepository('Application\\Entity\\Impact')->getAllAsArray()); if ($this->zfcUserAuthentication()->hasIdentity()) { $org = $this->zfcUserAuthentication()->getIdentity()->getOrganisation(); $form->get('organisation')->setValue($org->getId()); } $form->get('startdate')->setAttribute('required', true); $form->get('status')->setValue(3); $form->get('punctual')->setValue(true); $form->add(new CustomFieldset($this->getServiceLocator(), $event->getCategory()->getId())); $form->get('custom_fields')->get($event->getCategory()->getFrequencyField()->getId())->setValue($idfreq); $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Enregistrer', 'class' => 'btn btn-primary'))); $form->add(array('name' => 'submitfne', 'attributes' => array('type' => 'submit', 'value' => 'Enregistrer + FNE', 'class' => 'btn btn-primary'))); return array('form' => $form, 'event' => $event); }
public function switchradarAction() { $messages = array(); if ($this->isGranted('events.write') && $this->zfcUserAuthentication()->hasIdentity()) { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $post = $this->getRequest()->getPost(); $state = $this->params()->fromQuery('state', null); $radarid = $this->params()->fromQuery('radarid', null); $now = new \DateTime('NOW'); $now->setTimezone(new \DateTimeZone("UTC")); if ($state != null && $radarid) { $events = $em->getRepository('Application\\Entity\\Event')->getCurrentEvents('Application\\Entity\\RadarCategory'); $radarevents = array(); foreach ($events as $event) { $radarfield = $event->getCategory()->getRadarfield(); foreach ($event->getCustomFieldsValues() as $value) { if ($value->getCustomField()->getId() == $radarfield->getId()) { if ($value->getValue() == $radarid) { $radarevents[] = $event; } } } } if ($state == 'true') { // passage d'un radar à l'état OPE -> recherche de l'evt à fermer if (count($radarevents) == 1) { $event = $radarevents[0]; $endstatus = $em->getRepository('Application\\Entity\\Status')->find('3'); $event->setStatus($endstatus); $event->setEnddate($now); $em->persist($event); try { $em->flush(); $messages['success'][] = "Evènement radar correctement terminé."; } catch (\Exception $e) { $messages['error'][] = $e->getMessage(); } } else { $messages['error'][] = "Impossible de déterminer l'évènement à terminer."; } } else { // passage d'un radar à l'état HS -> on vérifie qu'il n'y a pas d'evt en cours if (count($radarevents) > 0) { $messages['error'][] = "Un évènement est déjà en cours pour ce radar, impossible d'en créer un nouveau"; } else { $event = new Event(); $status = $em->getRepository('Application\\Entity\\Status')->find('2'); $impact = $em->getRepository('Application\\Entity\\Impact')->find('3'); $event->setStatus($status); $event->setStartdate($now); $event->setImpact($impact); $event->setPunctual(false); $radar = $em->getRepository('Application\\Entity\\Radar')->find($radarid); $event->setOrganisation($radar->getOrganisation()); $event->setAuthor($this->zfcUserAuthentication()->getIdentity()); $categories = $em->getRepository('Application\\Entity\\RadarCategory')->findBy(array('defaultradarcategory' => true)); if ($categories) { $cat = $categories[0]; $radarfieldvalue = new CustomFieldValue(); $radarfieldvalue->setCustomField($cat->getRadarfield()); $radarfieldvalue->setValue($radarid); $radarfieldvalue->setEvent($event); $event->addCustomFieldValue($radarfieldvalue); $statusvalue = new CustomFieldValue(); $statusvalue->setCustomField($cat->getStatefield()); $statusvalue->setValue(true); $statusvalue->setEvent($event); $event->addCustomFieldValue($statusvalue); $event->setCategory($categories[0]); $em->persist($radarfieldvalue); $em->persist($statusvalue); //on ajoute les valeurs des champs persos if (isset($post['custom_fields'])) { foreach ($post['custom_fields'] as $key => $value) { // génération des customvalues si un customfield dont le nom est $key est trouvé $customfield = $em->getRepository('Application\\Entity\\CustomField')->findOneBy(array('id' => $key)); if ($customfield) { if (is_array($value)) { $temp = ""; foreach ($value as $v) { $temp .= (string) $v . "\r"; } $value = trim($temp); } $customvalue = new CustomFieldValue(); $customvalue->setEvent($event); $customvalue->setCustomField($customfield); $event->addCustomFieldValue($customvalue); $customvalue->setValue($value); $em->persist($customvalue); } } } //et on sauve le tout $em->persist($event); try { $em->flush(); $messages['success'][] = "Nouvel évènement radar créé."; } catch (\Exception $e) { $messages['error'][] = $e->getMessage(); } } else { $messages['error'][] = "Impossible de créer un nouvel évènement."; } } } } else { $messages['error'][] = "Requête incorrecte, impossible de trouver le radar correspondant."; } } else { $messages['error'][] = "Droits insuffisants pour modifier l'état du radar"; } return new JsonModel($messages); }
public function exclude(Event $event) { $exdate = new RecurrenceExDate($event->getStartdate()); $this->addExDates($exdate); $this->events->removeElement($event); }
/** * @param User $user * @param Event $event * @return null|object */ public function getRsvpForEventByUser(User $user, Event $event) { $entityRepository = $this->entityManager->getRepository('Application\\Entity\\RSVP'); $rsvp = $entityRepository->findOneBy(['event' => $event->getId(), 'user' => $user->getId()]); return $rsvp; }
/** * Cloture d'un evt : terminé ou annulé (statut 3 ou 4) * TODO : use $event->close or $event->cancel * * @param Event $event */ private function closeEvent(Event $event) { $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); foreach ($event->getChildren() as $child) { if ($child->getCategory() instanceof FrequencyCategory) { // on termine les évènements fils de type fréquence if ($event->getStatus()->getId() == 3) { // date de fin uniquement pour les fermetures $child->setEnddate($event->getEnddate()); } $child->setStatus($event->getStatus()); } else { if ($child->getCategory() instanceof \Application\Entity\AlarmCategory) { // si evt annulé uniquement : on annule toutes les alarmes if ($event->getStatus()->getId() == 4 || $event->getStatus()->getId() == 5) { $child->setStatus($event->getStatus()); } } } $objectManager->persist($child); } }
public function __construct(Member $memberEntity, Event $eventEntity, ObjectManager $objectManager) { parent::__construct('entry'); $this->filter = new InputFilter(); $dog = new AppElement\ObjectLiveSearch('dog'); $dog->setOption('object_manager', $objectManager); $dog->setOption('target_class', 'Application\\Entity\\Dog'); $dog->setOption('find_method', array('name' => 'findBy', 'params' => array('criteria' => array('primary' => $memberEntity->getId()), 'orderBy' => array('callName' => 'ASC')))); $dog->setEmptyOption('Select a Dog'); $this->add($dog); $dogFilter = new Input('dog'); $dogFilter->setRequired(true); $this->filter->add($dogFilter); $entryNum = 0; foreach ($eventEntity->getTrials() as $trialEntity) { $trial = new Form('trial_' . $trialEntity->getId()); $trial->setLabel($trialEntity->getDateDisplay()); $this->add($trial); foreach ($trialEntity->getTrialDivisions() as $trialDivisionEntity) { $divisionEntity = $trialDivisionEntity->getDivision(); for ($whichDivisionNum = 1; $whichDivisionNum <= $trialDivisionEntity->getNumOffered(); $whichDivisionNum++) { $entry = new Fieldset('entry_' . $entryNum++); $entry->setOption('twb-layout', 'inline'); $entry->setAttribute('data-price', trim($trialDivisionEntity->getEntryFee(), '$')); $entry->setAttribute('class', 'form-group entry-form'); $this->add($entry); $entry->filter = new InputFilter(); $this->filter->add($entry->filter); $hiddenTrial = new Element\Hidden('trial'); $hiddenTrial->setValue($trialEntity->getId()); $entry->add($hiddenTrial); $hiddenDivision = new Element\Hidden('division'); $hiddenDivision->setValue($divisionEntity->getId()); $entry->add($hiddenDivision); $whichDivision = new Element\Hidden('whichDivision'); $whichDivision->setValue($whichDivisionNum); $entry->add($whichDivision); $entered = new Element\Checkbox('entered'); $entered->setLabel($divisionEntity . ($trialDivisionEntity->getNumOffered() > 1 ? ' #' . $whichDivisionNum : '')); $entry->add($entered); $enteredFilter = new Input('entered'); $enteredFilter->setRequired(false); $entry->filter->add($enteredFilter); if (!$divisionEntity->isAllLevels()) { $level = new AppElement\ObjectLiveSearch('level'); $level->setOption('object_manager', $objectManager); $level->setOption('target_class', 'Application\\Entity\\Level'); $level->setOption('find_method', array('name' => 'findBy', 'params' => array('criteria' => array(), 'orderBy' => array('rank' => 'ASC')))); $level->setEmptyOption('Select a Level'); $entry->add($level); $levelFilter = new Input('level'); $levelFilter->setRequired(false); $entry->filter->add($levelFilter); } $exhibitionOnly = new Element\Checkbox('exhibitionOnly'); $exhibitionOnly->setLabelAttributes(array('class' => 'small col-md-offset-2')); $exhibitionOnly->setLabel('For exhibition only'); $entry->add($exhibitionOnly); $exhibitionOnlyFilter = new Input('exhibitionOnly'); $exhibitionOnlyFilter->setRequired(false); $entry->filter->add($exhibitionOnlyFilter); } } } $buttons = new Form('buttons'); $buttons->setOption('twb-layout', 'inline'); $buttons->setAttribute('class', 'form-group'); $submit = new Element\Submit('submit'); $submit->setAttribute('class', 'btn-event pull-right'); $submit->setOption('glyphicon', 'circle-arrow-up'); $submit->setLabel('Submit Entry'); $buttons->add($submit); $cancel = new Element\Submit('cancel'); $cancel->setAttribute('formnovalidate', true); $cancel->setAttribute('class', 'btn-warning pull-right'); $cancel->setOption('glyphicon', 'ban-circle'); $cancel->setLabel('Cancel'); $buttons->add($cancel); $this->add($buttons); }
/** * @param Event $event * @return bool */ public function hasEventEntry(Event $event) { $trialIds = []; foreach ($event->getTrials() as $trial) { $trialIds[] = $trial->getId(); } return (bool) count($this->entries->matching(Criteria::create()->where(Criteria::expr()->in('trial', $trialIds)))); }
public function createFromEvent(Event $e) { $this->setCategory($e->getCategory()); $this->setAuthor($e->getAuthor()); $this->setOrganisation($e->getOrganisation()); $this->setImpact($e->getImpact()); $this->setPunctual($e->isPunctual()); }
/** * Renvoit un nouvel évènement créé à partir d'un évènement et d'une date de début * Les notes ne sont pas copiées, le statut est mis à "nouveau" * @param Event $event * @param \DateTime $start UTC start date */ public function createFromEvent(Event $event, $start) { $newevent = new Event(); $newevent->setAuthor($event->getAuthor()); $newevent->setOrganisation($event->getOrganisation()); $newevent->setCategory($event->getCategory()); $newevent->setImpact($event->getImpact()); $newevent->setStatus($this->getEntityManager()->getRepository('Application\\Entity\\Status')->find(1)); if ($event->getPlace() !== null) { $newevent->setPlace($event->getPlace()); } //horaires $newevent->setScheduled($event->isScheduled()); $newevent->setPunctual($event->isPunctual()); if ($start !== null) { //actions can have no start date $newevent->setStartdate($start); if (!$event->isPunctual() && $event->getEnddate() !== null) { $diff = $event->getStartdate()->diff($event->getEnddate()); $end = clone $start; $end->add($diff); $newevent->setEnddate($end); } } //enfants foreach ($event->getChildren() as $child) { $childdate = $start; if ($child->getCategory() instanceof AlarmCategory) { $diff = $event->getStartdate()->diff($child->getStartdate()); $alarmdate = clone $newevent->getStartdate(); $alarmdate->add($diff); $childdate = $alarmdate; } else { if ($child->getCategory() instanceof ActionCategory) { $childdate = null; } } $childEvent = $this->createFromEvent($child, $childdate); $childEvent->setParent($newevent); $newevent->addChild($childEvent); } //champs foreach ($event->getCustomFieldsValues() as $customFieldsValue) { $customFieldValue = new CustomFieldValue(); $customFieldValue->setEvent($newevent); $customFieldValue->setCustomField($customFieldsValue->getCustomField()); $customFieldValue->setValue($customFieldsValue->getValue()); $newevent->addCustomFieldValue($customFieldValue); } //fichiers foreach ($event->getFiles() as $file) { $newevent->addFile($file); } return $newevent; }
private function doAddMilEvent(\Application\Entity\MilCategory $cat, \Application\Entity\Organisation $organisation, \Core\Entity\User $user, $designator, \DateTime $timeBegin, \DateTime $timeEnd, $upperLevel, $lowerLevel, &$messages) { $event = new \Application\Entity\Event(); $event->setOrganisation($organisation); $event->setAuthor($user); $event->setCategory($cat); $event->setScheduled(false); $event->setPunctual(false); $event->setStartdate($timeBegin); $status = $this->getEntityManager()->getRepository('Application\\Entity\\Status')->find('1'); $event->setStatus($status); $impact = $this->getEntityManager()->getRepository('Application\\Entity\\Impact')->find('2'); $event->setImpact($impact); $event->setEnddate($timeEnd); // name $name = new \Application\Entity\CustomFieldValue(); $name->setCustomField($cat->getFieldname()); $name->setEvent($event); $name->setValue($designator); // upperlevel $upper = new \Application\Entity\CustomFieldValue(); $upper->setCustomField($cat->getUpperLevelField()); $upper->setEvent($event); $upper->setValue($upperLevel); // lowerlevel $lower = new \Application\Entity\CustomFieldValue(); $lower->setCustomField($cat->getLowerLevelField()); $lower->setEvent($event); $lower->setValue($lowerLevel); // recherche d'un modèle existant $models = $this->getEntityManager()->getRepository('Application\\Entity\\PredefinedEvent')->findBy(array('name' => $designator, 'organisation' => $organisation, 'category' => $cat)); if (count($models) === 1) { $model = $models[0]; // ajout des mémos foreach ($model->getChildren() as $child) { if ($child->getCategory() instanceof \Application\Entity\AlarmCategory) { $alarm = new Event(); $alarm->setCategory($this->getEntityManager()->getRepository('Application\\Entity\\AlarmCategory')->findAll()[0]); $alarm->setAuthor($user); $alarm->setOrganisation($organisation); $alarm->setParent($event); $alarm->setStatus($status); $alarm->setPunctual(true); $alarm->setImpact($impact); $startdate = $timeBegin; $alarm->setStartdate($startdate); $namememo = new CustomFieldValue(); $namefield = $alarm->getCategory()->getNamefield(); $namememo->setCustomField($namefield); $namememo->setValue($child->getCustomFieldValue($namefield)->getValue()); $namememo->setEvent($alarm); $alarm->addCustomFieldValue($namememo); $comment = new CustomFieldValue(); $commentfield = $alarm->getCategory()->getTextfield(); $comment->setCustomField($commentfield); $comment->setValue($child->getCustomFieldValue($commentfield)->getValue()); $comment->setEvent($alarm); $alarm->addCustomFieldValue($comment); $deltabegin = new CustomFieldValue(); $beginfield = $alarm->getCategory()->getDeltaBeginField(); $deltabegin->setCustomField($beginfield); $deltabegin->setValue($child->getCustomFieldValue($beginfield)->getValue()); $deltabegin->setEvent($alarm); $alarm->addCustomFieldValue($deltabegin); $deltaend = new CustomFieldValue(); $endfield = $alarm->getCategory()->getDeltaEndField(); $deltaend->setCustomField($endfield); $deltaend->setValue($child->getCustomFieldValue($endfield)->getValue()); $deltaend->setEvent($alarm); $alarm->addCustomFieldValue($deltaend); $event->addChild($alarm); $this->getEntityManager()->persist($namememo); $this->getEntityManager()->persist($comment); $this->getEntityManager()->persist($deltabegin); $this->getEntityManager()->persist($deltaend); $this->getEntityManager()->persist($alarm); } } //ajout des fichiers foreach ($model->getFiles() as $file) { $file->addEvent($event); $this->getEntityManager()->persist($file); } $event->updateAlarms(); } try { $this->getEntityManager()->persist($name); $this->getEntityManager()->persist($upper); $this->getEntityManager()->persist($lower); $this->getEntityManager()->persist($event); $this->getEntityManager()->flush(); } catch (\Exception $ex) { error_log($ex->getMessage()); if ($messages != null) { $messages['error'][] = $ex->getMessage(); } } }
public function editAction() { $form = new \Admin\Form\EventForm(); $id = (int) $this->params()->fromRoute('id', 0); if ($id > 0) { $model = $this->getObjectManager()->find($this->_modelName, $id); $form->setData($model->toArray()); $form->setAttribute('action', '/admin/' . $this->_modelAlias . '/edit/' . $id); $form->get('submit')->setAttribute('value', 'Edit'); $model->setUpdatedDate(new \DateTime()); $viewVariables['action'] = 'Edit'; } else { $model = new Event(); $form->setAttribute('action', '/admin/' . $this->_modelAlias . '/add'); $form->get('submit')->setAttribute('value', 'Add'); $model->setUpdatedDate(new \DateTime()); $model->setCreatedDate(new \DateTime()); $viewVariables['action'] = 'Add'; } $thumbDateObject = new \DateTime(); $thumbDate = $thumbDateObject->format("Y-m-d"); if ($model->getUpdatedDate() instanceof \DateTime) { $thumbDate = $model->getUpdatedDate()->format("Y-m-d"); } elseif ($model->getCreatedDate() instanceof \DateTime) { $thumbDate = $model->getCreatedDate()->format("Y-m-d"); } $eventThumbFolder = '/public/uploads/events/' . $thumbDate; $viewVariables['eventThumbFolder'] = $eventThumbFolder; $tempFile = null; $prg = $this->fileprg($form); if ($prg instanceof \Zend\Http\PhpEnvironment\Response) { return $prg; } elseif (is_array($prg)) { $model->populate($form->getData()); $fileErrors = $form->get('thumb')->getMessages(); if (empty($fileErrors)) { $tempFile = $form->get('thumb')->getValue(); if (!is_null($tempFile)) { $tempFileName = $eventThumbFolder . "/" . basename($tempFile['tmp_name']); $model->setThumb($tempFileName); } } $model->setBody(stripslashes($model->getBody())); if ($form->isValid()) { $this->getObjectManager()->persist($model); $this->getObjectManager()->flush(); return $this->redirect()->toUrl('/admin/' . $this->_modelAlias); } else { var_dump($form->getMessages()); } } $viewVariables['form'] = $form; $viewVariables['model'] = $model; $this->_view->setTemplate('admin/' . $this->_modelAlias . '/edit'); $this->_view->setVariables($viewVariables); return $this->_view; }