Code Duplication    Length = 71-71 lines in 2 locations

controllers/PostTypes.php 1 location

@@ 19-89 (lines=71) @@
16
 *
17
 * @package GinoPane\BlogTaxonomy\Controllers
18
 */
19
class PostTypes extends Controller
20
{
21
    /**
22
     * Behaviours implemented by the controller
23
     *
24
     * @var array
25
     */
26
    public $implement = [
27
        FormController::class,
28
        ListController::class,
29
        RelationController::class
30
    ];
31
32
    public $formConfig = 'config_form.yaml';
33
    public $listConfig = 'config_list.yaml';
34
    public $relationConfig = 'config_relation.yaml';
35
36
    /**
37
     * Series constructor
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
43
        BackendMenu::setContext(Plugin::REQUIRED_PLUGIN_RAINLAB_BLOG, 'blog', 'post_types');
44
    }
45
46
    /**
47
     * Controller "update" action used for updating existing model records.
48
     * This action takes a record identifier (primary key of the model)
49
     * to locate the record used for sourcing the existing form values.
50
     *
51
     * @param int $recordId Record identifier
52
     * @param string $context Form context
53
     * @return void
54
     */
55
    public function update($recordId = null, $context = null)
56
    {
57
        $postType = PostType::whereId($recordId)->first();
58
59
        if ($postType !== null) {
60
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.post_types.edit_title', ['post_type' => $postType->name]);
61
        } else {
62
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.post_types.post_type_does_not_exist');
63
        }
64
65
        return $this->asExtension('FormController')->update($recordId, $context);
66
    }
67
68
    /**
69
     * Remove multiple post types
70
     *
71
     * @return mixed
72
     */
73
    public function onBulkDelete()
74
    {
75
        if ($checkedIds = (array)post('checked', [])) {
76
            $delete = PostType::whereIn('id', $checkedIds)->delete();
77
        }
78
79
        if (empty($delete)) {
80
            Flash::error(e(trans(Plugin::LOCALIZATION_KEY . 'form.errors.unknown')));
81
82
            return;
83
        }
84
85
        Flash::success(e(trans(Plugin::LOCALIZATION_KEY . 'form.post_types.delete_post_types_success')));
86
87
        return $this->listRefresh();
88
    }
89
}
90

controllers/Series.php 1 location

@@ 19-89 (lines=71) @@
16
 *
17
 * @package GinoPane\BlogTaxonomy\Controllers
18
 */
19
class Series extends Controller
20
{
21
    /**
22
     * Behaviours implemented by the controller
23
     *
24
     * @var array
25
     */
26
    public $implement = [
27
        FormController::class,
28
        ListController::class,
29
        RelationController::class
30
    ];
31
32
    public $formConfig = 'config_form.yaml';
33
    public $listConfig = 'config_list.yaml';
34
    public $relationConfig = 'config_relation.yaml';
35
36
    /**
37
     * Series constructor
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
43
        BackendMenu::setContext(Plugin::REQUIRED_PLUGIN_RAINLAB_BLOG, 'blog', 'series');
44
    }
45
46
    /**
47
     * Controller "update" action used for updating existing model records.
48
     * This action takes a record identifier (primary key of the model)
49
     * to locate the record used for sourcing the existing form values.
50
     *
51
     * @param int $recordId Record identifier
52
     * @param string $context Form context
53
     * @return void
54
     */
55
    public function update($recordId = null, $context = null)
56
    {
57
        $series = SeriesModel::whereId($recordId)->first();
58
59
        if ($series !== null) {
60
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.edit_title', ['series' => $series->title]);
61
        } else {
62
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.series_does_not_exist');
63
        }
64
65
        return $this->asExtension('FormController')->update($recordId, $context);
66
    }
67
68
    /**
69
     * Remove multiple tags
70
     *
71
     * @return mixed
72
     */
73
    public function onBulkDelete()
74
    {
75
        if ($checkedIds = (array)post('checked', [])) {
76
            $delete = SeriesModel::whereIn('id', $checkedIds)->delete();
77
        }
78
79
        if (empty($delete)) {
80
            Flash::error(e(trans(Plugin::LOCALIZATION_KEY . 'form.errors.unknown')));
81
82
            return;
83
        }
84
85
        Flash::success(e(trans(Plugin::LOCALIZATION_KEY . 'form.series.delete_series_success')));
86
87
        return $this->listRefresh();
88
    }
89
}
90