C
C
Cesare Borgia2014-06-04 17:33:16
Zend Framework
Cesare Borgia, 2014-06-04 17:33:16

How to implement next week check in Zend Framework?

Good day!
Recently I started to get acquainted with the Zend Framework and faced such a problem. I don’t know how to make a poll, or rather, a restriction on it in terms of the frequency of voting.
A user has the right to vote for another user once a week, but you can't just set a limit of 7 days, because. he must again be eligible to vote at the beginning of the week, no matter when his last vote was.
Everything is done in CMS Social Engine.
Perhaps someone has already encountered such a problem and can direct me to let the true one, I will be very grateful!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
Cesare Borgia, 2014-06-06
@Borgia

Thanks a lot for the answers!
As a result, I decided to do this:
1. We execute a query to the database, we find out there if the last record of the user has a date older than the start date of the week.

// Получаем первый день текущей недели
$getFirstDay = date('Y-m-d 00:00:00', strtotime('this week', time()));

2. If the query returns a record, then you can't vote. If there is nothing, then you can.

I
Ilya Lesnykh, 2014-06-04
@Aliance

$timestampFromStorage = 123456789; // когда пользователь последний раз голосовал
$votedWeek = date('W', $timestampFromStorage); // номер недели, когда пользователь голосовал
$todayWeek = date('W'); // номер текущей недели
if ($votedWeek * date('Y', $timestampFromStorage) < $todayWeek * date('Y')) {
    // можно голосовать повторно
}

S
Sergey, 2014-06-04
Protko @Fesor

Well, put a check, if we have the same year and week number in the year between the current date and the date of the last vote - we do not allow it. This is all the standard \DateTime or date can do,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question