/**
  * saveFile
  */
 public function saveFile($file_single, $survey_entry_id, $question_id, $answer_id)
 {
     // find survey_id by $survey_entry_id
     require_once 'models/education/education_survey_entry.php';
     $Survey_Entry = new education_survey_entry();
     $survey_entry_data = $Survey_Entry->detail($survey_entry_id);
     $survey_id = $survey_entry_data['survey_id'];
     /**
      * add prefix to filename (rename)
      */
     $file_single['name'] = $this->getFilenameToSave($file_single['name'], $survey_entry_id, $question_id, $answer_id);
     /**
      * file
      */
     require_once 'models/common/common_file.php';
     //getSingleUpload could be a static method
     $CommonFile = new common_file();
     $upload = $CommonFile->getSingleUpload($file_single, "var/surveys/{$survey_id}/");
     /**
      * array indicated the same file name already exists in the var/tmp/ folder
      * this should never happen as we have entry id in filename 
      */
     if (is_array($upload)) {
         $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload['temp_file'];
     } else {
         $attachment_saved_file = ONXSHOP_PROJECT_DIR . $upload;
     }
     /**
      * check if file exists and than return filename
      */
     if (file_exists($attachment_saved_file)) {
         $attachment_info = $CommonFile->getFileInfo($attachment_saved_file);
         return $attachment_info['filename'];
     }
 }
Exemplo n.º 2
0
 /**
  * getAnswerUsage
  */
 public function getAnswerUsage($question_answer_id, $relation_subject = false)
 {
     if (!is_numeric($question_answer_id)) {
         return false;
     }
     require_once 'models/education/education_survey_entry.php';
     $SurveyEntry = new education_survey_entry();
     $usage_count = $SurveyEntry->getAnswerUsageCount($question_answer_id, $relation_subject);
     return $usage_count;
 }
Exemplo n.º 3
0
 /**
  * calculateSurveyAverageRating
  */
 public function calculateSurveyAverageRating($survey_detail, $relation_subject = fals)
 {
     if (!is_array($survey_detail)) {
         return false;
     }
     if (!is_array($survey_detail['question_list'])) {
         return false;
     }
     $survey_total_x = 0;
     $survey_total_sum = 0;
     foreach ($survey_detail['question_list'] as $k => $item) {
         $question_total_x = 0;
         $question_total_sum = 0;
         if (($item['type'] == 'radio' || $item['type'] == 'select') && is_array($item['answer_list'])) {
             foreach ($item['answer_list'] as $answer_k => $answer_item) {
                 $question_total_x = $question_total_x + $answer_item['usage_count'] * $answer_item['points'];
                 $question_total_sum = $question_total_sum + $answer_item['usage_count'];
             }
             if ($question_total_sum > 0) {
                 $survey_detail['question_list'][$k]['average_rating'] = $question_total_x / $question_total_sum;
             } else {
                 $survey_detail['question_list'][$k]['average_rating'] = 'n/a';
             }
         } else {
             $survey_detail['question_list'][$k]['average_rating'] = 'n/a';
         }
         $survey_total_x = $survey_total_x + $question_total_x;
         $survey_total_sum = $survey_total_sum + $question_total_sum;
     }
     if ($survey_total_sum > 0) {
         $survey_detail['average_rating'] = $survey_total_x / $survey_total_sum;
     } else {
         $survey_detail['average_rating'] = 'n/a';
     }
     /**
      * weighted mean rating
      * calculating manually at this place, but we could use education_survey_entry->getWeightedMean()
      */
     /* Option 1: manual
     		$weighted_mean_top = 0;
     		$weighted_mean_bottom = 0;
     				
     		foreach ($survey_detail['question_list'] as $k=>$item) {
     			
     			if (is_numeric($item['average_rating'])) {
     			
     				$weighted_mean_top = $weighted_mean_top + $item['weight'] * $item['average_rating'];
     				$weighted_mean_bottom = $weighted_mean_bottom + $item['weight'];
     				
     			}
     			
     		}
     		
     		if ($weighted_mean_bottom > 0) {
     			
     			$survey_detail['weighted_mean'] = $weighted_mean_top / $weighted_mean_bottom;
     			
     		} else {
     			
     			$survey_detail['weighted_mean'] = 'n/a';
     			
     		}*/
     // Option 2: weighted mean calculated from education_survey_entry->getWeightedMean()
     require_once 'models/education/education_survey_entry.php';
     $SurveyEntry = new education_survey_entry();
     $weighted_mean = $SurveyEntry->getWeightedMean($survey_detail['id'], $relation_subject);
     if (is_numeric($weighted_mean)) {
         $survey_detail['weighted_mean'] = $weighted_mean;
     } else {
         $survey_detail['weighted_mean'] = 'n/a';
     }
     return $survey_detail;
 }