Skip to content

Commit

Permalink
galleries for news and pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Jan 27, 2015
1 parent 0a18fa7 commit f824af9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
13 changes: 0 additions & 13 deletions app/TypiCMS/Models/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,6 @@ public function tags()
return $this->morphToMany('TypiCMS\Modules\Tags\Models\Tag', 'taggable')->withTimestamps();
}

/**
* A model has many galleries.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function galleries()
{
return $this->morphToMany('TypiCMS\Modules\Galleries\Models\Gallery', 'galleryable')
->withPivot('position')
->orderBy('position')
->withTimestamps();
}

/**
* Get back office’s edit url of model
*
Expand Down
14 changes: 14 additions & 0 deletions app/TypiCMS/Modules/News/Models/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Carbon\Carbon;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use TypiCMS\Models\Base;
use TypiCMS\Presenters\PresentableTrait;
use TypiCMS\Traits\Historable;
Expand Down Expand Up @@ -50,4 +51,17 @@ class News extends Base
public $attachments = array(
'image',
);

/**
* A news has many galleries.
*
* @return MorphToMany
*/
public function galleries()
{
return $this->morphToMany('TypiCMS\Modules\Galleries\Models\Gallery', 'galleryable')
->withPivot('position')
->orderBy('position')
->withTimestamps();
}
}
17 changes: 16 additions & 1 deletion app/TypiCMS/Modules/News/Services/Form/NewsForm.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
namespace TypiCMS\Modules\News\Services\Form;

use Input;
use TypiCMS\Modules\News\Repositories\NewsInterface;
use TypiCMS\Services\Form\AbstractForm;
use TypiCMS\Services\Validation\ValidableInterface;
use TypiCMS\Modules\News\Repositories\NewsInterface;

class NewsForm extends AbstractForm
{
Expand All @@ -13,4 +14,18 @@ public function __construct(ValidableInterface $validator, NewsInterface $news)
$this->validator = $validator;
$this->repository = $news;
}

/**
* Update an existing item
*
* @param array $input
* @return boolean
*/
public function update(array $input)
{
// add relations data (default to empty array)
$input['galleries'] = Input::get('galleries', []);

return parent::update($input);
}
}
14 changes: 14 additions & 0 deletions app/TypiCMS/Modules/Pages/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Config;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use TypiCMS\Models\Base;
use TypiCMS\NestableCollection;
use TypiCMS\Presenters\PresentableTrait;
Expand Down Expand Up @@ -117,6 +118,19 @@ public function menulinks()
return $this->hasMany('TypiCMS\Modules\Menulinks\Models\Menulink');
}

/**
* A page has many galleries.
*
* @return MorphToMany
*/
public function galleries()
{
return $this->morphToMany('TypiCMS\Modules\Galleries\Models\Gallery', 'galleryable')
->withPivot('position')
->orderBy('position')
->withTimestamps();
}

/**
* A page can have children
*/
Expand Down
22 changes: 9 additions & 13 deletions app/TypiCMS/Modules/Pages/Services/Form/PageForm.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace TypiCMS\Modules\Pages\Services\Form;

use Input;
use Config;
use Input;
use TypiCMS\Modules\Pages\Repositories\PageInterface;
use TypiCMS\Services\Form\AbstractForm;
use TypiCMS\Services\Validation\ValidableInterface;
use TypiCMS\Modules\Pages\Repositories\PageInterface;

class PageForm extends AbstractForm
{
Expand All @@ -18,7 +18,8 @@ public function __construct(ValidableInterface $validator, PageInterface $page)

/**
* Create a new item
*
*
* @param array $input
* @return boolean
*/
public function save(array $input)
Expand All @@ -29,26 +30,21 @@ public function save(array $input)

/**
* Update an existing item
*
*
* @param array $input
* @return boolean
*/
public function update(array $input)
{
// add checkboxes data
foreach (Config::get('app.locales') as $locale) {
$input[$locale]['status'] = Input::get($locale.'.status', 0);
}
$input['rss_enabled'] = Input::get('rss_enabled', 0);
$input['comments_enabled'] = Input::get('comments_enabled', 0);
$input['is_home'] = Input::get('is_home', 0);
$input['parent_id'] = Input::get('parent_id') ? : null ;

$inputDot = array_dot($input);

if (! $this->valid($inputDot)) {
return false;
}
// add relations data (default to empty array)
$input['galleries'] = Input::get('galleries', []);

return $this->repository->update($input);
return parent::update($input);
}
}
2 changes: 1 addition & 1 deletion app/TypiCMS/Repositories/RepositoriesAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ protected function syncRelation($model, array $data, $table = null)
}

if (! isset($data[$table])) {
$data[$table] = [];
return false;
}

// add related items
Expand Down

0 comments on commit f824af9

Please sign in to comment.