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 ...@@ -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 int $count Count of tags that are about to be deleted
* @param string $originUrl An origin url
* @param string $newUrl The url of the desired action
* *
* @return $this->confirmAction * @return array
*/ */
protected function confirmTagsDelete($ids, $originUrl, $newUrl) protected function getConfirmDeleteMessages($count)
{ {
$messages = array(); $messages = array();
$count = count($ids);
$user = $this->getTable('user') $user = $this->getTable('user')
->select(array('id' => $this->getParam('user_id'))) ->select(array('id' => $this->getParam('user_id')))
->current(); ->current();
...@@ -236,12 +232,28 @@ class TagsController extends AbstractAdmin ...@@ -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(
'data' => array( 'data' => array(
'confirm' => $newUrl, 'confirm' => $newUrl,
'cancel' => $originUrl, 'cancel' => $originUrl,
'title' => "confirm_delete_tags_brief", 'title' => "confirm_delete_tags_brief",
'messages' => $messages, 'messages' => $this->getConfirmDeleteMessages($count),
'ids' => $ids, 'ids' => $ids,
'extras' => array( 'extras' => array(
'origin' => 'list', 'origin' => 'list',
...@@ -263,61 +275,24 @@ class TagsController extends AbstractAdmin ...@@ -263,61 +275,24 @@ class TagsController extends AbstractAdmin
* @param string $originUrl An origin url * @param string $originUrl An origin url
* @param string $newUrl The url of the desired action * @param string $newUrl The url of the desired action
* *
* @return $this->confirmAction * @return mixed
*/ */
protected function confirmTagsDeleteByFilter($tagModel, $originUrl, $newUrl) protected function confirmTagsDeleteByFilter($tagModel, $originUrl, $newUrl)
{ {
$messages = array();
$count = $tagModel->getResourceTags( $count = $tagModel->getResourceTags(
$this->convertFilter($this->getParam('user_id')), $this->convertFilter($this->getParam('user_id')),
$this->convertFilter($this->getParam('resource_id')), $this->convertFilter($this->getParam('resource_id')),
$this->convertFilter($this->getParam('tag_id')) $this->convertFilter($this->getParam('tag_id'))
)->getTotalItemCount(); )->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(
'data' => array( 'data' => array(
'confirm' => $newUrl, 'confirm' => $newUrl,
'cancel' => $originUrl, 'cancel' => $originUrl,
'title' => "confirm_delete_tags_brief", 'title' => "confirm_delete_tags_brief",
'messages' => $messages, 'messages' => $this->getConfirmDeleteMessages($count),
'origin' => 'manage',
'extras' => array( 'extras' => array(
'origin' => 'manage',
'type' => $this->getParam('type'), 'type' => $this->getParam('type'),
'user_id' => $this->getParam('user_id'), 'user_id' => $this->getParam('user_id'),
'tag_id' => $this->getParam('tag_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