public static function addTask(array $field, array $permissions) { // add task $result = TaskTable::add($field); if (!$result->isSuccess()) { throw new SystemException('cannot add task: ' . $field['NAME'] . "\n" . implode("\n", $result->getErrorMessages()) . "\n\n", 0, __FILE__, __LINE__); } // add task-operations $errors = ''; $taskId = $result->getId(); foreach ($permissions as $operId) { $result = TaskOperationTable::add(array('TASK_ID' => $taskId, 'OPERATION_ID' => $operId)); if (!$result->isSuccess()) { $errors .= 'cannot add task: ' . $taskId . ', operation: ' . $operId . "\n" . implode("\n", $result->getErrorMessages()) . "\n\n"; } } if ($errors) { throw new SystemException($errors, 0, __FILE__, __LINE__); } return $taskId; }