Answer the question
In order to leave comments, you need to log in
How to create an algorithm for adding a selected category?
Hello!
In general, the essence is this, there are 2 tables, the category table and the mod_subscribes_event_setting table in which (category id and id).
There is a page with a list of all categories with a checkbox, you need to write down the id of the categories if the checkbox is active in the mod_subscribes_event_setting
table
.
I have a function in the controller
public function eventSetting(){
/**Список всех категорий*/
$event_categories = $this->subscribes_model_events->getListCategory();
/**Чекбоксы которые активны array{*,*,*,*}*/
$idsCategory = $_POST['ids'];
if(!empty($idsCategory))
{
foreach ($event_categories as $category){
foreach($idsCategory as $id)
{
if($category['id'] == $id)
{
/**По получаем ID категории если она есть в таблице mod_subscribes_event_setting*/
$event_category_item = $this->subscribes_model_events->getItem( $category['id']);
if ($category['id'] != $event_category_item['event_category_id']){
/**Если нет то создаем*/
$data= array(
'event_category_id' => $category['id']
);
$this->subscribes_model_events->addSetting($data);
}
/**Как то нужно проверить если статья была но checkbox сняли удалить эту запись*/
showMessage('Данные добавлены '.$data['event_category_id'] );
}
}
}
}
/**Загружаем view передаем список всех категорий*/
\CMSFactory\assetManager::create()
->setData(array(
'event_categories' => $event_categories
))
->renderAdmin('subscriber_event/setting');
}
Answer the question
In order to leave comments, you need to log in
You can simply clear the mod_subscribes_event_setting table, and re-insert the selected categories with an INSERT INTO .. VALUES(*,*,*...) list. Total 2 requests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question