Skip to content

Commit

Permalink
moving some code about and adding the grouped fields to the save so t…
Browse files Browse the repository at this point in the history
…hat ordering works corrctly
  • Loading branch information
dogmatic69 committed Aug 19, 2012
1 parent 3990bf2 commit 64127ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
8 changes: 1 addition & 7 deletions Core/Libs/Controller/Component/InfinitasActionsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public function actionAdminMine() {
* @return void
*/
public function actionAdminReorder($id = null) {
$this->Controller->saveRedirectMarker();
$model = $this->Controller->modelClass;

if (!$id) {
Expand All @@ -285,13 +286,6 @@ public function actionAdminReorder($id = null) {
$this->Controller->request->data[$model]['id'] = $id;

if (!empty($this->Controller->request->params['named']['position'])) {
if(!$this->Controller->{$model}->Behaviors->attached('Sequence')) {
$this->Controller->notice(
__d('infinitas', 'A problem occured moving the ordered record.'),
$redirectConfig
);
}

$this->Controller->Infinitas->orderedMove();
}

Expand Down
40 changes: 32 additions & 8 deletions Core/Libs/Controller/Component/InfinitasComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,40 @@ public function orderedMove() {
$modelName = $this->Controller->modelClass;
$this->Controller->{$modelName}->transaction();

try {
if(!$this->Controller->{$modelName}->Behaviors->attached('Sequence')) {
throw new Exception('Cant move items');
}
if(!$this->Controller->{$modelName}->Behaviors->attached('Sequence')) {
$this->Controller->notice(
__d('infinitas', 'A problem occured moving the ordered record.'),
array(
'level' => 'error',
'redirect' => true
)
);
}

$this->Controller->request->data[$modelName]['ordering'] = $this->Controller->request->params['named']['position'];
$fields = array_values($this->Controller->{$modelName}->sequenceGroupFields());
$fields[] = $this->Controller->{$modelName}->alias . '.' . $this->Controller->{$modelName}->primaryKey;
$data = $this->Controller->{$modelName}->find(
'first',
array(
'fields' => $fields,
'conditions' => array(
$this->Controller->{$modelName}->alias . '.' . $this->Controller->{$modelName}->primaryKey => $this->Controller->request->data[$modelName][$this->Controller->{$modelName}->primaryKey]
),
'callbacks' => false
)
);
$data[$modelName]['ordering'] = $this->Controller->request->params['named']['position'];

$this->Controller->{$modelName}->save($this->Controller->request->data, array('validate' => false));
$this->Controller->{$modelName}->transaction(true);
return true;
try {
if($this->Controller->{$modelName}->save($data, array('validate' => false))) {
$this->Controller->{$modelName}->transaction(true);
$this->Controller->notice(
__d('infinitas', 'The record was moved'),
array(
'redirect' => ''
)
);
}
} catch(Exception $e) {
$this->Controller->{$modelName}->transaction(false);
$this->Controller->notice(
Expand Down

0 comments on commit 64127ba

Please sign in to comment.