Asana::getTasksByFilter PHP Method

getTasksByFilter() public method

For now (limited by Asana API), you may limit your query either to a specific project or to an assignee and workspace NOTE: As Asana API says, if you filter by assignee, you MUST specify a workspaceId and viceversa.
public getTasksByFilter ( array $filter = ['assignee' => '', 'project' => '', 'workspace' => ''], array $opts = [] ) : string
$filter array The filter with optional values. array( "assignee" => "", "project" => 0, "workspace" => 0 )
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null
    public function getTasksByFilter($filter = array('assignee' => '', 'project' => '', 'workspace' => ''), array $opts = array())
    {
        $url = '';
        $filter = array_merge(array('assignee' => '', 'project' => '', 'workspace' => ''), $filter);
        $url .= $filter['assignee'] !== '' ? '&assignee=' . $filter['assignee'] : '';
        $url .= $filter['project'] !== '' ? '&project=' . $filter['project'] : '';
        $url .= $filter['workspace'] !== '' ? '&workspace=' . $filter['workspace'] : '';
        if (count($opts) > 0) {
            $url .= '&' . http_build_query($opts);
        }
        if (strlen($url) > 0) {
            $url = '?' . substr($url, 1);
        }
        return $this->askAsana($this->taskUrl . $url);
    }

Usage Example

}
$workspacesJson = json_decode($workspaces);
foreach ($workspacesJson->data as $workspace) {
    echo '<h3>*** ' . $workspace->name . ' (id ' . $workspace->id . ')' . ' ***</h3><br />' . PHP_EOL;
    // Get all projects in the current workspace (all non-archived projects)
    $projects = $asana->getProjectsInWorkspace($workspace->id, $archived = false);
    // As Asana API documentation says, when response is successful, we receive a 200 in response so...
    if ($asana->responseCode != '200' || is_null($projects)) {
        echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
        continue;
    }
    $projectsJson = json_decode($projects);
    foreach ($projectsJson->data as $project) {

        // Get all tasks in the current project
        $tasks = $asana->getTasksByFilter(['project' => $project->id, 'workspace' => $workspace->id],
            ['modified_since' => $startTasksDate/*, 'opt_fields' => 'tags, name'*/]);
//        var_dump($tasks);die;

        $tasksJson = json_decode($tasks);
        if ($asana->responseCode != '200' || is_null($tasks)) {
            echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
            continue;
        }
        $tasks = array();
        foreach ($tasksJson->data as $task) {
            $lastChar = substr(trim($task->name), -1);
            if ($lastChar != ':') {
                $tasks[] = '+ <a target="_blank" href="https://app.asana.com/0/' . $project->id . '/' . $task->id . '">' . $task->name . '</a> '
                    /*.(($task->tags) ? " [".implode (", ", $task->tags)."] " : '')*/ . '<br>' . PHP_EOL;
            }
        }
All Usage Examples Of Asana::getTasksByFilter