/** * Overwrites a given demand object by an propertyName => $propertyValue array * * @param Tx_News_Domain_Model_Dto_NewsDemand $demand * @param array $overwriteDemand * @return Tx_News_Domain_Model_Dto_NewsDemand */ protected function overwriteDemandObject($demand, $overwriteDemand) { unset($overwriteDemand['orderByAllowed']); foreach ($overwriteDemand as $propertyName => $propertyValue) { Tx_Extbase_Reflection_ObjectAccess::setProperty($demand, $propertyName, $propertyValue); } return $demand; }
/** * @test */ public function setPropertyCanDirectlySetValuesInAnArrayObjectOrArray() { $arrayObject = new ArrayObject(); $array = array(); Tx_Extbase_Reflection_ObjectAccess::setProperty($arrayObject, 'publicProperty', 4242); Tx_Extbase_Reflection_ObjectAccess::setProperty($array, 'key', 'value'); $this->assertEquals(4242, $arrayObject['publicProperty']); $this->assertEquals('value', $array['key']); }
/** * Main action for administration * * @param Tx_News_Domain_Model_Dto_AdministrationDemand $demand * @dontvalidate $demand * @return void */ public function indexAction(Tx_News_Domain_Model_Dto_AdministrationDemand $demand = NULL) { if (is_null($demand)) { $demand = $this->objectManager->get('Tx_News_Domain_Model_Dto_AdministrationDemand'); // Preselect by TsConfig (e.g. tx_news.module.preselect.topNewsRestriction = 1) $tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pageUid); if (isset($tsConfig['tx_news.']['module.']['preselect.']) && is_array($tsConfig['tx_news.']['module.']['preselect.'])) { unset($tsConfig['tx_news.']['module.']['preselect.']['orderByAllowed']); foreach ($tsConfig['tx_news.']['module.']['preselect.'] as $propertyName => $propertyValue) { Tx_Extbase_Reflection_ObjectAccess::setProperty($demand, $propertyName, $propertyValue); } } } $demand = $this->createDemandObjectFromSettings($demand); $categories = $this->categoryRepository->findParentCategoriesByPid($this->pageUid); $idList = array(); foreach ($categories as $c) { $idList[] = $c->getUid(); } $this->view->assignMultiple(array('page' => $this->pageUid, 'demand' => $demand, 'news' => $this->newsRepository->findDemanded($demand, FALSE), 'categories' => $this->categoryRepository->findTree($idList), 'dateformat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'])); }
/** * Maps the given properties to the target object WITHOUT VALIDATING THE RESULT. * If the properties could be set, this method returns TRUE, otherwise FALSE. * Returning TRUE does not mean that the target object is valid and secure! * * Only use this method if you're sure that you don't need validation! * * @param array $propertyNames Names of the properties to map. * @param mixed $source Source containing the properties to map to the target object. Must either be an array, ArrayObject or any other object. * @param object $target The target object * @param array $optionalPropertyNames Names of optional properties. If a property is specified here and it doesn't exist in the source, no error is issued. * @return boolean TRUE if the properties could be mapped, otherwise FALSE * @see mapAndValidate() * @api */ public function map(array $propertyNames, $source, $target, $optionalPropertyNames = array()) { if (!is_object($source) && !is_array($source)) { throw new Tx_Extbase_Property_Exception_InvalidSource('The source object must be a valid object or array, ' . gettype($target) . ' given.', 1187807099); } if (is_string($target) && strpos($target, '_') !== FALSE) { return $this->transformToObject($source, $target, '--none--'); } if (!is_object($target) && !is_array($target)) { throw new Tx_Extbase_Property_Exception_InvalidTarget('The target object must be a valid object or array, ' . gettype($target) . ' given.', 1187807099); } $this->mappingResults = new Tx_Extbase_Property_MappingResults(); if (is_object($target)) { $targetClassSchema = $this->reflectionService->getClassSchema(get_class($target)); } else { $targetClassSchema = NULL; } foreach ($propertyNames as $propertyName) { $propertyValue = NULL; if (is_array($source) || $source instanceof ArrayAccess) { if (isset($source[$propertyName])) { $propertyValue = $source[$propertyName]; } } else { $propertyValue = Tx_Extbase_Reflection_ObjectAccess::getProperty($source, $propertyName); } if ($propertyValue === NULL && !in_array($propertyName, $optionalPropertyNames)) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Required property '{$propertyName}' does not exist.", 1236785359), $propertyName); } else { if ($targetClassSchema !== NULL && $targetClassSchema->hasProperty($propertyName)) { $propertyMetaData = $targetClassSchema->getProperty($propertyName); if (in_array($propertyMetaData['type'], array('array', 'ArrayObject', 'Tx_Extbase_Persistence_ObjectStorage')) && (strpos($propertyMetaData['elementType'], '_') !== FALSE || $propertyValue === '')) { $objects = array(); if (is_array($propertyValue)) { foreach ($propertyValue as $value) { $objects[] = $this->transformToObject($value, $propertyMetaData['elementType'], $propertyName); } } // make sure we hand out what is expected if ($propertyMetaData['type'] === 'ArrayObject') { $propertyValue = new ArrayObject($objects); } elseif ($propertyMetaData['type'] === 'Tx_Extbase_Persistence_ObjectStorage') { $propertyValue = new Tx_Extbase_Persistence_ObjectStorage(); foreach ($objects as $object) { $propertyValue->attach($object); } } else { $propertyValue = $objects; } } elseif ($propertyMetaData['type'] === 'DateTime' || strpos($propertyMetaData['type'], '_') !== FALSE) { $propertyValue = $this->transformToObject($propertyValue, $propertyMetaData['type'], $propertyName); if ($propertyValue === NULL) { continue; } } } elseif ($targetClassSchema !== NULL) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Property '{$propertyName}' does not exist in target class schema.", 1251813614), $propertyName); } if (is_array($target)) { $target[$propertyName] = $propertyValue; } elseif (Tx_Extbase_Reflection_ObjectAccess::setProperty($target, $propertyName, $propertyValue) === FALSE) { $this->mappingResults->addError(new Tx_Extbase_Error_Error("Property '{$propertyName}' could not be set.", 1236783102), $propertyName); } } } return !$this->mappingResults->hasErrors(); }
/** * 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'); }