public static function add_job($form_id, array $mail_packet, $mails_in_one_go = 20, $optional_callback = null)
 {
     $job_batch = get_option("rm_option_jobman_job", null);
     if ($job_batch == null) {
         $job_batch = array();
     }
     $test = RM_DBManager::count('SUBMISSIONS', array('form_id' => $form_id, 'user_email' => 'not null'));
     //Test if there is an 'user_email' entry for the given form
     if ($test === false || $test === 0) {
         return false;
     }
     $job = new stdClass();
     $job->form_id = $form_id;
     $job->job_size = $mails_in_one_go;
     $job->callback = $optional_callback;
     $job->offset = 0;
     $job->mail_packet = $mail_packet;
     $job->total = (int) RM_DBManager::count('SUBMISSIONS', array('form_id' => $form_id));
     $job->started_on = RM_Utilities::get_current_time();
     $form_fields = array();
     $fields = self::get_fields($form_id);
     if ($fields) {
         foreach ($fields as $field) {
             $form_fields[] = $field->field_type . "_" . $field->field_id;
         }
     }
     $job->form_fields = $form_fields;
     $job_batch["_" . $form_id] = $job;
     //error_log('job added');
     // self::log_var_dump($job_batch);
     update_option("rm_option_jobman_job", $job_batch);
     //error_log('exiting from add_job');
     return true;
 }
 public function get_submission_count($user_email)
 {
     return RM_DBManager::count('SUBMISSIONS', array('user_email' => $user_email));
 }
 public function count($model_identifier, $args)
 {
     return RM_DBManager::count($model_identifier, $args);
 }
 public function get_resp_count($form_id)
 {
     return (int) RM_DBManager::count('SUBMISSIONS', array('form_id' => $form_id));
 }
 public function get_field_stats($form_id)
 {
     $fields = RM_DBManager::get_fields_filtered_by_types($form_id, array('Select', 'Checkbox', 'Radio', 'Country'));
     $stat_arr = array();
     if (is_array($fields) || is_object($fields)) {
         foreach ($fields as $field) {
             $res = array();
             $tmp_obj = new stdClass();
             $vals = maybe_unserialize($field->field_value);
             $tmp_obj->label = $field->field_label;
             $tmp_obj->total_sub = 0;
             switch ($field->field_type) {
                 case 'Checkbox':
                     $temp = RM_DBManager::get('SUBMISSION_FIELDS', array('field_id' => $field->field_id), array('%d'), 'col', 0, 999999, "value");
                     if (!$temp) {
                         break;
                     }
                     foreach ($vals as $val) {
                         $res[$val] = 0;
                     }
                     $other_option_submission = 0;
                     foreach ($temp as $single_sub) {
                         if ($single_sub == NULL) {
                             continue;
                         }
                         $single_sub = maybe_unserialize($single_sub);
                         foreach ($single_sub as $f_v) {
                             if (isset($res[$f_v])) {
                                 $res[$f_v] += 1;
                             } else {
                                 $other_option_submission++;
                             }
                         }
                     }
                     $res['Other'] = $other_option_submission;
                     //IMPORTANT: Checkbox is a multiple value type submission,
                     //hence we can't just add up the submissions of individual option to get the total submissions.
                     $tmp_obj->total_sub = RM_DBManager::count('SUBMISSION_FIELDS', array('field_id' => $field->field_id));
                     break;
                 case 'Country':
                     $temp = RM_DBManager::count_multiple('SUBMISSION_FIELDS', "value", array('field_id' => $field->field_id));
                     if (!$temp) {
                         break;
                     }
                     foreach ($temp as $single_sub) {
                         $res[$single_sub->value] = (int) $single_sub->count;
                         $tmp_obj->total_sub += (int) $single_sub->count;
                     }
                     //Compensate for the cases when Country field was not submitted (blank values).
                     if (isset($res[''])) {
                         $tmp_obj->total_sub -= $res[''];
                         //We dont need this in stat, unset it.
                         unset($res['']);
                     }
                     break;
                 case 'Radio':
                 case 'Select':
                     if ($field->field_type == 'Select') {
                         $vals = explode(',', $field->field_value);
                     }
                     $temp = RM_DBManager::count_multiple('SUBMISSION_FIELDS', "value", array('field_id' => $field->field_id));
                     if (!$temp) {
                         break;
                     }
                     foreach ($temp as $single_sub) {
                         if (in_array($single_sub->value, $vals)) {
                             $res[$single_sub->value] = (int) $single_sub->count;
                             $tmp_obj->total_sub += (int) $single_sub->count;
                         }
                     }
                     break;
             }
             $tmp_obj->sub_stat = $res;
             $stat_arr[] = $tmp_obj;
         }
     }
     return $stat_arr;
 }