Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 16
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3b6956f228ffe7d4b3c7a6f22bf43d29d42aee6cfebd8b6c016911e2dfc9478b0b35137b8f34bb400a4337a91f46de2883c738863File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| } |
| 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]; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } | ||
| 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
Contributor 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; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.