コード例 #1
0
 /**
  * Lists all Categories.
  *
  * @EXT\Route(
  *      "/categories/{id}",
  *      name="cpasimusante_simupoll_category_manage",
  *      requirements={},
  *      options={"expose"=true}
  * )
  * @EXT\ParamConverter("simupoll", class="CPASimUSanteSimupollBundle:Simupoll", options={"id" = "id"})
  * @EXT\Template("CPASimUSanteSimupollBundle:Category:list.html.twig")
  *
  * @param int $simupoll id of Simupoll
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Simupoll $simupoll)
 {
     $sid = $simupoll->getId();
     $tree = $this->categoryManager->getCategoryTree($simupoll, $sid);
     return array('_resource' => $simupoll, 'sid' => $sid, 'tree2' => $tree);
 }
コード例 #2
0
 /**
  * Importing Simupoll data.
  *
  * @EXT\Route("/import/{id}",  name="cpasimusante_simupoll_import", requirements={"id" = "\d+"}, options={"expose"=true})
  * @EXT\ParamConverter("simupoll", class="CPASimUSanteSimupollBundle:Simupoll", options={"id" = "id"})
  * @EXT\Template("CPASimUSanteSimupollBundle:Simupoll:import.html.twig")
  *
  * @return array
  */
 public function importSimupollAction(Request $request, Simupoll $simupoll)
 {
     $sid = $simupoll->getId();
     $sim = $simupoll;
     //echo '<pre>$sim->getResourceNode()->getWorkspace()->getId';var_dump($sim->getResourceNode()->getWorkspace()->getId());echo '</pre>';
     if ($request->isMethod('POST')) {
         $questionfile = $request->files->get('questionfile');
         $categoryfile = $request->files->get('categoryfile');
         if (isset($questionfile)) {
             //if ($questionfile->getMimeType() != 'text/csv')
             $this->simupollManager->importFile($sid, $questionfile, 'question');
         }
         if (isset($categoryfile)) {
             $user = $this->container->get('security.token_storage')->getToken()->getUser();
             $this->simupollManager->importFile($sid, $categoryfile, 'category', $user);
         }
     }
     //echo '<pre>$sim->getResourceNode()->getWorkspace()->getId';var_dump($sim->getResourceNode()->getWorkspace()->getId());echo '</pre>';
     return ['_resource' => $sim];
 }
コード例 #3
0
 /**
  * Prepare the data for use in HTML, csv or graph display.
  *
  * @param $simupoll Simupoll
  * @param $categories array
  * @param $groupTitle string name of the group
  * @param $groupId integer id of the group
  * @param $userlist array list of user selected in Statmanage
  * @param $periods array list of Period entity for the Simupoll
  *
  * @return $row array
  *              - avgByPeriodAndUser[periodId][groupId][userId]
  *              - gAvgByPeriod[periodId]["period"][groupId]
  *              - user[userId](["uname"], ["mark"], ["start"], ["end"], ["question"][periodId], ["mean"])
  *              - question[questionId][name]
  */
 public function getResultsAndStatsForSimupoll(Simupoll $simupoll, $categories = array(), $groupTitle = '', $groupId = 0, $userlist = array(), $periods = array())
 {
     $row = array();
     $simupollId = $simupoll->getId();
     //list of labels for Choice
     $choicetmp = array();
     $tmpmean = array();
     $gmean = array();
     $row['question'] = array();
     $row['period'] = $periods;
     $row['simupoll'] = $simupoll->getTitle();
     $row['grouptitle'] = $groupTitle;
     $row['groupid'] = $groupId;
     //avg by period, group, user
     $averages = array();
     $tmpavg = $this->om->getRepository('CPASimUSanteSimupollBundle:Answer')->getAverageForSimupollInCategoriesByUserAndPeriod($simupollId, $categories, $userlist);
     foreach ($tmpavg as $avg) {
         $averages[$avg['period']][$groupId][$avg['user']] = $avg['average_mark'];
     }
     $row['avgByPeriodAndUser'] = $averages;
     //echo '<pre>';var_dump($averages);echo '</pre>';die();
     //general average (= for all users), by period
     $tmpgavg = $this->om->getRepository('CPASimUSanteSimupollBundle:Answer')->getGeneralAverageForSimupollInCategoriesByPeriod($simupollId, $categories);
     foreach ($tmpgavg as $id => $gavg) {
         $row['gAvgByPeriod'][$tmpgavg[$id]['period']][$groupId] = $gavg['average_mark'];
     }
     //general average all (= for all users), for all periods = 1 value
     $tmpaavg = $this->om->getRepository('CPASimUSanteSimupollBundle:Answer')->getGeneralAverageForSimupollInCategoriesAllPeriod($simupollId, $categories);
     $row['aAvg'][$groupId] = $tmpaavg[0]['average_mark'];
     //echo '<pre>';var_dump($tmpaavg);echo '</pre>';die();
     //get all answers
     $simupollAnswers = $this->om->getRepository('CPASimUSanteSimupollBundle:Answer')->getQuerySimupollAllResponsesInCategoriesForAllUsers($simupoll->getId(), $categories, 'id');
     foreach ($simupollAnswers as $answers) {
         $paper = $answers->getPaper();
         $paperId = $paper->getId();
         $userId = $paper->getUser()->getId();
         $period = $paper->getPeriod();
         $periodId = $period->getId();
         $question = $answers->getQuestion();
         $questionId = $question->getId();
         //user name
         $uname = $paper->getUser()->getLastName() . '-' . $paper->getUser()->getFirstName();
         $user[$userId] = $uname;
         //mark
         $mark = $answers->getMark();
         $row['user'][$userId]['uname'] = $uname;
         $row['user'][$userId]['mark'][$questionId][$periodId] = $mark;
         $row['user'][$userId]['start'][$periodId] = $paper->getStart()->format('Y-m-d H:i:s');
         $row['user'][$userId]['end'][$periodId] = '';
         //$paper->getEnd()->format('Y-m-d H:i:s');
         //can't get the choice directly in the first query (string with ;)
         $choice = array();
         $choiceIds = array_filter(explode(';', $answers->getAnswer()), 'strlen');
         //to avoid empty value
         foreach ($choiceIds as $cid) {
             if (!in_array($cid, $choicetmp)) {
                 //to avoid duplicate queries
                 $label = $this->om->getRepository('CPASimUSanteSimupollBundle:Proposition')->find($cid)->getChoice();
                 $choicetmp[$cid] = $label;
                 $choice[] = $label;
             } else {
                 $row['user'][$userId]['question'];
             }
         }
         //question title
         $row['question'][$questionId] = $question->getTitle();
         $row['user'][$userId]['proposition'][$questionId][$periodId] = implode(';', $choice);
         if (!isset($tmpmean[$periodId][$userId])) {
             $tmpmean[$periodId][$userId]['sum'] = $mark;
             $tmpmean[$periodId][$userId]['count'] = 1;
         } else {
             $tmpmean[$periodId][$userId]['sum'] += $mark;
             $tmpmean[$periodId][$userId]['count'] += 1;
         }
         if (!isset($gmean[$periodId]['mark'])) {
             $gmean[$periodId]['mark'] = $mark;
             $gmean[$periodId]['count'] = 1;
         } else {
             $gmean[$periodId]['mark'] += $mark;
             $gmean[$periodId]['count'] += 1;
         }
     }
     //compute mean
     foreach ($tmpmean as $tmpperiod) {
         foreach ($tmpperiod as $userId => $mean) {
             //compute mean for each user
             if (isset($mean['count'])) {
                 $row['user'][$userId]['mean'] = $mean['sum'] / $mean['count'];
             } else {
                 $row['user'][$userId]['mean'] = 0;
             }
             //general mean for user
             if (isset($row['mean'][$userId])) {
                 $row['mean'][$userId] += $row['user'][$userId]['mean'];
                 $row['mean_count'][$userId] += 1;
             } else {
                 $row['mean'][$userId] = $row['user'][$userId]['mean'];
                 $row['mean_count'][$userId] = 1;
             }
         }
     }
     foreach ($gmean as $periodId => $mean) {
         if ($mean['count'] != 0) {
             $row['galmean'][$periodId] = $mean['mark'] / $mean['count'];
         } else {
             $row['galmean'][$periodId] = 0;
         }
         //mean for all simupoll
         if (!isset($row['allgalmean'][$periodId])) {
             $row['allgalmean'][$periodId] = $row['galmean'][$periodId];
             $row['galmeancount'][$periodId] = 1;
         } else {
             $row['allgalmean'][$periodId] += $row['galmean'][$periodId];
             $row['galmeancount'][$periodId] += 1;
         }
         //Compute means
         if ($row['galmeancount'][$periodId] > 0) {
             $row['allgalmean'][$periodId] = $row['allgalmean'][$periodId] / $row['galmeancount'][$periodId];
             foreach ($row['mean'] as $u => $val) {
                 $row['mean'][$u] = $val / $row['mean_count'][$u];
             }
         }
     }
     return $row;
 }
コード例 #4
0
 /**
  * Lists all Period.
  *
  * @EXT\Route(
  *      "/periods/{id}",
  *      name="cpasimusante_simupoll_period_manage",
  *      requirements={},
  *      options={"expose"=true}
  * )
  * @EXT\ParamConverter("simupoll", class="CPASimUSanteSimupollBundle:Simupoll", options={"id" = "id"})
  * @EXT\Template("CPASimUSanteSimupollBundle:Period:list.html.twig")
  *
  * @param int $simupoll id of Simupoll
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Simupoll $simupoll)
 {
     $sid = $simupoll->getId();
     $periods = $this->periodManager->getPeriodBySimupoll($simupoll);
     return array('_resource' => $simupoll, 'sid' => $sid, 'periods' => $periods);
 }