ATK Demo Walkthrough – Lesson 10
From Achievo/ATK Wiki
Intro
In Lesson 3, we learned how to set up a relation between employees and their managers. One thing we did not do is to make sure that an employee's manager works in the same department as the employee. Furthermore, we did not make sure that employees are not their own managers.
Filters
To implement these rules, we can add a filter:
$mgr->addDestinationFilter("department_id = '[department_id.id]' AND id<>'[id]'");
Notice the syntax used in the filter. It is similar to that used in the descriptor_def function: identifiers in square brackets are substituted with the current node information, in this case the current department ID and the current employee ID.
The efect of this filter is that we will have a limited set of employees from which to select a manager.
Dependencies
Since the contents of the manager selection list depend on the selected department, we want to make sure that the manager selection list is updated every time the user selects a different department. To do this, we add the following line:
$dpt->addDependee("manager_id");
This function call tells the Department relation that the Manager relation depends on it. This is all that's needed to force the Manager relation to get reloaded at the right times. Whenever the user selects a Department, the Department relation tells the Manager relation to refresh itself.