Updating from min branch

skala
Julio Montoya 12 years ago
parent 4b13dee45d
commit 3bc5b206f1
  1. 81
      src/ChamiloLMS/Controller/Admin/Administrator/BranchController.php
  2. 22
      src/ChamiloLMS/Controller/Admin/Administrator/JuryController.php
  3. 108
      src/ChamiloLMS/Controller/Admin/Director/BranchDirectorController.php
  4. 288
      src/ChamiloLMS/Controller/Admin/JuryMember/JuryMemberController.php
  5. 171
      src/ChamiloLMS/Controller/Admin/JuryPresident/JuryPresidentController.php
  6. 25
      src/ChamiloLMS/Controller/IndexController.php
  7. 2
      src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumController.php
  8. 3
      src/ChamiloLMS/Form/JuryMembersType.php

@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Entity;
use ChamiloLMS\Form\BranchType;
use ChamiloLMS\Form\BranchUsersType;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
@ -38,8 +39,9 @@ class BranchController extends CommonController
$addChildren = '<a class="btn" href="'.$this->createUrl('add_from_parent_link', array('id' => $row['id'])).'">Add children</a>';
$readLink = '<a href="'.$this->createUrl('read_link', array('id' => $row['id'])).'">'.$row['branchName'].'</a>';
$editLink = '<a class="btn" href="'.$this->createUrl('update_link', array('id' => $row['id'])).'">Edit</a>';
$addDirector = '<a class="btn" href="'.$this->generateUrl('branch.controller:addDirectorAction', array('id' => $row['id'])).'">Add director</a>';
$deleteLink = '<a class="btn" href="'.$this->createUrl('delete_link', array('id' => $row['id'])).'"/>Delete</a>';
return $readLink.' '.$addChildren.' '.$editLink.' '.$deleteLink;
return $readLink.' '.$addChildren.' '.$addDirector.' '.$editLink.' '.$deleteLink;
}
//'representationField' => 'slug',
//'html' => true
@ -63,6 +65,83 @@ class BranchController extends CommonController
return new Response($response, 200, array());
}
/**
*
* @Route("/{id}/add-director", requirements={"id" = "\d+"})
* @Method({"GET"})
*/
public function addDirectorAction($id)
{
$extraJS[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$type = new BranchUsersType();
$branchUsers = new Entity\BranchUsers();
$form = $this->createForm($type, $branchUsers);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bind($request);
if ($form->isValid()) {
$item = $form->getData();
$userIdList = $item->getUserId();
$userId = ($userIdList[0]);
$user = $this->getManager()->getRepository('Entity\User')->find($userId);
if (!$user) {
throw new \Exception('Unable to found User');
}
$branch = $this->getRepository()->find($id);
if (!$branch) {
throw new \Exception('Unable to found branch');
}
$branchUsers->setUser($user);
$branchUsers->setBranch($branch);
$em = $this->getManager();
$em->persist($branchUsers);
$em->flush();
$this->get('session')->getFlashBag()->add('success', "Saved");
$url = $this->get('url_generator')->generate('branch.controller:readAction', array('id' => $id));
return $this->redirect($url);
}
}
$template = $this->get('template');
$template->assign('form', $form->createView());
$template->assign('id', $id);
$response = $template->render_template($this->getTemplatePath().'add_director.tpl');
return new Response($response, 200, array());
}
/**
*
* @Route("/{id}/remove-director/{userId}", requirements={"id" = "\d+"})
* @Method({"GET"})
*/
public function removeDirectorAction($id, $userId)
{
$criteria = array(
'branchId' => $id,
'userId' => $userId
);
$branchUser = $this->getManager()->getRepository('Entity\BranchUsers')->findOneBy($criteria);
if (!$branchUser) {
$this->createNotFoundException();
}
$this->getManager()->remove($branchUser);
$this->getManager()->flush();
$url = $this->createUrl('read_link', array('id' => $id));
$this->get('session')->getFlashBag()->add('success', "User removed");
return $this->redirect($url);
}
/**
*
* @Route("/{id}", requirements={"id" = "\d+"})

@ -105,9 +105,17 @@ class JuryController extends CommonController
{
$request = $this->getRequest();
$keyword = $request->get('tag');
$repo = $this->get('orm.em')->getRepository('Entity\User');
$entities = $repo->searchUserByKeyword($keyword);
$role = $request->get('role');
/** @var Entity\Repository\UserRepository $repo */
$repo = $this->getManager()->getRepository('Entity\User');
if (empty($role)) {
$entities = $repo->searchUserByKeyword($keyword);
} else {
$entities = $repo->searchUserByKeywordAndRole($keyword, $role);
}
$data = array();
if ($entities) {
/** @var \Entity\User $entity */
@ -127,16 +135,16 @@ class JuryController extends CommonController
*/
public function addMembersAction(Application $app, $id)
{
$extraJS[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$extraJS[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$extraJS = array(
'<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />',
'<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript"></script>'
);
$app['extraJS'] = $extraJS;
$juryUserType = new JuryMembersType();
$juryMember = new Entity\JuryMembers();
$juryMember->setJuryId($id);
$form = $this->get('form.factory')->create($juryUserType, $juryMember);
$form = $this->createForm($juryUserType, $juryMember);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bind($request);

@ -5,6 +5,8 @@ namespace ChamiloLMS\Controller\Admin\Director;
use ChamiloLMS\Controller\CommonController;
use ChamiloLMS\Form\BranchType;
use ChamiloLMS\Form\DirectorJuryUserType;
use ChamiloLMS\Form\JuryType;
use Entity;
use Silex\Application;
@ -28,12 +30,7 @@ class BranchDirectorController extends CommonController
*/
public function indexAction()
{
$token = $this->get('security')->getToken();
if (null !== $token) {
$user = $token->getUser();
$userId = $user->getUserId();
}
$userId = $this->getUser()->getUserId();
$options = array(
'decorate' => true,
@ -41,10 +38,31 @@ class BranchDirectorController extends CommonController
'rootClose' => '</ul>',
'childOpen' => '<li>',
'childClose' => '</li>',
'nodeDecorator' => function($row) {
//$addChildren = '<a class="btn" href="'.$this->createUrl('add_from_parent_link', array('id' => $row['id'])).'">Add children</a>';
$readLink = $row['branchName'].' <a class="btn" href="'.$this->createUrl('read_link', array('id' => $row['id'])).'">Assign users</a>';
return $readLink;
'nodeDecorator' => function ($row) {
/** @var Entity\BranchSync $branch */
$branch = $this->getManager()->getRepository('Entity\BranchSync')->find($row['id']);
$juries = $branch->getJuries();
/** @var Entity\Jury $jury */
$juryList = null;
foreach ($juries as $jury) {
$juryId = $jury->getId();
$url = $this->generateUrl(
'branch_director.controller:listUsersAction',
array('juryId' => $juryId, 'branchId' => $row['id'])
);
$viewUsers = ' <a class="btn" href="'.$url.'">User list</a>';
$url = $this->generateUrl(
'branch_director.controller:addUsersAction',
array('juryId' => $juryId, 'branchId' => $row['id'])
);
$addUserLink = ' <a class="btn" href="'.$url.'">Add users</a>';
$juryList .= $jury->getName() . ' '.$addUserLink.$viewUsers.'<br />';
}
return $row['branchName'].' <br />'.$juryList;
}
//'representationField' => 'slug',
//'html' => true
@ -57,6 +75,9 @@ class BranchDirectorController extends CommonController
->createQueryBuilder()
->select('node')
->from('Entity\BranchSync', 'node')
->innerJoin('node.users', 'u')
->where('u.userId = :userId')
->setParameter('userId', $userId)
->orderBy('node.root, node.lft', 'ASC')
->getQuery();
@ -83,13 +104,14 @@ class BranchDirectorController extends CommonController
$item = $this->getEntity($id);
$template->assign('item', $item);
$form = $this->get('form.factory')->create(new JuryType());
$form = $this->createForm(new JuryType());
if ($request->getMethod() == 'POST') {
if ($request->isMethod('POST')) {
$form->bind($this->getRequest());
if ($form->isValid()) {
}
}
@ -98,17 +120,71 @@ class BranchDirectorController extends CommonController
return new Response($response, 200, array());
}
private function saveUsers()
/**
*
* @Route("branches/{branchId}/jury/{juryId}/add-user")
* @Method({"GET"})
*/
public function addUsersAction($juryId, $branchId)
{
$template = $this->get('template');
$request = $this->getRequest();
}
$type = new DirectorJuryUserType();
private function getUserFormType($users)
{
$user = new Entity\User();
$form = $this->createForm($type, $user);
$form->handleRequest($request);
if ($form->isValid()) {
$jury = $this->getManager()->getRepository('Entity\Jury')->find($juryId);
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$pass = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($pass);
$user->setStatus(STUDENT);
$user->setChatcallUserId(0);
$user->setChatcallDate(null);
$user->setCurriculumItems(null);
$user->setChatcallText(' ');
$user->setActive(true);
$em = $this->getManager();
$em->persist($user);
$user->getUserId();
$role = current($user->getRoles());
$juryMember = new Entity\JuryMembers();
$juryMember->setJury($jury);
$juryMember->setRole($role);
$juryMember->setUser($user);
$em->persist($juryMember);
$em->flush();
$this->get('session')->getFlashBag()->add('success', "User saved");
//return $this->redirect($url);
}
$template->assign('form', $form->createView());
$template->assign('juryId', $juryId);
$template->assign('branchId', $branchId);
$response = $template->render_template($this->getTemplatePath().'add_user.tpl');
return new Response($response, 200, array());
}
/**
*
* @Route("branches/{branchId}/jury/{juryId}/list-user")
* @Method({"GET"})
*/
public function listUsersAction()
{
}
protected function getControllerAlias()
{

@ -9,18 +9,20 @@ use Entity;
use Silex\Application;
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
/**
* Class RoleController
* @todo @route and @method function don't work yet
* Class JuryMemberController
* @package ChamiloLMS\Controller
* @author Julio Montoya <gugli100@gmail.com>
*/
class JuryMemberController extends CommonController
{
public $maxCountOfMemberToVoteToConsiderEvaluated = 3;
/**
* @Route("/")
* @Method({"GET"})
@ -37,43 +39,195 @@ class JuryMemberController extends CommonController
*/
public function listUsersAction()
{
$userId = $this->getUser()->getUserId();
/** @var Entity\Jury $jury */
$jury = $this->getRepository()->getJuryByUserId($userId);
if (!$jury) {
$this->get('session')->getFlashBag()->add('warning', "No tiene un comité asignado.");
$url = $this->get('url_generator')->generate('jury_president.controller:indexAction');
return $this->redirect($url);
}
$attempts = $jury->getExerciseAttempts();
// @todo move logic in a repository
/** @var Entity\TrackExercise $attempt */
$relations = array();
$myStudentStatus = array();
foreach ($attempts as $attempt) {
$user = $attempt->getUser();
$juryAttempts = $attempt->getJuryAttempts();
/** @var Entity\TrackExerciseAttemptJury $juryAttempt */
$tempAttempt = array();
foreach ($juryAttempts as $juryAttempt) {
if (!isset($tempAttempt[$juryAttempt->getJuryUserId()])) {
$tempAttempt[$juryAttempt->getJuryUserId()] = 1;
} else {
$tempAttempt[$juryAttempt->getJuryUserId()]++;
}
}
$juryCorrections = 1;
foreach ($tempAttempt as $memberId => $answerCount) {
$relations[$attempt->getExeId()][$user->getUserId()][$memberId] = $answerCount;
// the jury_member correct the attempt
if (!empty($answerCount) && $userId == $memberId) {
$myStudentStatus[$attempt->getExeId()][$user->getUserId()] = true;
}
$juryCorrections++;
}
}
$members = $jury->getMembers();
/** @var Entity\JuryMembers $member */
$studentsByMember = array();
foreach ($members as $member) {
$students = $member->getStudents();
foreach ($students as $student) {
$studentsByMember[$member->getUserId()][] = $student->getUserId();
}
}
$template = $this->get('template');
$template->assign('my_student_status', $myStudentStatus);
$template->assign('relations', $relations);
$template->assign('attempts', $attempts);
$template->assign('members', $members);
$template->assign('students_by_member', $studentsByMember);
$template->assign('considered_evaluated', $this->maxCountOfMemberToVoteToConsiderEvaluated);
$template->assign('jury', $jury);
$response = $template->render_template($this->getTemplatePath().'assign_members.tpl');
return new Response($response, 200, array());
}
/**
* @Route("/score-user/{exeId}")
* @Route("/score-attempt/{exeId}/jury/{juryId}")
* @Method({"GET"})
*/
public function scoreUserAction($exeId)
public function scoreAttemptAction($exeId, $juryId)
{
$userId = $this->getUser()->getUserId();
$trackExercise = \ExerciseLib::get_exercise_track_exercise_info($exeId);
if (empty($trackExercise)) {
$this->createNotFoundException();
}
/** @var \Entity\Jury $jury */
$jury = $this->getRepository()->find($juryId);
if (empty($jury)) {
$this->createNotFoundException('Jury does not exists');
}
if ($jury->getExerciseId() != $trackExercise['exe_exo_id']) {
$this->createNotFoundException('Exercise attempt is not related with this jury.');
}
$members = $jury->getMembers();
$criteria = Criteria::create()
->where(Criteria::expr()->eq("userId", $userId))
->setFirstResult(0)
->setMaxResults(1);
/** @var Entity\JuryMembers $member */
$member = $members->matching($criteria)->first();
if (empty($member)) {
$this->createNotFoundException('You are not part of the jury.');
}
$students = $member->getStudents();
$criteria = Criteria::create()
->where(Criteria::expr()->eq("userId", $trackExercise['exe_user_id']))
->setFirstResult(0)
->setMaxResults(1);
/** @var Entity\JuryMembers $member */
$student = $students->matching($criteria)->first();
if (empty($student)) {
$this->createNotFoundException('You are not assigned to this user.');
}
$security = $this->get('security');
// Setting member only for president.
if ($security->isGranted('ROLE_JURY_PRESIDENT')) {
// Relating user with president
if ($member) {
$this->getManager()->getRepository('Entity\JuryMembers')->assignUserToJuryMember(
$trackExercise['exe_user_id'],
$member->getId()
);
}
}
$questionScoreTypeModel = array();
$criteria = array(
'exeId' => $exeId,
'juryUserId' => $userId
);
$trackJury = $this->getManager()->getRepository('Entity\TrackExerciseAttemptJury')->findBy($criteria);
if ($trackJury) {
$this->get('session')->getFlashBag()->add('info', "You already review this exercise attempt.");
/** @var Entity\TrackExerciseAttemptJury $track */
foreach ($trackJury as $track) {
$questionScoreTypeModel[$track->getQuestionId()] = $track->getQuestionScoreNameId();
}
}
$questionList = explode(',', $trackExercise['data_tracking']);
$exerciseResult = \ExerciseLib::getExerciseResult($trackExercise);
$counter = 1;
$objExercise = new \Exercise();
$objExercise = new \Exercise($trackExercise['c_id']);
$objExercise->read($trackExercise['exe_exo_id']);
$show_results = true;
$totalScore = $totalWeighting = 0;
$show_media = true;
$tempParentId = null;
$mediaCounter = 0;
$media_list = array();
$modelType = $objExercise->getScoreTypeModel();
$options = array();
if ($modelType) {
/** @var \Entity\QuestionScore $questionScoreName */
$questionScore = $this->get('orm.em')->getRepository('Entity\QuestionScore')->find($modelType);
if ($questionScore) {
$items = $questionScore->getItems();
/** @var \Entity\QuestionScoreName $score */
foreach ($items as $score) {
$options[$score->getId().':'.$score->getScore()] = $score;
}
}
} else {
return $this->createNotFoundException('The exercise does not contain a model type.');
}
$exerciseContent = null;
foreach ($questionList as $questionId) {
ob_start();
$choice = $exerciseResult[$questionId];
$choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : null;
// Creates a temporary Question object
/** @var \Question $objQuestionTmp */
$objQuestionTmp = \Question::read($questionId);
if ($objQuestionTmp->parent_id != 0) {
@ -94,7 +248,17 @@ class JuryMemberController extends CommonController
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$question_result = $objExercise->manageAnswers($exeId, $questionId, $choice,'exercise_show', array(), false, true, $show_results);
$question_result = $objExercise->manageAnswers(
$exeId,
$questionId,
$choice,
'exercise_show',
array(),
false,
true,
true
);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -103,23 +267,42 @@ class JuryMemberController extends CommonController
$totalWeighting += $questionWeighting;
$score = array();
if ($show_results) {
$score['result'] = get_lang('Score')." : ".\ExerciseLib::show_score($my_total_score, $my_total_weight, false, false);
$score['pass'] = $my_total_score >= $my_total_weight ? true : false;
$score['type'] = $answerType;
$score['score'] = $my_total_score;
$score['weight'] = $my_total_weight;
$score['comments'] = isset($comnt) ? $comnt : null;
}
$score['result'] = get_lang('Score')." : ".\ExerciseLib::show_score($my_total_score, $my_total_weight, false, false);
$score['pass'] = $my_total_score >= $my_total_weight ? true : false;
$score['type'] = $answerType;
$score['score'] = $my_total_score;
$score['weight'] = $my_total_weight;
$score['comments'] = isset($comnt) ? $comnt : null;
$contents = ob_get_clean();
$question_content = '<div class="question_row">';
$question_content .= $objQuestionTmp->return_header(null, $counter, $score, $show_media, $mediaCounter);
$question_content .= $objQuestionTmp->return_header($objExercise->feedback_type, $counter, $score, $show_media, $mediaCounter);
$question_content .= '</table>';
// display question category, if any
$question_content .= \Testcategory::getCategoryNamesForQuestion($questionId);
$question_content .= $contents;
$defaultValue = isset($questionScoreTypeModel[$questionId]) ? $questionScoreTypeModel[$questionId] : null;
//$question_content .= \Display::select('options['.$questionId.']', $options, $defaultValue);
foreach ($options as $value => $score) {
$attributes = array();
if ($score->getId() == $defaultValue) {
$attributes = array('checked' => 'checked');
}
$question_content .= '<label>';
$question_content .= \Display::input(
'radio',
'options['.$questionId.']',
$value,
$attributes
)
.' <span title="'.$score->getDescription().'" data-toggle="tooltip" > '.$score->getName().' </span>';
$question_content .= '</label>';
}
$question_content .= '</div>';
$exerciseContent .= $question_content;
@ -127,19 +310,72 @@ class JuryMemberController extends CommonController
}
$template = $this->get('template');
$template->assign('exercise', $exerciseContent);
$response = $this->get('template')->render_template($this->getTemplatePath().'score_user.tpl');
$template->assign('exe_id', $exeId);
$template->assign('jury_id', $juryId);
$response = $this->get('template')->render_template($this->getTemplatePath().'score_attempt.tpl');
return new Response($response, 200, array());
}
/**
* @Route("/save-score")
* @Route("/save-score/{exeId}/jury/{juryId}")
* @Method({"POST"})
*/
public function saveScoreAction()
public function saveScoreAction($exeId, $juryId)
{
$questionsAndScore = $this->getRequest()->get('options');
/** @var \Entity\TrackExercise $attempt */
$attempt = $this->getManager()->getRepository('Entity\TrackExercise')->find($exeId);
$totalScore = 0;
if ($attempt) {
$userId = $this->getUser()->getUserId();
$em = $this->getManager();
if (!empty($questionsAndScore)) {
foreach ($questionsAndScore as $questionId => $scoreInfo) {
$scoreInfo = explode(':', $scoreInfo);
$questionScoreNameId = $scoreInfo[0];
$score = $scoreInfo[1];
$criteria = array(
'exeId' => $exeId,
'questionId' => $questionId,
'juryUserId' => $userId
);
$totalScore += $score;
$obj = $this->getManager()->getRepository('Entity\TrackExerciseAttemptJury')->findOneBy($criteria);
if ($obj) {
$obj->setQuestionScoreNameId($questionScoreNameId);
$obj->setScore($score);
} else {
$obj = new Entity\TrackExerciseAttemptJury();
$obj->setJuryUserId($userId);
$obj->setAttempt($attempt);
$obj->setQuestionScoreNameId($questionScoreNameId);
$obj->setScore($score);
$obj->setQuestionId($questionId);
}
$em->persist($obj);
}
}
// Updating TrackExercise do not
$attempt->setJuryId($juryId);
//$attempt->setJuryScore($totalScore);
$em->persist($attempt);
$em->flush();
$this->get('session')->getFlashBag()->add('success', "Saved");
//$url = $this->generateUrl('jury_member.controller:scoreAttemptAction', array('exeId' => $exeId, 'juryId' => $juryId));
$url = $this->generateUrl('jury_member.controller:listUsersAction');
return $this->redirect($url);
} else {
return $this->createNotFoundException('Attempt not found');
}
}
@ -157,7 +393,7 @@ class JuryMemberController extends CommonController
}
/**
* @return \Entity\Repository\BranchSyncRepository
* @return \Entity\Repository\JuryRepository
*/
protected function getRepository()
{

@ -10,9 +10,11 @@ use Entity;
use Silex\Application;
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Whoops\Example\Exception;
/**
* Class RoleController
@ -22,6 +24,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
*/
class JuryPresidentController extends CommonController
{
public $maxCountOfMemberToVoteToConsiderEvaluated = 3;
/**
* @Route("/")
* @Method({"GET"})
@ -37,23 +40,22 @@ class JuryPresidentController extends CommonController
* @Route("/open-jury")
* @Method({"GET, POST"})
*/
public function openJuryAction(Application $app)
public function openJuryAction()
{
$token = $app['security']->getToken();
if (null !== $token) {
$user = $token->getUser();
}
$user = $this->getUser();
// @todo where is get this value?
$juryId = null;
/** @var Entity\Jury $jury */
$jury = $this->getEntity($juryId);
$jury->setOpeningDate(new \DateTime());
$jury->setOpeningUserId($user->getUserId());
$this->updateAction($jury);
$this->get('session')->getFlashBag()->add('success', "Comité abierto");
//$this->get('session')->getFlashBag()->add('success', "Comité no encontrado");
$url = $this->get('url_generator')->generate('jury_president.controller:indexAction');
return $this->redirect($url);
}
@ -64,10 +66,7 @@ class JuryPresidentController extends CommonController
*/
public function closeJuryAction(Application $app)
{
$token = $app['security']->getToken();
if (null !== $token) {
$user = $token->getUser();
}
$user = $this->getUser();
// @todo where is get this value?
$juryId = null;
@ -87,12 +86,9 @@ class JuryPresidentController extends CommonController
* @Route("/close-score")
* @Method({"GET, POST"})
*/
public function closeScoreAction(Application $app)
public function closeScoreAction()
{
$token = $app['security']->getToken();
if (null !== $token) {
$user = $token->getUser();
}
$user = $this->getUser();
// @todo where is get this value?
$juryId = null;
@ -109,20 +105,100 @@ class JuryPresidentController extends CommonController
}
/**
* @Route("/assign-members")
* @Route("/assign-user/{userId}/{juryMemberId}")
* @Method({"GET"})
*/
public function assignMembersAction()
public function assignUserToJuryMemberAction($userId, $juryMemberId)
{
$token = $this->get('security')->getToken();
return $this->getManager()->getRepository('Entity\JuryMembers')->assignUserToJuryMember($userId, $juryMemberId);
}
if (null !== $token) {
$user = $token->getUser();
$userId = $user->getUserId();
/**
* @Route("/remove-user/{userId}/{juryMemberId}")
* @Method({"GET"})
*/
public function removeUserToJuryMemberAction($userId, $juryMemberId)
{
return $this->getManager()->getRepository('Entity\JuryMembers')->removeUserToJuryMember($userId, $juryMemberId);
}
/**
* @Route("/auto-assign-users/{juryId}")
* @Method({"GET"})
*/
public function autoAssignUsersAction($juryId)
{
$userId = $this->getUser()->getUserId();
/** @var \Entity\Jury $jury */
$jury = $this->getRepository()->find($juryId);
if (empty($jury)) {
$this->createNotFoundException('Jury does not exists');
}
$members = $jury->getMembers();
$criteria = Criteria::create()
->where(Criteria::expr()->eq("userId", $userId))
->setFirstResult(0)
->setMaxResults(1);
/** @var Entity\JuryMembers $member */
$member = $members->matching($criteria)->first();
if (empty($member)) {
$this->createNotFoundException('You are not part of the jury.');
}
$exerciseAttempt = $jury->getExerciseAttempts();
$hasStudents = $this->getRepository()->getStudentsByJury($juryId);
// Nothing was saved and no assignation exists
if (empty($trackJuryAttempts) && $hasStudents == false) {
$userList = array();
/** @var Entity\TrackExercise $attempt */
foreach ($exerciseAttempt as $attempt) {
$studentId = $attempt->getExeUserId();
if (!in_array($studentId, $userList)) {
$userList[] = $attempt->getExeUserId();
}
}
$members = $jury->getMembers()->getValues();
$count = count($members);
$maxCount = $this->maxCountOfMemberToVoteToConsiderEvaluated;
if ($count < $this->maxCountOfMemberToVoteToConsiderEvaluated) {
$maxCount = $count;
}
foreach ($userList as $userId) {
$randomMembers = array_rand($members, $maxCount);
foreach ($randomMembers as $randomMember) {
$member = $members[$randomMember];
$this->getManager()->getRepository('Entity\JuryMembers')->assignUserToJuryMember($userId, $member->getId());
}
}
$this->get('session')->getFlashBag()->add('success', "Los usuarios fueron asignados al azar");
$url = $this->get('url_generator')->generate('jury_president.controller:assignMembersAction');
return $this->redirect($url);
}
}
/**
* @Route("/assign-members")
* @Method({"GET"})
*/
public function assignMembersAction()
{
$user = $this->getUser();
$userId = $user->getUserId();
/** @var Entity\Jury $jury */
$jury = $this->getRepository()->getJuryByPresidentId($userId);
$jury = $this->getRepository()->getJuryByUserId($userId);
if (!$jury) {
$this->get('session')->getFlashBag()->add('warning', "No tiene un comité asignado.");
@ -130,52 +206,67 @@ class JuryPresidentController extends CommonController
return $this->redirect($url);
}
// @todo add to a repository
// $students = $this->getRepository()->getStudentsByJury($jury->getId());
$attempts = $jury->getExerciseAttempts();
// @todo move logic in a repository
/** @var Entity\TrackExercise $attempt */
$students = array();
$relations = array();
$myStatusForStudent = array();
$globalStudentStatus = array();
$myStudentStatus = array();
foreach ($attempts as $attempt) {
$user = $attempt->getUser();
$students[] = $user;
$juryAttempts = $attempt->getJuryAttempts();
/** @var Entity\TrackExerciseAttemptJury $juryAttempt */
$tempAttempt = array();
foreach ($juryAttempts as $juryAttempt) {
if (!isset($tempAttempt[$juryAttempt->getJuryMemberId()])) {
$tempAttempt[$juryAttempt->getJuryMemberId()] = 1;
if (!isset($tempAttempt[$juryAttempt->getJuryUserId()])) {
$tempAttempt[$juryAttempt->getJuryUserId()] = 1;
} else {
$tempAttempt[$juryAttempt->getJuryMemberId()]++;
$tempAttempt[$juryAttempt->getJuryUserId()]++;
}
}
$juryCorrections = 1;
foreach ($tempAttempt as $memberId => $answerCount) {
$relations[$user->getUserId()][$memberId] = $answerCount;
if ($userId == $memberId) {
if ($answerCount == 3) {
$myStatusForStudent[$user->getUserId()] = true;
} else {
$myStatusForStudent[$user->getUserId()] = false;
}
$relations[$attempt->getExeId()][$user->getUserId()][$memberId] = $answerCount;
// the jury_member correct the attempt
if (!empty($answerCount) && $userId == $memberId) {
$myStudentStatus[$attempt->getExeId()][$user->getUserId()] = true;
}
if ($juryCorrections == $this->maxCountOfMemberToVoteToConsiderEvaluated) {
$globalStudentStatus[$user->getUserId()] = true;
} else {
$globalStudentStatus[$user->getUserId()] = false;
}
$juryCorrections++;
}
}
$members = $jury->getMembers();
/** @var Entity\JuryMembers $member */
$studentsByMember = array();
foreach ($members as $member) {
$students = $member->getStudents();
foreach ($students as $student) {
$studentsByMember[$member->getUserId()][] = $student->getUserId();
}
}
$hasStudents = $this->getRepository()->getStudentsByJury($jury->getId());
$template = $this->get('template');
$template->assign('my_status_for_student', $myStatusForStudent);
$template->assign('has_students', $hasStudents);
$template->assign('global_student_status', $globalStudentStatus);
$template->assign('my_student_status', $myStudentStatus);
$template->assign('relations', $relations);
$template->assign('attempts', $attempts);
$template->assign('members', $members);
//$template->assign('students', $students);
$template->assign('students_by_member', $studentsByMember);
$template->assign('considered_evaluated', $this->maxCountOfMemberToVoteToConsiderEvaluated);
$template->assign('jury', $jury);
$response = $template->render_template($this->getTemplatePath().'assign_members.tpl');

@ -100,31 +100,6 @@ class IndexController extends CommonController
$app['this_section'] = SECTION_CAMPUS;
$request = $app['request'];
/*
$sql = 'SELECT * from user WHERE user_id = 1';
var_dump($sql);
$result = \Database::query($sql);
var_dump(\Database::fetch_object($result));*/
// Testing translation using translator
//echo $app['translator']->trans('Wiki Search Results');
//echo $app['translator']->trans('Profile');
//$token = $app['security']->getToken();
//$article = $app['orm.em']->getRepository('Entity\Course');
//$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\Course a');
//$a = new Course();
//$article = $app['orm.em']->getRepository('Course');
//var_dump($article);
//$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\Course a');
/*
$paginator = new Doctrine\ORM\Tools\Pagination\Paginator($courses_query, $fetchJoinCollection = true);
$c = count($paginator);
foreach ($paginator as $course) {
echo $course->getCode() . "\n";
}
exit; */
if (api_get_setting('allow_terms_conditions') == 'true') {
unset($_SESSION['term_and_condition']);
}

@ -24,7 +24,7 @@ class CurriculumController extends CommonController
* @Route("/")
* @Method({"GET"})
*/
public function indexAction($course)
public function indexAction()
{
// Redirecting to curriculum user
// @todo Fix redirection

@ -29,14 +29,13 @@ class JuryMembersType extends AbstractType
$factory = $builder->getFormFactory();
// Fixes issue with the ajax select, waiting this workaround until symfony add ajax search into the core
$builder->addEventListener(FormEvents::PRE_BIND, function($event) use ($factory, $builder) {
$builder->addEventListener(FormEvents::PRE_SUBMIT, function($event) use ($factory, $builder) {
$form = $event->getForm();
$case = $event->getData();
$id = $case['user_id'][0];
if ($case) {
$form->remove('user_id');
$form->add($factory->createNamed('user_id', 'hidden', $id, array('auto_initialize' => false)));
}
});

Loading…
Cancel
Save