diff --git a/protected/modules_core/comment/CommentModule.php b/protected/modules_core/comment/CommentModule.php
index ab7faf82cf..3a357aa1fb 100644
--- a/protected/modules_core/comment/CommentModule.php
+++ b/protected/modules_core/comment/CommentModule.php
@@ -6,14 +6,16 @@
* @package humhub.modules_core.comment
* @since 0.5
*/
-class CommentModule extends CWebModule {
+class CommentModule extends CWebModule
+{
/**
* On content deletion make sure to delete all its comments
*
* @param CEvent $event
*/
- public static function onContentDelete($event) {
+ public static function onContentDelete($event)
+ {
foreach (Comment::model()->findAllByAttributes(array('object_model' => get_class($event->sender), 'object_id' => $event->sender->id)) as $comment) {
$comment->delete();
@@ -25,7 +27,8 @@ class CommentModule extends CWebModule {
*
* @param CEvent $event
*/
- public static function onUserDelete($event) {
+ public static function onUserDelete($event)
+ {
foreach (Comment::model()->findAllByAttributes(array('created_by' => $event->sender->id)) as $comment) {
$comment->delete();
@@ -38,7 +41,8 @@ class CommentModule extends CWebModule {
*
* @param CEvent $event
*/
- public static function onIntegrityCheck($event) {
+ public static function onIntegrityCheck($event)
+ {
$integrityChecker = $event->sender;
$integrityChecker->showTestHeadline("Validating Comment Module (" . Comment::model()->count() . " entries)");
@@ -59,13 +63,9 @@ class CommentModule extends CWebModule {
*
* @param CEvent $event
*/
- public static function onWallEntryLinksInit($event) {
-
- $event->sender->addWidget('application.modules_core.comment.widgets.CommentLinkWidget', array(
- 'modelName' => $event->sender->object->content->object_model,
- 'modelId' => $event->sender->object->content->object_id,
- ), array('sortOrder' => 10)
- );
+ public static function onWallEntryLinksInit($event)
+ {
+ $event->sender->addWidget('application.modules_core.comment.widgets.CommentLinkWidget', array('object' => $event->sender->object), array('sortOrder' => 10));
}
/**
@@ -73,13 +73,9 @@ class CommentModule extends CWebModule {
*
* @param CEvent $event
*/
- public static function onWallEntryAddonInit($event) {
-
- $event->sender->addWidget('application.modules_core.comment.widgets.CommentsWidget', array(
- 'modelName' => $event->sender->object->content->object_model,
- 'modelId' => $event->sender->object->content->object_id,
- ), array('sortOrder' => 20)
- );
+ public static function onWallEntryAddonInit($event)
+ {
+ $event->sender->addWidget('application.modules_core.comment.widgets.CommentsWidget', array('object' => $event->sender->object), array('sortOrder' => 20));
}
-}
\ No newline at end of file
+}
diff --git a/protected/modules_core/comment/controllers/CommentController.php b/protected/modules_core/comment/controllers/CommentController.php
index 55321588eb..6a81ae73a1 100644
--- a/protected/modules_core/comment/controllers/CommentController.php
+++ b/protected/modules_core/comment/controllers/CommentController.php
@@ -6,7 +6,8 @@
* @package humhub.modules_core.comment.controllers
* @since 0.5
*/
-class CommentController extends Controller {
+class CommentController extends Controller
+{
// Used by loadTargetModel() to avoid multiple loading
private $cachedLoadedTarget = null;
@@ -14,7 +15,8 @@ class CommentController extends Controller {
/**
* @return array action filters
*/
- public function filters() {
+ public function filters()
+ {
return array(
'accessControl', // perform access control for CRUD operations
);
@@ -25,7 +27,8 @@ class CommentController extends Controller {
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
- public function accessRules() {
+ public function accessRules()
+ {
return array(
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'users' => array('@'),
@@ -42,7 +45,8 @@ class CommentController extends Controller {
*
* @return type
*/
- private function loadTargetModel() {
+ private function loadTargetModel()
+ {
// Fast lane
if ($this->cachedLoadedTarget != null)
@@ -83,7 +87,8 @@ class CommentController extends Controller {
/**
* Returns a List of all Comments belong to this Model
*/
- public function actionShow() {
+ public function actionShow()
+ {
$target = $this->loadTargetModel();
@@ -101,10 +106,31 @@ class CommentController extends Controller {
Yii::app()->end();
}
+ public function actionShowPopup()
+ {
+
+ $target = $this->loadTargetModel();
+
+ $output = "";
+
+ // Get new current comments
+ $comments = Comment::model()->findAllByAttributes(array('object_model' => get_class($target), 'object_id' => $target->id));
+
+ foreach ($comments as $comment) {
+ $output .= $this->widget('application.modules_core.comment.widgets.ShowCommentWidget', array('comment' => $comment), true);
+ }
+
+
+ $id = get_class($target) . "_" . $target->id;
+ $this->renderPartial('show', array('object' => $target, 'output' => $output, 'id' => $id), false, true);
+
+ }
+
/**
* Handles AJAX Post Request to submit new Comment
*/
- public function actionPost() {
+ public function actionPost()
+ {
$this->forcePostRequest();
$target = $this->loadTargetModel();
@@ -151,7 +177,8 @@ class CommentController extends Controller {
* Handles AJAX Request for Comment Deletion.
* Currently this is only allowed for the Comment Owner.
*/
- public function actionDelete() {
+ public function actionDelete()
+ {
$this->forcePostRequest();
$target = $this->loadTargetModel();
@@ -175,4 +202,4 @@ class CommentController extends Controller {
return $this->actionShow();
}
-}
\ No newline at end of file
+}
diff --git a/protected/modules_core/comment/views/comment/show.php b/protected/modules_core/comment/views/comment/show.php
new file mode 100644
index 0000000000..1af08140df
--- /dev/null
+++ b/protected/modules_core/comment/views/comment/show.php
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
diff --git a/protected/modules_core/comment/widgets/CommentFormWidget.php b/protected/modules_core/comment/widgets/CommentFormWidget.php
new file mode 100644
index 0000000000..25d3e3f385
--- /dev/null
+++ b/protected/modules_core/comment/widgets/CommentFormWidget.php
@@ -0,0 +1,57 @@
+object->content->object_model;
+ $modelId = $this->object->content->object_id;
+ $id = $modelName . "_" . $modelId;
+
+ $this->render('form', array(
+ 'modelName' => $modelName,
+ 'modelId' => $modelId,
+ 'id' => $modelName . "_" . $modelId,
+ ));
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/protected/modules_core/comment/widgets/CommentLinkWidget.php b/protected/modules_core/comment/widgets/CommentLinkWidget.php
index 35d29bfa0f..ff6b2ae85d 100644
--- a/protected/modules_core/comment/widgets/CommentLinkWidget.php
+++ b/protected/modules_core/comment/widgets/CommentLinkWidget.php
@@ -6,27 +6,52 @@
* @package humhub.modules_core.comment
* @since 0.5
*/
-class CommentLinkWidget extends HWidget {
+class CommentLinkWidget extends HWidget
+{
+
+ const MODE_INLINE = 'inline';
+ const MODE_POPUP = 'popup';
/**
- * Model Name (e.g. Post) to identify which posts we shall show
- *
- * @var String
+ * Content Object
*/
- public $modelName = "";
+ public $object;
/**
- * The primary key of the model
- *
- * @var String
+ * Mode
+ *
+ * inline: Show comments on the same page with CommentsWidget (default)
+ * popup: Open comments popup, display only link
+ *
+ * @var type
*/
- public $modelId = "";
+ public $mode;
/**
* Executes the widget.
*/
- public function run() {
- $this->render('commentsLink', array('id' => $this->modelName . "_" . $this->modelId));
+ public function run()
+ {
+
+ if ($this->mode == "")
+ $this->mode = self::MODE_INLINE;
+
+ $this->render('link', array(
+ 'id' => $this->object->content->object_model . "_" . $this->object->content->object_id,
+ 'mode' => $this->mode,
+ 'objectModel' => $this->object->content->object_model,
+ 'objectId' => $this->object->content->object_id,
+ ));
+ }
+
+ /**
+ * Returns count of existing comments
+ *
+ * @return Int Comment Count
+ */
+ public function getCommentsCount()
+ {
+ return Comment::GetCommentCount(get_class($this->object), $this->object->getPrimaryKey());
}
}
diff --git a/protected/modules_core/comment/widgets/CommentsWidget.php b/protected/modules_core/comment/widgets/CommentsWidget.php
index a5eebb5b00..902eb7a946 100644
--- a/protected/modules_core/comment/widgets/CommentsWidget.php
+++ b/protected/modules_core/comment/widgets/CommentsWidget.php
@@ -9,42 +9,40 @@
* @package humhub.modules_core.comment
* @since 0.5
*/
-class CommentsWidget extends HWidget {
+class CommentsWidget extends HWidget
+{
/**
- * Model Name (e.g. Post) to identify which posts we shall show
- *
- * @var String
+ * Content Object
*/
- public $modelName = "";
-
- /**
- * The primary key of the Model
- *
- * @var Integer
- */
- public $modelId = "";
+ public $object;
/**
* Executes the widget.
*/
- public function run() {
+ public function run()
+ {
+ $modelName = $this->object->content->object_model;
+ $modelId = $this->object->content->object_id;
+
// Indicates that the number of comments was limited
$isLimited = false;
// Count all Comments
- $commentCount = Comment::GetCommentCount($this->modelName, $this->modelId);
- $comments = Comment::GetCommentsLimited($this->modelName, $this->modelId, 2);
+ $commentCount = Comment::GetCommentCount($modelName, $modelId);
+ $comments = Comment::GetCommentsLimited($modelName, $modelId, 2);
if ($commentCount > 2)
$isLimited = true;
$this->render('comments', array(
+ 'object' => $this->object,
+
'comments' => $comments,
- 'modelName' => $this->modelName,
- 'modelId' => $this->modelId,
- 'id' => $this->modelName . "_" . $this->modelId,
+ 'modelName' => $modelName,
+ 'modelId' => $modelId,
+ 'id' => $modelName . "_" . $modelId,
'isLimited' => $isLimited,
'total' => $commentCount
)
diff --git a/protected/modules_core/comment/widgets/views/comments.php b/protected/modules_core/comment/widgets/views/comments.php
index d339d6af5d..f067faaf11 100644
--- a/protected/modules_core/comment/widgets/views/comments.php
+++ b/protected/modules_core/comment/widgets/views/comments.php
@@ -25,7 +25,7 @@
$reloadUrl = CHtml::normalizeUrl(Yii::app()->createUrl('comment/comment/show', array('model' => $modelName, 'id' => $modelId)));
echo HHtml::ajaxLink($showAllLabel, $reloadUrl, array(
'success' => "function(html) { $('#comments_area_" . $id . "').html(html); }",
- ), array('id' => $id . "_showAllLink", 'class' => 'show show-all-link'));
+ ), array('id' => $id . "_showAllLink", 'class' => 'show show-all-link'));
?>
@@ -35,87 +35,16 @@
-
-
\ No newline at end of file
diff --git a/protected/modules_core/comment/widgets/views/commentsLink.php b/protected/modules_core/comment/widgets/views/commentsLink.php
deleted file mode 100644
index 25c348fc0b..0000000000
--- a/protected/modules_core/comment/widgets/views/commentsLink.php
+++ /dev/null
@@ -1,16 +0,0 @@
- "$('#comment_" . $id . "').show();$('#newCommentForm_" . $id . "').focus();return false;"));
-?>
diff --git a/protected/modules_core/comment/widgets/views/form.php b/protected/modules_core/comment/widgets/views/form.php
new file mode 100644
index 0000000000..8f08465bbc
--- /dev/null
+++ b/protected/modules_core/comment/widgets/views/form.php
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/protected/modules_core/comment/widgets/views/link.php b/protected/modules_core/comment/widgets/views/link.php
new file mode 100644
index 0000000000..5f324c45fd
--- /dev/null
+++ b/protected/modules_core/comment/widgets/views/link.php
@@ -0,0 +1,23 @@
+
+
+
+ Comments (getCommentsCount(); ?>)
+
+ "$('#comment_" . $id . "').show();$('#newCommentForm_" . $id . "').focus();return false;")); ?>
+
\ No newline at end of file
diff --git a/protected/modules_core/comment/widgets/views/showComment.php b/protected/modules_core/comment/widgets/views/showComment.php
index 47c969a7be..2c708ce948 100644
--- a/protected/modules_core/comment/widgets/views/showComment.php
+++ b/protected/modules_core/comment/widgets/views/showComment.php
@@ -9,47 +9,40 @@
* @since 0.5
*/
?>
-