Skip to content

Commit

Permalink
Optimization and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Feb 18, 2015
1 parent 5ceb760 commit 58ec6fe
Show file tree
Hide file tree
Showing 21 changed files with 271 additions and 222 deletions.
8 changes: 3 additions & 5 deletions src/com_weblinks/admin/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
defined('_JEXEC') or die;

/**
* Weblinks Weblink Controller
* Weblinks Main Controller
*
* @since 1.5
*/
Expand All @@ -22,7 +22,7 @@ class WeblinksController extends JControllerLegacy
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @return JControllerLegacy This object to support chaining.
*
* @since 1.5
*/
Expand All @@ -45,8 +45,6 @@ public function display($cachable = false, $urlparams = false)
return false;
}

parent::display();

return $this;
return parent::display();
}
}
18 changes: 7 additions & 11 deletions src/com_weblinks/admin/controllers/weblink.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ protected function allowAdd($data = array())
$allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
}

if ($allow === null)
{
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
else
if ($allow !== null)
{
return $allow;
}

// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}

/**
Expand Down Expand Up @@ -73,11 +71,9 @@ protected function allowEdit($data = array(), $key = 'id')
// The category has been set. Check the category permissions.
return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId);
}
else
{
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}

// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}

/**
Expand Down
18 changes: 1 addition & 17 deletions src/com_weblinks/admin/controllers/weblinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@ class WeblinksControllerWeblinks extends JControllerAdmin
*/
public function getModel($name = 'Weblink', $prefix = 'WeblinksModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);

return $model;
}

/**
* Method to provide child classes the opportunity to process after the delete task.
*
* @param JModelLegacy $model The model for the component
* @param mixed $ids array of ids deleted.
*
* @return void
*
* @since 3.1
*/
protected function postDeleteHook(JModelLegacy $model, $ids = null)
{
return parent::getModel($name, $prefix, $config);
}
}
35 changes: 14 additions & 21 deletions src/com_weblinks/admin/models/weblink.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

use Joomla\Registry\Registry;
use Joomla\String\String;

/**
* Weblinks model.
Expand All @@ -18,12 +19,11 @@
*/
class WeblinksModelWeblink extends JModelAdmin
{

/**
* The type alias for this content type.
*
* @var string
* @since 3.2
* @var string
* @since 3.2
*/
public $typeAlias = 'com_weblinks.weblink';

Expand Down Expand Up @@ -52,16 +52,13 @@ protected function canDelete($record)
{
return;
}
$user = JFactory::getUser();

if ($record->catid)
{
return $user->authorise('core.delete', 'com_weblinks.category.'.(int) $record->catid);
}
else
{
return parent::canDelete($record);
return JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid);
}

return parent::canDelete($record);
}
}

Expand All @@ -76,16 +73,12 @@ protected function canDelete($record)
*/
protected function canEditState($record)
{
$user = JFactory::getUser();

if (!empty($record->catid))
{
return $user->authorise('core.edit.state', 'com_weblinks.category.'.(int) $record->catid);
}
else
{
return parent::canEditState($record);
return JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid);
}

return parent::canEditState($record);
}

/**
Expand Down Expand Up @@ -234,11 +227,11 @@ protected function prepareTable($table)
$user = JFactory::getUser();

$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
$table->alias = JApplication::stringURLSafe($table->alias);
$table->alias = JApplicationHelper::stringURLSafe($table->alias);

if (empty($table->alias))
{
$table->alias = JApplication::stringURLSafe($table->title);
$table->alias = JApplicationHelper::stringURLSafe($table->title);
}

if (empty($table->id))
Expand All @@ -262,7 +255,7 @@ protected function prepareTable($table)
{
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->get('id');
$table->modified_by = $user->id;
}
}

Expand Down Expand Up @@ -332,10 +325,10 @@ protected function generateNewTitle($category_id, $alias, $name)
{
if ($name == $table->title)
{
$name = JString::increment($name);
$name = String::increment($name);
}

$alias = JString::increment($alias, 'dash');
$alias = String::increment($alias, 'dash');
}

return array($name, $alias);
Expand Down
22 changes: 15 additions & 7 deletions src/com_weblinks/admin/models/weblinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class WeblinksModelWeblinks extends JModelList
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
Expand Down Expand Up @@ -54,8 +55,9 @@ public function __construct($config = array())
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
Expand Down Expand Up @@ -94,8 +96,10 @@ protected function populateState($ordering = null, $direction = null)
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
Expand All @@ -114,6 +118,7 @@ protected function getStoreId($id = '')
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
Expand All @@ -128,9 +133,7 @@ protected function getListQuery()
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
'a.hits,' .
'a.state, a.access, a.ordering,' .
'a.language, a.publish_up, a.publish_down'
'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
)
);
$query->from($db->quoteName('#__weblinks') . ' AS a');
Expand Down Expand Up @@ -166,6 +169,7 @@ protected function getListQuery()

// Filter by published state
$published = $this->getState('filter.state');

if (is_numeric($published))
{
$query->where('a.state = ' . (int) $published);
Expand All @@ -177,13 +181,15 @@ protected function getListQuery()

// Filter by category.
$categoryId = $this->getState('filter.category_id');

if (is_numeric($categoryId))
{
$query->where('a.catid = ' . (int) $categoryId);
}

// Filter by search in title
$search = $this->getState('filter.search');

if (!empty($search))
{
if (stripos($search, 'id:') === 0)
Expand All @@ -204,6 +210,7 @@ protected function getListQuery()
}

$tagId = $this->getState('filter.tag');

// Filter by a single tag.
if (is_numeric($tagId))
{
Expand All @@ -218,13 +225,14 @@ protected function getListQuery()
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');

if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}

$query->order($db->escape($orderCol . ' ' . $orderDirn));

//echo nl2br(str_replace('#__','jos_',$query));
return $query;
}
}
2 changes: 1 addition & 1 deletion src/com_weblinks/admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Com_WeblinksInstallerScript
/**
* Function to perform changes during install
*
* @param JInstallerComponent $parent The class calling this method
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
Expand Down
Loading

0 comments on commit 58ec6fe

Please sign in to comment.