/** * Test task loading */ public function loadTasks($id) { $load_task = new TaskerMAN\Application\Task($id); $this->assertEquals($load_task->created_uid, 1); $this->assertEquals($load_task->assignee_uid, 1); $this->assertEquals($load_task->status, 1); $this->assertEquals($load_task->title, 'PHPUnit Testing'); // Get steps $steps = $load_task->getSteps(); $this->assertEquals($steps[0]['title'], 'Write some unit tests'); }
<?php TaskerMAN\WebInterface\WebInterface::setTitle('Create New Task'); if (isset($_POST['submit'])) { try { $task = new TaskerMAN\Application\Task(); $task->setCreatedByUser(TaskerMAN\WebInterface\WebInterface::$user->getID()); $task->setAssignee(TaskerMAN\Core\IO::POST('assigned-to')); $task->setDueBy(TaskerMAN\Core\IO::POST('due-date')); $task->setStatus(1); // Allocated $task->setTitle(TaskerMAN\Core\IO::POST('task-title')); $task->createStep(TaskerMAN\Core\IO::POST('step-text')); $task->save(); header('Location: index.php?p=task&id=' . $task->id); exit; } catch (TaskerMAN\Application\UserManagementException $e) { $alert = '<div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div>'; } catch (TaskerMAN\Application\TaskException $e) { $alert = '<div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div>'; } } ?> <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> <?php if (isset($alert)) { echo $alert; } ?>
$verbs = array('Fix', 'Create', 'Confirm', 'Eat', 'Drink', 'Paint', 'Code', 'Test'); $things = array('beer', 'user interface', 'burgers', 'pizza', 'code', 'Jack Reed', 'desktop application', 'Java', 'PHP', 'coffee', 'meeting', 'pasta'); // Get array of all user IDs $query = new TaskerMAN\Core\DBQuery("SELECT `id` FROM `users`"); $query->execute(); while ($row = $query->row()) { $users[] = $row['id']; } // Get array of all admins $query = new TaskerMAN\Core\DBQuery("SELECT `id` FROM `users` WHERE `admin` = '1'"); $query->execute(); while ($row = $query->row()) { $admins[] = $row['id']; } foreach ($tasks as $i) { $t = new TaskerMAN\Application\Task(); $t->setAssignee($users[array_rand($users)]); $due_by = rand_future_time(); $t->setDueBy(date('Y-m-d', $due_by)); $t->setCreatedByUser($admins[array_rand($admins)]); if (rand(1, 5) > 2) { $status = 2; } else { $status = 1; } $t->setStatus($status); $steps = range(1, rand(1, 3)); foreach ($steps as $step_i) { $t->createStep('Step #' . $step_i, 'Not done yet, sorry'); } if ($status == 2) {
<?php // Get task ID and status variables $task_id = (int) TaskerMAN\Core\IO::GET('id'); $status = (int) TaskerMAN\Core\IO::GET('status'); // Expects time in UNIX timestamp format $completed_time = (int) TaskerMAN\Core\IO::GET('completed_time'); // If no completed time is passed, use current time if (empty($completed_time)) { $completed_time = time(); } $task = new TaskerMAN\Application\Task($task_id); if (empty($task->id)) { // Unable to load task, throw error throw new TaskerMAN\Application\APIErrorException('Invalid task ID'); } switch ($status) { // Make sure we're not setting the status to a state it's already in case $task->status: throw new TaskerMAN\Application\APIErrorException('Trying to change status to same value as it already has'); break; // allocated // allocated case 1: $task->setStatus(1); $task->setCompletedTime('0000-00-00 00:00:00'); break; // completed // completed case 2: $task->setStatus(2);
<?php // Get array of task IDs $ids = explode(',', TaskerMAN\Core\IO::GET('id')); // Remove non-numeric IDs foreach ($ids as $key => $id) { if (!is_numeric($id)) { unset($ids[$key]); } } $steps = array(); // Loop through each task foreach ($ids as $id) { $task = new TaskerMAN\Application\Task($id); if (is_null($task->id)) { // Unable to load task throw new TaskerMAN\Application\APIErrorException('Task ' . $id . ' does not exist'); } if ((int) $task->assignee_uid !== TaskerMAN\Application\API::$uid) { throw new TaskerMAN\Application\APIErrorException('User does not have access to task ' . $id); } // Load steps into response array $steps[$id] = $task->getSteps(); } if (empty($steps)) { throw new TaskerMAN\Application\APIErrorException('No steps found'); } echo TaskerMAN\Application\API::response(array('steps' => $steps));
<?php $task_id = TaskerMAN\Core\IO::GET('id'); // Check task exists $task = new TaskerMAN\Application\Task($task_id); if (is_null($task->id)) { throw new TaskerMAN\Core\FatalException('404 - Page Not Found', new \Exception('Requested task (' . $task_id . ') was not found')); } TaskerMAN\WebInterface\WebInterface::setTitle('Task ' . $task_id); ?> <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> <?php if (isset($_POST['submit'])) { try { $task->setTitle(TaskerMAN\Core\IO::POST('task-title')); $task->setDueBy(TaskerMAN\Core\IO::POST('due-date')); $task->setAssignee(TaskerMAN\Core\IO::POST('assigned-to')); // Task changed to completed if ($task->status != 2 && TaskerMAN\Core\IO::POST('status') == 2) { $task->setCompletedTime(); } $task->setStatus(TaskerMAN\Core\IO::POST('status')); $task->save(); } catch (TaskerMAN\Application\TaskException $e) { $alert = '<div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div>'; } } if (isset($alert)) { echo $alert;
<?php $id = (int) TaskerMAN\Core\IO::GET('id'); $task = new TaskerMAN\Application\Task($id); if (is_null($task->id)) { // Unable to load task throw new TaskerMAN\Application\APIErrorException('Task does not exist'); } if ((int) $task->assignee_uid !== TaskerMAN\Application\API::$uid) { throw new TaskerMAN\Application\APIErrorException('User does not have access to this task'); } $result = array('id' => $task->id, 'created_uid' => $task->created_uid, 'created_name' => $task->created_name, 'assignee_uid' => $task->assignee_uid, 'assignee_name' => $task->assignee_name, 'due_by' => $task->due_by, 'completed_time' => $task->completed_time, 'status' => $task->status, 'title' => $task->title, 'steps' => $task->getSteps()); echo TaskerMAN\Application\API::response($result);