Exemplo n.º 1
0
 /**
  * Returns a plain value, i.e. objects are flattened out if possible.
  * Multi value objects or arrays will be converted to a comma-separated list for use in IN SQL queries.
  *
  * @param mixed $input The value that will be converted.
  * @param ColumnMap $columnMap Optional column map for retrieving the date storage format.
  * @param callable $parseStringValueCallback Optional callback method that will be called for string values. Can be used to do database quotation.
  * @param array $parseStringValueCallbackParameters Additional parameters that will be passed to the callabck as second parameter.
  * @throws \InvalidArgumentException
  * @throws UnexpectedTypeException
  * @return int|string
  */
 public function getPlainValue($input, $columnMap = null, $parseStringValueCallback = null, array $parseStringValueCallbackParameters = [])
 {
     if ($input === null) {
         return 'NULL';
     }
     if ($input instanceof Persistence\Generic\LazyLoadingProxy) {
         $input = $input->_loadRealInstance();
     }
     if (is_bool($input)) {
         $parameter = (int) $input;
     } elseif ($input instanceof \DateTime) {
         if (!is_null($columnMap) && !is_null($columnMap->getDateTimeStorageFormat())) {
             $storageFormat = $columnMap->getDateTimeStorageFormat();
             $timeZoneToStore = clone $input;
             // set to UTC to store in database
             $timeZoneToStore->setTimezone(new \DateTimeZone('UTC'));
             switch ($storageFormat) {
                 case 'datetime':
                     $parameter = $timeZoneToStore->format('Y-m-d H:i:s');
                     break;
                 case 'date':
                     $parameter = $timeZoneToStore->format('Y-m-d');
                     break;
                 default:
                     throw new \InvalidArgumentException('Column map DateTime format "' . $storageFormat . '" is unknown. Allowed values are datetime or date.', 1395353470);
             }
         } else {
             $parameter = $input->format('U');
         }
     } elseif (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
         $plainValueArray = [];
         foreach ($input as $inputElement) {
             $plainValueArray[] = $this->getPlainValue($inputElement, $columnMap, $parseStringValueCallback, $parseStringValueCallbackParameters);
         }
         $parameter = implode(',', $plainValueArray);
     } elseif ($input instanceof DomainObjectInterface) {
         $parameter = (int) $input->getUid();
     } elseif (is_object($input)) {
         if (TypeHandlingUtility::isCoreType($input)) {
             $parameter = $this->getPlainStringValue($input, $parseStringValueCallback, $parseStringValueCallbackParameters);
         } else {
             throw new UnexpectedTypeException('An object of class "' . get_class($input) . '" could not be converted to a plain value.', 1274799934);
         }
     } else {
         $parameter = $this->getPlainStringValue($input, $parseStringValueCallback, $parseStringValueCallbackParameters);
     }
     return $parameter;
 }
Exemplo n.º 2
0
 /**
  * Returns an "in" criterion used for matching objects against a query. It
  * matches if the property's value is contained in the multivalued operand.
  *
  * @param string $propertyName The name of the property to compare against
  * @param mixed $operand The value to compare with, multivalued
  * @throws Exception\UnexpectedTypeException
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface
  * @api
  */
 public function in($propertyName, $operand)
 {
     if (!\TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::isValidTypeForMultiValueComparison($operand)) {
         throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('The "in" operator must be given a multivalued operand (array, ArrayAccess, Traversable).', 1264678095);
     }
     return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand);
 }