*/ class TaskModel extends FormModel { public function getRepository(): TaskRepository { $repository = $this->em->getRepository(Task::class); \assert($repository instanceof TaskRepository); return $repository; } public function getPermissionBase(): string { return 'program:tasks'; } public function getEntity($id = null): ?Task { if (null === $id) { return new Task(); } $task = parent::getEntity($id); return $task instanceof Task ? $task : null; } /** * The plan's tasks as rows for the initiative's Tasks tab: the tasks ordered by name, each with its * dependencies and RACI rows loaded. The former parent/child tree is gone; the tab lists the * tasks flat, and the dependencies are shown per task. * * @return array */ public function getTaskTree(Initiative $initiative): array { $rows = []; foreach ($this->getRepository()->findByInitiative($initiative) as $task) { $rows[] = ['task' => $task, 'depth' => 0]; } return $rows; } /** * @param array $options */ public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface { if (!$entity instanceof Task) { throw new MethodNotAllowedHttpException(['Task']); } if (!empty($action)) { $options['action'] = $action; } return $formFactory->create(TaskType::class, $entity, $options); } }