Exemplo n.º 1
0
 /**
  * @test
  */
 public function isPropertySettableWorksOnStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'foo';
     $this->assertTrue(\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'property'));
     $this->assertFalse(\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($stdClassObject, 'undefinedProperty'));
 }
 /**
  * Creates a demand from given settings
  *
  * @param $settings
  * @return ReservationDemand
  */
 protected function createDemandFromSettings($settings)
 {
     /** @var ReservationDemand $demand */
     $demand = $this->objectManager->get(ReservationDemand::class);
     foreach ($settings as $propertyName => $propertyValue) {
         if (empty($propertyValue)) {
             continue;
         }
         switch ($propertyName) {
             case 'maxItems':
                 $demand->setLimit($propertyValue);
                 break;
                 // all following fall through (see below)
             // all following fall through (see below)
             case 'periodType':
             case 'periodStart':
             case 'periodEndDate':
             case 'periodDuration':
             case 'search':
                 break;
             default:
                 if (ObjectAccess::isPropertySettable($demand, $propertyName)) {
                     ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
                 }
         }
     }
     if (isset($settings['period'])) {
         $demand->setPeriod($settings['period']);
         if ($demand->getPeriod() === 'futureOnly' or $demand->getPeriod() == 'pastOnly') {
             $timeZone = new \DateTimeZone(date_default_timezone_get());
             $demand->setStartDate(new \DateTime('midnight', $timeZone));
         }
     }
     if (isset($settings['order']) and is_string($settings['order'])) {
         $demand->setOrder($settings['order']);
     }
     if (isset($settings['maxItems'])) {
         $demand->setLimit($settings['maxItems']);
     }
     return $demand;
 }
 /**
  * Create Demand from Settings
  *
  * @param array $settings
  * @return \DWenzel\T3events\Domain\Model\Dto\EventDemand
  */
 protected function createDemandFromSettings($settings)
 {
     $demand = $this->objectManager->get(CourseDemand::class);
     $demand->setSortBy('headline');
     foreach ($settings as $propertyName => $propertyValue) {
         if (empty($propertyValue)) {
             continue;
         }
         switch ($propertyName) {
             case 'eventTypes':
                 $demand->setEventType($propertyValue);
                 break;
             case 'venues':
                 $demand->setVenue($propertyValue);
                 break;
             case 'maxItems':
                 $demand->setLimit($propertyValue);
                 break;
             case 'genres':
                 $demand->setGenre($propertyValue);
                 break;
                 // all following fall through (see below)
             // all following fall through (see below)
             case 'periodType':
             case 'periodStart':
             case 'periodEndDate':
             case 'periodDuration':
             case 'search':
                 break;
             default:
                 if (ObjectAccess::isPropertySettable($demand, $propertyName)) {
                     ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
                 }
         }
     }
     if (isset($settings['sortBy']) && isset($settings['sortDirection'])) {
         $demand->setOrder($settings['sortBy'] . '|' . $settings['sortDirection']);
     } else {
         $demand->setOrder('headline');
     }
     if ($settings['period'] == 'specific') {
         $demand->setPeriodType($settings['periodType']);
     }
     if (isset($settings['periodType']) and $settings['periodType'] != 'byDate') {
         $demand->setPeriodStart($settings['periodStart']);
         $demand->setPeriodDuration($settings['periodDuration']);
     }
     if ($settings['periodType'] == 'byDate') {
         if ($settings['periodStartDate']) {
             $demand->setStartDate($settings['periodStartDate']);
         }
         if ($settings['periodEndDate']) {
             $demand->setEndDate($settings['periodEndDate']);
         }
     }
     return $demand;
 }
 /**
  * action clone news
  *
  * @param \int $uid	 
  * @return void
  */
 public function cloneNewsAction($uid = 0)
 {
     if ($uid > 0) {
         $defaultStorageFields = array("categories", "contentElements", "relatedFiles", "relatedLinks", "media", "falMedia", "falRelatedFiles");
         $testedStorageFields = array("categories");
         $storageClasses = array("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage");
         $original = $this->newsRepository->findByUid($uid, FALSE);
         $clone = $this->objectManager->create('Tx_MooxNews_Domain_Model_News');
         // $product = source object
         $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getSettablePropertyNames($original);
         foreach ($properties as $name) {
             $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($original, $name);
             if (!in_array($name, $defaultStorageFields) && (!is_object($value) || is_object($value) && !in_array(get_class($value), $storageClasses))) {
                 \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($clone, $name, $value);
             }
         }
         foreach ($properties as $name) {
             $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($original, $name);
             if (in_array($name, $defaultStorageFields) && in_array($name, $testedStorageFields) || !in_array($name, $defaultStorageFields) && is_object($value) && in_array(get_class($value), $storageClasses)) {
                 $getCall = "get" . ucfirst($name);
                 $setCall = "get" . ucfirst($name);
                 if (method_exists($original, $getCall)) {
                     $objects = $original->{$getCall}();
                     if (method_exists($clone->{$getCall}(), "attach")) {
                         if (count($objects)) {
                             foreach ($objects as $object) {
                                 if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($object, "uid")) {
                                     //$object->setUid(NULL);
                                 }
                                 $clone->{$getCall}()->attach($object);
                             }
                         }
                     } elseif (method_exists($clone, $setCall)) {
                         $clone->{$setCall}($objects);
                     }
                 }
             }
         }
         $clone->setTitle($original->getTitle() . " [Kopie]");
         $clone->setHidden(1);
         $this->newsRepository->add($clone);
         $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll();
         $this->flashMessageContainer->add('', 'Eintrag wurde dupliziert', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
     }
     $this->redirect("index");
 }
 /**
  * action create
  *
  * @param Reservation $newReservation
  * @return void
  */
 public function createAction(Reservation $newReservation)
 {
     if (!is_null($newReservation->getUid()) || $this->session instanceof SessionInterface && $this->session->has(self::SESSION_IDENTIFIER_RESERVATION)) {
         $this->denyAccess();
         return;
     }
     if ($contact = $newReservation->getContact()) {
         $contact->setReservation($newReservation);
     }
     $newReservation->setStatus(Reservation::STATUS_DRAFT);
     if ($newReservation->getContactIsParticipant() && is_object($contact)) {
         $participant = new Person();
         foreach (ObjectAccess::getGettableProperties($contact) as $propertyName => $propertyValue) {
             if (ObjectAccess::isPropertySettable($participant, $propertyName)) {
                 ObjectAccess::setProperty($participant, $propertyName, $propertyValue);
             }
         }
         $participant->setType(Person::PERSON_TYPE_PARTICIPANT);
         $newReservation->addParticipant($participant);
         $newReservation->getLesson()->addParticipant($participant);
     }
     $this->addFlashMessage($this->translate('message.reservation.create.success'));
     $this->reservationRepository->add($newReservation);
     $this->persistenceManager->persistAll();
     $this->session->set(self::SESSION_IDENTIFIER_RESERVATION, $newReservation->getUid());
     $this->redirect('edit', null, null, ['reservation' => $newReservation]);
 }
 /**
  * Create demand from settings
  *
  * @param array $settings
  * @return \CPSIT\T3eventsReservation\Domain\Model\Dto\PersonDemand
  */
 protected function createDemandFromSettings($settings)
 {
     /**@var \CPSIT\T3eventsReservation\Domain\Model\Dto\PersonDemand $demand */
     $demand = $this->objectManager->get(PersonDemand::class);
     $demand->setTypes((string) Person::PERSON_TYPE_PARTICIPANT);
     foreach ($settings as $propertyName => $propertyValue) {
         if (empty($propertyValue)) {
             continue;
         }
         switch ($propertyName) {
             case 'maxItems':
                 $demand->setLimit($propertyValue);
                 break;
             case 'category':
                 $demand->setCategories($propertyValue);
                 break;
                 // all following fall through (see below)
             // all following fall through (see below)
             case 'periodType':
             case 'periodStart':
             case 'periodEndDate':
             case 'periodDuration':
             case 'search':
                 break;
             default:
                 if (ObjectAccess::isPropertySettable($demand, $propertyName)) {
                     ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
                 }
         }
     }
     if ($demand->getLessonPeriod() === 'futureOnly' or $demand->getLessonPeriod() === 'pastOnly') {
         $timeZone = new \DateTimeZone(date_default_timezone_get());
         $demand->setLessonDate(new \DateTime('midnight', $timeZone));
     }
     return $demand;
 }