Posted by dosken on January 19, 2011 at 4:26am
いつもお世話になっております。
コメント機能について困っており質問させていただきます。
会員制のポータルサイトを作成しております。
会員には下記のような2つの権限をもった会員がいます。
・閲覧会員:コメント投稿可能
・編集会員:ノードを作成、編集可能の権限
ノード内にコメント機能が実装されており閲覧会員はコメントを残すことができます。
現状では閲覧会員が残したコメントを編集会員が修正することができないのですが
編集会員自身が作成したノード内のコメントだけ編集・削除できるようにしたいと考えております。
Advanced Commentモジュールを試したのですがうまくいかず悩んでおります。
何かアドバイス頂ければ幸いです。
よろしくお願い致します。
dosken

Comments
必要に迫られたことがなかったので考えたこともありませんでし
必要に迫られたことがなかったので考えたこともありませんでしたが、便利そうな機能ですね。
Drupal coreのIssue queueには、Drupal 8 向けにこのリクエストがありました(http://drupal.org/node/146714 )
そこまで待っていられない人はこのモジュールを使うようです。
http://drupal.org/project/usercomment
dokumoriさま お世話になっております。 早速のご返
dokumoriさま
お世話になっております。
早速のご返信ありがとうございます。
>Drupal coreのIssue queueには、Drupal 8 向けにこのリクエストがありました(http://drupal.org/node/146714 )
このリクエストはまさに私の質問と同じですね!
ユーザーにブログを書かせてコメント管理までしてもらえばポータルサイトとして十分機能しそうです。
モジュールの紹介ありがとうございます。
試してみてまたご連絡させていただきます。
よろしくお願いします。
dosken
こんにちは、doskenさん Commentモジュールのコ
こんにちは、doskenさん
Commentモジュールのコメント編集権限は以下のコードで実装されています。
comment.module
<?php
/**
* Implementation of hook_menu().
*/
function comment_menu() {
...
$items['comment/edit'] = array(
'title' => 'Edit comment', //ページタイトル
'page callback' => 'comment_edit', //ページ表示時に実行するファンクション
'access arguments' => array('post comments'), //ページアクセス時に実行するファンクションに渡す引数
'type' => MENU_CALLBACK,
'file' => 'comment.pages.inc',
);
...
return $items;
?>
comment.pages.inc
<?php
/**
* Form builder; generate a comment editing form.
<em>
* @param $cid
* ID of the comment to be edited.
* @ingroup forms
*/
function comment_edit($cid) {
global $user; //アクセス中のユーザー
$comment = db_fetch_object(db_query('SELECT c.</em>, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid)); //コメントデータの取得
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (comment_access('edit', $comment)) { //ページの表示権限のチェック
return comment_form_box((array)$comment); //エディットフォーム
}
else {
drupal_access_denied(); //アクセスが拒否されました!
}
}
?>
advanced commentを参考にモジュールを書いていましたので、お使いください。
node_creater_comment.info
<?php
name = Node Creater Comment Edit
description = Enhancing the core comment features
core = 6.x
dependencies[] = comment
?>
node_creater_comment.module
<?php
/<strong>
* Implementation of hook_perm().
*/
function node_creater_comment_perm() {
return array('edit own node comments'); //新しい権利の作成
}
/</strong>
* Implementation of hook_menu_alter().
*
* Use our own access callback to remove the edit callback if the node has
* been set to flat commenting.
*/
function node_creater_comment_menu_alter(&$items) {
$items['comment/edit']['page callback'] = 'node_creater_comment_edit'; //ページ表示時に実行するファンクションを上書き
}
/<strong>
* Form builder; generate a comment editing form.
<em>
* @param $cid
* ID of the comment to be edited.
* @ingroup forms
*/
function node_creater_comment_edit($cid) {
global $user; //アクセス中のユーザー
$comment = db_fetch_object(db_query('SELECT c.</em>, u.uid, u.name AS registered_name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid)); //コメントデータの取得
$comment = drupal_unpack($comment);
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
if (node_creater_comment_access('edit', $comment)) { //ページの表示権限をチェックする関数を変更
return comment_form_box((array)$comment); //エディットフォーム
}
else {
drupal_access_denied(); //アクセスが拒否されました!
}
}
/</strong>
* This is *not* a hook_access() implementation. This function is called
* to determine whether the current user has access to a particular comment.
*
* Authenticated users can edit their comments as long they have not been
* replied to. This prevents people from changing or revising their
* statements based on the replies to their posts.
*
* @param $op
* The operation that is to be performed on the comment. Only 'edit' is recognized now.
* @param $comment
* The comment object.
* @return
* TRUE if the current user has acces to the comment, FALSE otherwise.
*/
function node_creater_comment_access($op, $comment) {
global $user;
$node = node_load($comment->nid); //ノードの取得
if ($op == 'edit') {
return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0 && $comment->status == COMMENT_PUBLISHED) || user_access('administer comments') || $node->nid == $user->uid && user_access('edit own node comments')); //もしノードの作成者がアクセス中のユーザーかつ、ノードコメントの権利があるなら TRUE
}
}
?>
と書いてはみたんですが、試して見てないので何か不都合あれば教えてください。
jun784さま お世話になっております。 モジュールを書
jun784さま
お世話になっております。
モジュールを書いて下さりありがとうございます!!!!!
試した後 報告させていただきます。
よろしくお願い致します。
dosken