Skip to content
Snippets Groups Projects
Commit 8fb2a976 authored by Demian Katz's avatar Demian Katz
Browse files

Refactored redundant code; fixed position of 'origin' in array.

parent 95051838
No related merge requests found
......@@ -192,19 +192,15 @@ class TagsController extends AbstractAdmin
}
/**
* Confirm Delete by Id
* Get confirmation messages.
*
* @param array $ids A list of resource tag Ids
* @param string $originUrl An origin url
* @param string $newUrl The url of the desired action
* @param int $count Count of tags that are about to be deleted
*
* @return $this->confirmAction
* @return array
*/
protected function confirmTagsDelete($ids, $originUrl, $newUrl)
protected function getConfirmDeleteMessages($count)
{
$messages = array();
$count = count($ids);
$user = $this->getTable('user')
->select(array('id' => $this->getParam('user_id')))
->current();
......@@ -236,12 +232,28 @@ class TagsController extends AbstractAdmin
)
);
}
return $messages;
}
/**
* Confirm Delete by Id
*
* @param array $ids A list of resource tag Ids
* @param string $originUrl An origin url
* @param string $newUrl The url of the desired action
*
* @return mixed
*/
protected function confirmTagsDelete($ids, $originUrl, $newUrl)
{
$count = count($ids);
$data = array(
'data' => array(
'confirm' => $newUrl,
'cancel' => $originUrl,
'title' => "confirm_delete_tags_brief",
'messages' => $messages,
'messages' => $this->getConfirmDeleteMessages($count),
'ids' => $ids,
'extras' => array(
'origin' => 'list',
......@@ -263,61 +275,24 @@ class TagsController extends AbstractAdmin
* @param string $originUrl An origin url
* @param string $newUrl The url of the desired action
*
* @return $this->confirmAction
* @return mixed
*/
protected function confirmTagsDeleteByFilter($tagModel, $originUrl, $newUrl)
{
$messages = array();
$count = $tagModel->getResourceTags(
$this->convertFilter($this->getParam('user_id')),
$this->convertFilter($this->getParam('resource_id')),
$this->convertFilter($this->getParam('tag_id'))
)->getTotalItemCount();
$user = $this->getTable('user')
->select(array('id' => $this->getParam('user_id')))
->current();
$userMsg = (false !== $user)
? $user->username . " (" . $user->id . ")" : "All";
$tag = $this->getTable('tags')
->select(array('id' => $this->getParam('tag_id')))
->current();
$tagMsg = (false !== $tag)
? $tag->tag. " (" . $tag->id . ")" : " All";
$resource = $this->getTable('resource')
->select(array('id' => $this->getParam('resource_id')))
->current();
$resourceMsg = (false !== $resource)
? $resource->title. " (" . $resource->id . ")" : " All";
$messages[] = array(
'msg' => 'tag_delete_warning',
'tokens' => array('%count%' => $count)
);
if (false !== $user || false!== $tag || false !== $resource) {
$messages[] = array(
'msg' => 'tag_delete_filter',
'tokens' => array(
'%username%' => $userMsg,
'%tag%' => $tagMsg,
'%resource%' => $resourceMsg
)
);
}
$data = array(
'data' => array(
'confirm' => $newUrl,
'cancel' => $originUrl,
'title' => "confirm_delete_tags_brief",
'messages' => $messages,
'origin' => 'manage',
'messages' => $this->getConfirmDeleteMessages($count),
'extras' => array(
'origin' => 'manage',
'type' => $this->getParam('type'),
'user_id' => $this->getParam('user_id'),
'tag_id' => $this->getParam('tag_id'),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment