You are here

public function OpignoModuleManagerController::ajaxCheckedActivities in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Controller/OpignoModuleManagerController.php \Drupal\opigno_module\Controller\OpignoModuleManagerController::ajaxCheckedActivities()

Ajax callback.

1 string reference to 'OpignoModuleManagerController::ajaxCheckedActivities'
opigno_module.routing.yml in ./opigno_module.routing.yml
opigno_module.routing.yml

File

src/Controller/OpignoModuleManagerController.php, line 120

Class

OpignoModuleManagerController
Controller for all the actions of the Opigno module manager.

Namespace

Drupal\opigno_module\Controller

Code

public function ajaxCheckedActivities() {
  if (!empty($_POST['data'])) {
    $data = json_decode($_POST['data']);
    $checkboxes_ids = !empty($_SESSION['activities_bank']['checkboxes_ids']) ? $_SESSION['activities_bank']['checkboxes_ids'] : [];
    $activities_ids = !empty($_SESSION['activities_bank']['activities_ids']) ? $_SESSION['activities_bank']['activities_ids'] : [];
    if (!empty($data->checked) && array_search($data->checked, $checkboxes_ids) === FALSE) {
      $checkboxes_ids[] = $data->checked;
      $activities_ids[] = $data->activityID;
    }
    elseif (!empty($data->unchecked)) {
      $key = array_search($data->unchecked, $checkboxes_ids);
      if ($key !== FALSE) {
        unset($checkboxes_ids[$key]);
      }
      $key = array_search($data->activityID, $activities_ids);
      if ($key !== FALSE) {
        unset($activities_ids[$key]);
      }
    }
    $_SESSION['activities_bank'] = [
      'checkboxes_ids' => $checkboxes_ids,
      'activities_ids' => $activities_ids,
    ];
  }
  die;
}