Exemple #1
0
 public function checkpost()
 {
     $predmeti = Input::all();
     if (!array_key_exists('ans', $predmeti)) {
         $success = false;
         // $err_data["d"] = "nistga";
         $message = array('success' => $success);
         return json_encode($message);
         // return View::make('surveys.error')->with('message',"Greška. Treba da popunite bar jedan predmet.");
     }
     // //Check
     $success = true;
     $err_data = array();
     $popunjeni = explode("x", Input::get('names'));
     $predmeti = $predmeti['ans'];
     foreach ($predmeti as $predmetID => $ocene) {
         if (in_array($predmetID . "", $popunjeni)) {
             $nepopounjeni = array();
             if (($key = array_search($predmetID, $popunjeni)) !== false) {
                 unset($popunjeni[$key]);
             }
             for ($i = 1; $i < 11; $i++) {
                 if (!array_key_exists($i, $ocene)) {
                     $success = false;
                     array_push($nepopounjeni, $i);
                 }
             }
             $err_data[$predmetID] = $nepopounjeni;
         }
     }
     foreach ($popunjeni as $key => $predmetID) {
         if ($predmetID != "") {
             $err_data[$predmetID] = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
         }
     }
     try {
         DB::beginTransaction();
         $newEntry = new Ps_surveyentry();
         $newEntry->survey_id = $survey = Ps_survey::where('active', 1)->first()->id;
         $newEntry->department = Input::get('department');
         $newEntry->semester = Input::get('semester');
         $newEntry->ip = Request::getClientIp();
         $newEntry->save();
         // $predmeti = $predmeti['ans'];
         foreach ($predmeti as $predmetID => $ocene) {
             $newEval = new Ps_surveyeval();
             $newEval->result = implode(",", $ocene);
             $newEval->subject_id = $predmetID;
             $newEval->surveyentry_id = $newEntry->id;
             $newEval->save();
         }
         DB::commit();
         // return View::make('surveys.success')->with(array('data'=>Input::all()['ans'], 'entry'=>$newEntry));
     } catch (\PDOException $e) {
         //	DB::rollBack();
         // return View::make('surveys.error')->with('message',"Došlo je do neočekivane greške. Molimo vas da nam javite detalje na info@puskice.org.");
         $success = false;
     }
     $message = array('success' => $success, 'errors' => $err_data);
     return json_encode($message);
 }
Exemple #2
0
 public function prepareOverallResults()
 {
     $survey = Ps_survey::where('active', 1)->first();
     //check if survey exists
     // if(is_null($survey) || $survey->id!=$id){
     // 	$message = "Tražena anketa ne postoji ili nije aktivna.";
     // 	return View::make('surveys.error')->with('message',$message);
     // } else {
     $entries = Ps_surveyeval::all();
     $appd = array();
     $appd['ukupno'] = $this->createAnswer('Ukupno', 'sum-data');
     $appd['prva'] = $this->createAnswer('Prva godina', 'sum-data');
     $appd['druga'] = $this->createAnswer('Druga godina', 'sum-data');
     $appd['treca'] = $this->createAnswer('Treća godina', 'sum-data');
     $appd['cetvrta'] = $this->createAnswer('Četvrta godina', 'sum-data');
     $appd['isit'] = $this->createAnswer('Informacioni sistemi i tehnologije', 'sum-data');
     $appd['men'] = $this->createAnswer('Menadžment', 'sum-data');
     $appd['om'] = $this->createAnswer('Operacioni menadžment', 'sum-data');
     $appd['uk'] = $this->createAnswer('Upravljanje kvalitetom', 'sum-data');
     foreach ($entries as $key => $entry) {
         try {
             $newsid = $entry->subject->news->id;
         } catch (Exception $e) {
             dd($entry);
         }
         if (!array_key_exists($newsid, $appd)) {
             //kreiranje za predmete
             $appd[$newsid] = $this->createAnswer($entry->subject->news->title);
         }
         $res_arr = explode(",", $entry->result);
         $department_semester = "dep" . $entry->surveyentry->department . "sem" . $entry->surveyentry->semester;
         if (!in_array($department_semester, $appd[$newsid]['classes'])) {
             array_push($appd[$newsid]['classes'], $department_semester);
         }
         foreach ($res_arr as $key => $res) {
             // if(!is_array($appd[$newsid][++$key])){
             $appd[$newsid][++$key][$res] += 1;
             $appd['ukupno'][$key][$res] += 1;
             switch ($entry->surveyentry->department) {
                 case 0:
                     $appd['prva'][$key][$res] += 1;
                     break;
                 case 1:
                     $appd['isit'][$key][$res] += 1;
                     break;
                 case 2:
                     $appd['men'][$key][$res] += 1;
                     break;
                 case 3:
                     $appd['om'][$key][$res] += 1;
                     break;
                 case 4:
                     $appd['uk'][$key][$res] += 1;
                     break;
             }
             switch (ceil($entry->surveyentry->semester / 2)) {
                 case 2:
                     $appd['druga'][$key][$res] += 1;
                     break;
                 case 3:
                     $appd['treca'][$key][$res] += 1;
                     break;
                 case 4:
                     $appd['cetvrta'][$key][$res] += 1;
                     break;
             }
             // }
             // array_push($appd[$newsid][$key], $res);
         }
     }
     return $appd;
     //return View::make('surveys.results')->with('data',$appd);
     // }
 }