Skip to content

Instantly share code, notes, and snippets.

@eoghanobrien
Last active December 17, 2015 06:19
Show Gist options
  • Save eoghanobrien/5564773 to your computer and use it in GitHub Desktop.
Save eoghanobrien/5564773 to your computer and use it in GitHub Desktop.
Grabbing Project Tasks from Asana API
<table id="projects">
<?php foreach ($data as $project): ?>
<tr>
<td class="projectName">
<?php echo $project['name']; ?>
</td>
<td class="projectVersion noresize">
<?php echo sprintf('%s/%s', $project['completedCount'], $project['totalCount']); ?>
</td>
<td class="projectsBars">
<?php
$c = (int) $project['completedCount'];
$t = (int) $project['totalCount'];
if ($t > 0):
?>
<?php
$bars = range(8, $t * 8, $t);
sort($bars, SORT_NUMERIC);
foreach($bars as $k => $v):
if ($v <= $c * 8):
?>
<div class="barSegment value<?php echo $k + 1; ?>"></div>
<?php
else:
?>
<div class="barSegment"></div>
<?php
endif;
endforeach;
endif;
?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php
// Show All Errors
ini_set('display_errors', true);
error_reporting(E_ALL);
function dump($var) {
echo '<pre>';
var_dump($var);
echo '</pre>';
echo '<hr />';
}
// Define Asana API Key
define('ASANA_API_KEY', '');
define('ASANA_WORKSPACE_ID', '');
// Include Asana API Class
require_once('path/to/asana.php');
// Initialize Asana API Class
$asana = new Asana(ASANA_API_KEY);
// Get the projects
$projects = json_decode($asana->getProjectsInWorkspace(ASANA_WORKSPACE_ID));
if (!is_object($projects) || empty($projects->data)) {
die('No projects available.');
}
$data = array();
foreach ($projects->data as $project) {
$completedCount = 0;
$tasks = json_decode($asana->getTasksByProjectId($project->id, 'completed'));
if (!is_object($tasks) || empty($tasks->data)) {
continue;
}
foreach ($tasks->data as $task) {
$completedCount += (int) $task->completed;
}
$data[$project->id] = array(
'name' => $project->name,
'completedCount' => $completedCount,
'totalCount' => count($tasks->data)
);
}
include_once('asana-status-board-display.php');
@michaelwschultz
Copy link

UPDATE, had to add your custom method found inside your asana task project. However, I am only seeing one project. I saw on your website that others were having the same issue.

ERROR: Call to undefined method Asana::getTasksByProjectId()
Doesn't look like that method is included in Ajimix's wrapper. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment