/** * 指派TODO给其他人 * * 不可以分配给自己 * * @param string token , 必填 * @param string tid - TODOid, 必填 * @param string uid - 要指派的用户id, 必填 * @return todo array * @author EasyChen */ public function todo_assign($tid = false, $uid = false, $in = false) { if (!$tid) { $tid = intval(v('tid')); } if (intval($tid) < 1) { return self::send_error(LR_API_ARGS_ERROR, __('INPUT_CHECK_BAD_ARGS', 'TID')); } if (!$uid) { $uid = intval(v('uid')); } if (intval($uid) < 1) { return self::send_error(LR_API_ARGS_ERROR, __('INPUT_CHECK_BAD_ARGS', 'UID')); } if ($uid == $_SESSION['uid']) { return self::send_error(LR_API_ARGS_ERROR, __('API_MESSAGE_TODO_ASSIGN_TO_SELF')); } if (!($tinfo = get_line("SELECT * FROM `todo_user` WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . uid() . "' LIMIT 1"))) { if (db_errno() != 0) { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } else { return self::send_error(LR_API_DB_EMPTY_RESULT, __('API_MESSAGE_EMPTY_RESULT_DATA')); } } else { if ($tinfo['uid'] != uid()) { return self::send_error(LR_API_FORBIDDEN, __('API_MESSAGE_CANNOT_ASSIGN_OTHERS_TODO')); } // 更新todo表 $sql = "UPDATE `todo` SET `owner_uid` = '" . intval($uid) . "' WHERE `id` = '" . intval($tid) . "' LIMIT 1"; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } } // 将新的uid加入 todo_user 表 $sql = "REPLACE INTO `todo_user` ( `uid` , `tid` , `status` , `last_action_at` ) VALUES ( '" . intval($uid) . "' , '" . intval($tid) . "' , 1 , NOW() ) "; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } } // 将现有uid 变为follow状态 $sql = "UPDATE `todo_user` SET `is_follow` = 1 WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . intval($_SESSION['uid']) . "' LIMIT 1"; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } } // 获取被转让人的信息 $uinfo = get_user_info_by_id($uid); $todo_text = get_todo_text_by_id($tid); $todo_count = get_var("SELECT `comment_count` FROM `todo` WHERE `id` = '" . intval($tid) . "'"); // 向todo新主人发送通知 send_notice(intval($uid), __('API_TEXT_ASSIGN_TODO_TO_U', array(uname(), $todo_text)), 1, array('tid' => intval($tid), 'count' => $todo_count)); // 向todo关注者发送通知 $sql = "SELECT `uid` FROM `todo_user` WHERE `tid`= '" . intval($tid) . "' AND `is_follow` = 1 "; if ($uitems = get_data($sql)) { foreach ($uitems as $uitem) { // 避免向当前转让人发送通知 if ($uitem['uid'] != uid()) { send_notice($uitem['uid'], __('API_TEXT_ASSIGN_TODO_FOLLOWED', array(uname(), $todo_text, $uinfo['name'])), 1, array('tid' => intval($tid), 'count' => $todo_count)); } } } add_history($tid, __('API_TEXT_ASSIGN_TODO')); publish_feed(__('API_TEXT_ASSIGN_TODO_DETAIL', array(uname(), $todo_text, $uinfo['name'])), uid(), 2, $tid); if ($in) { return get_todo_info_by_id($tid); } else { return self::send_result(get_todo_info_by_id($tid)); } } }
/** * 指派TODO给其他人 * * 不可以分配给自己 * * @param string token , 必填 * @param string tid - TODOid, 必填 * @param string uid - 要指派的用户id, 必填 * @return todo array * @author EasyChen */ public function todo_assign($tid = false, $uid = false, $in = false) { if (!$tid) { $tid = intval(v('tid')); } if (intval($tid) < 1) { return $this->send_error(LR_API_ARGS_ERROR, 'TID NOT EXISTS'); } if (!$uid) { $uid = intval(v('uid')); } if (intval($uid) < 1) { return $this->send_error(LR_API_ARGS_ERROR, 'UIDS ERROR'); } if ($uid == $_SESSION['uid']) { return $this->send_error(LR_API_ARGS_ERROR, 'ASSIGN TO SELF'); } if (!($tinfo = get_line("SELECT * FROM `todo_user` WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . uid() . "' LIMIT 1"))) { if (db_errno() != 0) { return $this->send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . mysql_error()); } else { return $this->send_error(LR_API_DB_EMPTY_RESULT, 'DATA NOT EXISTS'); } } else { if ($tinfo['uid'] != uid()) { return $this->send_error(LR_API_FORBIDDEN, 'CANNOT ASSING OTHER\'S TODO'); } // 更新todo表 $sql = "UPDATE `todo` SET `owner_uid` = '" . intval($uid) . "' WHERE `id` = '" . intval($tid) . "' LIMIT 1"; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return $this->send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . mysql_error()); } } // 将新的uid加入 todo_user 表 $sql = "REPLACE INTO `todo_user` ( `uid` , `tid` , `status` , `last_action_at` ) VALUES ( '" . intval($uid) . "' , '" . intval($tid) . "' , 1 , NOW() ) "; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return $this->send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . mysql_error()); } } // 将现有uid 变为follow状态 $sql = "UPDATE `todo_user` SET `is_follow` = 1 WHERE `tid` = '" . intval($tid) . "' AND `uid` = '" . intval($_SESSION['uid']) . "' LIMIT 1"; run_sql($sql); if (db_errno() != 0) { if ($in) { return false; } else { return $this->send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . mysql_error()); } } // 获取被转让人的信息 $uinfo = get_user_info_by_id($uid); $todo_text = get_todo_text_by_id($tid); $todo_count = get_var("SELECT `comment_count` FROM `todo` WHERE `id` = '" . intval($tid) . "'"); // 向todo新主人发送通知 send_notice(intval($uid), uname() . '向你转让了TODO【' . $todo_text . '】', 1, array('tid' => intval($tid), 'count' => $todo_count)); // 向todo关注者发送通知 $sql = "SELECT `uid` FROM `todo_user` WHERE `tid`= '" . intval($tid) . "' AND `is_follow` = 1 "; if ($uitems = get_data($sql)) { foreach ($uitems as $uitem) { // 避免向当前转让人发送通知 if ($uitem['uid'] != uid()) { send_notice($uitem['uid'], uname() . '将你关注的TODO【' . $todo_text . '】转让给了' . $uinfo['name'], 1, array('tid' => intval($tid), 'count' => $todo_count)); } } } add_history($tid, '转让了TODO'); publish_feed(uname() . '将TODO【' . $todo_text . '】转让给了' . $uinfo['name'], uid(), 2, $tid); if ($in) { return get_todo_info_by_id($tid); } else { return $this->send_result(get_todo_info_by_id($tid)); } } }