Exemple #1
0
 public function save(Note $note)
 {
     $data = array('user' => $note->getUser(), 'title' => $note->getTitle(), 'content' => $note->getContent(), 'register_date' => date("Y-m-d H:i:s", time()));
     $id = (int) $note->getId();
     $params = array();
     $params['table'] = $this->tableGateway->getTableName();
     $params['operation'] = 1;
     $params['data'] = json_encode($data);
     if ($id == 0) {
         $this->tableGateway->insert($data);
         $id = $this->tableGateway->getLastInsertValue();
         if ($id) {
             $params['id'] = $id;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             return $id;
         } else {
             return false;
         }
     } else {
         if ($this->get($id)) {
             $params['id'] = $id;
             $params['operation'] = 2;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             $this->tableGateway->update($data, array('id' => $id));
             return $id;
         } else {
             return false;
         }
     }
 }
Exemple #2
0
 public function addAction()
 {
     //$escaper = new Escaper('utf-8');
     $jsonModel = new JsonModel();
     $note = new Note();
     //$escaper->escapeHtmlAttr();
     $title = $this->params()->fromPost('title');
     $content = $this->params()->fromPost('content');
     if (!empty($title) && !empty($content)) {
         $authenticationService = new AuthenticationService();
         $user = $authenticationService->getStorage()->read();
         $note->setUser($user->id);
         $note->setTitle($title);
         $note->setContent($content);
         $result = $this->getNoteTable()->save($note);
         $jsonModel->setVariable("result", $result);
     } else {
         $result = false;
     }
     $jsonModel->setVariable("result", $result);
     return $jsonModel;
 }