1. Go to this page and download the library: Download lyrasoft/feedback library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lyrasoft / feedback example snippets
$this->lang->loadAllFromVendor('lyrasoft/feedback', 'ini');
// OR
$this->lang->loadAllFromVendor(\Lyrasoft\Feedback\FeedbackPackage::class, 'ini');
/** @var \Lyrasoft\Feedback\Service\CommentService $commentService */
$commentService->addComment(
'flower', // Type
$targetId, // Target ID
'Comment Text...', // Content
$user->getId(), // User ID
);
use Lyrasoft\Feedback\Entity\Comment;
/** @var \Lyrasoft\Feedback\Service\CommentService $commentService */
$commentService->addComment(
'flower', // Type
$targetId, // Target ID
'Comment Text...', // Content
$user->getId(), // User ID
// The extra can be callback or array
extra: function (Comment $comment) {
$comment->setRating(5); // If user mark as 5 star
$comment->setNickname('Another nickname');
}
);
/** @var \Lyrasoft\Feedback\Service\CommentService $commentService */
$commentService->addComment(
'flower', // Type
$targetId, // Target ID
'Comment Text...', // Content
$user->getId(), // User ID or User entity
extra: function (Comment $comment) {
// This optional if you want to set ordering to one comment
$comment->setOrdering($comment->count() + 1);
}
);
// Or reorder all comments of one target item.
$commentService->reorderComments(
'flower', // Type
$targetId, // Target ID
);
/** @var \Lyrasoft\Feedback\Service\CommentService $commentService */
$commentService->addInstantReply(
$comment, // Can be ID or entity
'Reply text...',
$user->getId(), // User ID or User entity
);
/** @var \Lyrasoft\Feedback\Service\CommentService $commentService */
$childComment = $commentService->addSubReply(
$parentComment, // Can be ID or entity
'Reply text...',
$user->getId(), // User ID or User entity
extra: function (Comment $comment) {
// Configure comment entity before save
}
);
// Optional: if you want to reorder it.
$commentService->reorderComments(
$parentComment->getType(), // Type
$parentComment->getTargetId(), // Target ID
$parentComment->getId(), // Parent ID
);
/** @var \Lyrasoft\Feedback\Service\RatingService $ratingService */
$ratingService->addRating(
'flower', // Type
$targetId, // Target ID
$user->getId(), // User ID
);
use Lyrasoft\Feedback\Entity\Rating;
/** @var \Lyrasoft\Feedback\Service\RatingService $ratingService */
$ratingService->addRatingIfNotRated(
'flower', // Type
$targetId, // Target ID
$user->getId(), // User ID
// The extra can be callback or array
extra: function (Rating $rating) {
$rating->setRank(4.5); // If user mark as 4.5 star
}
);
/** @var \Lyrasoft\Feedback\Service\RatingService $ratingService */
$ratingService->addRating(
'flower', // Type
$targetId, // Target ID
$user->getId(), // User ID or User entity
extra: function (Rating $rating) {
// This optional if you want to set ordering to one comment
$rating->setOrdering($rating->count() + 1);
}
);
// Or reorder all comments of one target item.
$ratingService->reorderRatings(
'flower', // Type
$targetId, // Target ID
);
/** @var \Lyrasoft\Feedback\Service\RatingService $ratingService */
// Calc average rank
$avg = $ratingService->calcAvgRank($type, $targetId);
// Get rating item or check is rated
$item = $ratingService->getRating($type, $targetId);
$bool = $ratingService->isRated($type, $targetId);
return [
'feedback' => [
// ...
'rating' => [
'ajax_type_protect' => true,
'ajax_allow_types' => [
'article',
'...' // <-- Add your new types here
]
],
]
];
use Lyrasoft\Feedback\Repository\RatingRepository;
// In any repository
public function getFrontListSelector(?User $user = null): ListSelector
{
$selector = $this->getListSelector();
if ($user && $user->isLogin()) {
RatingRepository::joinRating(
$selector,
'item',
$user->getId(),
'item.id'
);
}
// ...
php windwalker pkg:install lyrasoft/feedback -t lang
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.