You are here

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

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

Update activity weight.

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

File

src/Controller/OpignoModuleManagerController.php, line 610

Class

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

Namespace

Drupal\opigno_module\Controller

Code

public function activityUpdateWeight(Request $request) {
  $datas = json_decode($request
    ->getContent());
  if (empty($datas->acitivies_weight)) {
    return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
  }
  $db_connection = \Drupal::service('database');
  foreach ($datas->acitivies_weight as $value) {
    $db_connection
      ->merge('opigno_module_relationship')
      ->keys([
      'omr_id' => $value->omr_id,
    ])
      ->fields([
      'weight' => $value->weight,
    ])
      ->execute();
  }
  return new JsonResponse(NULL, Response::HTTP_OK);
}