What this solution does
The module implements a like/dislike functionality for any Bitrix entity. The content type ID is defined arbitrarily within the project scope.
The solution is built on the PHP ORM class Ylab\Likes\YlabLikesTable. It defines the VoteDislike constant for dislikes and the VoteLike constant for likes.
Static methods are available for managing votes:
setLike($iContentId, $iContentType, $iUserId) — records a like from a specified user.
setDislike($iContentId, $iContentType, $iUserId) — records a dislike from a specified user.
In both methods, $iContentId and $iContentType identify the object and content type, while $iUserId specifies the user ID casting the vote.
The getContentStat($mContentId, $iContentType, $iUserLike = null) method returns vote statistics. The $mContentId parameter accepts a single ID or an array of IDs. The $iContentType parameter specifies the content type. The optional $iUserLike parameter allows retrieving the voting status of a specific user.
To integrate the interface in JavaScript, initialize the YlabLikesForm library using CJSCore::Init(['YlabLikesForm']).
The YLab: Likes/Dislikes module is a library for managing voting systems within the 1C-Bitrix environment. It enables recording content ratings on behalf of the current user and retrieving up-to-date statistics.
The BX.Ylab.Likes.setAjaxPath(AjaxPath) method configures the paths to event PHP handlers. The default configuration specifies the following routes: /bitrix/themes/ylab.likes/ajax/setLike.php for likes, /bitrix/themes/ylab.likes/ajax/setDislike.php for dislikes, and /bitrix/themes/ylab.likes/ajax/getContentStat.php for retrieving statistics.
The BX.Ylab.Likes.setLike(iContentId, iContentType, oCallback) method records a like vote for specified content. It accepts the content ID, content type ID, and a callback function that executes after the request is sent.
The BX.Ylab.Likes.setDislike(iContentId, iContentType, oCallback) method similarly records a dislike vote for the specified content, utilizing the same parameters: content ID, content type ID, and a callback function.
The BX.Ylab.Likes.getContentStat(iContentId, iContentType, oCallback) method requests data on the total number of votes for the content and the current user's voting status. The result is passed to the specified callback function.
The component is ready for use and includes all necessary functionality for displaying likes and dislikes. To integrate it, call the component by specifying the element ID and the content type ID. Caching parameters are set via CACHE_TYPE and CACHE_TIME.
If “YLab: Likes/Dislikes” is required, General iT can help with installation, configuration and a technical check after integration.