From 5b9a27c5cad7f1c00ffd44f2a57308fb6634f4cd Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 21 Jan 2015 17:24:55 -0500 Subject: [PATCH] Add API function to archive / unarchive an Event --- web/api/app/Controller/EventsController.php | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/web/api/app/Controller/EventsController.php b/web/api/app/Controller/EventsController.php index 89c5bdd32..c1d0ce727 100644 --- a/web/api/app/Controller/EventsController.php +++ b/web/api/app/Controller/EventsController.php @@ -248,4 +248,28 @@ class EventsController extends AppController { } + public function archive($id = null) { + $this->Event->recursive = -1; + if (!$this->Event->exists($id)) { + throw new NotFoundException(__('Invalid event')); + } + + // Get the current value of Archive + $archived = $this->Event->find('first', array( + 'fields' => array('Event.Archived'), + 'conditions' => array('Event.Id' => $id) + )); + // If 0, 1, if 1, 0 + $archiveVal = (($archived['Event']['Archived'] == 0) ? 1 : 0); + + // Save the new value + $this->Event->id = $id; + $this->Event->saveField('Archived', $archiveVal); + + $this->set(array( + 'archived' => $archiveVal, + '_serialize' => array('archived') + )); + } + }