netcommons/content-comments

ContentComments for NetCommons Plugin

Installs: 25 014

Dependents: 5

Suggesters: 0

Security: 0

Stars: 0

Watchers: 13

Forks: 1

Open Issues: 0

Type:cakephp-plugin

3.3.7.0 2023-10-09 08:41 UTC

README

Tests Status Coverage Status Stable Version

phpdoc

概要

コンテンツの一覧にコメント数を表示する機能と、コンテンツの詳細でコメントを投稿する機能を提供します。
利用するプラグインはコメントの使用有無(use_comment)、コメントの承認有無(use_comment_approval)を定義してください。

コンテンツの一覧にコメント数を表示

ContentCommentBehaviorとContentCommentHelperを使用します。
コメントと紐づくモデルにContentCommentBehavior、
コンテンツ一覧のコントローラーにContentCommentHelperを定義してください。

サンプルコード
コントローラー
class VideosController extends VideosAppController {

	public $uses = array(
		'Videos.Video',
		'Videos.VideoSetting'
	);

	public $helpers = array(
		'ContentComments.ContentComment' => array(
			'viewVarsKey' => array(
				'contentKey' => 'video.Video.key',
				'contentTitleForMail' => 'video.Video.title',
				'useComment' => 'videoSetting.use_comment',
				'useCommentApproval' => 'videoSetting.use_comment_approval'
			)
		)
	);

	public function index() {
		$query = array(
			'conditions' => array(
				'VideoSetting.block_key' => Current::read('Block.key')
			)
		);
		$viewVars['videoSetting'] = $this->VideoSetting->find('first', $query);
		$viewVars['videos'] = $this->Video->find('all');

		$this->set($viewVars);
	}
}
モデル
class Video extends VideoAppModel {
	public $actsAs = array(
		'ContentComments.ContentComment'
	);
}
ビュー(ctpテンプレート)
<?php
	foreach ($videos as $video) {
		echo $video['Video']['title'];
		echo $this->ContentComment->count($video);
	}
?>

コンテンツの詳細でコメントを投稿する

ContentCommentsComponentとContentCommentHelperを使用します。
コンテンツ詳細のコントローラーにContentCommentsComponentを定義してください。

サンプルコード
コントローラー
class VideosController extends VideosAppController {

	public $uses = array(
		'Videos.Video',
		'Videos.VideoSetting'
	);

	public $components = array(
		'ContentComments.ContentComments' => array(
			'viewVarsKey' => array(
				'contentKey' => 'video.Video.key',
				'contentTitleForMail' => 'video.Video.title',
				'useComment' => 'videoSetting.use_comment'
				'useCommentApproval' => 'videoSetting.use_comment_approval'
			),
			'allow' => array('view')
		)
	)

	public function view($videoKey) {
		$query = array(
			'conditions' => array(
				'VideoSetting.block_key' => Current::read('Block.key')
			)
		);
		$viewVars['videoSetting'] = $this->VideoSetting->find('first', $query);

		$query = array(
			'conditions' => array(
				'Video.key' => $videoKey,
				'Video.language_id' => Current::read('Language.id')
			)
		);
		$viewVars['video'] = $this->Video->find('first', $query);

		$this->set($viewVars);
	}
}
ビュー(ctpテンプレート)
<?php
	echo $video['title'];
	echo $this->ContentComment->index($video);
?>