Return to Snippet

Revision: 31185
at August 31, 2010 20:42 by stolkchris


Initial Code
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());
        }
    }

Initial URL

                                

Initial Description
This snippet can be called in every controller, all you need to do is to specify the form name, the model name and the data.

Initial Title
CakePHP -  Quick record actions

Initial Tags
php, cakephp

Initial Language
PHP