From 4cc587bd1a7e502c7046e5aa73e88f5fa6365207 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 12 Nov 2019 11:15:00 -0500 Subject: [PATCH] Update comments fields to use custom 'CommentField' class rather than 'Field' class --- .../FieldtypeComments/CommentField.php | 108 ++++++++++++++++++ .../FieldtypeComments.module | 5 + 2 files changed, 113 insertions(+) create mode 100644 wire/modules/Fieldtype/FieldtypeComments/CommentField.php diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentField.php b/wire/modules/Fieldtype/FieldtypeComments/CommentField.php new file mode 100644 index 00000000..14d8e1ed --- /dev/null +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentField.php @@ -0,0 +1,108 @@ +getFieldtype()->find($selectorString, $this, $options); + } + + /** + * Return total quantity of comments matching the selector + * + * @param string|null $selectorString Selector string with query + * @return int + * + */ + public function count($selectorString) { + return $this->getFieldtype()->count($selectorString, $this); + } + + /** + * Given a comment code or subcode, return the associated comment ID or 0 if it doesn't exist + * + * @param Page|int|string $page + * @param string $code + * @return Comment|null + * + */ + public function getCommentByCode($page, $code) { + return $this->getFieldtype()->getCommentByCode($page, $this, $code); + } + + /** + * Get a comment by ID or NULL if not found + * + * @param Page|int|string $page + * @param int $id + * @return Comment|null + * + */ + public function getCommentByID($page, $id) { + return $this->getFieldtype()->getCommentByID($page, $this, $id); + } + + /** + * Update specific properties for a comment + * + * @param Page $page + * @param Comment $comment + * @param array $properties Associative array of properties to update + * @return mixed + * + */ + public function updateComment(Page $page, Comment $comment, array $properties) { + return $this->getFieldtype()->updateComment($page, $this, $comment, $properties); + } + + /** + * Delete a given comment + * + * @param Page $page + * @param Comment $comment + * @param string $notes + * @return mixed + * + */ + public function deleteComment(Page $page, Comment $comment, $notes = '') { + return $this->getFieldtype()->deleteComment($page, $this, $comment, $notes); + } + + /** + * Add a vote to the current comment from the current user/IP + * + * @param Page $page + * @param Comment $comment + * @param bool $up Specify true for upvote, or false for downvote + * @return bool Returns true on success, false on failure or duplicate + * + */ + public function voteComment(Page $page, Comment $comment, $up = true) { + return $this->getFieldtype()->voteComment($page, $this, $comment, $up); + } + + /** + * @return FieldtypeComments|Fieldtype + * + */ + public function getFieldtype() { + return parent::getFieldtype(); + } +} \ No newline at end of file diff --git a/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module b/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module index ef8ee1c3..5e52cc46 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module +++ b/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module @@ -21,6 +21,7 @@ require_once($dirname . "/CommentStars.php"); require_once($dirname . "/CommentArray.php"); require_once($dirname . "/CommentList.php"); require_once($dirname . "/CommentForm.php"); +require_once($dirname . "/CommentField.php"); /** * ProcessWire Comments Fieldtype @@ -107,6 +108,10 @@ class FieldtypeComments extends FieldtypeMulti { $inputfield->set('class', $this->className()); return $inputfield; } + + public function getFieldClass(array $a = array()) { + return 'CommentField'; + } /** * Update a query to match the text with a fulltext index