/**
  * @test
  */
 public function getGettablePropertyNamesReturnsAllPropertiesWhichAreAvailable()
 {
     $gettablePropertyNames = Tx_Extbase_Reflection_ObjectAccess::getGettablePropertyNames($this->dummyObject);
     $expectedPropertyNames = array('anotherProperty', 'booleanProperty', 'property', 'property2', 'publicProperty', 'publicProperty2');
     $this->assertEquals($gettablePropertyNames, $expectedPropertyNames, 'getGettablePropertyNames returns not all gettable properties.');
 }
Example #2
0
 /**
  * action beCopy
  *
  * @param Tx_WoehrlSeminare_Domain_Model_Event $event
  * @ignorevalidation $event
  * @return void
  */
 public function beCopyAction($event)
 {
     $availableProperties = Tx_Extbase_Reflection_ObjectAccess::getGettablePropertyNames($event);
     $newEvent = $this->objectManager->create('Tx_WoehrlSeminare_Domain_Model_Event');
     foreach ($availableProperties as $propertyName) {
         if (Tx_Extbase_Reflection_ObjectAccess::isPropertySettable($newEvent, $propertyName) && !in_array($propertyName, array('uid', 'pid', 'subscribers', 'cancelled', 'subEndDateTime', 'subEndDateInfoSent', 'categories', 'discipline'))) {
             $propertyValue = Tx_Extbase_Reflection_ObjectAccess::getProperty($event, $propertyName);
             Tx_Extbase_Reflection_ObjectAccess::setProperty($newEvent, $propertyName, $propertyValue);
         }
     }
     foreach ($event->getCategories() as $cat) {
         $newEvent->addCategory($cat);
     }
     foreach ($event->getDiscipline() as $discipline) {
         $newEvent->addDiscipline($discipline);
     }
     if ($event->getGeniusBar()) {
         $newEvent->setTitle('Wissensbar ' . $newEvent->getContact()->getName());
     } else {
         $newEvent->setTitle($newEvent->getTitle());
     }
     $newEvent->setHidden(TRUE);
     $this->eventRepository->add($newEvent);
     $this->flashMessageContainer->add('Die Veranstaltung ' . $newEvent->getTitle() . ' wurde kopiert.');
     $this->redirect('beList');
 }
 /**
  * Traverses the given object structure in order to transform it into an
  * array structure.
  *
  * @param object $object Object to traverse
  * @param mixed $configuration Configuration for transforming the given object or NULL
  * @return array Object structure as an aray
  * @author Christopher Hlubek <*****@*****.**>
  * @author Dennis Ahrens <*****@*****.**>
  */
 protected function transformObject($object, $configuration)
 {
     // hand over DateTime as ISO formatted string
     if ($object instanceof DateTime) {
         return $object->format('c');
     }
     // load LayzyLoadingProxy instances
     if ($object instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
         $object = $object->_loadRealInstance();
     }
     $propertyNames = Tx_Extbase_Reflection_ObjectAccess::getGettablePropertyNames($object);
     $propertiesToRender = array();
     foreach ($propertyNames as $propertyName) {
         if (isset($configuration['_only']) && is_array($configuration['_only']) && !in_array($propertyName, $configuration['_only'])) {
             continue;
         }
         if (isset($configuration['_exclude']) && is_array($configuration['_exclude']) && in_array($propertyName, $configuration['_exclude'])) {
             continue;
         }
         $propertyValue = Tx_Extbase_Reflection_ObjectAccess::getProperty($object, $propertyName);
         if (!is_array($propertyValue) && !is_object($propertyValue)) {
             $propertiesToRender[$propertyName] = $propertyValue;
         } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) {
             $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]);
         } else {
         }
     }
     if (isset($configuration['_exposeObjectIdentifier']) && $configuration['_exposeObjectIdentifier'] === TRUE) {
         // we don't use the IdentityMap like its done in FLOW3 because there are some cases objects are not registered there.
         // TODO: rethink this solution - it is really quick and dirty...
         $propertiesToRender['__identity'] = $object->getUid();
     }
     return $propertiesToRender;
 }
Example #4
0
 /**
  * Gets the TCA-defined uploadfolder for $object. If no propertyName, then
  * all all properties with uploadfolders are returned as keys along with
  * their respective upload folders as value
  * @param mixed $object
  * @param string $propertyName
  * @return mixed
  * @api
  */
 public function getUploadFolder($object, $propertyName = NULL)
 {
     if (is_object($object) === FALSE) {
         $className = $object;
         $object = $this->objectManager->get($className);
     }
     if ($propertyName === NULL) {
         $properties = Tx_Extbase_Reflection_ObjectAccess::getGettablePropertyNames($object);
         $folders = array();
         foreach ($properties as $propertyName) {
             $uploadFolder = $this->getUploadFolder($object, $propertyName);
             if (is_dir(PATH_site . $uploadFolder)) {
                 $folders[$propertyName] = $uploadFolder;
             }
         }
         return $folders;
     }
     $tableName = $this->getDatabaseTable($object);
     t3lib_div::loadTCA($tableName);
     $underscoredPropertyName = $this->convertCamelCaseToLowerCaseUnderscored($propertyName);
     $uploadFolder = $GLOBALS['TCA'][$tableName]['columns'][$underscoredPropertyName]['config']['uploadfolder'];
     return $uploadFolder;
 }