public function batchAction()
 {
     if (!$this->request->isPut()) {
         return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW');
     }
     $idArray = $this->request->getPut('id');
     if (!is_array($idArray) || count($idArray) < 1) {
         return $this->showErrorMessageAsJson(401, 'ERR_REQUEST_PARAMS_INCORRECT');
     }
     $status = $this->request->getPut('status');
     $entries = array();
     try {
         foreach ($idArray as $id) {
             $entry = Models\Entry::findFirst($id);
             if ($entry) {
                 $entry->status = $status;
                 $entry->save();
                 $entries[] = $entry;
             }
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $entry->getMessages());
     }
     return $this->response->setJsonContent($entries);
 }
Exemple #2
0
 public function editAction()
 {
     $this->view->changeRender('admin/entry/create');
     $entry = Models\Entry::findFirst($this->dispatcher->getParam('id'));
     if (!$entry) {
         throw new ResourceNotFoundException('ERR_BLOG_POST_NOT_FOUND');
     }
     $form = new Forms\EntryForm();
     $form->setModel($entry);
     $form->addForm('text', 'Eva\\Wiki\\Forms\\EntryTextForm');
     $this->view->setVar('form', $form);
     $this->view->setVar('item', $entry);
     if (!$this->request->isPost()) {
         return false;
     }
     $data = $this->request->getPost();
     if (!$form->isFullValid($data)) {
         return $this->showInvalidMessages($form);
     }
     try {
         $form->save('updateEntry');
     } catch (\Exception $e) {
         return $this->showException($e, $form->getModel()->getMessages());
     }
     $this->flashSession->success('SUCCESS_ENTRY_UPDATED');
     return $this->redirectHandler('/admin/wiki/edit/' . $entry->id);
 }