public static function demo() { echo "LiquidPlanner email: "; $email = trim(fgets(STDIN)); echo "LiquidPlanner password for {$email}: "; system('stty -echo'); $password = trim(fgets(STDIN)); system('stty echo'); echo PHP_EOL; $lp = new LiquidPlanner($email, $password); $account = $lp->account(); echo "You are {$account->user_name} ({$account->id})" . PHP_EOL; $workspaces = $lp->workspaces(); $count = count($workspaces); $plural = $count == 1 ? '' : 's'; echo "You have {$count} workspace{$plural}" . PHP_EOL; foreach ($workspaces as $ws) { echo " {$ws->name}\n"; } $ws = $workspaces[0]; $lp->workspace_id = $ws->id; $projects = $lp->projects(); $count = count($projects); echo "These are the {$count} projects in your '{$ws->name}' workspace" . PHP_EOL; foreach ($projects as $i => $p) { echo ' ' . ($i + 1) . '. ' . $p->name . PHP_EOL; } echo "Should I add a task to your first project? (y for yes) "; $add_task = fgets(STDIN); if ('Y' == strtoupper(substr(trim($add_task), 0, 1))) { $task = array('name' => 'learn the API', 'parent_id' => $projects[0]->id); $result = $lp->create_task($task); $update = array('name' => 'learn more about the API', 'id' => $result->id); print_r($lp->update_task($update)); } }
public static function demo() { echo "LiquidPlanner email: "; $email = trim(fgets(STDIN)); echo "LiquidPlanner password for {$email}: "; system('stty -echo'); $password = trim(fgets(STDIN)); system('stty echo'); echo PHP_EOL; $lp = new LiquidPlanner($email, $password); $workspaces = $lp->workspaces(); $lp->workspace_id = $workspaces[0]->id; $help = $lp->help(); if (!isset($help->Task) || !isset($help->Task->assignments)) { print "LiquidPlanner does not yet support multiple owners" . PHP_EOL; exit; } $two_tasks = $lp->tasks("?limit=2"); $two_events = $lp->events("?limit=2"); if (count($two_tasks) < 2 || count($two_events) < 2) { print "Make sure you have at least two tasks and at least two events." . PHP_EOL; exit; } $lp->member_lookup = $lp->workspace_members(); $lp->team_lookup = $lp->workspace_teams(); print "We're going to swap ownership for the first two tasks, and the " . "two events: " . PHP_EOL; print "Tasks: (before)" . PHP_EOL; foreach ($two_tasks as &$task) { $lp->inspect_ownership($task); } print "Events: (before)" . PHP_EOL; foreach ($two_events as &$event) { $lp->inspect_ownership($event); } list($assignment_1, $assignment_2) = array_map(function ($task) { return $task->assignments[0]; }, $two_tasks); $two_tasks[0] = $lp->update_assignment($two_tasks[0]->id, array("assignment_id" => $assignment_1->id, "person_id" => isset($assignment_2->person_id) ? $assignment_2->person_id : NULL, "team_id" => isset($assignment_2->team_id) ? $assignment_2->team_id : NULL)); $two_tasks[1] = $lp->update_assignment($two_tasks[1]->id, array("assignment_id" => $assignment_2->id, "person_id" => isset($assignment_1->person_id) ? $assignment_1->person_id : NULL, "team_id" => isset($assignment_1->team_id) ? $assignment_1->team_id : NULL)); list($assignment_1, $assignment_2) = array_map(function ($event) use($lp) { return $lp->event_owners($event); }, $two_events); $two_events[0] = $lp->update_assignment($two_events[0]->id, $assignment_2); $two_events[1] = $lp->update_assignment($two_events[1]->id, $assignment_1); print "Tasks: (after)" . PHP_EOL; foreach ($two_tasks as &$task) { $lp->inspect_ownership($task); } print "Events: (after)" . PHP_EOL; foreach ($two_events as &$event) { $lp->inspect_ownership($event); } }