Passed
Push — master ( cf9ff7...c199aa )
by Nicolaas
02:20
created
src/Api/DefaultDashboardProvider.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         $this->addFindPages();
33 33
         $this->addFilesAndImages();
34 34
         $this->addSiteConfigLinks();
35
-        if(Permission::check('ADMIN')) {
35
+        if (Permission::check('ADMIN')) {
36 36
             $this->addSecurityLinks();
37 37
         }
38 38
         $this->addModelAdminLinks();
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
     protected function addPagesLinks()
49 49
     {
50 50
         $this->addGroup('PAGES', 'Pages', 10);
51
-        $this->addLink('PAGES', $this->phrase('add'). ' Page', '/admin/pages/add');
51
+        $this->addLink('PAGES', $this->phrase('add') . ' Page', '/admin/pages/add');
52 52
         $pagesCount = DataObject::get('Page')->count();
53
-        $this->addLink('PAGES', $this->phrase('edit'). ' Pages ('.$pagesCount.')', '/admin/pages');
53
+        $this->addLink('PAGES', $this->phrase('edit') . ' Pages (' . $pagesCount . ')', '/admin/pages');
54 54
         $pageLastEdited = DataObject::get_one('Page', '', true, 'LastEdited DESC');
55 55
         if ($pageLastEdited) {
56
-            $this->addLink('PAGES', '✎ Last Edited Page: '.$pageLastEdited->Title, $pageLastEdited->CMSEditLink());
56
+            $this->addLink('PAGES', '✎ Last Edited Page: ' . $pageLastEdited->Title, $pageLastEdited->CMSEditLink());
57 57
         }
58
-        $this->addLink('PAGES', $this->phrase('review'). ' Page Reports', '/admin/reports');
59
-        $lastWeekLink = '/admin/pages?'.'q[LastEditedFrom]='.date('Y-m-d', strtotime('-1 week'));
60
-        $this->addLink('PAGES', $this->phrase('review'). ' Recently Modified Pages', $lastWeekLink);
58
+        $this->addLink('PAGES', $this->phrase('review') . ' Page Reports', '/admin/reports');
59
+        $lastWeekLink = '/admin/pages?' . 'q[LastEditedFrom]=' . date('Y-m-d', strtotime('-1 week'));
60
+        $this->addLink('PAGES', $this->phrase('review') . ' Recently Modified Pages', $lastWeekLink);
61 61
     }
62 62
 
63 63
     protected function addFindPages()
@@ -67,23 +67,23 @@  discard block
 block discarded – undo
67 67
             $pages[$className] = $className;
68 68
 
69 69
         }
70
-        $this->addGroup('PAGEFILTER', 'Page Types ('.count($pages).')', 300);
70
+        $this->addGroup('PAGEFILTER', 'Page Types (' . count($pages) . ')', 300);
71 71
         $count = 0;
72
-        foreach($pages as $pageClassName) {
72
+        foreach ($pages as $pageClassName) {
73 73
             $pageCount = $pageClassName::get()->count();
74
-            if($pageCount < 1) {
74
+            if ($pageCount < 1) {
75 75
                 continue;
76 76
             }
77 77
             $count++;
78
-            if($count > 7) {
78
+            if ($count > 7) {
79 79
                 $this->addLink('PAGEFILTER', 'More ...', '/admin/pages');
80 80
                 break;
81 81
             }
82 82
             $page = Injector::inst()->get($pageClassName);
83 83
             $pageTitle = $page->i18n_singular_name();
84
-            $query = urlencode('q[ClassName]='.$pageClassName);
84
+            $query = urlencode('q[ClassName]=' . $pageClassName);
85 85
             $link = 'admin/pages?' . $query;
86
-            $this->addLink('PAGEFILTER', $this->phrase('edit'). ' '.$pageTitle.' ('.$pageCount.')', $link);
86
+            $this->addLink('PAGEFILTER', $this->phrase('edit') . ' ' . $pageTitle . ' (' . $pageCount . ')', $link);
87 87
         }
88 88
     }
89 89
     protected function addFilesAndImages()
@@ -93,44 +93,44 @@  discard block
 block discarded – undo
93 93
         $uploadFolderName = Config::inst()->get(Upload::class, 'uploads_folder');
94 94
         $uploadFolder = Folder::find_or_make($uploadFolderName);
95 95
         // all
96
-        $this->addLink('FILESANDIMAGES', $this->phrase('edit'). ' Open File Browswer', '/admin/assets');
96
+        $this->addLink('FILESANDIMAGES', $this->phrase('edit') . ' Open File Browswer', '/admin/assets');
97 97
         // per type
98 98
         $filesCount = File::get()->exclude(['ClassName' => [Folder::class, Image::class]])->count();
99 99
         $imageCount = File::get()->filter(['ClassName' => [Image::class]])->count();
100
-        $this->addLink('FILESANDIMAGES', $this->phrase('review'). ' Images ('.$imageCount.')', 'admin/assets?filter[appCategory]=IMAGE');
101
-        $this->addLink('FILESANDIMAGES', $this->phrase('review'). ' Files ('.$filesCount.')', 'admin/assets?filter[appCategory]=DOCUMENT');
100
+        $this->addLink('FILESANDIMAGES', $this->phrase('review') . ' Images (' . $imageCount . ')', 'admin/assets?filter[appCategory]=IMAGE');
101
+        $this->addLink('FILESANDIMAGES', $this->phrase('review') . ' Files (' . $filesCount . ')', 'admin/assets?filter[appCategory]=DOCUMENT');
102 102
 
103 103
         // default upload folder
104
-        $this->addLink('FILESANDIMAGES', $this->phrase('review'). ' Open Default Upload Folder', $uploadFolder->CMSEditLink());
104
+        $this->addLink('FILESANDIMAGES', $this->phrase('review') . ' Open Default Upload Folder', $uploadFolder->CMSEditLink());
105 105
 
106 106
         // recent
107
-        $lastWeekLink = '/admin/assets?'.'filter[lastEditedFrom]='.date('Y-m-d', strtotime('-1 week')).'&view=tile';
108
-        $this->addLink('FILESANDIMAGES', $this->phrase('review'). ' Recently modified Files', $lastWeekLink);
107
+        $lastWeekLink = '/admin/assets?' . 'filter[lastEditedFrom]=' . date('Y-m-d', strtotime('-1 week')) . '&view=tile';
108
+        $this->addLink('FILESANDIMAGES', $this->phrase('review') . ' Recently modified Files', $lastWeekLink);
109 109
     }
110 110
 
111 111
     protected function addSiteConfigLinks()
112 112
     {
113 113
         $this->addGroup('SITECONFIG', 'Site Wide Configuration', 20);
114
-        $this->addLink('SITECONFIG', $this->phrase('review'). ' Site Settings', '/admin/settings');
114
+        $this->addLink('SITECONFIG', $this->phrase('review') . ' Site Settings', '/admin/settings');
115 115
     }
116 116
 
117 117
     protected function addSecurityLinks()
118 118
     {
119 119
         $this->addGroup('SECURITY', 'Security', 30);
120
-        $this->addLink('SECURITY', $this->phrase('add'). ' User', '/admin/security/users/EditForm/field/users/item/new');
120
+        $this->addLink('SECURITY', $this->phrase('add') . ' User', '/admin/security/users/EditForm/field/users/item/new');
121 121
         $userCount = Member::get()->count();
122 122
         $groupCount = Group::get()->count();
123
-        $this->addLink('SECURITY', $this->phrase('review'). ' Users ('.$userCount.')', '/admin/security');
124
-        $this->addLink('SECURITY', $this->phrase('review'). ' Groups  ('.$groupCount.')', '/admin/security/groups');
123
+        $this->addLink('SECURITY', $this->phrase('review') . ' Users (' . $userCount . ')', '/admin/security');
124
+        $this->addLink('SECURITY', $this->phrase('review') . ' Groups  (' . $groupCount . ')', '/admin/security/groups');
125 125
         DefaultAdminService::singleton()->extend('addSecurityLinks', $this);
126 126
         $adminGroup = Permission::get_groups_by_permission('ADMIN')->first();
127
-        if($adminGroup) {
127
+        if ($adminGroup) {
128 128
             $userCount = $adminGroup->Members()->count();
129
-            $this->addLink('SECURITY', $this->phrase('review'). ' Administrators ('.$userCount.')', '/admin/security/groups/EditForm/field/groups/item/'.$adminGroup->ID.'/edit');
129
+            $this->addLink('SECURITY', $this->phrase('review') . ' Administrators (' . $userCount . ')', '/admin/security/groups/EditForm/field/groups/item/' . $adminGroup->ID . '/edit');
130 130
         }
131
-        if(class_exists(EnabledMembers::class)) {
131
+        if (class_exists(EnabledMembers::class)) {
132 132
             $obj = Injector::inst()->get(EnabledMembers::class);
133
-            $this->addLink('SECURITY', $this->phrase('review'). ' Multi-Factor Authentication Status', $obj->getLink());
133
+            $this->addLink('SECURITY', $this->phrase('review') . ' Multi-Factor Authentication Status', $obj->getLink());
134 134
 
135 135
         }
136 136
     }
@@ -142,58 +142,58 @@  discard block
 block discarded – undo
142 142
     {
143 143
         $modelAdmins = [];
144 144
         foreach (ClassInfo::subclassesFor(ModelAdmin::class, false) as $className) {
145
-            if($className === ArchiveAdmin::class) {
145
+            if ($className === ArchiveAdmin::class) {
146 146
                 continue;
147 147
             }
148 148
             $modelAdmins[$className] = $className;
149 149
 
150 150
         }
151
-        foreach($modelAdmins as $modelAdminClassName) {
151
+        foreach ($modelAdmins as $modelAdminClassName) {
152 152
             $groupAdded = false;
153 153
             $ma = Injector::inst()->get($modelAdminClassName);
154
-            if($ma->canView()) {
154
+            if ($ma->canView()) {
155 155
                 $mas = $ma->getManagedModels();
156
-                if(count($mas)) {
156
+                if (count($mas)) {
157 157
                     $numberOfModels = count($mas);
158 158
                     $groupCode = strtoupper($modelAdminClassName);
159 159
                     $count = 0;
160
-                    foreach($mas as $model => $title) {
160
+                    foreach ($mas as $model => $title) {
161 161
                         $count++;
162
-                        if($count > 7) {
162
+                        if ($count > 7) {
163 163
                             $this->addLink('PAGEFILTER', 'More ...', $ma->Link());
164 164
                             break;
165 165
                         }
166
-                        if(is_array($title)) {
166
+                        if (is_array($title)) {
167 167
                             $title = $title['title'];
168 168
                             $model = $title['dataClass'] ?? $model;
169 169
                         }
170
-                        if(! class_exists($model)) {
170
+                        if (!class_exists($model)) {
171 171
                             continue;
172 172
                         }
173 173
                         $obj = Injector::inst()->get($model);
174
-                        if($obj && $obj->canView()) {
175
-                            if(! $groupAdded) {
174
+                        if ($obj && $obj->canView()) {
175
+                            if (!$groupAdded) {
176 176
                                 $this->addGroup($groupCode, $ma->menu_title(), 100);
177 177
                                 $groupAdded = true;
178 178
                             }
179 179
                             $link = '';
180
-                            if($obj->hasMethod('CMSListLink')) {
180
+                            if ($obj->hasMethod('CMSListLink')) {
181 181
                                 $link = $obj->CMSListLink();
182 182
                             } else {
183 183
                                 $link = $ma->getLinkForModelTab($model);
184 184
                             }
185 185
                             $objectCount = $model::get()->count();
186
-                            $titleContainsObjectCount = strpos($title, ' ('.$objectCount.')');
187
-                            if($titleContainsObjectCount === false) {
188
-                                $title .= ' ('.$objectCount.')';
186
+                            $titleContainsObjectCount = strpos($title, ' (' . $objectCount . ')');
187
+                            if ($titleContainsObjectCount === false) {
188
+                                $title .= ' (' . $objectCount . ')';
189 189
                             }
190
-                            $this->addLink($groupCode, $this->phrase('edit'). ' '.$title, $link);
191
-                            if($numberOfModels < 4) {
190
+                            $this->addLink($groupCode, $this->phrase('edit') . ' ' . $title, $link);
191
+                            if ($numberOfModels < 4) {
192 192
                                 $obj = Injector::inst()->get($model);
193
-                                if($obj->canCreate()) {
193
+                                if ($obj->canCreate()) {
194 194
                                     $classNameEscaped = str_replace('\\', '-', $model);
195
-                                    $linkNew = $link .= '/EditForm/field/'.$classNameEscaped.'/item/new';
196
-                                    $this->addLink($groupCode, $this->phrase('add'). ' '.$obj->i18n_singular_name(), $linkNew);
195
+                                    $linkNew = $link .= '/EditForm/field/' . $classNameEscaped . '/item/new';
196
+                                    $this->addLink($groupCode, $this->phrase('add') . ' ' . $obj->i18n_singular_name(), $linkNew);
197 197
                                 }
198 198
                             }
199 199
                         }
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 
233 233
     protected function phrase(string $phrase): string
234 234
     {
235
-        if($phrase === 'add') {
235
+        if ($phrase === 'add') {
236 236
             $phrase = $this->config()->get('new_phrase');
237
-        } elseif($phrase === 'review') {
237
+        } elseif ($phrase === 'review') {
238 238
             $phrase = $this->config()->get('review_phrase');
239
-        } elseif($phrase === 'edit') {
239
+        } elseif ($phrase === 'edit') {
240 240
             $phrase = $this->config()->get('edit_phrase');
241 241
         }
242
-        return _t('DashboardWelcomeQuicklinks.'.$phrase, $phrase);
242
+        return _t('DashboardWelcomeQuicklinks.' . $phrase, $phrase);
243 243
     }
244 244
 
245 245
 }
Please login to merge, or discard this patch.