Answer the question
In order to leave comments, you need to log in
How to prevent the addition of items no more than three per day?
I have a feedback functionality, reviews on the site are added to the info block. How can I make it so that one user cannot add reviews, no more than three per day.
function getCountTodayMessages(){
$today=date("Y.m.d H:i:s");
$arFilter = array('IBLOCK_ID' => 5,"=TIMESTAMP_X" => $today);
$arSort = array ('TIMESTAMP_X' => 'DESC');
$items = CIBlockElement::GetList($arSort,$arFilter);
while ($obItem = $items->GetNextElement()){
$arItem = $obItem->GetFields();
print_r( $arItem["NAME"]."sdfsdf");
}
}
Answer the question
In order to leave comments, you need to log in
Use the OnBeforeIBlockElementAdd
event.
Make a request to the feedback infoblock with the current date and user parameters. Count the reviews. If the number of reviews == 3, the OnBeforeIBlockElementAdd event must return false. Then the element will not be added.
If you add reviews from a self-written script via ajax, then check for the number of reviews in this script.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question