User’s Vote

Persistent data store for user-specific votes.


  • Private repository access.

Download Buy

5 stars out of 5

1 0 0 0 0
  • Author Taufik Nurrohman
  • Maintainer 1
  • Member 2
  • Version 1.1.0

This extension allows you to remember the voting status based on the currently active user. Without this extension, the voting status will be stored in a cookie that can be deleted by the user at any time, and will be automatically deleted when the cookie expires. However, this extension allows you to remember their voting status as long as they are logged in, even if they have deleted the browser cookies.

Methods

A method to obtain a list of voted pages is available on every instance of a User class:

User::getVotesAsPages(string $key = "", string $folder = 'page'): Pages;

It returns an instance of a Pages class that you can iterate over:

// Create a new user object
$user = new User(LOT . D . 'user' . D . 'user-name.page');

// Get user votes as pages
$votes = $user->getVotesAsPages();

// Get user votes as pages when a vote is taken on a user page
$votes = $user->getVotesAsPages("", 'user');

// Get user votes with key `love` as pages
$votes = $user->getVotesAsPages('love');

// Get user votes with key `love` as pages when a vote is taken on a user page
$votes = $user->getVotesAsPages('love', 'user');

foreach ($votes as $vote) {
    echo '<h3>' . $vote->title . '</h3>';
    echo '<p>' . $vote->description . '</p>';
}

echo '<hr>';

$count = $votes->count;

echo '<p>' . i('%d Vote' . (1 === $count ? "" : 's'), $count) . '</p>';

0 Comments

No comments yet.