1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 11:44:42 +02:00

Update comments fields to use custom 'CommentField' class rather than 'Field' class

This commit is contained in:
Ryan Cramer
2019-11-12 11:15:00 -05:00
parent 4eeca2eeeb
commit 4cc587bd1a
2 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php namespace ProcessWire;
/**
* ProcessWire Comments Field
*
* Custom “Field” class for Comments fields.
*
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
* https://processwire.com
*
*/
class CommentField extends Field {
/**
* Find comments matching given selector
*
* @param $selectorString
* @param array $options
* @return CommentArray
*
*/
public function find($selectorString, array $options = array()) {
return $this->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();
}
}

View File

@@ -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