public function executeCommand() { $note = $this->_receiver; $this->_db = Zend_Registry::get('db'); //解析post数据 $user_id = $this->_param['user_id']; $old_cate_id = $this->_param['old_category_id']; $new_cate_id = $this->_param['new_category_id']; $note_id = $this->_param['note_id']; if ($this->checkPermission($user_id, 'note_id', $note_id)) { //出入双链 $list = LinkedList_Factory::factory('database'); $list->outList($note_id, true, true); $list->pushInto($note_id, $new_cate_id); $ln_cate = new Database_NotesLinkCategorys($this->_db); return $ln_cate->changeCategoryFormTo($note_id, $old_cate_id, $new_cate_id); } else { Lds_Helper_Log::writeLog('This user delete note which not belong to him' . $user_id); return 'permission denied'; } //fi }
public function delHelper($user_id, $cate_id, $delAllNote) { if ($this->checkPermission($user_id, 'category_id', $cate_id)) { $noteLinkCate = new Database_NotesLinkCategorys($this->_db); //删除该category所拥有的所有note if ($delAllNote == 1) { $this->_receiver->delNotesByCategoryId($cate_id); //删除连接 $noteLinkCate->removeNoteCategoryLink($cate_id); var_dump('del note'); } else { var_dump('just del cate'); //把所有该名下的note转移到inbox下 $notes = $this->_receiver; //$notes = new Database_Notes($this->_db); $myNotes = $notes->getAllNoteByCategoryIdAndUserId($cate_id, $user_id); $new_cate_id = $notes->createCategoryToUser('Inbox', $user_id); foreach ($myNotes as $note) { $noteLinkCate->changeCategoryFormTo($note['note_id'], $cate_id, $new_cate_id); } } //如果不是系统所用则可以直接删除category本身 if ($cate_id > 10) { $cate_db = new Database_NotesCategorys($this->_db); $cate_db->delCategoryById($cate_id); } //删除连接 $userLinkCate = new Database_UserLinkCategory($this->_db); $userLinkCate->removeUserCategoryLink($cate_id); return true; } else { Lds_Helper_Log::writeLog('This user delete note which not belong to him' . $user_id); return 'permission denied'; } //fi }
/** * addCategory时需要为note和category创建链接 * * @param $category_id * * @return */ public function makeCategoryLink($category_id) { if ($this->getId()) { $taglink = new Database_NotesLinkCategorys($this->_db); $taglink->category_id = $category_id; $taglink->note_id = $this->getid(); $taglink->save(); return $taglink->getId(); } }