/** * Delete */ public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $milestoneId) { if (!($milestone = Model::find($milestoneId))) { continue; } $milestone->delete(); } Flash::success("Successfully deleted"); } else { Flash::error("An error occurred when trying to delete this item"); } return $this->listRefresh(); }
public function onRun() { $instance = GradeModel::find($this->property('gradeInstance')); if (!is_null($this->property('experienceInstance'))) { $experienceInstance = ExperienceModel::find($this->property('experienceInstance')); $exComp = new ExperienceComponent(); //set class variables $stDate = new DateTime($experienceInstance->start_date); $endDate = new DateTime($experienceInstance->end_date); $ptsPerSecond = $exComp->getPtsPerSecond($stDate, $endDate, $experienceInstance->total_points); $exComp->setPtsPerSecond($ptsPerSecond); $exComp->setStartDate($stDate); $exComp->setBonusPerSecond($experienceInstance->bonus_per_day / 24 / 60 / 60); $exComp->setBonusSeconds($experienceInstance->bonus_days * 24 * 60 * 60); $exComp->setPenaltyPerSecond($experienceInstance->penalty_per_day / 24 / 60 / 60); $exComp->setPenaltySeconds($experienceInstance->penalty_days * 24 * 60 * 60); $points = $exComp->getUserPoints(); $milestonesDesc = Milestone::where('experience_id', '=', $experienceInstance->id)->orderBy('points', 'desc')->get(); $mileClearance = $exComp->getMilestoneClearanceInfo($milestonesDesc); $bonusPenalties = 0; foreach ($mileClearance as $item) { if ($item->cleared) { $bonusPenalties = $bonusPenalties + $item->bonusPenalty; } } $this->page['XP'] = round($points, 2); $this->page['gradeBonus'] = round($bonusPenalties, 2); } else { $this->page['XP'] = 0; $this->page['gradeBonus'] = 0; } //todo: get the bonus, etc from blade, not from experience $this->page['gradeSize'] = $instance->Size; $this->getGradeData(); $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"); }
public function getMilestoneClearanceInfo($experienceInstanceId) { $this->initVariables($experienceInstanceId); $milestonesDesc = Milestone::where('experience_id', '=', $experienceInstanceId)->orderBy('points', 'desc')->get(); $localMilestones = $milestonesDesc; //order submissions by date usort($this->submissions, function ($a, $b) { $ad = new DateTime($a['submitted_at']); $bd = new DateTime($b['submitted_at']); if ($ad == $bd) { return 0; } return $ad > $bd ? 1 : -1; }); $milestoneInfo = array(); $carryingScore = 0; foreach ($this->submissions as $submission) { $carryingScore = $carryingScore + intval($submission['score']); foreach ($localMilestones as $key => $mile) { if ($carryingScore >= $mile->points) { $mileClearance = new \stdClass(); $mileClearance->milestone_id = $mile->id; $mileClearance->name = $mile->name; $mileClearance->cleared = 1; $mileClearance->cleared_at = $submission['submitted_at']; $mileClearance->bonusPenalty = $this->calculateBonusOrPenalty($mile->points, new DateTime($submission['submitted_at'])); $mileClearance->points = $mile->points; $mileClearance->due_at = $this->calculateMilestoneDueDate($mile->points); $milestoneInfo[] = $mileClearance; unset($localMilestones[$key]); } } } //sort the remaining milestones by points asc $mileArray = $milestonesDesc->toArray(); usort($mileArray, function ($a, $b) { $ad = $a['points']; $bd = $b['points']; if ($ad == $bd) { return 0; } return $ad > $bd ? 1 : -1; }); foreach ($mileArray as $left) { //for the milestones that were left $mileClearance = new \stdClass(); $mileClearance->milestone_id = $left['id']; $mileClearance->name = $left['name']; $mileClearance->cleared = 0; $mileClearance->cleared_at = null; $mileClearance->bonusPenalty = $this->calculateBonusOrPenalty($left['points'], new DateTime('now')); $mileClearance->points = $left['points']; $date = $this->calculateMilestoneDueDate($left['points']); $mileClearance->due_at = $date; $milestoneInfo[] = $mileClearance; } return $milestoneInfo; }
public function getMilestoneClearanceInfo() { $this->submissions = $this->getSubmissions(); $instanceId = \Input::get('experienceInstanceId'); $this->instance = ExperienceModel::find($instanceId); $stDate = new DateTime($this->instance->start_date); $endDate = new DateTime($this->instance->end_date); $this->startDate = $stDate; $this->endDate = $endDate; $this->ptsPerSecond = $this->getPtsPerSecond($stDate, $endDate, $this->instance->total_points); $this->penaltySeconds = $this->instance->penalty_days * 24 * 60 * 60; $this->penaltyPerSecond = $this->instance->penalty_per_day / 24 / 60 / 60; //convert it to milliseconds $this->bonusSeconds = $this->instance->bonus_days * 24 * 60 * 60; $this->bonusPerSecond = $this->instance->bonus_per_day / 24 / 60 / 60; $localMilestones = Milestone::where('experience_id', '=', $instanceId)->orderBy('points', 'desc')->get(); //order submissions by date usort($this->submissions, function ($a, $b) { $ad = new DateTime($a['submitted_at']); $bd = new DateTime($b['submitted_at']); if ($ad == $bd) { return 0; } return $ad > $bd ? 1 : -1; }); $milestoneInfo = array(); $carryingScore = 0; foreach ($this->submissions as $submission) { $carryingScore = $carryingScore + intval($submission['score']); foreach ($localMilestones as $key => $mile) { if ($carryingScore >= $mile->points) { $mileClearance = new \stdClass(); $mileClearance->milestone_id = $mile->id; $mileClearance->name = $mile->name; $mileClearance->cleared = 1; $mileClearance->cleared_at = $submission['submitted_at']; $mileClearance->bonusPenalty = $this->calculateBonusOrPenalty($mile->points, new DateTime($submission['submitted_at'])); $mileClearance->points = $mile->points; $mileClearance->due_at = $this->calculateMilestoneDueDate($mile->points); $milestoneInfo[] = $mileClearance; unset($localMilestones[$key]); } } } //sort the remaining milestones by points asc $mileArray = $localMilestones->toArray(); usort($mileArray, function ($a, $b) { $ad = $a['points']; $bd = $b['points']; if ($ad == $bd) { return 0; } return $ad > $bd ? 1 : -1; }); foreach ($mileArray as $left) { //for the milestones that were left $mileClearance = new \stdClass(); $mileClearance->milestone_id = $left['id']; $mileClearance->name = $left['name']; $mileClearance->cleared = 0; $mileClearance->cleared_at = null; $mileClearance->bonusPenalty = $this->calculateBonusOrPenalty($left['points'], new DateTime('now')); $mileClearance->points = $left['points']; $date = $this->calculateMilestoneDueDate($left['points']); $mileClearance->due_at = $date; $milestoneInfo[] = $mileClearance; } return $milestoneInfo; }
public function onRun() { try { $this->addJs("/plugins/delphinium/blossom/assets/javascript/d3.min.js"); $this->addJs("/plugins/delphinium/blossom/assets/javascript/experience.js"); $this->addCss("/plugins/delphinium/blossom/assets/css/experience.css"); $this->addCss("/plugins/delphinium/blossom/assets/css/main.css"); $this->addCss("/plugins/delphinium/blossom/assets/css/font-awesome.min.css"); $this->roots = new Roots(); $instance = ExperienceModel::find($this->property('Instance')); $milestonesDesc = Milestone::where('experience_id', '=', $instance->id)->orderBy('points', 'desc')->get(); $milestonesAsc = Milestone::where('experience_id', '=', $instance->id)->orderBy('points', 'asc')->get(); $milestoneArr = array(); foreach ($milestonesAsc as $item) { $milestoneArr[] = $item->name; } //set class variables $stDate = new DateTime($instance->start_date); $endDate = new DateTime($instance->end_date); $this->startDate = $stDate; $this->endDate = $endDate; $this->submissions = $this->getSubmissions(); $this->ptsPerSecond = $this->getPtsPerSecond($stDate, $endDate, $instance->total_points); $this->penaltySeconds = $instance->penalty_days * 24 * 60 * 60; $this->penaltyPerSecond = $instance->penalty_per_day / 24 / 60 / 60; //convert it to milliseconds $this->bonusSeconds = $instance->bonus_days * 24 * 60 * 60; $this->bonusPerSecond = $instance->bonus_per_day / 24 / 60 / 60; //set page variables $this->page['numMilestones'] = count($milestonesDesc); $this->page['encouragement'] = json_encode($milestoneArr); $this->page['experienceXP'] = $this->getUserPoints(); //current points $this->page['maxXP'] = $instance->total_points; //total points for this experience $this->page['startDate'] = $instance->start_date; $this->page['endDate'] = $instance->end_date; $this->page['experienceSize'] = $instance->size; $this->page['experienceAnimate'] = $instance->animate; $redLine = $this->calculateRedLine($this->startDate, $this->endDate, $instance->total_points); //up to here good $this->page['redLine'] = $redLine; $milestoneClearanceInfo = $this->getMilestoneClearanceInfo($milestonesDesc); $this->page['milestoneClearance'] = json_encode($milestoneClearanceInfo); $this->page['studentScores'] = json_encode($this->getAllStudentScores()); $bonus = 0; $penalties = 0; foreach ($milestoneClearanceInfo as $item) { if ($item->bonusPenalty > 0 && $item->cleared) { $bonus = $bonus + $item->bonusPenalty; } else { if ($item->bonusPenalty < 0 && $item->cleared) { $penalties = $penalties + $item->bonusPenalty; } } } $this->page['experienceGrade'] = round($this->getUserPoints() + $bonus + $penalties, 2); //? $this->page['experienceBonus'] = $bonus; $this->page['experiencePenalties'] = $penalties; /* //run rules $cType = ComponentTypes::where(array('type' => 'experience'))->first(); $componentRules = ComponentRules::where(array('component_id' => $cType->id)); $source = new DataSource(false); if(!isset($_SESSION)) { session_start(); } $userId = $_SESSION['userID']; $params = array('student_ids'=>$userId, '$all_assignments'=>true, 'fresh_data'=>0, 'prettyprint'=>1, 'rg'=>'experience'); echo json_encode($source->getMultipleSubmissions($params)); //calculated variables $this->page['milestone_status']= array(); * */ } catch (\GuzzleHttp\Exception\ClientException $e) { echo "You must be a student to use this app, or go into 'Student View'. " . "Also, make sure that an Instructor has approved this application"; return; } }