Ejemplo n.º 1
0
 /**
  * Add statcategorygroup.
  *
  * @param \CPASimUSante\SimupollBundle\Entity\Statcategorygroup $statcategorygroup
  *
  * @return Statmanage
  */
 public function addStatcategorygroup(\CPASimUSante\SimupollBundle\Entity\Statcategorygroup $statcategorygroup)
 {
     $this->statcategorygroups[] = $statcategorygroup;
     $statcategorygroup->setStatmanage($this);
     return $this;
 }
Ejemplo n.º 2
0
 public function statSetupAction(Request $request, $simupoll)
 {
     $categories = [];
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $uids = '';
     $datatosave = [];
     //TODO : change for dynamic group number
     $groupNb = 9;
     //TODO : manage user administrate stat display OR  chose a stat for him
     //can user OPEN ? Not ADMINISTRATE because user can make its
     $simupollAdmin = $this->container->get('cpasimusante_simupoll.services.simupoll')->isGrantedAccess($simupoll, 'OPEN');
     $allowToCompose = 0;
     //If user is auth
     if (is_object($user) && $simupollAdmin === true) {
         $allowToCompose = 1;
         //retrieve data
         $statsmanage = $this->statmanageManager->getStatmanageBySimupollAndUser($user, $simupoll);
         $statcategorygroup = [];
         $titles = [];
         $categorygroupsWithComma = [];
         if ($statsmanage !== []) {
             //retrieve users
             $uids = $statsmanage[0]->getUserList();
             $statcategorygroup = $this->statcategorygroupManager->getStatcategorygroupByStatmanage($statsmanage[0]);
             //retrieve title & categorygroups
             foreach ($statcategorygroup as $scg) {
                 $titles[] = $scg->getTitle();
                 $categorygroupsWithComma[] = ',' . $scg->getGroup() . ',';
             }
         }
         if ($request->isMethod('POST')) {
             //list of users
             $uids = $request->request->get('simupoll_userlist');
             for ($i = 0; $i <= $groupNb; ++$i) {
                 //raw values from request
                 $title = $request->request->get('group_title' . $i);
                 $categorygroup = $request->request->get('categorygroup' . $i);
                 $titles[$i] = $title;
                 if (isset($categorygroup)) {
                     $categorygroup = implode(',', $categorygroup);
                     $categorygroupsWithComma[$i] = ',' . $categorygroup . ',';
                 }
                 //group to save
                 if (trim($title) !== '') {
                     $datatosave[] = ['title' => $title, 'group' => $categorygroup];
                 }
             }
             //echo '<pre>';var_dump($datatosave);echo '</pre>';
             $em = $this->getDoctrine()->getManager();
             //save Statmanage
             if ($statsmanage === []) {
                 $statsmanage = new Statmanage();
                 $statsmanage->setUser($user);
                 $statsmanage->setSimupoll($simupoll);
                 $statsmanage->setUserList($uids);
                 $em->persist($statsmanage);
                 $sm = $statsmanage;
             } else {
                 $statsmanage[0]->setUserList($uids);
                 $em->persist($statsmanage[0]);
                 $sm = $statsmanage[0];
             }
             $em->flush();
             if ($datatosave !== []) {
                 //save Statcategorygroup
                 if ($statcategorygroup !== []) {
                     //delete old value
                     foreach ($statcategorygroup as $scg) {
                         $em->remove($scg);
                     }
                 }
                 //insert new values
                 foreach ($datatosave as $value) {
                     $statcategorygroup = new Statcategorygroup();
                     $statcategorygroup->setStatmanage($sm);
                     $statcategorygroup->setTitle($value['title']);
                     $statcategorygroup->setGroup($value['group']);
                     $em->persist($statcategorygroup);
                 }
                 $em->flush();
             }
         }
         $tree = $this->categoryManager->getCategoryTreeForStatsV2($simupoll, $categorygroupsWithComma, $groupNb);
         return ['groupNb' => $groupNb, 'userlist' => $uids, 'titles' => $titles, 'tree' => $tree, 'allowToCompose' => $allowToCompose, '_resource' => $simupoll];
         //User not auth => get out!
     } else {
         return $this->redirect($this->generateUrl('cpasimusante_simupoll_open', ['id' => $simupoll->getId()]));
     }
     /*
             if ($statsmanage != array()) {
                 $uids = $statsmanage[0]->getUserList();
                 $cats = $statsmanage[0]->getCategoryList();
                 $categories = ($cats != '') ? explode(',', $cats) : array();
             }
             if ($request->isMethod('POST')) {
                 $uids = $request->request->get('simupoll_userlist');
                 $categories = $request->request->get('categorygroup');
                 $cats = ($categories != null) ? implode(',', $categories) : '';
                 //generate list of all categories
                 $allcats = $this->categoryManager->getCategoryListStats($simupoll->getId(), $categories);
                 if ($statsmanage == null) {
                     $statsmanage = new Statmanage();
                     $statsmanage->setUser($user);
                     $statsmanage->setSimupoll($simupoll);
                     $statsmanage->setCategoryList($cats);
                     $statsmanage->setUserList($uids);
                     $statsmanage->setCompleteCategoryList($allcats);
                     $em->persist($statsmanage);
                 } else {
                     $statsmanage[0]->setCategoryList($cats);
                     $statsmanage[0]->setUserList($uids);
                     $statsmanage[0]->setCompleteCategoryList($allcats);
                     $em->persist($statsmanage[0]);
                 }
                 $em->flush();
             }
     */
 }