@@ -44,9 +44,9 @@ |
||
44 | 44 | public function actionDelete() |
45 | 45 | { |
46 | 46 | if (!request()->isPost) abort(400, 'Must be a post method'); |
47 | - $url = request()->postRequired('url', ); |
|
47 | + $url = request()->postRequired('url',); |
|
48 | 48 | $redirect = CmsUrl::find()->where(['not', ['redirect' => null]])->andWhere(['url' => $url])->one(); |
49 | - if ($redirect===null) abort(404); |
|
49 | + if ($redirect === null) abort(404); |
|
50 | 50 | return $redirect->delete(); |
51 | 51 | } |
52 | 52 | } |
@@ -23,7 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function actionAdd() |
25 | 25 | { |
26 | - if (!request()->isPost) abort(400, 'Must be a post method'); |
|
26 | + if (!request()->isPost) { |
|
27 | + abort(400, 'Must be a post method'); |
|
28 | + } |
|
27 | 29 | |
28 | 30 | $req = request()->validateData(['url' => null, 'redirect' => null], [ |
29 | 31 | [['url', 'redirect'], 'required'], |
@@ -43,10 +45,14 @@ discard block |
||
43 | 45 | |
44 | 46 | public function actionDelete() |
45 | 47 | { |
46 | - if (!request()->isPost) abort(400, 'Must be a post method'); |
|
48 | + if (!request()->isPost) { |
|
49 | + abort(400, 'Must be a post method'); |
|
50 | + } |
|
47 | 51 | $url = request()->postRequired('url', ); |
48 | 52 | $redirect = CmsUrl::find()->where(['not', ['redirect' => null]])->andWhere(['url' => $url])->one(); |
49 | - if ($redirect===null) abort(404); |
|
53 | + if ($redirect===null) { |
|
54 | + abort(404); |
|
55 | + } |
|
50 | 56 | return $redirect->delete(); |
51 | 57 | } |
52 | 58 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function getThemeAlias() |
212 | 212 | { |
213 | - return '@root/themes/' . $this->getThemeName(); |
|
213 | + return '@root/themes/'.$this->getThemeName(); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @inheritdoc |
254 | 254 | * @unsupported - $filters is not currently supported |
255 | 255 | */ |
256 | - public function getDataMap($key, $query='', $filters=[], $fields=[], $start = 0, $limit = 100) |
|
256 | + public function getDataMap($key, $query = '', $filters = [], $fields = [], $start = 0, $limit = 100) |
|
257 | 257 | { |
258 | 258 | if ($key === 'pages') { |
259 | 259 | return $this->getPagesMap($query, $filters, $fields, $start, $limit); |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function formatPageMapResults($pages, $fields) |
308 | 308 | { |
309 | - return collect($pages)->mapWithKeys(function ($item) use($fields) { |
|
309 | + return collect($pages)->mapWithKeys(function($item) use($fields) { |
|
310 | 310 | if (empty($fields)) |
311 | - return [$item['id'] => $item['nice_id'] . ': ' . $item['title']]; |
|
311 | + return [$item['id'] => $item['nice_id'].': '.$item['title']]; |
|
312 | 312 | return [$item['id'] => $item]; |
313 | 313 | })->all(); |
314 | 314 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * @param array $fields |
337 | 337 | * @return array - @see $this->formatPageMapResults(); |
338 | 338 | */ |
339 | - public function getPagesMap($query=null, $filters=[], $fields=[], $start=0, $limit=100) |
|
339 | + public function getPagesMap($query = null, $filters = [], $fields = [], $start = 0, $limit = 100) |
|
340 | 340 | { |
341 | 341 | $pages = CmsPage::find() |
342 | 342 | ->select(array_merge(['id', 'nice_id', 'title'], $fields)) |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | */ |
371 | 371 | private function checkThemeName($name) |
372 | 372 | { |
373 | - if ( preg_match('/[^A-Za-z0-9_-]/', $name, $matches) ) { |
|
373 | + if (preg_match('/[^A-Za-z0-9_-]/', $name, $matches)) { |
|
374 | 374 | throw new \InvalidArgumentException("Error trying to set the theme name to '$name'" |
375 | 375 | ."\n"."The theme name must consist of only 'a-z', '0-9', '_' and '-' characters." |
376 | - ."\n".'The following character is not allowed in theme names: ' . \yii\helpers\VarDumper::dumpAsString($matches[0]) ); |
|
376 | + ."\n".'The following character is not allowed in theme names: '.\yii\helpers\VarDumper::dumpAsString($matches[0])); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 |
@@ -155,11 +155,13 @@ discard block |
||
155 | 155 | public function getThemeHierarchy() |
156 | 156 | { |
157 | 157 | // if we have a theme hierarchy use that |
158 | - if (count($this->_themeHierarchy)) |
|
159 | - return $this->_themeHierarchy; |
|
158 | + if (count($this->_themeHierarchy)) { |
|
159 | + return $this->_themeHierarchy; |
|
160 | + } |
|
160 | 161 | // otherwise drop back to the themeName |
161 | - if (!empty($this->_themeName)) |
|
162 | - return [$this->_themeName]; |
|
162 | + if (!empty($this->_themeName)) { |
|
163 | + return [$this->_themeName]; |
|
164 | + } |
|
163 | 165 | // otherwise return nothing |
164 | 166 | return []; |
165 | 167 | } |
@@ -270,8 +272,9 @@ discard block |
||
270 | 272 | */ |
271 | 273 | public function getMapResults($requestKey) |
272 | 274 | { |
273 | - if (!isset($this->_mapRequestKey[$requestKey])) |
|
274 | - throw new \InvalidArgumentException('The provided request key "'.$requestKey.'" does not exist'); |
|
275 | + if (!isset($this->_mapRequestKey[$requestKey])) { |
|
276 | + throw new \InvalidArgumentException('The provided request key "'.$requestKey.'" does not exist'); |
|
277 | + } |
|
275 | 278 | list($key, $ids, $fields) = $this->_mapRequestKey[$requestKey]; |
276 | 279 | if ($key === 'pages') { |
277 | 280 | $pages = CmsPage::find()->select(array_merge(['id', 'nice_id', 'title'], $fields)) |
@@ -307,8 +310,9 @@ discard block |
||
307 | 310 | public function formatPageMapResults($pages, $fields) |
308 | 311 | { |
309 | 312 | return collect($pages)->mapWithKeys(function ($item) use($fields) { |
310 | - if (empty($fields)) |
|
311 | - return [$item['id'] => $item['nice_id'] . ': ' . $item['title']]; |
|
313 | + if (empty($fields)) { |
|
314 | + return [$item['id'] => $item['nice_id'] . ': ' . $item['title']]; |
|
315 | + } |
|
312 | 316 | return [$item['id'] => $item]; |
313 | 317 | })->all(); |
314 | 318 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | 'class' => UniqueValidator::class, |
58 | 58 | 'targetClass'=> CmsUrl::class, |
59 | 59 | 'targetAttribute'=>'url', |
60 | - ],[],'unique'); |
|
60 | + ], [], 'unique'); |
|
61 | 61 | |
62 | 62 | $this->addValidator([ |
63 | 63 | 'class' => RegularExpressionValidator::class, |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | ]); |
67 | 67 | |
68 | 68 | // assuming operation using DDS where form $name maps to dds classType |
69 | - if (!$this->hasForm()) return; |
|
69 | + if (!$this->hasForm()) { |
|
70 | + return; |
|
71 | + } |
|
70 | 72 | $classType = $this->getForm()->getName(); |
71 | 73 | Event::on(DdsObjectManager::class, "dds.afterAdd.$classType", [$this, 'addCmsUrl']); |
72 | 74 | Event::on(DdsObjectManager::class, "dds.afterEdit.$classType", [$this, 'editCmsUrl']); |
@@ -91,13 +93,19 @@ discard block |
||
91 | 93 | */ |
92 | 94 | public function editCmsUrl(ObjectEditEvent $event) |
93 | 95 | { |
94 | - if (!isset($event->object[$this->name])) return; |
|
96 | + if (!isset($event->object[$this->name])) { |
|
97 | + return; |
|
98 | + } |
|
95 | 99 | $originalSlug = $event->originalValues[$this->name]; |
96 | 100 | $newSlug = $event->object[$this->name]; |
97 | 101 | // edit the slug in the cms_url table |
98 | 102 | $url = CmsUrl::findOne(['url' => $originalSlug]); |
99 | - if (empty($newSlug)) return; |
|
100 | - if ($url === null) $url = new CmsUrl(); |
|
103 | + if (empty($newSlug)) { |
|
104 | + return; |
|
105 | + } |
|
106 | + if ($url === null) { |
|
107 | + $url = new CmsUrl(); |
|
108 | + } |
|
101 | 109 | $url->url = $newSlug; |
102 | 110 | $url->nice_id = $this->pageId; |
103 | 111 | $url->save(); |
@@ -109,9 +117,13 @@ discard block |
||
109 | 117 | */ |
110 | 118 | public function addCmsUrl(ObjectAddEvent $event) |
111 | 119 | { |
112 | - if (!isset($event->object[$this->name])) return; |
|
120 | + if (!isset($event->object[$this->name])) { |
|
121 | + return; |
|
122 | + } |
|
113 | 123 | $slug = $event->object[$this->name]; |
114 | - if (empty($slug)) return; |
|
124 | + if (empty($slug)) { |
|
125 | + return; |
|
126 | + } |
|
115 | 127 | // add a new slug to cms url table |
116 | 128 | $cmsUrl = new CmsUrl(); |
117 | 129 | $cmsUrl->url = $slug; |
@@ -45,7 +45,7 @@ |
||
45 | 45 | public function getValue() |
46 | 46 | { |
47 | 47 | $form = $this->getParentForm(); |
48 | - if ($form===null) return; |
|
48 | + if ($form === null) return; |
|
49 | 49 | $field = $form->getField($this->linkedField); |
50 | 50 | $value = $field->getValue(); |
51 | 51 | if (!is_string($value)) |
@@ -45,11 +45,14 @@ |
||
45 | 45 | public function getValue() |
46 | 46 | { |
47 | 47 | $form = $this->getParentForm(); |
48 | - if ($form===null) return; |
|
48 | + if ($form===null) { |
|
49 | + return; |
|
50 | + } |
|
49 | 51 | $field = $form->getField($this->linkedField); |
50 | 52 | $value = $field->getValue(); |
51 | - if (!is_string($value)) |
|
52 | - return ['word_count'=>0, 'time_to_read'=>0]; |
|
53 | + if (!is_string($value)) { |
|
54 | + return ['word_count'=>0, 'time_to_read'=>0]; |
|
55 | + } |
|
53 | 56 | // calculate post reading time |
54 | 57 | $wordCount = Str::countWords(strip_tags($value)); |
55 | 58 | $averageWordsPerMinute = 265; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 'hint' => 'Mark the page as a collection if this page represents a resource - for example a blog post, an ecommerce product' |
52 | 52 | ]); |
53 | 53 | |
54 | - $items = collect(neon()->getDaedalus()->getIDdsClassManagement()->listClasses(null,$total)) |
|
54 | + $items = collect(neon()->getDaedalus()->getIDdsClassManagement()->listClasses(null, $total)) |
|
55 | 55 | ->flatMap(function($item) { return [$item['class_type'] => $item['label']]; }); |
56 | 56 | $this->addFieldSelect('collection_class', [ |
57 | 57 | 'label' => 'Collection Class', |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | $theme = neon()->getAlias(neon()->cms->getThemeAlias()); |
128 | 128 | $templates = []; |
129 | - foreach(File::findFiles("$theme", ['only' => ['*.tpl', '*.twig']]) as $file) { |
|
129 | + foreach (File::findFiles("$theme", ['only' => ['*.tpl', '*.twig']]) as $file) { |
|
130 | 130 | $path = str_replace("$theme/", '', $file); |
131 | 131 | if (Str::startsWith($path, 'pages/') || Str::startsWith($path, 'partials/')) { |
132 | 132 | $templates[$path] = $path; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | // create a migration file |
194 | 194 | $templateFile = __DIR__.'/templates/ddsMigration.php'; |
195 | 195 | $input = file_get_contents($templateFile); |
196 | - $output = str_replace('__MIGRATION__',$this->_classname,$input); |
|
196 | + $output = str_replace('__MIGRATION__', $this->_classname, $input); |
|
197 | 197 | file_put_contents($this->_file, $output, LOCK_EX); |
198 | 198 | return $this->_filename; |
199 | 199 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param boolean $refresh whether to refresh the cache before fetching this setting defaults to false |
50 | 50 | * @return string |
51 | 51 | */ |
52 | - public function get($app, $key, $default=null, $refresh=false) |
|
52 | + public function get($app, $key, $default = null, $refresh = false) |
|
53 | 53 | { |
54 | 54 | $settings = $this->getSettings($refresh); |
55 | 55 | return isset($settings[$app][$key]) && $settings[$app][$key] !== '' ? $settings[$app][$key] : $default; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $result = $setting->save(); |
78 | 78 | |
79 | 79 | if (!$result) { |
80 | - throw new \Exception('Unable to save setting. ' . print_r($setting->getErrors(), true)); |
|
80 | + throw new \Exception('Unable to save setting. '.print_r($setting->getErrors(), true)); |
|
81 | 81 | } |
82 | 82 | neon()->cache->delete('neon_settings'); |
83 | 83 | $this->_settings[$app][$key] = $value; |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @param boolean $refresh if true forces a reload of the the settings |
91 | 91 | * @return array in the format @see self::$_settings |
92 | 92 | */ |
93 | - public function getAll($refresh=false) |
|
93 | + public function getAll($refresh = false) |
|
94 | 94 | { |
95 | 95 | if ($refresh) neon()->cache->delete('neon_settings'); |
96 | 96 | return $this->_settings = neon()->cache->getOrSet('neon_settings', function() { |
97 | 97 | $settingRows = Setting::find()->asArray()->all(); |
98 | 98 | $this->_settings = []; |
99 | - foreach($settingRows as $setting) { |
|
99 | + foreach ($settingRows as $setting) { |
|
100 | 100 | $this->_settings[$setting['app']][$setting['key']] = $this->_decode($setting['value']); |
101 | 101 | } |
102 | 102 | return $this->_settings; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param boolean $refresh if true forces a reload of the the settings |
110 | 110 | * @return array in the format @see self::$_settings |
111 | 111 | */ |
112 | - public function getSettings($refresh=false) |
|
112 | + public function getSettings($refresh = false) |
|
113 | 113 | { |
114 | 114 | return $this->getAll($refresh); |
115 | 115 | } |
@@ -92,7 +92,9 @@ |
||
92 | 92 | */ |
93 | 93 | public function getAll($refresh=false) |
94 | 94 | { |
95 | - if ($refresh) neon()->cache->delete('neon_settings'); |
|
95 | + if ($refresh) { |
|
96 | + neon()->cache->delete('neon_settings'); |
|
97 | + } |
|
96 | 98 | return $this->_settings = neon()->cache->getOrSet('neon_settings', function() { |
97 | 99 | $settingRows = Setting::find()->asArray()->all(); |
98 | 100 | $this->_settings = []; |
@@ -76,7 +76,7 @@ |
||
76 | 76 | * @throws \yii\web\HttpException |
77 | 77 | * @return boolean - whether new url was saved |
78 | 78 | */ |
79 | - public function redirect($newUrl, $createRedirect, $throw=true) |
|
79 | + public function redirect($newUrl, $createRedirect, $throw = true) |
|
80 | 80 | { |
81 | 81 | // find urls that link to this page |
82 | 82 | $urls = CmsUrl::find()->where(['nice_id' => $this->nice_id])->limit(10)->all(); |
@@ -81,7 +81,9 @@ |
||
81 | 81 | // find urls that link to this page |
82 | 82 | $urls = CmsUrl::find()->where(['nice_id' => $this->nice_id])->limit(10)->all(); |
83 | 83 | if (count($urls) > 1) { |
84 | - if ($throw) abort(400, 'There must be only one url that links to this page - otherwise the wrong url may be updated'); |
|
84 | + if ($throw) { |
|
85 | + abort(400, 'There must be only one url that links to this page - otherwise the wrong url may be updated'); |
|
86 | + } |
|
85 | 87 | return false; |
86 | 88 | } |
87 | 89 | $url = $urls[0]; |
@@ -133,7 +133,7 @@ |
||
133 | 133 | { |
134 | 134 | return static::cache()->getOrSet('cms_url_pages', function() { |
135 | 135 | return collect(CmsPage::find()->select('id, nice_id')->asArray()->all()) |
136 | - ->flatMap(function($i){ return [$i['id'] => $i['nice_id']]; }) |
|
136 | + ->flatMap(function($i) { return [$i['id'] => $i['nice_id']]; }) |
|
137 | 137 | ->all(); |
138 | 138 | }); |
139 | 139 | } |
@@ -18,59 +18,59 @@ |
||
18 | 18 | */ |
19 | 19 | class DdsDataType extends \yii\db\ActiveRecord |
20 | 20 | { |
21 | - /** |
|
22 | - * @inheritdoc |
|
23 | - */ |
|
24 | - public static function tableName() |
|
25 | - { |
|
26 | - return '{{%dds_data_type}}'; |
|
27 | - } |
|
21 | + /** |
|
22 | + * @inheritdoc |
|
23 | + */ |
|
24 | + public static function tableName() |
|
25 | + { |
|
26 | + return '{{%dds_data_type}}'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @inheritdoc |
|
31 | - */ |
|
32 | - public function rules() |
|
33 | - { |
|
34 | - return [ |
|
35 | - [['data_type_ref', 'storage_ref'], 'required'], |
|
36 | - [['deleted'], 'integer'], |
|
37 | - [['data_type_ref', 'storage_ref'], 'string', 'max' => 50], |
|
38 | - [['label'], 'string', 'max' => 300], |
|
39 | - [['description'], 'string', 'max' => 1000], |
|
40 | - [['definition'], 'string', 'max' => 2000], |
|
41 | - [['data_type_ref'], 'unique'], |
|
42 | - [['storage_ref'], 'exist', 'skipOnError' => true, 'targetClass' => DdsStorage::className(), 'targetAttribute' => ['storage_ref' => 'storage_ref']], |
|
43 | - ]; |
|
44 | - } |
|
29 | + /** |
|
30 | + * @inheritdoc |
|
31 | + */ |
|
32 | + public function rules() |
|
33 | + { |
|
34 | + return [ |
|
35 | + [['data_type_ref', 'storage_ref'], 'required'], |
|
36 | + [['deleted'], 'integer'], |
|
37 | + [['data_type_ref', 'storage_ref'], 'string', 'max' => 50], |
|
38 | + [['label'], 'string', 'max' => 300], |
|
39 | + [['description'], 'string', 'max' => 1000], |
|
40 | + [['definition'], 'string', 'max' => 2000], |
|
41 | + [['data_type_ref'], 'unique'], |
|
42 | + [['storage_ref'], 'exist', 'skipOnError' => true, 'targetClass' => DdsStorage::className(), 'targetAttribute' => ['storage_ref' => 'storage_ref']], |
|
43 | + ]; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @inheritdoc |
|
48 | - */ |
|
49 | - public function attributeLabels() |
|
50 | - { |
|
51 | - return [ |
|
52 | - 'data_type_ref' => 'Data Type Ref', |
|
53 | - 'label' => 'Label', |
|
54 | - 'description' => 'Description', |
|
55 | - 'definition' => 'Definition', |
|
56 | - 'storage_ref' => 'Storage Ref', |
|
57 | - 'deleted' => 'Deleted', |
|
58 | - ]; |
|
59 | - } |
|
46 | + /** |
|
47 | + * @inheritdoc |
|
48 | + */ |
|
49 | + public function attributeLabels() |
|
50 | + { |
|
51 | + return [ |
|
52 | + 'data_type_ref' => 'Data Type Ref', |
|
53 | + 'label' => 'Label', |
|
54 | + 'description' => 'Description', |
|
55 | + 'definition' => 'Definition', |
|
56 | + 'storage_ref' => 'Storage Ref', |
|
57 | + 'deleted' => 'Deleted', |
|
58 | + ]; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return \yii\db\ActiveQuery |
|
63 | - */ |
|
64 | - public function getStorageRef() |
|
65 | - { |
|
66 | - return $this->hasOne(DdsStorage::className(), ['storage_ref' => 'storage_ref']); |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return \yii\db\ActiveQuery |
|
63 | + */ |
|
64 | + public function getStorageRef() |
|
65 | + { |
|
66 | + return $this->hasOne(DdsStorage::className(), ['storage_ref' => 'storage_ref']); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return \yii\db\ActiveQuery |
|
71 | - */ |
|
72 | - public function getDdsMembers() |
|
73 | - { |
|
74 | - return $this->hasMany(DdsMember::className(), ['data_type_ref' => 'data_type_ref']); |
|
75 | - } |
|
69 | + /** |
|
70 | + * @return \yii\db\ActiveQuery |
|
71 | + */ |
|
72 | + public function getDdsMembers() |
|
73 | + { |
|
74 | + return $this->hasMany(DdsMember::className(), ['data_type_ref' => 'data_type_ref']); |
|
75 | + } |
|
76 | 76 | } |