示例#1
0
 function AddCategoryToPost($params, $category)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-post-update.php';
     $postid = $params['postid'];
     $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid,parentid,tags,title,content,qcount,position,backpath FROM ^categories WHERE title=$', $category), true);
     if (empty($result)) {
         //create category
         $tags = str_replace(' ', '-', $category);
         $catID = $this->CreatCategory($category, $tags);
         qa_db_post_set_category($postid, $catID, null, null);
         qa_db_posts_calc_category_path($postid);
         $path = qa_db_post_get_category_path($postid);
         qa_db_category_path_qcount_update($path);
     } else {
         // update category
         $oldpath = qa_db_post_get_category_path($postid);
         $tags = $result['tags'];
         $catID = $result['categoryid'];
         qa_db_post_set_category($postid, $catID, null, null);
         qa_db_posts_calc_category_path($postid);
         $path = qa_db_post_get_category_path($postid);
         qa_db_category_path_qcount_update($oldpath);
         qa_db_category_path_qcount_update($path);
     }
 }
function qa_question_set_category($oldquestion, $categoryid, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost = null, $silent = false)
{
    $oldpath = qa_db_post_get_category_path($oldquestion['postid']);
    qa_db_post_set_category($oldquestion['postid'], $categoryid, $silent ? null : $userid, $silent ? null : qa_remote_ip_address());
    qa_db_posts_calc_category_path($oldquestion['postid']);
    $newpath = qa_db_post_get_category_path($oldquestion['postid']);
    qa_db_category_path_qcount_update($oldpath);
    qa_db_category_path_qcount_update($newpath);
    $otherpostids = array();
    foreach ($answers as $answer) {
        $otherpostids[] = $answer['postid'];
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C') {
            $otherpostids[] = $comment['postid'];
        }
    }
    if (@$closepost['parentid'] == $oldquestion['postid']) {
        $otherpostids[] = $closepost['postid'];
    }
    qa_db_posts_set_category_path($otherpostids, $newpath);
    $searchmodules = qa_load_modules_with('search', 'move_post');
    foreach ($searchmodules as $searchmodule) {
        $searchmodule->move_post($oldquestion['postid'], $categoryid);
        foreach ($otherpostids as $otherpostid) {
            $searchmodule->move_post($otherpostid, $categoryid);
        }
    }
    qa_report_event('q_move', $userid, $handle, $cookieid, array('postid' => $oldquestion['postid'], 'oldquestion' => $oldquestion, 'categoryid' => $categoryid, 'oldcategoryid' => $oldquestion['categoryid']));
}
function qa_question_set_category($oldquestion, $categoryid, $userid, $handle, $cookieid, $answers, $commentsfollows)
{
    $oldpath = qa_db_post_get_category_path($oldquestion['postid']);
    qa_db_post_set_category($oldquestion['postid'], $categoryid);
    qa_db_posts_calc_category_path($oldquestion['postid']);
    $newpath = qa_db_post_get_category_path($oldquestion['postid']);
    qa_db_category_path_qcount_update($oldpath);
    qa_db_category_path_qcount_update($newpath);
    $otherpostids = array();
    foreach ($answers as $answer) {
        $otherpostids[] = $answer['postid'];
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C') {
            $otherpostids[] = $comment['postid'];
        }
    }
    qa_db_posts_set_category_path($otherpostids, $newpath);
    qa_report_event('q_move', $userid, $handle, $cookieid, array('postid' => $oldquestion['postid'], 'categoryid' => $categoryid, 'oldcategoryid' => $oldquestion['categoryid']));
}