-
Notifications
You must be signed in to change notification settings - Fork 15
Feature/cur 4002 publish activity to canvas #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aqeel-tkxel
merged 15 commits into
develop
from
feature/CUR-4002-publish-activity-to-canvas
Sep 26, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3b6956f
initial commit CUR 4002
AqibYounasAtTkxel 228ffe7
initial commit CUR 4002
AqibYounasAtTkxel d4b3c7a
CUR 4004 commit to clear working tree
AqibYounasAtTkxel 6f22bf4
CUR 4004 commit to clear working tree
AqibYounasAtTkxel 3d29d42
CUR 4004 publish activity/playlist/project to canvas with same flow …
AqibYounasAtTkxel aee6cfe
Merge branch 'develop' of https://github.com/ActiveLearningStudio/Act…
AqibYounasAtTkxel bd8b6c0
uncomment code which was commented by mistake
AqibYounasAtTkxel 16911e2
Merge branch 'develop' of https://github.com/ActiveLearningStudio/Act…
AqibYounasAtTkxel dfc9478
CUR 4004 i missed the new course creation API on the last commits
AqibYounasAtTkxel b0b3513
Merge branch 'develop' of https://github.com/ActiveLearningStudio/Act…
AqibYounasAtTkxel 7b8f34b
Merge branch 'develop' of https://github.com/ActiveLearningStudio/Act…
AqibYounasAtTkxel b400a43
develop PULL
AqibYounasAtTkxel 37a91f4
Merge branch 'develop' of https://github.com/ActiveLearningStudio/Act…
AqibYounasAtTkxel 6de2883
fix the deleted files by pull
AqibYounasAtTkxel c738863
some code changes asked by a PR reviewer
AqibYounasAtTkxel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
app/CurrikiGo/Canvas/Commands/CreateAssignmentCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace App\CurrikiGo\Canvas\Commands; | ||
|
||
use App\CurrikiGo\Canvas\Contracts\Command; | ||
|
||
/** | ||
* This class handles fetching Course details in Canvas LMS | ||
*/ | ||
class CreateAssignmentCommand implements Command | ||
{ | ||
/** | ||
* API URL | ||
* | ||
* @var string | ||
*/ | ||
public $apiURL; | ||
/** | ||
* Access Token for api requests | ||
* | ||
* @var string | ||
*/ | ||
public $accessToken; | ||
/** | ||
* HTTP Client instance | ||
* | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
public $httpClient; | ||
/** | ||
* Course Id | ||
* | ||
* @var int | ||
*/ | ||
private $courseId; | ||
/** | ||
* Request Assignment Group Id | ||
* | ||
* @var array | ||
*/ | ||
private $assignmentGroupId; | ||
/** | ||
* Request new assignment name | ||
* | ||
* @var array | ||
*/ | ||
private $assignmentName; | ||
/** | ||
* Id of activity in curriki | ||
* | ||
* @var array | ||
*/ | ||
private $currikiActivityId; | ||
|
||
/** | ||
* Creates an instance of the command class | ||
* | ||
* @param int $courseId | ||
* @param string $queryString | ||
* @return void | ||
*/ | ||
public function __construct($courseId, $assignmentGroupId, $assignmentName, $currikiActivityId) | ||
{ | ||
$this->courseId = $courseId; | ||
$this->assignmentGroupId = $assignmentGroupId; | ||
$this->assignmentName = $assignmentName; | ||
$this->currikiActivityId = $currikiActivityId; | ||
$this->endpoint = config('constants.canvas_api_endpoints.create_assignment'); | ||
$this->courseData = $this->prepareCourseData($assignmentGroupId, $assignmentName, $this->currikiActivityId); | ||
} | ||
|
||
/** | ||
* Execute an API request for fetching course details | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute() | ||
{ | ||
$assignment = $this->courseData; | ||
$response = null; | ||
try { | ||
$response = $this->httpClient->request('POST', $this->apiURL . '/courses/' . $this->courseId . '/' . $this->endpoint, [ | ||
'headers' => ['Authorization' => "Bearer {$this->accessToken}"], | ||
'json' => ['assignment' => $assignment] | ||
])->getBody()->getContents(); | ||
$response = json_decode($response); | ||
} catch (Exception $ex) { | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Prepare course data for API payload | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
public function prepareCourseData($assignmentGroupId, $assignmentGroupName, $currikiActivityId) | ||
{ | ||
$assignment = []; | ||
$assignment["name"] = $assignmentGroupName; | ||
$assignment['assignment_group_id'] = $assignmentGroupId; | ||
$assignment['self_signup'] = 'enabled'; | ||
$assignment['position'] = 1; | ||
$assignment['submission_types'][] = 'external_tool'; | ||
$assignment['return_type'] = 'lti_launch_url'; | ||
$assignment['workflow_state'] = 'published'; | ||
$assignment['points_possible'] = 100; | ||
$assignment['published'] = true; | ||
$assignment['external_tool_tag_attributes']['url'] = config('constants.curriki-tsugi-host') . "?activity=" . $currikiActivityId; | ||
return $assignment; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
app/CurrikiGo/Canvas/Commands/CreateAssignmentGroupsCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace App\CurrikiGo\Canvas\Commands; | ||
|
||
use App\CurrikiGo\Canvas\Contracts\Command; | ||
|
||
/** | ||
* This class handles fetching Course details in Canvas LMS | ||
*/ | ||
class CreateAssignmentGroupsCommand implements Command | ||
{ | ||
/** | ||
* API URL | ||
* | ||
* @var string | ||
*/ | ||
public $apiURL; | ||
/** | ||
* Access Token for api requests | ||
* | ||
* @var string | ||
*/ | ||
public $accessToken; | ||
/** | ||
* HTTP Client instance | ||
* | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
public $httpClient; | ||
/** | ||
* Course Id | ||
* | ||
* @var int | ||
*/ | ||
private $courseId; | ||
/** | ||
* Request queryString | ||
* | ||
* @var array | ||
*/ | ||
private $assignmentGroupName; | ||
|
||
/** | ||
* Creates an instance of the command class | ||
* | ||
* @param int $courseId | ||
* @param string $queryString | ||
* @return void | ||
*/ | ||
public function __construct($courseId, $assignmentGroupName) | ||
{ | ||
$this->courseId = $courseId; | ||
$this->endpoint = config('constants.canvas_api_endpoints.assignment_groups'); | ||
$this->courseData = $this->prepareCourseData($assignmentGroupName); | ||
} | ||
|
||
/** | ||
* Execute an API request for fetching course details | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute() | ||
{ | ||
$response = null; | ||
try { | ||
$response = $this->httpClient->request('POST', $this->apiURL . '/courses/' . $this->courseId . '/' . $this->endpoint, [ | ||
'headers' => ['Authorization' => "Bearer {$this->accessToken}"], | ||
'json' => $this->courseData | ||
])->getBody()->getContents(); | ||
$response = json_decode($response); | ||
} catch (Exception $ex) { | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Prepare course data for API payload | ||
* | ||
* @param array $data | ||
* @return array | ||
*/ | ||
public function prepareCourseData($assignmentGroupName) | ||
{ | ||
return ["name" => $assignmentGroupName]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace App\CurrikiGo\Canvas\Commands; | ||
|
||
use App\CurrikiGo\Canvas\Contracts\Command; | ||
|
||
/** | ||
* This class handles fetching courses in Canvas LMS | ||
*/ | ||
class GetAllCoursesCommand implements Command | ||
{ | ||
/** | ||
* API URL | ||
* | ||
* @var string | ||
*/ | ||
public $apiURL; | ||
/** | ||
* Access Token for api requests | ||
* | ||
* @var string | ||
*/ | ||
public $accessToken; | ||
/** | ||
* HTTP Client instance | ||
* | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
public $httpClient; | ||
|
||
/** | ||
* Creates an instance of the command class | ||
* | ||
* @param int $accountId | ||
* @param string $programName | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Execute an API request for getting courses | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute() | ||
{ | ||
$response = null; | ||
try { | ||
$url = $this->apiURL . '/courses' . '?per_page=1000'; | ||
$response = $this->httpClient->request('GET', $url, [ | ||
'headers' => ['Authorization' => "Bearer {$this->accessToken}", 'Accept' => 'application/json'] | ||
])->getBody()->getContents(); | ||
$response = json_decode($response); | ||
} catch (Exception $ex) { | ||
} | ||
|
||
return $response; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/CurrikiGo/Canvas/Commands/GetAssignmentGroupsCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace App\CurrikiGo\Canvas\Commands; | ||
|
||
use App\CurrikiGo\Canvas\Contracts\Command; | ||
|
||
/** | ||
* This class handles fetching Course details in Canvas LMS | ||
*/ | ||
class GetAssignmentGroupsCommand implements Command | ||
{ | ||
/** | ||
* API URL | ||
* | ||
* @var string | ||
*/ | ||
public $apiURL; | ||
/** | ||
* Access Token for api requests | ||
* | ||
* @var string | ||
*/ | ||
public $accessToken; | ||
/** | ||
* HTTP Client instance | ||
* | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
public $httpClient; | ||
/** | ||
* Course Id | ||
* | ||
* @var int | ||
*/ | ||
private $courseId; | ||
/** | ||
* Request queryString | ||
* | ||
* @var array | ||
*/ | ||
private $queryString; | ||
|
||
/** | ||
* Creates an instance of the command class | ||
* | ||
* @param int $courseId | ||
* @param string $queryString | ||
* @return void | ||
*/ | ||
public function __construct($courseId) | ||
{ | ||
$this->courseId = $courseId; | ||
$this->endpoint = config('constants.canvas_api_endpoints.assignment_groups'); | ||
} | ||
|
||
/** | ||
* Execute an API request for fetching course details | ||
* | ||
* @return string|null | ||
*/ | ||
public function execute() | ||
{ | ||
$response = null; | ||
try { | ||
$response = $this->httpClient->request('GET', $this->apiURL . '/courses/' . $this->courseId . '/' . $this->endpoint . '?per_page=1000', [ | ||
'headers' => ['Authorization' => "Bearer {$this->accessToken}"] | ||
])->getBody()->getContents(); | ||
$response = json_decode($response); | ||
} catch (Exception $ex) { | ||
} | ||
Comment on lines
+64
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pulling in too many records here? |
||
|
||
return $response; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.