0

I have written one extension for making service order. The issue I am facing here is,

There are FE users belong to three FE user groups namely "client", "Admin" and "Employee".

Here the client can make order and he should be able to see only his orders. And the admin can see all orders done by different clients. And the employee should be able to see only some clients orders.

Currently I made a order table with N:1 relation with FE user table. So every order should relate with any one client.

So in controller, I am checking the login user and using custom query in repository, I am accessing order related to loggedin client (FE user)

In file OrdersController.php

public function listAction() {
     $orders = $this->ordersRepository->orderForLoginUsr();
     $this->view->assign('orders', $orders);
}

In file OrdersRepository.php

public function orderForLoginUsr(){
      $loggedInUserId = $GLOBALS ['TSFE']->fe_user->user['uid'];
      $query = $this->createQuery();
      $query->matching(
         $query->equals('user', $loggedInUserId)
      );
      $query->setOrderings(array('crdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
      return $query->execute();
}

But here my question is how to make admin user able to see all the orders done by all clients? I have to write different template and action that calling function findAll() ?

$orders = $this->ordersRepository->findAll();

And how to set for usergroup Employee ?

Thanks in Advance

2 Answers2

0

I think that the easiest way is to actually implement 3 actions with 3 different plugins, something like: listClientAction, listAdminAction and listEmployeeAction

In each of those action, you implement a method in your repository that fetch the right list of order with the good ordering: orderForLoginClient(), orderForLoginEmployee(), orderForLoginAdmin()

What does the trick actually is that there will be 3 plugins on your page, one for each action. In each instance of your plugin, you set the access for the right be_group.

Don't forget to add the actions and plugin in the localconf and ext_table files.

I hope it will help! Olivier

DaikonBoy
  • 158
  • 6
0

If your view is almost the same for client, admin, employee you should simply add a method like getOrderWithPermissionsForUser($currentUser);

In the method itself you should check for the usergroup and call different queries on your Repo.

If your view is different from usergroup to usergroup, you should use different templates with partials for the same parts.

If the data of the views is the same, just change the template for each usergroup in the action. If not use different actions.

Here is a helper method for easily changing your templatefile.

/**
 * This method can change the used template file in an action method.
 *
 * @param string $templateName Something like "List" or "Foldername/Actionname".
 * @param string $templateExtension Default is "html", but for other output types this may be changed as well.
 * @param string $controllerName Optionally uses another subfolder of the Templates/ directory
 *                  By default, the current controller name is used. Example value: "JobOffer"
 * @param \TYPO3\CMS\Fluid\View\AbstractTemplateView $viewObject The view to set this template to. Default is $this->view
 */
protected function changeTemplateFile($templateName, $templateExtension = 'html', $controllerName = null, AbstractTemplateView $viewObject = null)
{
    if (is_null($viewObject)) {
        $viewObject = $this->view;
    }

    if (is_null($controllerName)) {
        $controllerName = $this->getControllerContext()->getRequest()->getControllerName();
    }

    $templatePathAndFilename = $this->getTemplateRootpathForView($controllerName . '/' . $templateName . '.' . $templateExtension);
    $viewObject->setTemplatePathAndFilename($templatePathAndFilename);
}
Stephan
  • 161
  • 1
  • 9