/**
  * @return array
  */
 public function categoriesDataProvider()
 {
     $category1 = $this->getMock('Pws\\KesearchCategories\\Domain\\Model\\Category', array(), array(), '', false);
     $category1->expects($this->once())->method('getFilterOptionTag')->willReturn('onetitle');
     $category2 = $this->getMock('Pws\\KesearchCategories\\Domain\\Model\\Category', array(), array(), '', false);
     $category2->expects($this->once())->method('getFilterOptionTag')->willReturn('secondtitle');
     $objectStorage = new ObjectStorage();
     $objectStorage->attach($category1);
     $objectStorage->attach($category2);
     return array(array($objectStorage));
 }
Esempio n. 2
0
 /**
  * @return ObjectStorage
  */
 public function constructObjectStorageContainingFrontendUsersWithUserGroups()
 {
     $storage = new ObjectStorage();
     $userGroup1 = new FrontendUserGroup('my first group');
     $userGroup2 = new FrontendUserGroup('my second group');
     $user1 = new FrontendUser();
     $user2 = new FrontendUser();
     $user1->addUsergroup($userGroup1);
     $user2->addUsergroup($userGroup2);
     $storage->attach($user1);
     $storage->attach($user2);
     return $storage;
 }
 /**
  * Validate object
  *
  * @param mixed $object
  * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException
  * @throws \InvalidArgumentException
  * @return boolean|\TYPO3\CMS\Extbase\Error\Result
  */
 public function validate($object)
 {
     $messages = new \TYPO3\CMS\Extbase\Error\Result();
     if (self::$instancesCurrentlyUnderValidation === NULL) {
         self::$instancesCurrentlyUnderValidation = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     }
     if ($object === NULL) {
         return $messages;
     }
     if (!$this->canValidate($object)) {
         $messages->addError(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notvalidatable', 'StoreFinder'), 1301599551);
         return $messages;
     }
     if (self::$instancesCurrentlyUnderValidation->contains($object)) {
         return $messages;
     } else {
         self::$instancesCurrentlyUnderValidation->attach($object);
     }
     $this->model = $object;
     $propertyValidators = $this->getValidationRulesFromSettings();
     foreach ($propertyValidators as $propertyName => $validatorsNames) {
         if (!property_exists($object, $propertyName)) {
             $messages->addError(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notexists', 'StoreFinder'), 1301599575);
         } else {
             $this->currentPropertyName = $propertyName;
             $propertyValue = $this->getPropertyValue($object, $propertyName);
             $this->checkProperty($propertyValue, (array) $validatorsNames, $messages->forProperty($propertyName));
         }
     }
     self::$instancesCurrentlyUnderValidation->detach($object);
     return $messages;
 }
 /**
  * Update an object in the persistence.
  *
  * @param object $object The modified object
  * @return void
  * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
  * @api
  */
 public function update($object)
 {
     if ($this->isNewObject($object)) {
         throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The object of type "' . get_class($object) . '" given to update must be persisted already, but is new.', 1249479819);
     }
     $this->changedObjects->attach($object);
 }
Esempio n. 5
0
 /**
  * Call the view helper associated with this object.
  *
  * First, it evaluates the arguments of the view helper.
  *
  * If the view helper implements \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface,
  * it calls setChildNodes(array childNodes) on the view helper.
  *
  * Afterwards, checks that the view helper did not leave a variable lying around.
  *
  * @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return string evaluated node after the view helper has been called.
  */
 public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     if ($this->viewHelpersByContext->contains($renderingContext)) {
         $viewHelper = $this->viewHelpersByContext[$renderingContext];
         $viewHelper->resetState();
     } else {
         $viewHelper = clone $this->uninitializedViewHelper;
         $this->viewHelpersByContext->attach($renderingContext, $viewHelper);
     }
     $evaluatedArguments = array();
     if (count($viewHelper->prepareArguments())) {
         foreach ($viewHelper->prepareArguments() as $argumentName => $argumentDefinition) {
             if (isset($this->arguments[$argumentName])) {
                 $argumentValue = $this->arguments[$argumentName];
                 $evaluatedArguments[$argumentName] = $argumentValue->evaluate($renderingContext);
             } else {
                 $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue();
             }
         }
     }
     $viewHelper->setArguments($evaluatedArguments);
     $viewHelper->setViewHelperNode($this);
     $viewHelper->setRenderingContext($renderingContext);
     if ($viewHelper instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface) {
         $viewHelper->setChildNodes($this->childNodes);
     }
     $output = $viewHelper->initializeArgumentsAndRender();
     return $output;
 }
Esempio n. 6
0
 /**
  * @param object $object
  * @param int $level
  * @param bool $plainText
  * @param bool $ansiColors
  * @return string The rendered body content of the Object(Storage)
  */
 protected static function renderContent($object, $level, $plainText, $ansiColors)
 {
     $dump = '';
     if ($object instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage || $object instanceof \Iterator || $object instanceof \ArrayObject) {
         $dump .= self::renderCollection($object, $level, $plainText, $ansiColors);
     } else {
         self::$renderedObjects->attach($object);
         if (!$plainText) {
             $dump .= '<a name="' . spl_object_hash($object) . '" id="' . spl_object_hash($object) . '"></a>';
         }
         if (get_class($object) === 'stdClass') {
             $objReflection = new \ReflectionObject($object);
             $properties = $objReflection->getProperties();
         } else {
             $classReflection = new \ReflectionClass(get_class($object));
             $properties = $classReflection->getProperties();
         }
         foreach ($properties as $property) {
             if (self::isBlacklisted($property)) {
                 continue;
             }
             $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level) . ($plainText ? '' : '<span class="extbase-debug-property">') . self::ansiEscapeWrap($property->getName(), '37', $ansiColors) . ($plainText ? '' : '</span>') . ' => ';
             $property->setAccessible(true);
             $dump .= self::renderDump($property->getValue($object), $level, $plainText, $ansiColors);
             if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject && !$object->_isNew() && $object->_isDirty($property->getName())) {
                 if ($plainText) {
                     $dump .= ' ' . self::ansiEscapeWrap('modified', '43;30', $ansiColors);
                 } else {
                     $dump .= '<span class="extbase-debug-dirty">modified</span>';
                 }
             }
         }
     }
     return $dump;
 }
 /**
  * @test
  */
 public function sortElementsAsDefinedInFlexFormsWithObjectStorage()
 {
     $records = new ObjectStorage();
     $videoMock1 = $this->getMock(Video::class, ['getUid']);
     $videoMock1->expects($this->any())->method('getUid')->will($this->returnValue(1));
     $videoMock2 = $this->getMock(Video::class, ['getUid']);
     $videoMock2->expects($this->any())->method('getUid')->will($this->returnValue(3));
     $videoMock3 = $this->getMock(Video::class, ['getUid']);
     $videoMock3->expects($this->any())->method('getUid')->will($this->returnValue(4));
     $videoMock4 = $this->getMock(Video::class, ['getUid']);
     $videoMock4->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $records->attach($videoMock1);
     $records->attach($videoMock2);
     $records->attach($videoMock3);
     $records->attach($videoMock4);
     self::assertSame([$videoMock2, $videoMock3, $videoMock1, $videoMock4], $this->subject->sortElementsAsDefinedInFlexForms('3,4,1,5', $records));
 }
Esempio n. 8
0
 /**
  * Deletes an object
  *
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object The object to be removed from the storage
  * @param boolean $markAsDeleted Wether to just flag the row deleted (default) or really delete it
  * @return void
  */
 protected function removeEntity(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $markAsDeleted = TRUE)
 {
     $this->signalSlotDispatcher->dispatch('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', 'beforeRemoveObjectHijax', array('object' => $object));
     // TODO: check if object is not already deleted
     parent::removeEntity($object, $markAsDeleted);
     // TODO: check if object is removed indeed
     $this->signalSlotDispatcher->dispatch('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', 'afterRemoveObjectHijax', array('object' => $object));
     $this->_removedObjects->attach($object);
 }
Esempio n. 9
0
 /**
  * @return array
  */
 public function getNegativeTestValues()
 {
     $bar = new Bar();
     ObjectAccess::setProperty($bar, 'uid', 1, TRUE);
     $foo = new Foo();
     ObjectAccess::setProperty($foo, 'uid', 2, TRUE);
     $objectStorage = new ObjectStorage();
     $objectStorage->attach($bar);
     /** @var LazyObjectStorage $lazyObjectStorage */
     $lazyObjectStorage = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage', $bar, 'foo', 0);
     ObjectAccess::setProperty($lazyObjectStorage, 'isInitialized', TRUE, TRUE);
     $lazyObjectStorage->attach($foo);
     return array(array(array('foo'), 'bar'), array('foo,baz', 'bar'), array($objectStorage, $foo), array($lazyObjectStorage, $bar));
 }
 /**
  * @param $pages
  */
 public function getEntriesFromPages($pages)
 {
     foreach ($pages as $page) {
         if (intval($page['doktype']) === 1) {
             $urlEntry = new UrlEntry();
             $uri = $this->generatePageUrl($page['uid']);
             $urlEntry->setLoc($uri);
             $urlEntry->setLastmod(date('Y-m-d', $page['tstamp']));
             if (isset($page['sitemap_priority'])) {
                 $urlEntry->setPriority(number_format($page['sitemap_priority'] / 10, 1, '.', ''));
             }
             if (isset($page['sitemap_changefreq'])) {
                 $urlEntry->setChangefreq($page['sitemap_changefreq']);
             }
             $this->entryStorage->attach($urlEntry);
         }
     }
 }
Esempio n. 11
0
 /**
  * @test
  */
 public function tansientObjectsWithObjectStorageAreConvertedToAnArrayOfProperties()
 {
     $mockValueObject = new ValueObjectFixture();
     $objectStorage = new ObjectStorage();
     $mockValueObject->name = 'foo';
     $mockValueObject2 = new ValueObjectFixture();
     $mockValueObject2->name = 'bar';
     $objectStorage->attach($mockValueObject2);
     $mockValueObject->object = $objectStorage;
     $uriBuilder = new UriBuilder();
     $actualResult = $uriBuilder->convertTransientObjectToArray($mockValueObject);
     $expectedResult = array('name' => 'foo', 'object' => array(array('name' => 'bar', 'uid' => null, 'pid' => null, 'object' => null)), 'uid' => null, 'pid' => null);
     $this->assertEquals($expectedResult, $actualResult);
 }
 /**
  * @test
  */
 public function prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndSecondPage()
 {
     $this->controller->_set('currentPage', 2);
     $objects = new ObjectStorage();
     for ($i = 0; $i <= 55; $i++) {
         $item = new \stdClass();
         $objects->attach($item);
     }
     $this->controller->_set('objects', $objects);
     $expectedPortion = array();
     for ($j = 10; $j <= 19; $j++) {
         $expectedPortion[] = $objects->toArray()[$j];
     }
     $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 10));
 }
Esempio n. 13
0
 /**
  * @test
  */
 public function getModelDataRecursiveWithObjectStorageTest()
 {
     $testDate = new \DateTime();
     $model = new MyNestedModelWithObjectStorage();
     $model->setDate($testDate);
     $model->_setProperty('uid', 1);
     $childModel = new MyNestedModel();
     $childModel->setDate($testDate);
     $childModel->_setProperty('uid', 2);
     $children = new ObjectStorage();
     $children->attach($model);
     $children->attach($childModel);
     $model->setChildren($children);
     $expectedOutput = array('base' => 'Base', 'date' => $testDate, 'child' => array('uid' => null, 'pid' => null, '__class' => 'Cundd\\Rest\\Tests\\MyModel', 'name' => 'Initial value'), 'uid' => 1, 'pid' => null, '__class' => 'Cundd\\Rest\\Tests\\MyNestedModelWithObjectStorage', 'children' => array(0 => 'http:///rest/cundd-rest-tests-my_nested_model_with_object_storage/1/', 1 => array('base' => 'Base', 'date' => $testDate, 'uid' => 2, 'pid' => null, '__class' => 'Cundd\\Rest\\Tests\\MyNestedModel', 'child' => array('name' => 'Initial value', 'uid' => null, 'pid' => null, '__class' => 'Cundd\\Rest\\Tests\\MyModel'))));
     $this->assertEquals($expectedOutput, $this->fixture->getModelData($model));
     // Make sure the same result is returned if getModelData() is invoked again
     $this->assertEquals($expectedOutput, $this->fixture->getModelData($model));
 }
 /**
  * @param ObjectStorage $categories
  * @return ObjectStorage
  */
 protected function getChildCategories(ObjectStorage $categories)
 {
     $childCategories = new ObjectStorage();
     foreach ($categories as $category) {
         if ($children = $this->getCatgeoryRepository()->findByParent($category)) {
             while ($children->current()) {
                 $childCategories->attach($children->current());
                 $children->next();
             }
         }
     }
     return $childCategories;
 }
Esempio n. 15
0
 /**
  * @param object $object
  * @param int $level
  * @param bool $plainText
  * @param bool $ansiColors
  * @return string The rendered body content of the Object(Storage)
  */
 protected static function renderContent($object, $level, $plainText, $ansiColors)
 {
     $dump = '';
     if ($object instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage || $object instanceof \Iterator || $object instanceof \ArrayObject) {
         $dump .= self::renderCollection($object, $level, $plainText, $ansiColors);
     } else {
         self::$renderedObjects->attach($object);
         if (!$plainText) {
             $dump .= '<a name="' . spl_object_hash($object) . '" id="' . spl_object_hash($object) . '"></a>';
         }
         if ($object instanceof \Closure) {
             $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level) . ($plainText ? '' : '<span class="extbase-debug-closure">') . self::ansiEscapeWrap('function (', '33', $ansiColors) . ($plainText ? '' : '</span>');
             $reflectionFunction = new \ReflectionFunction($object);
             $params = [];
             foreach ($reflectionFunction->getParameters() as $parameter) {
                 $parameterDump = '';
                 if ($parameter->isArray()) {
                     if ($plainText) {
                         $parameterDump .= self::ansiEscapeWrap('array ', '36', $ansiColors);
                     } else {
                         $parameterDump .= '<span class="extbase-debug-type">array </span>';
                     }
                 } elseif ($parameter->getClass()) {
                     if ($plainText) {
                         $parameterDump .= self::ansiEscapeWrap($parameter->getClass()->name . ' ', '36', $ansiColors);
                     } else {
                         $parameterDump .= '<span class="extbase-debug-type">' . htmlspecialchars($parameter->getClass()->name) . '</span>';
                     }
                 }
                 if ($parameter->isPassedByReference()) {
                     $parameterDump .= '&';
                 }
                 if ($plainText) {
                     $parameterDump .= self::ansiEscapeWrap('$' . $parameter->name, '37', $ansiColors);
                 } else {
                     $parameterDump .= '<span class="extbase-debug-property">' . htmlspecialchars('$' . $parameter->name) . '</span>';
                 }
                 if ($parameter->isOptional()) {
                     $parameterDump .= ' = ';
                     if ($plainText) {
                         $parameterDump .= self::ansiEscapeWrap(var_export($parameter->getDefaultValue(), true), '33', $ansiColors);
                     } else {
                         $parameterDump .= '<span class="extbase-debug-string">' . htmlspecialchars(var_export($parameter->getDefaultValue(), true)) . '</span>';
                     }
                 }
                 $params[] = $parameterDump;
             }
             $dump .= implode(', ', $params);
             if ($plainText) {
                 $dump .= self::ansiEscapeWrap(') {' . PHP_EOL, '33', $ansiColors);
             } else {
                 $dump .= '<span class="extbase-debug-closure">) {' . PHP_EOL . '</span>';
             }
             $lines = file($reflectionFunction->getFileName());
             for ($l = $reflectionFunction->getStartLine(); $l < $reflectionFunction->getEndLine() - 1; ++$l) {
                 $dump .= $plainText ? $lines[$l] : htmlspecialchars($lines[$l]);
             }
             $dump .= str_repeat(self::PLAINTEXT_INDENT, $level);
             if ($plainText) {
                 $dump .= self::ansiEscapeWrap('}' . PHP_EOL, '33', $ansiColors);
             } else {
                 $dump .= '<span class="extbase-debug-closure">}</span>';
             }
         } else {
             if (get_class($object) === 'stdClass') {
                 $objReflection = new \ReflectionObject($object);
                 $properties = $objReflection->getProperties();
             } else {
                 $classReflection = new \ReflectionClass(get_class($object));
                 $properties = $classReflection->getProperties();
             }
             foreach ($properties as $property) {
                 if (self::isBlacklisted($property)) {
                     continue;
                 }
                 $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level);
                 if ($plainText) {
                     $dump .= self::ansiEscapeWrap($property->getName(), '37', $ansiColors);
                 } else {
                     $dump .= '<span class="extbase-debug-property">' . htmlspecialchars($property->getName()) . '</span>';
                 }
                 $dump .= ' => ';
                 $property->setAccessible(true);
                 $visibility = $property->isProtected() ? 'protected' : ($property->isPrivate() ? 'private' : 'public');
                 if ($plainText) {
                     $dump .= self::ansiEscapeWrap($visibility, '42;30', $ansiColors) . ' ';
                 } else {
                     $dump .= '<span class="extbase-debug-visibility">' . $visibility . '</span>';
                 }
                 $dump .= self::renderDump($property->getValue($object), $level, $plainText, $ansiColors);
                 if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject && !$object->_isNew() && $object->_isDirty($property->getName())) {
                     if ($plainText) {
                         $dump .= ' ' . self::ansiEscapeWrap('modified', '43;30', $ansiColors);
                     } else {
                         $dump .= '<span class="extbase-debug-dirty">modified</span>';
                     }
                 }
             }
         }
     }
     return $dump;
 }
Esempio n. 16
0
 /**
  * @test
  */
 public function returnsArrayForTypeObjectStorage()
 {
     $domainObject = new Foo();
     $storage = new ObjectStorage();
     $storage->attach($domainObject);
     $viewHelper = $this->getAccessibleMock('FluidTYPO3\\Vhs\\ViewHelpers\\Variable\\ConvertViewHelper', array('renderChildren'));
     $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue($storage));
     $viewHelper->setArguments(array('type' => 'array'));
     $converted = $viewHelper->render();
     $this->assertInternalType('array', $converted);
     $this->assertEquals(1, count($converted));
 }
 /**
  * Test for isValid()
  *
  * @param string $value
  * @param bool $expectedResult
  * @return void
  * @dataProvider validateIsValidReturnsBoolDataProvider
  * @test
  */
 public function validateIsValidReturnsBool($value, $expectedResult)
 {
     $mail = new Mail();
     $field = new Field();
     $field->setType(1);
     $answer1 = new Answer();
     $answer1->setValueType(3);
     $answer1->setValue($value);
     $answer1->setField($field);
     $objectStorage = new ObjectStorage();
     $objectStorage->attach($answer1);
     $mail->setAnswers($objectStorage);
     if ($expectedResult === false) {
         $this->generalValidatorMock->expects($this->once())->method('setErrorAndMessage');
     } else {
         $this->generalValidatorMock->expects($this->never())->method('setErrorAndMessage');
     }
     $this->generalValidatorMock->_callRef('isValid', $mail);
 }
 /**
  * @return array
  */
 public function getAssertFrontendUsersLoggedInTestValues()
 {
     $user1 = new FrontendUser();
     ObjectAccess::setProperty($user1, 'uid', 1, TRUE);
     $user2 = new FrontendUser();
     ObjectAccess::setProperty($user2, 'uid', 2, TRUE);
     $user3 = new FrontendUser();
     ObjectAccess::setProperty($user3, 'uid', 3, TRUE);
     $users = new ObjectStorage();
     $users->attach($user1);
     $users->attach($user2);
     $contained = $user2;
     $notContained = $user3;
     return array(array($users, $notContained, FALSE), array($users, $contained, TRUE));
 }
Esempio n. 19
0
 /**
  * Adds a new child node before a given child node
  *
  * @param Tx_PtExtbase_Tree_NodeInterface $newChildNode
  * @param Tx_PtExtbase_Tree_NodeInterface $nodeToAddBefore
  */
 public function addChildBefore(Tx_PtExtbase_Tree_NodeInterface $newChildNode, Tx_PtExtbase_Tree_NodeInterface $nodeToAddBefore)
 {
     $newChildren = new ObjectStorage();
     foreach ($this->children as $child) {
         if ($child == $nodeToAddBefore) {
             $newChildren->attach($newChildNode);
         }
         $newChildren->attach($child);
     }
     $this->children = $newChildren;
 }
 /**
  * hasFormAnUploadFieldReturnBool Test
  *
  * @return void
  * @test
  */
 public function hasFormAnUploadFieldReturnBool()
 {
     $fieldObjectStorage = new ObjectStorage();
     $field = new Field();
     $field->setType('captcha');
     $fieldObjectStorage->attach($field);
     $field2 = new Field();
     $field2->setType('file');
     $fieldObjectStorage->attach($field2);
     $pagesObjectStorage = new ObjectStorage();
     $page = new Page();
     $page->setFields($fieldObjectStorage);
     $pagesObjectStorage->attach($page);
     $form = new Form();
     $form->setPages($pagesObjectStorage);
     $this->assertTrue(BasicFileUtility::hasFormAnUploadField($form));
     $field2->setType('textarea');
     $this->assertFalse(BasicFileUtility::hasFormAnUploadField($form));
 }
 /**
  * [findDemanded description]
  * @param  R3H6\LocallangTools\Domain\Model\Dto\TranslationDemand $demand [description]
  * @return TYPO3\CMS\Extbase\Persistence\ObjectStorage<R3H6\LocallangTools\Domain\Model\Translation>
  */
 public function findDemanded(TranslationDemand $demand)
 {
     $demand->setLanguage('de');
     $translations = new ObjectStorage();
     $files = (array) $demand->getFiles();
     if ($demand->getExtensions()) {
         $extensionPaths = [];
         foreach ($demand->getExtensions() as $extensionKey) {
             $extensionPaths[] = 'EXT:' . $extensionKey;
         }
         $files = $files + PathUtility::getLocallangPaths($extensionPaths);
     } elseif (empty($files)) {
         $files = PathUtility::getLocallangPaths();
     }
     $language = $demand->getLanguage();
     if (empty($language)) {
         $language = self::DEFAULT_LANGUAGE;
     }
     foreach ($files as $file) {
         $filePath = PathUtility::getAbsolutePath($file);
         $parsedData = $this->localizationFactory->getParsedData($filePath, $language, LocalizationFactory::CHARSET, LocalizationFactory::ERROR_MODE_EXCEPTION);
         foreach ($parsedData[self::DEFAULT_LANGUAGE] as $key => $value) {
             $default = $value[0]['source'];
             $source = isset($parsedData[$language][$key][0]['source']) ? $parsedData[$language][$key][0]['source'] : null;
             $target = isset($parsedData[$language][$key][0]['target']) ? $parsedData[$language][$key][0]['target'] : null;
             $translation = GeneralUtility::makeInstance(Translation::class, $file, $key, $language, $default, $source, $target);
             if ($demand->getState() && $demand->getState() !== $translation->getState()) {
                 continue;
             }
             if ($demand->getKey() && stripos($translation->getKey(), $demand->getKey()) === false) {
                 continue;
             }
             if ($demand->getSearch() && stripos($translation->getTarget(), $demand->getSearch()) === false && stripos($translation->getSource(), $demand->getSearch()) === false) {
                 continue;
             }
             $translations->attach($translation);
         }
     }
     return $translations;
 }
Esempio n. 22
0
 /**
  * Adds our models to the storage
  *
  * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $storage
  */
 protected function fillStorage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $storage)
 {
     foreach ($this->models as $model) {
         $storage->attach($model);
     }
 }
 /**
  * @test
  */
 public function setParticipantsUpdatesTotalPrice()
 {
     $this->subject = $this->getAccessibleMock(Reservation::class, ['getLesson']);
     $singlePrice = 123.45;
     $totalPrice = 2 * $singlePrice;
     $firstParticipant = new Person();
     $secondParticipant = new Person();
     $objectStorageContainingTwoParticipants = new ObjectStorage();
     $objectStorageContainingTwoParticipants->attach($firstParticipant);
     $objectStorageContainingTwoParticipants->attach($secondParticipant);
     $lesson = $this->getMock(Schedule::class, ['getPrice']);
     $lesson->expects($this->any())->method('getPrice')->will($this->returnValue($singlePrice));
     $this->subject->expects($this->any())->method('getLesson')->will($this->returnValue($lesson));
     $this->subject->setParticipants($objectStorageContainingTwoParticipants);
     $this->assertSame($totalPrice, $this->subject->getTotalPrice());
 }
Esempio n. 24
0
 /**
  * Sort a list of persons by first and last name
  *
  * @param ObjectStorage $persons Persons
  * @return array Sorted list of persons
  */
 protected function sortPersons(ObjectStorage $persons)
 {
     $sortedPersons = [];
     foreach ($persons as $person) {
         $sortedPersons[] = $person;
     }
     usort($sortedPersons, function ($person1, $person2) {
         /**
          * @var Person $person1
          * @var Person $person2
          */
         return strnatcasecmp($person1->getLastName() . ',' . $person1->getFirstName(), $person2->getLastName() . ',' . $person2->getFirstName());
     });
     $sortedPersonsObjStorage = new ObjectStorage();
     foreach ($sortedPersons as $sortedPerson) {
         $sortedPersonsObjStorage->attach($sortedPerson);
     }
     return $sortedPersonsObjStorage;
 }
Esempio n. 25
0
 /**
  * Replace a reconstituted object, leaves the clean data unchanged.
  *
  * @param object $oldEntity
  * @param object $newEntity
  * @return void
  */
 public function replaceReconstitutedEntity($oldEntity, $newEntity)
 {
     $this->reconstitutedEntities->detach($oldEntity);
     $this->reconstitutedEntities->attach($newEntity);
 }
Esempio n. 26
0
 /**
  * @param object $object The object to add.
  * @param mixed $data The data to associate with the object.
  *
  * @see \TYPO3\CMS\Extbase\Persistence\ObjectStorage::attach
  */
 public function attach($object, $data = NULL)
 {
     $this->initialize();
     parent::attach($object, $data);
 }
Esempio n. 27
0
 /**
  * Returns the given result as property value of the specified property type.
  *
  * @param DomainObjectInterface $parentObject
  * @param string $propertyName
  * @param mixed $result The result
  * @return mixed
  */
 public function mapResultToPropertyValue(DomainObjectInterface $parentObject, $propertyName, $result)
 {
     $propertyValue = null;
     if ($result instanceof Persistence\Generic\LoadingStrategyInterface) {
         $propertyValue = $result;
     } else {
         $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
         if (in_array($propertyMetaData['type'], ['array', 'ArrayObject', 'SplObjectStorage', \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
             $objects = [];
             foreach ($result as $value) {
                 $objects[] = $value;
             }
             if ($propertyMetaData['type'] === 'ArrayObject') {
                 $propertyValue = new \ArrayObject($objects);
             } elseif (in_array($propertyMetaData['type'], [\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class], true)) {
                 $propertyValue = new Persistence\ObjectStorage();
                 foreach ($objects as $object) {
                     $propertyValue->attach($object);
                 }
                 $propertyValue->_memorizeCleanState();
             } else {
                 $propertyValue = $objects;
             }
         } elseif (strpbrk($propertyMetaData['type'], '_\\') !== false) {
             if (is_object($result) && $result instanceof Persistence\QueryResultInterface) {
                 $propertyValue = $result->getFirst();
             } else {
                 $propertyValue = $result;
             }
         }
     }
     return $propertyValue;
 }
Esempio n. 28
0
 /**
  * Adds given elements of an array to given object storage
  *
  * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $objectStorage
  * @param array $arrayToBeAdded
  */
 protected function addObjectsToObjectStorageByArray(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objectStorage, $arrayToBeAdded)
 {
     foreach ($arrayToBeAdded as $key => $value) {
         $objectStorage->attach($value, $key);
     }
 }
 /**
  * @test
  */
 public function participantCanBeRemoved()
 {
     $participants = new ObjectStorage();
     /** @var Person $mockParticipant */
     $mockParticipant = $this->getMock(Person::class, [], [], '', false);
     $participants->attach($mockParticipant);
     $this->subject->setParticipants($participants);
     $this->subject->removeParticipant($mockParticipant);
     $this->assertFalse($this->subject->getParticipants()->contains($mockParticipant));
 }
 /**
  * @test
  */
 public function setAttendeesForObjectStorageContainingAttendeeSetsAttendees()
 {
     $attendee = new Attendee();
     $objectStorage = new ObjectStorage();
     $objectStorage->attach($attendee);
     $this->subject->setAttendees($objectStorage);
     $this->assertAttributeEquals($objectStorage, 'attendees', $this->subject);
 }