Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mtelgkamp committed Aug 3, 2018
0 parents commit 23b34b3
Show file tree
Hide file tree
Showing 18 changed files with 1,277 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Classes/Domain/Model/FileReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Mindscreen\FalUpload\Domain\Model;

/***************************************************************
* Copyright notice
*
* (c) 2018 mindscreen GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Class FileReference
*/
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference
{

/**
* Uid of a sys_file
*
* @var integer
*/
protected $originalFileIdentifier;

/**
* @param \TYPO3\CMS\Core\Resource\FileReference $originalResource
*/
public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource)
{
$this->originalResource = $originalResource;
$this->originalFileIdentifier = (int)$originalResource->getOriginalFile()->getUid();
}
}
125 changes: 125 additions & 0 deletions Classes/Domain/Model/Upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace Mindscreen\FalUpload\Domain\Model;

/***************************************************************
* Copyright notice
*
* (c) 2018 mindscreen GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

/**
*
*
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class Upload extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

/**
* Title
*
* @var string
* @validate NotEmpty
*/
protected $title = '';

/**
* Image
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $image;

/**
* Image
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $imageCollection;

public function __construct()
{
$this->imageCollection = new ObjectStorage();
}

/**
* Returns the title
*
* @return string $title
*/
public function getTitle()
{
return $this->title;
}

/**
* Sets the title
*
* @param string $title
* @return void
*/
public function setTitle($title)
{
$this->title = $title;
}

/**
* Returns the image
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage()
{
return $this->image;
}

/**
* Sets the image
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* @return void
*/
public function setImage($image)
{
$this->image = $image;
}

/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getImageCollection()
{
return $this->imageCollection;
}

/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $imageCollection
*/
public function setImageCollection($imageCollection)
{
$this->imageCollection = $imageCollection;
}

}
38 changes: 38 additions & 0 deletions Classes/Domain/Repository/UploadRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Mindscreen\FalUpload\Domain\Repository;

/***************************************************************
* Copyright notice
*
* (c) 2018 mindscreen GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
*
*
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class UploadRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{

}
81 changes: 81 additions & 0 deletions Classes/Property/TypeConverter/ObjectStorageConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Mindscreen\FalUpload\Property\TypeConverter;

/***************************************************************
* Copyright notice
*
* (c) 2018 mindscreen GmbH
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the text file GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Class ObjectStorageConverter
*/
class ObjectStorageConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\ObjectStorageConverter
{

/**
* Take precedence over the available ObjectStorageConverter
*
* @var integer
*/
protected $priority = 2;

/**
* Return the source, if it is an array, otherwise an empty array.
* Filter out empty uploads
*
* @param mixed $source
* @return array
* @api
*/
public function getSourceChildPropertiesToBeConverted($source)
{
$propertiesToConvert = array();

// TODO: Find a nicer way to throw away empty uploads
foreach ($source as $propertyName => $propertyValue) {
if ($this->isUploadType($propertyValue)) {
if ($propertyValue['error'] !== \UPLOAD_ERR_NO_FILE || isset($propertyValue['submittedFile']['resourcePointer'])) {
$propertiesToConvert[$propertyName] = $propertyValue;
}
} else {
$propertiesToConvert[$propertyName] = $propertyValue;
}
}

return $propertiesToConvert;
}

/**
* Check if this is an upload type
*
* @param mixed $propertyValue
* @return bool
*/
protected function isUploadType($propertyValue)
{
return is_array($propertyValue) && isset($propertyValue['tmp_name']) && isset($propertyValue['error']);
}

}
Loading

0 comments on commit 23b34b3

Please sign in to comment.