/**
  * @EXT\Route(
  *     "/{workspace}/tools/order/update/tool/{orderedTool}/with/{otherOrderedTool}/mode/{mode}/type/{type}",
  *     name="claro_workspace_update_ordered_tool_order",
  *     defaults={"type"=0},
  *     options={"expose"=true}
  * )
  * @param Workspace $workspace
  * @param OrderedTool $orderedTool
  * @param OrderedTool $otherOrderedTool
  * @param string $mode
  * @param int type
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function updateWorkspaceOrderedToolOrderAction(Workspace $workspace, OrderedTool $orderedTool, OrderedTool $otherOrderedTool, $mode, $type = 0)
 {
     $this->checkAccess($workspace);
     if ($orderedTool->getWorkspace() === $workspace && $otherOrderedTool->getWorkspace() === $workspace) {
         $order = $orderedTool->getOrder();
         $otherOrder = $otherOrderedTool->getOrder();
         if ($mode === 'previous') {
             if ($otherOrder > $order) {
                 $newOrder = $otherOrder;
             } else {
                 $newOrder = $otherOrder + 1;
             }
         } elseif ($mode === 'next') {
             if ($otherOrder > $order) {
                 $newOrder = $otherOrder - 1;
             } else {
                 $newOrder = $otherOrder;
             }
         } else {
             return new Response('Bad Request', 400);
         }
         $this->toolManager->updateWorkspaceOrderedToolOrder($orderedTool, $newOrder, $type);
         return new Response('success', 204);
     } else {
         throw new AccessDeniedException();
     }
 }
예제 #2
0
 public function updateWorkspaceOrderedToolOrder(OrderedTool $orderedTool, $newOrder, $type = 0, $executeQuery = true)
 {
     $order = $orderedTool->getOrder();
     if ($newOrder < $order) {
         $this->orderedToolRepo->incWorkspaceOrderedToolOrderForRange($orderedTool->getWorkspace(), $newOrder, $order, $type, $executeQuery);
     } else {
         $this->orderedToolRepo->decWorkspaceOrderedToolOrderForRange($orderedTool->getWorkspace(), $order, $newOrder, $type, $executeQuery);
     }
     $orderedTool->setOrder($newOrder);
     $this->om->persist($orderedTool);
     $this->om->flush();
 }