Skip to content

Commit

Permalink
added plugin files
Browse files Browse the repository at this point in the history
  • Loading branch information
amanintech committed Aug 30, 2020
1 parent 5f14aae commit 159b279
Show file tree
Hide file tree
Showing 9 changed files with 1,803 additions and 0 deletions.
Binary file added Wordpress Plugin/assets/monday-cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions Wordpress Plugin/inc/graphql-api/graphql-get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

class MONDAY_GRAPHQL_QUERY {

private $token;

//setting monday token
function __construct( $token ) {
$this->token = $token;
}

// request monday
public function request_monday( $query ) {
$request = wp_remote_post( 'https://api.monday.com/v2', [
'headers' => [
'Content-Type' => 'application/json',
'authorization' => $this->token
],
'body' => wp_json_encode( [
'query' => $query
] )
] );

return json_decode( $request['body'], true );
}

// get Boards
public function get_board( $boardId ) {

$query = 'query MyQuery {
boards(ids: ' . $boardId . ') {
name
}
}';

$result = $this->request_monday( $query );

return $result['data']['boards'];
}

//get board columns meta
public function get_board_columns( $boardId ) {

$query = 'query MyQuery {
boards(ids: ' . $boardId . ') {
columns {
title
id
type
}
}
}
';
$result = $this->request_monday( $query );

return $result['data']['boards'][0]['columns'];
}

//get monday users
public function get_monday_user() {
$query = 'query MyQuery {
users {
email
id
}
}';
$result = $this->request_monday( $query );

return $result['data']['users'];
}

}

global $token;
$monday_query = new MONDAY_GRAPHQL_QUERY( $token );




152 changes: 152 additions & 0 deletions Wordpress Plugin/inc/graphql-api/graphql-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

class MONDAY_GRAPHQL_MUTATION {

private $token;

//setting monday token
function __construct( $token ) {
$this->token = $token;
}

// request monday
public function send_monday( $query ) {
$request = wp_remote_post( 'https://api.monday.com/v2', [
'headers' => [
'Content-Type' => 'application/json',
'authorization' => $this->token
],
'body' => wp_json_encode( [
'query' => $query
] )
] );

return json_decode( $request['body'], true );
}

/**
* Creates new column in a board
*
* @param integer $boardId this is monday board id
* @param string $title give a meaningful name to monday column
* @param string $column_type a predefined type for a column e.g. auto_number, checkbox, country, color_picker, creation_log, date, dropdown, email, hour, item_id, last_updated, link, location, long_text, numbers, people, phone, progress, rating, status, team, tags, text, timeline, time_tracking, vote, week, world_clock, integration,
*
* @return array Array ( [data] => Array ( [create_column] => Array ( [id] => testing9 ) ) [account_id] => 5764226 )
*/
public function create_column( $boardId, $title, $column_type ) {
$query = 'mutation {
create_column (board_id: ' . $boardId . ', title:"' . $title . '", column_type: ' . $column_type . ') {
id
}
}';

return $this->send_monday( $query );

}

/**
* Creates an item in a board
*
* @param integer $boardId this is monday board id
* @param array $column_values_array pass an array
* @param string $item_name give a name to item
*
* @return array Array ( [data] => Array ( [create_item] => Array ( [id] => 704866515 ) ) [account_id] => 5764226 )
*/
public function create_item( $boardId, $column_values_array, $item_name ) {

$column_values_array_scaped = wp_json_encode( json_encode( $column_values_array, JSON_NUMERIC_CHECK ) );

$query = 'mutation {
create_item (board_id: ' . $boardId . ', column_values: ' . $column_values_array_scaped . ',item_name:"' . $item_name . '") {
id
}
}';

return $this->send_monday( $query );
}

/**
* Creates a tag for a board
*
* @param integer $boardId this is monday board id
* @param string $tag_name give a name to tag
*
* @return array Array ( [data] => Array ( [create_or_get_tag] => Array ( [id] => 6589377 ) ) [account_id] => 5764226 )
*
*/
public function create_tag( $boardId, $tag_name ) {

$query = 'mutation {
create_or_get_tag (tag_name: "' . $tag_name . '", board_id:' . $boardId . ') {
id
}
}';

return $this->send_monday( $query );
}

/**
* Creates an item in a board
*
* @param integer $boardId this is monday board id
* @param array $column_values_array pass an array
* @param integer $itemId provide an item id
*
* @return array Array ( [data] => Array ( [change_multiple_column_values] => Array ( [id] => 704509316 ) ) [account_id] => 5764226 )
*/
public function change_multiple_column_values( $boardId, $column_values_array, $itemId ) {

$column_values_array_scaped = wp_json_encode( json_encode( $column_values_array, JSON_NUMERIC_CHECK ) );

$query = 'mutation {
change_multiple_column_values (board_id: ' . $boardId . ', column_values: ' . $column_values_array_scaped . ',item_id:' . $itemId . ') {
id
state
}
}';

return $this->send_monday( $query );
}

/**
* Creates an update to an item
*
* @param integer $itemId monday board item id
* @param string $itemBody updates to send in an item
*
* @return array Array ( [data] => Array ( [create_update] => Array ( [id] => 775967330 ) ) [account_id] => 5764226 )
*
*/
public function create_update( $itemId, $itemBody ) {

$query = 'mutation {
create_update (item_id: ' . $itemId . ', body: "' . $itemBody . '") {
id
}
}';

return $this->send_monday( $query );
}

/**
* Delete an item
*
* @param integer $itemId monday board item id
* @return array Array ( [data] => Array ( [delete_item] => Array ( [id] => 775967330 ) ) [account_id] => 5764226 )
*/
public function delete_item( $itemId ) {

$query = 'mutation {
delete_item (item_id: ' . $itemId . ') {
id
}
}';

return $this->send_monday( $query );
}
}

global $token;
$monday_mutation = new MONDAY_GRAPHQL_MUTATION( $token );

2 changes: 2 additions & 0 deletions Wordpress Plugin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// silence is strength
Loading

0 comments on commit 159b279

Please sign in to comment.