@@ -111,14 +111,14 @@ public function save($data)
111111
112112 // Create default step for new tour
113113 if ($ result && $ input ->getCmd ('task ' ) !== 'save2copy ' && $ this ->getState ($ this ->getName () . '.new ' )) {
114- $ tour_id = (int ) $ this ->getState ($ this ->getName () . '.id ' );
114+ $ tourId = (int ) $ this ->getState ($ this ->getName () . '.id ' );
115115
116116 $ table = $ this ->getTable ('Step ' );
117117
118118 $ table ->id = 0 ;
119119 $ table ->title = 'COM_GUIDEDTOURS_BASIC_STEP ' ;
120120 $ table ->description = '' ;
121- $ table ->tour_id = $ tour_id ;
121+ $ table ->tour_id = $ tourId ;
122122 $ table ->published = 1 ;
123123
124124 $ table ->store ();
@@ -194,19 +194,17 @@ public function getForm($data = [], $loadData = true)
194194
195195 $ item = $ this ->getItem ($ id );
196196
197- $ canEditState = $ this ->canEditState ((object ) $ item );
198-
199197 // Modify the form based on access controls.
200- if (!$ canEditState || !empty ($ item ->default )) {
201- if (!$ canEditState ) {
202- $ form ->setFieldAttribute ('published ' , 'disabled ' , 'true ' );
203- $ form ->setFieldAttribute ('published ' , 'required ' , 'false ' );
204- $ form ->setFieldAttribute ('published ' , 'filter ' , 'unset ' );
205- }
198+ if (!$ this ->canEditState ((object ) $ item )) {
199+ $ form ->setFieldAttribute ('published ' , 'disabled ' , 'true ' );
200+ $ form ->setFieldAttribute ('published ' , 'required ' , 'false ' );
201+ $ form ->setFieldAttribute ('published ' , 'filter ' , 'unset ' );
206202 }
207203
208- $ form ->setFieldAttribute ('created ' , 'default ' , Factory::getDate ()->toSql ());
209- $ form ->setFieldAttribute ('modified ' , 'default ' , Factory::getDate ()->toSql ());
204+ $ currentDate = Factory::getDate ()->toSql ();
205+
206+ $ form ->setFieldAttribute ('created ' , 'default ' , $ currentDate );
207+ $ form ->setFieldAttribute ('modified ' , 'default ' , $ currentDate );
210208
211209 return $ form ;
212210 }
@@ -245,7 +243,7 @@ protected function loadFormData()
245243 protected function canDelete ($ record )
246244 {
247245 if (!empty ($ record ->id )) {
248- return Factory:: getUser ()->authorise ('core.delete ' , 'com_guidedtours.tour. ' . (int ) $ record ->id );
246+ return $ this -> getCurrentUser ()->authorise ('core.delete ' , 'com_guidedtours.tour. ' . (int ) $ record ->id );
249247 }
250248
251249 return false ;
@@ -263,11 +261,9 @@ protected function canDelete($record)
263261 */
264262 protected function canEditState ($ record )
265263 {
266- $ user = Factory::getUser ();
267-
268264 // Check for existing tour.
269265 if (!empty ($ record ->id )) {
270- return $ user ->authorise ('core.edit.state ' , 'com_guidedtours.tour. ' . (int ) $ record ->id );
266+ return $ this -> getCurrentUser () ->authorise ('core.edit.state ' , 'com_guidedtours.tour. ' . (int ) $ record ->id );
271267 }
272268
273269 // Default to component settings if neither tour nor category known.
@@ -285,14 +281,13 @@ protected function canEditState($record)
285281 */
286282 public function getItem ($ pk = null )
287283 {
288- $ lang = Factory::getLanguage ();
289- $ lang ->load ('com_guidedtours.sys ' , JPATH_ADMINISTRATOR );
284+ Factory::getLanguage ()->load ('com_guidedtours.sys ' , JPATH_ADMINISTRATOR );
290285
291- if ( $ result = parent ::getItem ($ pk )) {
292- if (! empty ( $ result -> id )) {
293- $ result -> title_translation = Text:: _ ( $ result ->title );
294- $ result ->description_translation = Text::_ ($ result ->description );
295- }
286+ $ result = parent ::getItem ($ pk );
287+
288+ if (! empty ( $ result ->id )) {
289+ $ result ->title_translation = Text::_ ($ result ->title );
290+ $ result -> description_translation = Text:: _ ( $ result -> description );
296291 }
297292
298293 return $ result ;
@@ -330,7 +325,7 @@ public function delete(&$pks)
330325 return false ;
331326 }
332327
333- $ tour_id = $ table ->id ;
328+ $ tourId = $ table ->id ;
334329
335330 if (!$ table ->delete ($ pk )) {
336331 $ this ->setError ($ table ->getError ());
@@ -342,7 +337,7 @@ public function delete(&$pks)
342337 $ db = $ this ->getDatabase ();
343338 $ query = $ db ->getQuery (true )
344339 ->delete ($ db ->quoteName ('#__guidedtour_steps ' ))
345- ->where ($ db ->quoteName ('tour_id ' ) . '= ' . $ tour_id );
340+ ->where ($ db ->quoteName ('tour_id ' ) . '= ' . $ tourId );
346341 $ db ->setQuery ($ query );
347342 $ db ->execute ();
348343
@@ -391,7 +386,7 @@ public function duplicate(&$pks)
391386 $ db = $ this ->getDatabase ();
392387
393388 // Access checks.
394- if (!$ user ->authorise ('core.create ' , 'com_tours ' ) || ! $ user -> authorise ( ' core.create ' , ' __guidedtour_steps ' ) ) {
389+ if (!$ user ->authorise ('core.create ' , 'com_tours ' )) {
395390 throw new \Exception (Text::_ ('JERROR_CORE_CREATE_NOT_PERMITTED ' ));
396391 }
397392
0 commit comments