Пример #1
0
 public function onRun()
 {
     if (!is_null($this->property('experienceInstance'))) {
         $instance = ExperienceModel::find($this->property('experienceInstance'));
         $maxExperiencePts = $instance->total_points;
         $exComp = new ExperienceComponent();
         $exComp->initVariables($this->property('experienceInstance'));
         $points = $exComp->getUserPoints();
         $roots = new Roots();
         $standards = $roots->getGradingStandards();
         $grading_scheme = $standards[0]->grading_scheme;
         $letterGrade = $this->getLetterGrade($points, $maxExperiencePts, $grading_scheme);
         $bonusPenaltiesObj = $exComp->calculateTotalBonusPenalties($this->property('experienceInstance'));
         $totalBonusPenalties = $bonusPenaltiesObj->bonus + $bonusPenaltiesObj->penalties;
         //penalties come with negative sign
         $this->page['XP'] = round($points, 2);
         $this->page['gradeBonus'] = round($totalBonusPenalties, 2);
         $this->page['letterGrade'] = $letterGrade;
     } else {
         $this->page['XP'] = 0;
         $this->page['gradeBonus'] = 0;
         $this->page['letterGrade'] = "F";
     }
     //todo: get the bonus, etc from blade, not from experience
     $size = $this->property('size');
     $this->page['gradeSize'] = $size;
     $this->addJs("/plugins/delphinium/blossom/assets/javascript/grade.js");
     $this->addCss("/plugins/delphinium/blossom/assets/css/animate.css");
     $this->addCss("/plugins/delphinium/blossom/assets/css/grade.css");
     $this->addCss("/plugins/delphinium/blossom/assets/css/main.css");
 }
Пример #2
0
 public function saveUserInfo()
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $code = \Input::get('code');
     $lti = \Input::get('lti');
     $instanceFromDB = LtiConfigurations::find($lti);
     $clientId = $instanceFromDB['DeveloperId'];
     $developerSecret = $instanceFromDB['DeveloperSecret'];
     $opts = array('http' => array('method' => 'POST'));
     $context = stream_context_create($opts);
     $url = "https://{$_SESSION['domain']}/login/oauth2/token?client_id={$clientId}&client_secret={$developerSecret}&code={$code}";
     $userTokenJSON = file_get_contents($url, false, $context, -1, 40000);
     $userToken = json_decode($userTokenJSON);
     $actualToken = $userToken->access_token;
     $encryptedToken = \Crypt::encrypt($actualToken);
     $_SESSION['userToken'] = $encryptedToken;
     //store encrypted token in the database
     $courseId = $_SESSION['courseID'];
     $userId = $_SESSION['userID'];
     //make sure we have the user stored in the user table and in the userCourse table.
     $roots = new Roots();
     //when we get the user from the LMS it gets stored in the DB.
     $roots->getUser($userId);
     $dbHelper = new DbHelper();
     $role = $dbHelper->getRole('Approver');
     $userCourse = UserCourse::firstOrNew(array('user_id' => $userId, 'course_id' => $courseId));
     $userCourse->user_id = $userId;
     $userCourse->course_id = $courseId;
     $userCourse->role = $role->id;
     $userCourse->encrypted_token = $encryptedToken;
     $userCourse->save();
     echo "App has been approved. Please reload this page";
 }
Пример #3
0
 public function getModules($freshData)
 {
     $moduleId = null;
     $moduleItemId = null;
     $includeContentDetails = true;
     $includeContentItems = true;
     $module = null;
     $moduleItem = null;
     $req = new ModulesRequest(ActionType::GET, $moduleId, $moduleItemId, $includeContentItems, $includeContentDetails, $module, $moduleItem, $freshData);
     $roots = new Roots();
     $moduleData = $roots->modules($req);
     $modArr = $moduleData->toArray();
     $simpleModules = array();
     foreach ($modArr as $item) {
         $mod = new \stdClass();
         $mod->id = $item['module_id'];
         $mod->value = $item['name'];
         $simpleModules[] = $mod;
     }
     $this->page['rawData'] = json_encode($simpleModules);
     $iris = new IrisClass();
     $result = $iris->buildTree($modArr);
     $tempArray = array();
     if (count($result) < 1) {
         $parent;
         $allChildren;
         $final = array();
         //The parent will be the first PUBLISHED item
         $firstItem;
         foreach ($moduleData as $item) {
             if ($item['published'] == "1") {
                 $firstItem = $item;
                 break;
             }
         }
         $newArr = $this->unsetValue($modArr, $firstItem);
         //remove parent from array
         $firstParentId = $firstItem["module_id"];
         $i = 0;
         foreach ($newArr as $item) {
             $item["parent_id"] = $firstParentId;
             //each item must have a parentId of the first module
             $item["children"] = [];
             $item["order"] = $i;
             $final[] = $item;
             $i++;
         }
         //remove the first Item (which is the parent)
         $firstItem["parent_id"] = 1;
         $firstItem["children"] = $final;
         $firstItem["order"] = 0;
         $tempArray[] = $firstItem;
     } else {
         $tempArray = $result;
     }
     return $tempArray;
 }
Пример #4
0
 public function doBltiHandshake()
 {
     //first obtain the details of the LTI configuration they chose
     $instanceFromDB = LtiConfigurations::find($this->property('ltiInstance'));
     $approver = $this->property('approver');
     $arr = $this->getApproverOptions();
     $approverRole = $arr[$approver];
     if (!isset($_SESSION)) {
         session_start();
     }
     $_SESSION['baseUrl'] = Config::get('app.url', 'backend');
     $_SESSION['courseID'] = \Input::get('custom_canvas_course_id');
     $_SESSION['userID'] = \Input::get('custom_canvas_user_id');
     $_SESSION['domain'] = \Input::get('custom_canvas_api_domain');
     //TODO: make sure this parameter below works with all other LMSs
     $_SESSION['lms'] = \Input::get('tool_consumer_info_product_family_code');
     //check to see if user is an Instructor
     $rolesStr = \Input::get('roles');
     $consumerKey = $instanceFromDB['ConsumerKey'];
     $clientId = $instanceFromDB['DeveloperId'];
     //Check to see if the lti handshake passes
     $context = new Blti($consumerKey, false, false);
     if ($context->valid) {
         // query DB to see if user has token, if yes, go to LTI.
         $userCheck = User::where('course_id', $_SESSION['courseID'])->first();
         if (!$userCheck) {
             //if no user is found, redirect to canvas permission page
             if (stristr($rolesStr, $approverRole)) {
                 //As per my discussion with Jared, we will use the instructor's token only. This is the token that will be stored in the DB
                 //and the one that will be used to make all requests. We will NOT store student's tokens.
                 //TODO: take this redirectUri out into some parameter somewhere...
                 $redirectUri = "{$_SESSION['baseUrl']}saveUserInfo?lti={$this->property('ltiInstance')}";
                 $url = "https://{$_SESSION['domain']}/login/oauth2/auth?client_id={$clientId}&response_type=code&redirect_uri={$redirectUri}";
                 $this->redirect($url);
             } else {
                 echo "A(n) {$approverRole} must authorize this course. Please contact your instructor.";
                 return;
             }
         } else {
             //set the professor's token
             $_SESSION['userToken'] = $userCheck->encrypted_token;
             //get the timezone
             $roots = new Roots();
             $course = $roots->getCourse();
             $account_id = $course->account_id;
             $account = $roots->getAccount($account_id);
             $_SESSION['timezone'] = new \DateTimeZone($account->default_time_zone);
         }
     } else {
         echo 'There is a problem. Please notify your instructor';
     }
 }
Пример #5
0
 public function getFilterOptions()
 {
     $req = new ModulesRequest(ActionType::GET, null, null, true, true, null, null, false);
     $roots = new Roots();
     $moduleData = $roots->modules($req);
     $arr = $moduleData->toArray();
     $tree = $this->buildTree($arr, 1);
     $dash = "";
     $result = array();
     $result[$tree[0]['module_id']] = "({$tree[0]['name']})";
     foreach ($tree as $item) {
         $this->recursion($item['children'], $dash, $result);
     }
     return $result;
 }
Пример #6
0
 public function getStudentSubmissions()
 {
     $studentId = \Input::get('studentId');
     $studentIds = array($studentId);
     $assignmentIds = array();
     //if we leave this param empty it will return all of the available submissions
     //(see https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.for_students)
     $multipleStudents = false;
     $multipleAssignments = true;
     $allStudents = false;
     $allAssignments = true;
     //can have the student Id param null if multipleUsers is set to false (we'll only get the current user's submissions)
     $req = new SubmissionsRequest(ActionType::GET, $studentIds, $allStudents, $assignmentIds, $allAssignments, $multipleStudents, $multipleAssignments);
     $roots = new Roots();
     $res = $roots->submissions($req);
     return $res;
 }
Пример #7
0
 public function onRun()
 {
     $config = Configuration::find($this->property('devConfig'));
     if (!isset($_SESSION)) {
         session_start();
     }
     $_SESSION['userID'] = $config->User_id;
     $_SESSION['userToken'] = \Crypt::encrypt($config->Token);
     $_SESSION['courseID'] = $config->Course_id;
     $_SESSION['domain'] = $config->Domain;
     $_SESSION['lms'] = $config->Lms;
     //get the timezone
     $roots = new Roots();
     $course = $roots->getCourse();
     $account_id = $course->account_id;
     $account = $roots->getAccount($account_id);
     $_SESSION['timezone'] = new \DateTimeZone($account->default_time_zone);
 }
Пример #8
0
 private function getSubmissions()
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $userId = $_SESSION['userID'];
     $roots = new Roots();
     $request = new SubmissionsRequest(ActionType::GET, array($userId), false, array(), true, false, true, false);
     $submissions = $roots->submissions($request);
     return $submissions;
 }
Пример #9
0
 public function updateModule()
 {
     $name = \Input::get('name');
     $date = \Input::get('unlock_at');
     $unlock_at = new DateTime($date);
     $prerequisite_module_ids = \Input::get('prerequisites');
     $published = \Input::get('published');
     $module_id = \Input::get('module_id');
     $module = new Module($name, $unlock_at, $prerequisite_module_ids, $published, null);
     //update a module (changing title and published to false)
     $req = new ModulesRequest(ActionType::PUT, $module_id, null, false, false, $module, null, false);
     $roots = new Roots();
     return $roots->modules($req);
 }
Пример #10
0
 public function getSubmissions($userId = null)
 {
     if (is_null($userId)) {
         if (!isset($_SESSION)) {
             session_start();
         }
         $userId = $_SESSION['userID'];
     }
     $roots = new Roots();
     $request = new SubmissionsRequest(ActionType::GET, array($userId), false, array(), true, false, true, false);
     try {
         $submissions = $roots->submissions($request);
         return $submissions;
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         return [];
     }
 }
Пример #11
0
 public function uploadFileStepThree()
 {
     $location = \Input::get('location');
     $roots = new Roots();
     return $roots->uploadFileStepThree($location);
 }
Пример #12
0
 public function doBltiHandshake()
 {
     //first obtain the details of the LTI configuration they chose
     $dbHelper = new DbHelper();
     $instanceFromDB = LtiConfigurations::find($this->property('ltiInstance'));
     $approver = $this->property('approver');
     $arr = $this->getApproverOptions();
     $approverRole = $arr[$approver];
     if (!isset($_SESSION)) {
         session_start();
     }
     $_SESSION['baseUrl'] = Config::get('app.url', 'backend');
     $_SESSION['courseID'] = \Input::get('custom_canvas_course_id');
     $_SESSION['userID'] = \Input::get('custom_canvas_user_id');
     $_SESSION['domain'] = \Input::get('custom_canvas_api_domain');
     //TODO: make sure this parameter below works with all other LMSs
     $_SESSION['lms'] = \Input::get('tool_consumer_info_product_family_code');
     //check to see if user is an Instructor
     $rolesStr = \Input::get('roles');
     $consumerKey = $instanceFromDB['ConsumerKey'];
     $clientId = $instanceFromDB['DeveloperId'];
     //Check to see if the lti handshake passes
     $context = new Blti($consumerKey, false, false);
     if ($context->valid) {
         // query DB to see if user has token, if yes, go to LTI.
         $userCheck = $dbHelper->getCourseApprover($_SESSION['courseID']);
         if (!$userCheck) {
             //if no user is found, redirect to canvas permission page
             if (stristr($rolesStr, $approverRole)) {
                 //As per my discussion with Jared, we will use the instructor's token only. This is the token that will be stored in the DB
                 //and the one that will be used to make all requests. We will NOT store student's tokens.
                 //TODO: take this redirectUri out into some parameter somewhere...
                 $redirectUri = "{$_SESSION['baseUrl']}saveUserInfo?lti={$this->property('ltiInstance')}";
                 $url = "https://{$_SESSION['domain']}/login/oauth2/auth?client_id={$clientId}&response_type=code&redirect_uri={$redirectUri}";
                 $this->redirect($url);
             } else {
                 echo "A(n) {$approverRole} must authorize this course. Please contact your instructor.";
                 return;
             }
         } else {
             //set the professor's token
             $_SESSION['userToken'] = $userCheck->encrypted_token;
             //get the timezone
             $roots = new Roots();
             $course = $roots->getCourse();
             $account_id = $course->account_id;
             $account = $roots->getAccount($account_id);
             $courseId = $_SESSION['courseID'];
             $_SESSION['timezone'] = new \DateTimeZone($account->default_time_zone);
             //to maintain the users table synchronized with Canvas, everytime a student comes in we'll check to make sure they're in the DB.
             //If they're not, we will pull all the students from Canvas and refresh our users table.
             $dbHelper = new DbHelper();
             $user = $dbHelper->getUserInCourse($courseId, $_SESSION['userID']);
             if (is_null($user)) {
                 //get all students from Canvas
                 $roots = new Roots();
                 $roots->getStudentsInCourse();
             }
             //Also, every so often (every 12 hrs?) we will check to make sure that students who have dropped the class are deleted from the users_course table
             //Failing to do so will make it so that when we request their submissions along with other students' submissions, the entire
             // call returns with an Unauthorized error message
             $approver = $dbHelper->getCourseApprover($courseId);
             $now = Carbon::now();
             $updatedDate = $approver->updated_at;
             $diff = $updatedDate->diffInHours($now, false);
             if ($diff > 24) {
                 $allStudentsDb = $dbHelper->getUsersInCourseWithRole($_SESSION['courseID'], 'Learner');
                 $allStudentsFromCanvas = $roots->getStudentsInCourse();
                 foreach ($allStudentsDb as $dbStudent) {
                     $filteredItems = array_values(array_filter($allStudentsFromCanvas, function ($elem) use($dbStudent) {
                         return intval($elem->user_id) === intval($dbStudent->user_id);
                     }));
                     if (count($filteredItems) < 1) {
                         $dbHelper->deleteUserFromRole($courseId, $dbStudent->user_id, 'Learner');
                     }
                 }
                 //update the approver
                 $approver->updated_at = $now;
                 $approver->save();
             }
         }
     } else {
         echo 'There is a problem. Please notify your instructor';
     }
 }