Skip to content

Commit

Permalink
Use JModelAdmin::delete() instead of a custom method.
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Jun 21, 2011
1 parent 9b093f9 commit c3819f7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
29 changes: 21 additions & 8 deletions admin/controllers/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,28 @@ function save()
*/
function remove()
{
JRequest::checkToken() or jexit( 'Invalid Token' );
//Load model and delete entry - redirect afterwards
$model = $this->getModel( 'entry' );
if (!$model->delete()) {
$msg = JText::_('COM_HELPDESK_ERROR_ENTRY_DELETED');
$type = 'error';
// Check for request forgeries
JRequest::checkToken() or jexit('Invalid Token');

// Get items to remove from the request.
$cid = JRequest::getVar('cid', array(), '', 'array');

if (!is_array($cid) || count($cid) < 1) {
JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
} else {
$msg = JText::_('COM_HELPDESK_ENTRY_DELETED');
$type = 'message';
// Get the model.
$model = $this->getModel();

// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);

// Remove the items.
if ($model->delete($cid)) {
$this->setMessage(JText::plural($this->text_prefix.'_N_ITEMS_DELETED', count($cid)));
} else {
$this->setMessage($model->getError());
}
}
$this->setRedirect( JRoute::_( 'index.php?option=com_helpdesk', false ), $msg, $type );
}
Expand Down
26 changes: 5 additions & 21 deletions admin/models/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class HelpdeskModelEntry extends JModelAdmin
var $_data = null;
var $_id = null;


/**
* Constructor that retrieves the ID from the request
*
Expand All @@ -30,7 +29,7 @@ function __construct()
$array = JRequest::getVar('cid', 0, '', 'array');
$this->setId((int)$array[0]);
}

/**
* Method to set the entry identifier
*
Expand All @@ -44,7 +43,7 @@ public function setId($id)
$this->_id = $id;
$this->_data = null;
}

/**
* Method to get a entry
*
Expand All @@ -66,7 +65,7 @@ function getData()

return $this->_data;
}

/**
* Method to store a record
*
Expand Down Expand Up @@ -97,21 +96,6 @@ public function store()

return true;
}

public function delete()
{
$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$row =& $this->getTable();

foreach($cids as $cid) {
if (!$row->delete( $cid )) {
$this->setError( $row->_db->getErrorMsg() );
return false;
}
}

return true;
}

// Publishes an entry or unpublishes it
public function publish($state)
Expand All @@ -126,7 +110,7 @@ public function publish($state)

return true;
}

public function getForm($data = array(), $loadData = true)
{
$app = JFactory::getApplication();
Expand All @@ -139,7 +123,7 @@ public function getForm($data = array(), $loadData = true)

return $form;
}

protected function loadFormData()
{
$app = JFactory::getApplication();
Expand Down
15 changes: 12 additions & 3 deletions admin/tables/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ class TableEntry extends JTable
var $hcomment = null;
var $published = null;
var $decline = null;
var $hfac = null;
var $hfac = null;
var $hmajor = null;
var $hfile = null;
var $htype = null;
var $hsize = null;
var $hstatus = null;


/**
* Constructor
*
* @param object Database connector object
*/
function __construct(&$db)
{
parent::__construct('#__helpdesk', 'id', $db);
}

/**
* Constructor
*
Expand All @@ -35,6 +45,5 @@ class TableEntry extends JTable
function TableEntry( &$db ) {
parent::__construct('#__helpdesk', 'id', $db);
}

}
?>

0 comments on commit c3819f7

Please sign in to comment.