Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todoist_api
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
todoist_api
Commits
c6f9f003
Commit
c6f9f003
authored
4 months ago
by
Arjun Kumar
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3472829
by manav: Create list to show all the tasks.
parent
cf43078e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Controller/TodoistapiTasks.php
+104
-0
104 additions, 0 deletions
src/Controller/TodoistapiTasks.php
with
104 additions
and
0 deletions
src/Controller/TodoistapiTasks.php
0 → 100644
+
104
−
0
View file @
c6f9f003
<?php
namespace
Drupal\todoist_api\Controller
;
use
Drupal\Core\Controller\ControllerBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
GuzzleHttp\ClientInterface
;
class
TodoistapiTasks
extends
ControllerBase
{
/**
* Guzzle\Client instance.
*
* @var \GuzzleHttp\ClientInterface
*/
protected
$httpClient
;
/**
* {@inheritdoc}
*/
public
function
__construct
(
ClientInterface
$http_client
)
{
$this
->
httpClient
=
$http_client
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'http_client'
)
);
}
/**
* Posts route callback.
*
* @param int $limit
* The total number of posts we want to fetch.
* @param string $sort
* The sorting order.
*
* @return array
* A render array used to show the Posts list.
*/
/**
* A simple controller method to explain what the tablesort example is about.
*/
public
function
build
()
{
// We are going to output the results in a table with a nice header.
$header
=
[
// The header gives the table the information it needs in order to make
// the query calls for ordering. TableSort uses the field information
// to know what database column to sort by.
[
'data'
=>
$this
->
t
(
'Task'
),
'field'
=>
'content'
],
[
'data'
=>
$this
->
t
(
'Task added date'
),
'field'
=>
'description'
],
[
'data'
=>
$this
->
t
(
'Task due date'
),
'field'
=>
'created_at'
],
[
'data'
=>
$this
->
t
(
'Action'
),
'field'
=>
'created_at'
]
];
// $result = [
// ['number' => '1', 'alpha' => 'aaa', 'random' => '912cv21'],
// ['number' => '2', 'alpha' => 'bbb', 'random' => '0kuykuh'],
// ['number' => '3', 'alpha' => 'ccc', 'random' => '0kuykuh'],
// ['number' => '4', 'alpha' => 'ddd', 'random' => '0kuykuh'],
// ['number' => '5', 'alpha' => 'eee', 'random' => '0kuykuh'],
// ['number' => '6', 'alpha' => 'fff', 'random' => '0kuykuh'],
// ];
$options
=
[
'headers'
=>
[
'Authorization'
=>
'Bearer a0dc04e0c04e0e19ac7621cd5385f5111920bf2f'
]];
$request
=
$this
->
httpClient
->
request
(
'GET'
,
'https://api.todoist.com/rest/v2/tasks'
,
$options
);
$response_data
=
json_decode
(
$request
->
getBody
()
->
getContents
(),
TRUE
);
//dump($response_data);
//die;
$rows
=
[];
foreach
(
$response_data
as
$row
)
{
$created_date
=
(
new
\DateTime
(
$row
[
'created_at'
]))
->
getTimestamp
();
//dump($row);
$rows
[]
=
[
'data'
=>
[
$row
[
'content'
],
$row
[
'description'
],
$created_date
]
];
}
//dump($rows);
// Build the table for the nice output.
$build
=
[
'#markup'
=>
'<p>'
.
$this
->
t
(
'The layout here is a themed as a table
that is sortable by clicking the header name.'
)
.
'</p>'
,
];
$build
[
'tablesort_table'
]
=
[
'#theme'
=>
'table'
,
'#header'
=>
$header
,
'#rows'
=>
$rows
,
];
return
$build
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment