Passed
Push — 1.0 ( 748b47...49e249 )
by Morven
08:23
created

ContactAdmin::getList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
c 3
b 0
f 0
dl 0
loc 14
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace SilverCommerce\ContactAdmin\Admin;
4
5
use SilverStripe\Dev\CsvBulkLoader;
6
use Colymba\BulkManager\BulkManager;
7
use SilverStripe\Forms\CheckboxField;
8
use SilverCommerce\ContactAdmin\Model\Contact;
9
use SilverCommerce\ContactAdmin\Model\ContactTag;
10
use SilverCommerce\ContactAdmin\Model\ContactList;
11
use SilverCommerce\ContactAdmin\BulkActions\AddTagsHandler;
12
use SilverCommerce\ContactAdmin\BulkActions\AddToListHandler;
13
use ilateral\SilverStripe\ModelAdminPlus\ModelAdminPlus;
14
15
/**
16
 * Management interface for contacts
17
 * 
18
 * @author  ilateral
19
 * @package Contacts
20
 */
21
class ContactAdmin extends ModelAdminPlus
22
{
23
    private static $menu_priority = 0;
0 ignored issues
show
introduced by
The private property $menu_priority is not used, and could be removed.
Loading history...
24
25
    private static $managed_models = [
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
26
        Contact::class,
27
        ContactTag::class,
28
        ContactList::class
29
    ];
30
31
    private static $url_segment = 'contacts';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
32
33
    private static $menu_title = 'Contacts';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
34
35
    private static $model_importers = [
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
36
        Contact::class => CSVBulkLoader::class,
37
        ContactTag::class => CSVBulkLoader::class,
38
        ContactList::class => CSVBulkLoader::class
39
    ];
40
41
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
42
        "SearchForm"
43
    ];
44
45
    public $showImportForm = [
46
        Contact::class,
47
        ContactTag::class,
48
        ContactList::class
49
    ];
50
51
    /**
52
     * @var string
53
     */
54
    private static $menu_icon_class = 'font-icon-torso';
0 ignored issues
show
introduced by
The private property $menu_icon_class is not used, and could be removed.
Loading history...
55
56
    /**
57
     * Listen for customised export fields on the currently managed object
58
     *
59
     * @return array
60
     */
61
    public function getExportFields()
62
    {
63
        $model = singleton($this->modelClass);
64
        if ($model->hasMethod('getExportFields')) {
65
            return $model->getExportFields();
66
        }
67
68
        return parent::getExportFields();
69
    }
70
71
    public function getEditForm($id = null, $fields = null)
72
    {
73
        $form = parent::getEditForm($id, $fields);
74
        $class = $this->sanitiseClassName($this->modelClass);
75
        $gridField = $form->Fields()->fieldByName($class);
76
        $config = $gridField->getConfig();
77
78
        // Add bulk editing to gridfield
79
        $manager = $config->getComponentByType(BulkManager::class);
80
81
        if ($this->modelClass == Contact::class) {
82
            $manager->addBulkAction(AddTagsHandler::class);
83
            $manager->addBulkAction(AddToListHandler::class);
84
        }
85
86
        $this->extend("updateEditForm", $form);
87
88
        return $form;
89
    }
90
91
    public function getList()
92
    {
93
        // Get contacts via Search Context results
94
        if ($this->modelClass == Contact::class) {
95
            /** @var Contact */
96
            $context = singleton(Contact::class)->getDefaultSearchContext();
97
            return $context->getResults([]);
98
        }
99
100
        $list = parent::getList();
101
102
        $this->extend('updateContactAdminList', $list);
103
104
        return $list;
105
    }
106
}