Skip to content

Commit

Permalink
Merge pull request #1158 from stefk/activity-evaluation
Browse files Browse the repository at this point in the history
Dispatch an event on activity evaluation
  • Loading branch information
ngodfraind committed Apr 28, 2015
2 parents 7614981 + 38debd1 commit 2fa5b4e
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 501 deletions.
20 changes: 3 additions & 17 deletions Controller/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,11 @@ public function displayActivityEvaluationAction(
ActivityParameters $params
)
{
$evaluation = $this->activityManager
->getEvaluationByUserAndActivityParams($currentUser, $params);
$evaluation =
$this->activityManager->getEvaluationByUserAndActivityParams($currentUser, $params) ?:
$this->activityManager->createBlankEvaluation($currentUser, $params);
$pastEvals = $this->activityManager
->getPastEvaluationsByUserAndActivityParams($currentUser, $params);

if (is_null($evaluation)) {
$evaluationType = $params->getEvaluationType();
$status = ($evaluationType === 'automatic') ?
'not_attempted' :
null;

$evaluation = $this->activityManager->createEvaluation(
$currentUser,
$params,
null,
null,
$status
);
}
$ruleScore = null;
$isResultVisible = false;

Expand Down
61 changes: 20 additions & 41 deletions Controller/WorkspaceAnalyticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Claroline\CoreBundle\Controller;

use Claroline\CoreBundle\Entity\Activity\AbstractEvaluation;
use Claroline\CoreBundle\Entity\Activity\ActivityParameters;
use Claroline\CoreBundle\Entity\Resource\Activity;
use Claroline\CoreBundle\Entity\User;
Expand Down Expand Up @@ -166,9 +167,9 @@ public function workspaceActivitiesEvaluationsShowAction(
)
{
if (!$this->securityContext->isGranted('analytics', $workspace)) {

throw new AccessDeniedException();
}

$roleNames = $currentUser->getRoles();
$isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);

Expand Down Expand Up @@ -240,23 +241,12 @@ public function workspaceActivitiesEvaluationsShowAction(
$evaluationType = $params->getEvaluationType();

if (!isset($evaluationsAssoc[$activity->getId()])) {
$status = ($evaluationType === 'automatic') ?
'not_attempted' :
null;

$evaluation = $this->activityManager->createEvaluation(
$currentUser,
$params,
null,
null,
$status
);
$evaluationsAssoc[$activity->getId()] = $evaluation;
$evaluationsAssoc[$activity->getId()] = $this->activityManager
->createBlankEvaluation($currentUser, $params);
}

if ($evaluationType === 'automatic' &&
count($params->getRules()) > 0) {

if ($evaluationType === AbstractEvaluation::TYPE_AUTOMATIC
&& count($params->getRules()) > 0) {
$rule = $params->getRules()->first();
$isResultVisible = $rule->getIsResultVisible();

Expand All @@ -276,9 +266,10 @@ public function workspaceActivitiesEvaluationsShowAction(
}
}

if ($evaluationsAssoc[$activity->getId()]->getStatus() === 'completed' ||
$evaluationsAssoc[$activity->getId()]->getStatus() === 'passed') {
$status = $evaluationsAssoc[$activity->getId()]->getStatus();

if ($status === AbstractEvaluation::STATUS_COMPLETED
|| $status === AbstractEvaluation::STATUS_PASSED) {
$nbSuccess++;
}
}
Expand Down Expand Up @@ -356,9 +347,8 @@ public function workspaceActivitiesPastEvaluationsShowAction(
$ruleScore = null;
$isResultVisible = false;

if ($activityParameters->getEvaluationType() === 'automatic' &&
count($activityParameters->getRules()) > 0) {

if ($activityParameters->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC
&& count($activityParameters->getRules()) > 0) {
$rule = $activityParameters->getRules()->first();
$score = $rule->getResult();
$scoreMax = $rule->getResultMax();
Expand Down Expand Up @@ -423,9 +413,9 @@ public function workspaceManagerActivityEvaluationsShowAction(
$isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);

if (!$isWorkspaceManager) {

throw new AccessDeniedException();
}

$resourceNode = $activity->getResourceNode();
$activityParams = $activity->getParameters();
$roles = $this->roleManager
Expand All @@ -437,6 +427,7 @@ public function workspaceManagerActivityEvaluationsShowAction(
foreach ($usersPager as $user) {
$users[] = $user;
}

$allEvaluations = $this->activityManager
->getEvaluationsByUsersAndActivityParams($users, $activityParams);
$evaluations = array();
Expand All @@ -449,26 +440,15 @@ public function workspaceManagerActivityEvaluationsShowAction(
$nbSuccess = 0;

foreach ($users as $user) {

if (!isset($evaluations[$user->getId()])) {
$evaluationType = $activityParams->getEvaluationType();
$status = ($evaluationType === 'automatic') ?
'not_attempted' :
null;

$evaluation = $this->activityManager->createEvaluation(
$user,
$activityParams,
null,
null,
$status
);
$evaluations[$user->getId()] = $evaluation;
$evaluations[$user->getId()] = $this->activityManager
->createBlankEvaluation($user, $activityParams);
}

if ($evaluations[$user->getId()]->getStatus() === 'completed' ||
$evaluations[$user->getId()]->getStatus() === 'passed') {
$status = $evaluations[$user->getId()]->getStatus();

if ($status === AbstractEvaluation::STATUS_COMPLETED
|| $status === AbstractEvaluation::STATUS_PASSED) {
$nbSuccess++;
}
}
Expand All @@ -478,9 +458,8 @@ public function workspaceManagerActivityEvaluationsShowAction(

$ruleScore = null;

if ($activityParams->getEvaluationType() === 'automatic' &&
count($activityParams->getRules()) > 0) {

if ($activityParams->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC
&& count($activityParams->getRules()) > 0) {
$rule = $activityParams->getRules()->first();
$score = $rule->getResult();
$scoreMax = $rule->getResultMax();
Expand Down
207 changes: 207 additions & 0 deletions Entity/Activity/AbstractEvaluation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<?php

/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\CoreBundle\Entity\Activity;

use Claroline\CoreBundle\Entity\Log\Log;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass
*/
class AbstractEvaluation
{
const TYPE_AUTOMATIC = 'automatic';
const TYPE_MANUAL = 'manual';

const STATUS_PASSED = 'passed';
const STATUS_FAILED = 'failed';
const STATUS_COMPLETED = 'completed';
const STATUS_INCOMPLETE = 'incomplete';
const STATUS_NOT_ATTEMPTED = 'not_attempted';
const STATUS_UNKNOWN = 'unknown';

/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(name="evaluation_type", nullable=true)
*/
protected $type;

/**
* @ORM\Column(name="evaluation_status", nullable=true)
*/
protected $status;

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $duration;

/**
* @ORM\Column(nullable=true)
*/
protected $score;

/**
* @ORM\Column(name="score_num", type="integer", nullable=true)
*/
protected $numScore;

/**
* @ORM\Column(name="score_min", type="integer", nullable=true)
*/
protected $scoreMin;

/**
* @ORM\Column(name="score_max", type="integer", nullable=true)
*/
protected $scoreMax;

/**
* @ORM\Column(name="evaluation_comment", nullable=true)
*/
protected $comment;

/**
* @ORM\Column(type="json_array", nullable=true)
*/
protected $details;

/**
* @ORM\ManyToOne(targetEntity="Claroline\CoreBundle\Entity\Log\Log")
* @ORM\JoinColumn(onDelete="SET NULL")
*/
protected $log;

public function getId()
{
return $this->id;
}

public function getType()
{
return $this->type;
}

public function setType($type)
{
$this->type = $type;
}

public function getStatus()
{
return $this->status;
}

public function setStatus($status)
{
$this->status = $status;
}

public function getDuration()
{
return $this->duration;
}

public function setDuration($duration)
{
$this->duration = $duration;
}

public function getScore()
{
return $this->score;
}

public function setScore($score)
{
$this->score = $score;
}

public function getNumScore()
{
return $this->numScore;
}

public function setNumScore($numScore)
{
$this->numScore = $numScore;
}

public function getScoreMin()
{
return $this->scoreMin;
}

public function setScoreMin($scoreMin)
{
$this->scoreMin = $scoreMin;
}

public function getScoreMax()
{
return $this->scoreMax;
}

public function setScoreMax($scoreMax)
{
$this->scoreMax = $scoreMax;
}

public function getComment()
{
return $this->comment;
}

public function setComment($comment)
{
$this->comment = $comment;
}

public function getDetails()
{
return $this->details;
}

public function setDetails($details)
{
$this->details = $details;
}

public function getLog()
{
return $this->log;
}

public function setLog(Log $log)
{
$this->log = $log;
}

public function isTerminated()
{
return $this->status !== self::STATUS_NOT_ATTEMPTED
&& $this->status !== self::STATUS_INCOMPLETE
&& $this->status !== self::STATUS_UNKNOWN;
}

public function isSuccessful()
{
return $this->status === self::STATUS_PASSED
|| $this->status === self::STATUS_COMPLETED;
}
}
Loading

0 comments on commit 2fa5b4e

Please sign in to comment.