Skip to content

Commit

Permalink
Merge 3a4f18d into f4fa58e
Browse files Browse the repository at this point in the history
  • Loading branch information
Redjik committed Jan 28, 2016
2 parents f4fa58e + 3a4f18d commit 5ccc07a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 132 deletions.
33 changes: 0 additions & 33 deletions api/app/Http/Controllers/AbstractSectionController.php
Expand Up @@ -10,42 +10,9 @@

namespace App\Http\Controllers;

use App\Models\Section;
use Spira\Core\Controllers\ChildEntityController;
use Spira\Core\Model\Model\BaseModel;

class AbstractSectionController extends ChildEntityController
{
protected $relationName = 'sections';

/**
* @param $requestEntity
* @param array $validationRules
* @param BaseModel $existingModel
* @param bool $limitToKeysPresent
* @return bool
*/
public function validateRequest($requestEntity, $validationRules, BaseModel $existingModel = null, $limitToKeysPresent = false)
{
$contentRules = $this->getContentRules($requestEntity);

foreach ($contentRules as $attribute => $rule) {
$validationRules['content.'.$attribute] = $rule;
}

return parent::validateRequest($requestEntity, $validationRules, $existingModel, $limitToKeysPresent);
}

/**
* @param $requestEntity
* @return array
*/
protected function getContentRules($requestEntity)
{
if (! isset(Section::$contentTypeMap[$requestEntity['type']])) {
return [];
}

return with(new Section::$contentTypeMap[$requestEntity['type']])->getValidationRules();
}
}
11 changes: 4 additions & 7 deletions api/app/Models/Section.php
Expand Up @@ -43,12 +43,6 @@ class Section extends BaseModel implements LocalizableModelInterface
Article::class,
];

protected static $validationRules = [
'section_id' => 'required|uuid',
'content' => 'required_if:type,'.RichTextContent::CONTENT_TYPE.','.BlockquoteContent::CONTENT_TYPE.','.MediaContent::CONTENT_TYPE,
'type' => 'required|section_type',
];

protected $casts = [
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
Expand All @@ -66,8 +60,11 @@ public static function getValidationRules($entityId = null, array $requestEntity
{
return [
'section_id' => 'required|uuid',
'content' => 'required_if:type,'.RichTextContent::CONTENT_TYPE.','.BlockquoteContent::CONTENT_TYPE.','.MediaContent::CONTENT_TYPE,
'content' => 'required_if:type,'.RichTextContent::CONTENT_TYPE.','.BlockquoteContent::CONTENT_TYPE.','.MediaContent::CONTENT_TYPE.'|array',
'type' => 'required|in:'.implode(',', static::getContentTypes()),
'content.body' => 'required_if:type,'.RichTextContent::CONTENT_TYPE.','.BlockquoteContent::CONTENT_TYPE.'|string',
'content.author' => 'required_if:type,'.BlockquoteContent::CONTENT_TYPE.'|string',
'content.media' => 'required_if:type,'.MediaContent::CONTENT_TYPE.'|array',
];
}

Expand Down
5 changes: 0 additions & 5 deletions api/app/Models/Sections/BlockquoteContent.php
Expand Up @@ -25,9 +25,4 @@ class BlockquoteContent extends VirtualModel
'body',
'author',
];

protected static $validationRules = [
'body' => 'required|string',
'author' => 'required|string',
];
}
4 changes: 0 additions & 4 deletions api/app/Models/Sections/MediaContent.php
Expand Up @@ -46,8 +46,4 @@ class MediaContent extends VirtualModel
protected $fillable = [
'media',
];

protected static $validationRules = [
'media' => 'required|array',
];
}
3 changes: 0 additions & 3 deletions api/app/Models/Sections/PromoContent.php
Expand Up @@ -23,7 +23,4 @@ class PromoContent extends VirtualModel
*/
protected $fillable = [
];

protected static $validationRules = [
];
}
4 changes: 0 additions & 4 deletions api/app/Models/Sections/RichTextContent.php
Expand Up @@ -24,8 +24,4 @@ class RichTextContent extends VirtualModel
protected $fillable = [
'body',
];

protected static $validationRules = [
'body' => 'required|string',
];
}

0 comments on commit 5ccc07a

Please sign in to comment.