Exemplo n.º 1
0
 public function executeCommand()
 {
     $note = $this->_receiver;
     //解析post数据
     $params = array();
     //解析main input的内容
     $i_helper = new Lds_Helper_MainInput($this->_param['note-data']);
     $i_helper->parse();
     $dueDate = $i_helper->makeDate();
     $content = $i_helper->getString();
     $params['content'] = $content;
     if ($dueDate !== null) {
         $params['dueDate'] = $dueDate;
     }
     $params['user_id'] = $this->_param['user_id'];
     //必须设置category,未指定则放置于系统分类Inbox中
     if (isset($this->_param['categorys']) && $this->_param['categorys'] != '') {
         $params['categorys'] = $this->_param['categorys'];
     } else {
         $params['categorys'] = 'Inbox';
     }
     //确保内容不为空
     if ($params['content'] != null || $params['content'] != '') {
         //在数据库中新建note
         $data = $note->createNote($params);
         //为加入双链表中准备数据
         $note_id = $data['note_id'];
         $cate_id = $data['category_id'];
         //存入双链顺序表
         $list = LinkedList_Factory::factory('database');
         $list->pushInto($note_id, $cate_id);
         //数据库需要时间戳
         //TODO : 添加时解析时间和日期尚为解决
         if (isset($data['dueDate']) && $data['dueDate'] !== null) {
             $data['dueDate'] = Lds_Helper_MainInput::dateFormater($data['dueDate']);
         }
         //fi
     } else {
         $data = 'content can not be null.';
     }
     return $data;
 }
Exemplo n.º 2
0
 public function executeCommand()
 {
     $note = $this->_receiver;
     $params = $this->_param;
     if (array_key_exists('user_id', $params)) {
         $user_id = $this->_param['user_id'];
         $category_id = (int) $this->_param['category_id'];
         //var_dump($user_id);
         //var_dump($category_id);
         //var_dump($category_id);
         $notes = $note->getAllNoteByCategoryIdAndUserId($category_id, $user_id);
         //预处理输出数据格式
         foreach ($notes as &$note) {
             //去转义符
             $note['content'] = stripslashes($note['content']);
             //格式化时间日期
             if (isset($note['dueDate'])) {
                 try {
                     $note['dueDate'] = Lds_Helper_MainInput::dateFormater($note['dueDate']);
                 } catch (Exception $e) {
                     Lds_Helper_Log::writeLog($e);
                 }
             }
         }
         if (count($notes) > 0) {
             //根据双链表对notes排序显示
             $list = LinkedList_Factory::factory('array');
             $list->setBaseArray($notes);
             $ordered_notes = $list->orderList();
             var_dump('note');
             var_dump($note);
             var_dump('noteorder');
             var_dump($ordered_notes);
             //排序表出错,记录到日志并直接返回未排序的结果
             if (count($notes) > count($ordered_notes)) {
                 Lds_Helper_Log::writeLog('order wrong.category_id: ' . $category_id);
                 return $notes;
             } else {
                 return $ordered_notes;
             }
         }
         return null;
     }
 }
Exemplo n.º 3
0
 public function alterNote($data)
 {
     //为setContent的储存结果
     $result = true;
     $note_id = $data['note_id'];
     $this->load($note_id);
     $dueDate = $this->dueDate;
     //允许修改的字段
     $alterable = array('content', 'dueDate', 'dueDate_date', 'dueDate_time', 'star', 'style');
     //避免修改其不应该修改的字段
     foreach ($data as $key => $value) {
         if (in_array($key, $alterable)) {
             //content在外表中
             if ($key == 'content') {
                 $result = $this->setContent($note_id, $value);
             } elseif ($key == 'dueDate_date') {
                 $this->dueDate = Lds_Helper_MainInput::makeDateStatic($dueDate, $value, null);
             } elseif ($key == 'dueDate_time') {
                 $this->dueDate = Lds_Helper_MainInput::makeDateStatic($dueDate, null, $value);
             } else {
                 $this->{$key} = $value;
             }
         }
     }
     return $this->save() && $result;
 }