CakePhp : Quick record actions

function quick_actions($form, $model, $data) {
        $action = $this->data[$form]['actions'];
        App::Import('Model', $model);
        $this->DynamicModel = new $form;
        if ($action == 'delete') {
            foreach ($this->data[$form]['id'] as $key => $value) {
                if ($value != 0) {
                    $this->DynamicModel->delete($key);
                    $this->Session->setFlash('Items permanent verwijderd', 'notifications/tray_top');
                    $return = true;
                }
            }
        }
        if ($action == 'return') {
            foreach ($this->data[$form]['id'] as $key => $value) {
                if ($value != 0) {
                    if ($this->DynamicModel->updateAll(array($form.'.deleted'=>'0'),array($form.'.id'=>$key))) {
                        $this->Session->setFlash('Items teruggezet', 'notifications/tray_top');
                        $return = true;
                    }
                }
            }
        }
        if ($action == 'remove') {
            foreach ($this->data[$form]['id'] as $key => $value) {
                if ($value != 0) {
                    if ($this->DynamicModel->updateAll(array($form.'.deleted'=>'1'),array($form.'.id'=>$key))) {
                        $this->Session->setFlash('Items verwijderd naar prullenbak', 'notifications/tray_top');
                        $return = true;
                    }
                }
            }
        }
        if ($action == 'publish') {
            foreach ($this->data[$form]['id'] as $key => $value) {
                if ($value != 0) {
                    if ($this->DynamicModel->updateAll(array($form.'.published'=>'1'),array($form.'.id'=>$key))) {
                        $this->Session->setFlash('Items gepubliceerd', 'notifications/tray_top');
                        $return = true;
                    }
                }
            }
        }
        if ($action == 'unpublish') {
            foreach ($this->data[$form]['id'] as $key => $value) {
                if ($value != 0) {
                    if($this->DynamicModel->updateAll(array($form.'.published'=>'0'),array($form.'.id'=>$key))){
                       $this->Session->setFlash('Items geweigerd', 'notifications/tray_top');
                       $return = true;
                    }
                }
            }
        }
        if (isset($return)) {
            $this->redirect($this->referer());
        } elseif (!isset($return)) {
            $this->Session->setFlash('Er is een fout opgetreden, probeer opnieuw','notifications/error');
            $this->redirect($this->referer());
        }
    }
Processing your request, Please wait....

No Responses to “CakePhp : Quick record actions”

Comments (Your Comments)

Leave a Reply

You must be logged in to post a comment.