ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 7295


Ignore:
Timestamp:
May 21, 2008, 5:48:44 PM (11 years ago)
Author:
ebihara
Message:

#2432:日記コメント記入履歴を取得する際、日記の閲覧権限を考慮するようにした

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/branches/stable-2.12.x/webapp/lib/db/diary.php

    r7242 r7295  
    543543    $is_recurred = false;
    544544
    545     $sql = 'SELECT c_diary_id, r_datetime as maxdate' .
    546            ' FROM c_diary_comment_log' .
    547            ' WHERE c_member_id = ?' .
    548            ' ORDER BY maxdate DESC';
    549     $list = db_get_assoc_limit($sql, 0, $limit, array(intval($c_member_id)));
    550 
    551     $result = array();
    552     foreach ($list as $c_diary_id => $r_datetime) {
    553         $item = db_diary_get_c_diary4id($c_diary_id);
    554         if ($item['public_flag'] == 'friend' && !db_friend_is_friend($c_member_id, $item['c_member_id'])) {
    555             continue;
    556         }
    557         $item += db_member_c_member4c_member_id_LIGHT($item['c_member_id']);
    558         $item['r_datetime'] = $r_datetime;
    559         $item['num_comment'] = db_diary_count_c_diary_comment4c_diary_id($c_diary_id);
    560         $result[] = $item;
    561     }
    562     return $result;
     545    $sql = 'SELECT cdcl.c_diary_id, cdcl.r_datetime AS maxdate, cd.*'
     546         . ' FROM c_diary_comment_log AS cdcl INNER JOIN c_diary AS cd USING (c_diary_id) '
     547         . ' WHERE cdcl.c_member_id = ?'
     548         . ' AND cd.public_flag <> \'private\'';
     549
     550    $blocked = db_member_access_block_list4c_member_id_to($c_member_id);
     551    $blocked_ids = implode(',', array_map('intval', $blocked));
     552    if ($blocked_ids) {
     553        $sql .= ' AND cd.c_member_id NOT IN (' . $blocked_ids . ')';
     554    }
     555
     556    $friends = db_friend_c_member_id_list($c_member_id);
     557    $friend_ids = implode(',', array_map('intval', $friends));
     558    if ($friend_ids) {
     559         $sql .= ' AND (cd.public_flag = \'public\''
     560               . ' OR (cd.public_flag = \'friend\' AND cd.c_member_id IN (' . $friend_ids . ')))';
     561    }
     562
     563    $sql .= ' ORDER BY maxdate DESC';
     564    $params = array(intval($c_member_id));
     565    $list = db_get_all_limit($sql, 0, $limit, $params);
     566
     567    foreach ($list as $key => $value) {
     568        $list[$key] += db_member_c_member4c_member_id_LIGHT($value['c_member_id']);
     569        $list[$key]['r_datetime'] = $value['maxdate'];
     570        $list[$key]['num_comment'] = db_diary_count_c_diary_comment4c_diary_id($value['c_diary_id']);
     571    }
     572
     573    return $list;
    563574}
    564575
    565576function p_h_diary_comment_list_c_diary_my_comment_list4c_member_id($c_member_id, $page, $page_size)
    566577{
    567     $sql = 'SELECT c_diary_id, c_member_id, r_datetime' .
    568            ' FROM c_diary_comment_log' .
    569            ' WHERE c_member_id = ?' .
    570            ' ORDER BY r_datetime DESC';
     578    $select = 'SELECT cdcl.c_diary_id, cdcl.r_datetime AS maxdate, cd.*';
     579    $from = ' FROM c_diary_comment_log AS cdcl INNER JOIN c_diary AS cd USING (c_diary_id) ';
     580    $where = ' WHERE cdcl.c_member_id = ? AND cd.public_flag <> \'private\'';
     581
     582
     583    $blocked = db_member_access_block_list4c_member_id_to($c_member_id);
     584    $blocked_ids = implode(',', array_map('intval', $blocked));
     585    if ($blocked_ids) {
     586        $where .= ' AND cd.c_member_id NOT IN (' . $blocked_ids . ')';
     587    }
     588
     589    $friends = db_friend_c_member_id_list($c_member_id);
     590    $friend_ids = implode(',', array_map('intval', $friends));
     591    if ($friend_ids) {
     592         $where .= ' AND (cd.public_flag = \'public\''
     593               . ' OR (cd.public_flag = \'friend\' AND cd.c_member_id IN (' . $friend_ids . ')))';
     594    }
     595
     596    $sql = $select . $from . $where . ' ORDER BY maxdate DESC';
    571597    $params = array(intval($c_member_id));
    572598    $list = db_get_all_page($sql, $page, $page_size, $params);
    573599
    574600    foreach ($list as $key => $value) {
    575         $diary = db_diary_get_c_diary4id($value['c_diary_id']);
    576         $list[$key] += db_member_c_member4c_member_id_LIGHT($diary['c_member_id']);
    577         $list[$key]['subject'] = $diary['subject'];
     601        $list[$key] += db_member_c_member4c_member_id_LIGHT($value['c_member_id']);
     602        $list[$key]['r_datetime'] = $value['maxdate'];
    578603        $list[$key]['num_comment'] = db_diary_count_c_diary_comment4c_diary_id($value['c_diary_id']);
    579604    }
    580605
    581     $sql = 'SELECT COUNT(c_diary_id)' .
    582            ' FROM c_diary_comment_log' .
    583            ' WHERE c_member_id = ?';
     606    $sql = 'SELECT COUNT(cdcl.c_diary_id)' . $from . $where;
    584607    $params = array(intval($c_member_id));
    585608    $total_num = db_get_one($sql, $params);
Note: See TracChangeset for help on using the changeset viewer.