Skip to content

Commit

Permalink
passing named and pass params in the url to the redirected controller…
Browse files Browse the repository at this point in the history
… when doing generic mass actions
  • Loading branch information
dogmatic69 committed Jun 27, 2012
1 parent e6c14bb commit a78d702
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions Core/Libs/Controller/Component/MassActionComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class MassActionComponent extends InfinitasComponent {
public function initialize($Controller) {
parent::initialize($Controller);

if($this->getAction(false) == 'cancel') {
$Controller->Event->trigger(
'editCanceled',
Expand All @@ -35,7 +35,7 @@ public function initialize($Controller) {
$Controller->redirect($Controller->getPageRedirectVar());
}
}

/**
* Mass actions
*
Expand All @@ -47,15 +47,15 @@ public function initialize($Controller) {
*/
public function actionAdminMass() {
$massAction = $this->getAction();

if(isset($this->Controller->modelClass)) {
$modelName = $this->Controller->modelClass;
}

if(!empty($this->Controller->request->data['Confirm']['model'])) {
$modelName = $this->Controller->request->data['Confirm']['model'];
}

$ids = $this->getIds(
$massAction,
$this->Controller->request->data[$modelName]
Expand All @@ -73,7 +73,7 @@ public function actionAdminMass() {

return $this->generic($massAction, $ids);
}

/**
* Get submitted ids.
*
Expand Down Expand Up @@ -154,7 +154,7 @@ public function filter($null = null) {
foreach($this->Controller->{$this->Controller->modelClass}->belongsTo as $model => $options) {
if(empty($this->Controller->data[$model])) {
continue;
}
}

foreach((array)$this->Controller->data[$model] as $k => $field) {
if ((empty($field) && $field !== 0) || is_int($k) || $k == 'all' || $k == 'massCheckBox') {
Expand Down Expand Up @@ -215,7 +215,7 @@ public function delete($ids) {
$this->Controller->render($this->Controller->plugin . '.Global/delete');
return;
}

$this->Controller->render('Libs.Global/delete');
$this->Controller->saveRedirectMarker();
}
Expand All @@ -241,7 +241,7 @@ public function __handleDeletes($ids) {
$this->Controller->{$this->Controller->modelClass}->transaction(true);
$this->Controller->notice('deleted');
}

$this->Controller->{$this->Controller->modelClass}->transaction(false);
$this->Controller->notice('not_deleted');
}
Expand All @@ -258,11 +258,11 @@ public function toggle($ids) {
if(!$this->Controller->{$this->Controller->modelClass}->hasField('active')) {
throw new Exception(sprintf('The model "%s" does not have an active field', $this->Controller->modelClass));
}

if(empty($ids)) {
return false;
}

$conditions = array($this->Controller->modelClass . '.id' => $ids);
$newValues = array(
$this->Controller->modelClass . '.active' => '1 - `' . $this->Controller->modelClass . '`.`active`'
Expand Down Expand Up @@ -313,7 +313,7 @@ public function toggle($ids) {
public function copy($ids) {
$copyText = sprintf(' - %s (%s)', __('copy'), date('Y-m-d'));
$saves = 0;

if($this->Controller->{$this->Controller->modelClass}->Behaviors->attached('Contentable')) {
$this->Controller->notice(
__d('content', 'Copy is not currently supported for this data'),
Expand All @@ -323,14 +323,14 @@ public function copy($ids) {
)
);
}

foreach($ids as $id) {
$record = $this->Controller->{$this->Controller->modelClass}->read(null, $id);

unset($record[$this->Controller->modelClass]['id']);

$check = $record[$this->Controller->modelClass][$this->Controller->{$this->Controller->modelClass}->displayField] != $this->Controller->{$this->Controller->modelClass}->primaryKey;

if ($check) {
$record[$this->Controller->modelClass][$this->Controller->{$this->Controller->modelClass}->displayField] =
$record[$this->Controller->modelClass][$this->Controller->{$this->Controller->modelClass}->displayField] . $copyText;
Expand All @@ -353,7 +353,7 @@ public function copy($ids) {
if(!empty($schema['key']) && $schema['key'] == 'unique') {
$record[$this->Controller->modelClass][$field] .= ' - ' . time();
}

if(strstr($field, '_count')) {
unset($record[$this->Controller->modelClass][$field]);
}
Expand Down Expand Up @@ -445,7 +445,7 @@ public function move($ids) {
$this->Controller->set(strtolower($alias), $_Model->find('list'));
}
}

if(array_filter(Set::flatten($relations)) == array()) {
$this->Controller->notice(
__d($this->Controller->request->params['plugin'], 'There is nothing to move for these records'),
Expand All @@ -458,15 +458,15 @@ public function move($ids) {
$modelSetup['displayField'] = $this->Controller->{$this->Controller->modelClass}->displayField;
$modelSetup['primaryKey'] = $this->Controller->{$this->Controller->modelClass}->primaryKey;
$this->Controller->set(compact('rows', 'model', 'modelSetup', 'relations'));

$this->Controller->saveRedirectMarker();

$pluginOverload = App::pluginPath($this->Controller->plugin) . 'View' . DS . 'Global' . DS . 'move.ctp';
if(is_file($pluginOverload)) {
$this->Controller->render($this->Controller->plugin . '.Global/move');
return;
}

$this->Controller->render('Libs.Global/move');
}

Expand Down Expand Up @@ -540,10 +540,11 @@ private function __handleMove($ids) {
* @param int $id the id of the record that is selected.
*/
public function generic($action = 'add', $ids = null) {
if (!$ids || !isset($ids[0])) {
$this->Controller->redirect(array('action' => $action));
$url = array('action' => $action);
if (!empty($ids)) {
$url = array_merge($url, $ids);
}

$this->Controller->redirect(array('action' => $action, $ids[0]));
$this->Controller->redirect(array_merge($url, $this->Controller->request->params['named'], (array)$this->request->params['pass']));
}
}

0 comments on commit a78d702

Please sign in to comment.