Example #1
0
 /**
  * Gets a property path from a given object or array.
  *
  * If propertyPath is "bla.blubb", then we first call getProperty($object, 'bla'),
  * and on the resulting object we call getProperty(..., 'blubb').
  *
  * For arrays the keys are checked likewise.
  *
  * @param mixed $subject An object or array
  * @param string $propertyPath
  * @param \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return mixed Value of the property
  */
 public static function getPropertyPath($subject, $propertyPath, \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     $propertyPathSegments = explode('.', $propertyPath);
     foreach ($propertyPathSegments as $pathSegment) {
         $propertyExists = FALSE;
         $propertyValue = \TYPO3\Fluid\Reflection\ObjectAccess::getPropertyInternal($subject, $pathSegment, FALSE, $propertyExists);
         if ($propertyExists !== TRUE && (is_array($subject) || $subject instanceof \ArrayAccess) && isset($subject[$pathSegment])) {
             $subject = $subject[$pathSegment];
         } else {
             $subject = $propertyValue;
         }
         if ($subject instanceof \TYPO3\Fluid\Core\Parser\SyntaxTree\RenderingContextAwareInterface) {
             $subject->setRenderingContext($renderingContext);
         }
     }
     return $subject;
 }
Example #2
0
 /**
  * @param string $term
  * @return string
  */
 public function autocompleteAction($term)
 {
     $searchProperty = $this->widgetConfiguration['searchProperty'];
     $query = $this->widgetConfiguration['objects']->getQuery();
     $constraint = $query->getConstraint();
     if ($constraint !== NULL) {
         $query->matching($query->logicalAnd($constraint, $query->like($searchProperty, '%' . $term . '%', FALSE)));
     } else {
         $query->matching($query->like($searchProperty, '%' . $term . '%', FALSE));
     }
     $results = $query->execute();
     $output = array();
     foreach ($results as $singleResult) {
         $val = \TYPO3\Fluid\Reflection\ObjectAccess::getProperty($singleResult, $searchProperty);
         $output[] = array('id' => $val, 'label' => $val, 'value' => $val);
     }
     return json_encode($output);
 }
Example #3
0
 /**
  * Groups the given array by the specified groupBy property.
  *
  * @param array $elements The array / traversable object to be grouped
  * @param string $groupBy Group by this property
  * @return array The grouped array in the form array('keys' => array('key1' => [key1value], 'key2' => [key2value], ...), 'values' => array('key1' => array([key1value] => [element1]), ...), ...)
  */
 protected function groupElements(array $elements, $groupBy)
 {
     $groups = array('keys' => array(), 'values' => array());
     foreach ($elements as $key => $value) {
         if (is_array($value)) {
             $currentGroupIndex = isset($value[$groupBy]) ? $value[$groupBy] : NULL;
         } elseif (is_object($value)) {
             $currentGroupIndex = \TYPO3\Fluid\Reflection\ObjectAccess::getPropertyPath($value, $groupBy);
         } else {
             throw new \TYPO3\Fluid\Core\ViewHelper\Exception('GroupedForViewHelper only supports multi-dimensional arrays and objects', 1253120365);
         }
         $currentGroupKeyValue = $currentGroupIndex;
         if (is_object($currentGroupIndex)) {
             $currentGroupIndex = spl_object_hash($currentGroupIndex);
         }
         $groups['keys'][$currentGroupIndex] = $currentGroupKeyValue;
         $groups['values'][$currentGroupIndex][$key] = $value;
     }
     return $groups;
 }
Example #4
0
 /**
  * Get the option value for an object
  *
  * @param mixed $valueElement
  * @return string
  */
 protected function getOptionValueScalar($valueElement)
 {
     if (is_object($valueElement)) {
         if ($this->hasArgument('optionValueField')) {
             return \TYPO3\Fluid\Reflection\ObjectAccess::getPropertyPath($valueElement, $this->arguments['optionValueField']);
         } else {
             if ($this->persistenceManager->getBackend()->getIdentifierByObject($valueElement) !== NULL) {
                 return $this->persistenceManager->getBackend()->getIdentifierByObject($valueElement);
             } else {
                 return (string) $valueElement;
             }
         }
     } else {
         return $valueElement;
     }
 }
 /**
  * Get the current property of the object bound to this form.
  *
  * @return mixed Value
  */
 protected function getPropertyValue()
 {
     $formObject = $this->viewHelperVariableContainer->get('TYPO3\\Fluid\\ViewHelpers\\FormViewHelper', 'formObject');
     $propertyName = $this->arguments['property'];
     if (is_array($formObject)) {
         return isset($formObject[$propertyName]) ? $formObject[$propertyName] : NULL;
     }
     return \TYPO3\Fluid\Reflection\ObjectAccess::getPropertyPath($formObject, $propertyName);
 }