| @@ -9,12 +9,14 @@ | ||
| 9 | 9 | /** |
| 10 | 10 | * Undocumented class |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -class FormEntryMetaModel extends Model { | |
| 13 | +class FormEntryMetaModel extends Model | |
| 14 | +{ | |
| 14 | 15 | protected static $table = 'bitforms_form_entrymeta'; |
| 15 | 16 | |
| 16 | - public function duplicateEntryMeta($data) { | |
| 17 | + public function duplicateEntryMeta($data) | |
| 18 | + { | |
| 17 | 19 | $values[] = $data['duplicateID']; |
| 18 | 20 | $values[] = $data['entryID']; |
| 19 | 21 | $sql = "INSERT INTO $this->table_name (bitforms_form_entry_id,meta_key,meta_value)" |
| 20 | 22 | . ' SELECT %d as bitforms_form_entry_id,meta_key,meta_value' |
| @@ -21,9 +23,10 @@ | ||
| 21 | 23 | . " FROM `$this->table_name` WHERE bitforms_form_entry_id = %d"; |
| 22 | 24 | return $this->execute($sql, $values)->getResult(); |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | - public function update(array $data, array $condition) { | |
| 27 | + public function update(array $data, array $condition) | |
| 28 | + { | |
| 26 | 29 | $entryID = $condition['bitforms_form_entry_id']; |
| 27 | 30 | if (empty($entryID)) { |
| 28 | 31 | return false; |
| 29 | 32 | } |
| @@ -93,9 +96,10 @@ | ||
| 93 | 96 | } |
| 94 | 97 | return $updatedData; |
| 95 | 98 | } |
| 96 | 99 | |
| 97 | - public function validQueryCondition($conditions) { | |
| 100 | + public function validQueryCondition($conditions) | |
| 101 | + { | |
| 98 | 102 | foreach ($conditions as $index => $condition) { |
| 99 | 103 | if (is_object($condition)) { |
| 100 | 104 | if (empty($condition->field) || empty($condition->logic) || empty($condition->val) && !in_array($condition->val, ['0', 0, 0.0], true)) { |
| 101 | 105 | unset($conditions[$index], $conditions[$index + 1]); |
| @@ -104,9 +108,10 @@ | ||
| 104 | 108 | } |
| 105 | 109 | return $conditions; |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | - public function sqlQryGenerateByFldCondition($conditions) { | |
| 112 | + public function sqlQryGenerateByFldCondition($conditions) | |
| 113 | + { | |
| 109 | 114 | $dbHelper = new Helper(); |
| 110 | 115 | $sql = ''; |
| 111 | 116 | |
| 112 | 117 | $dateQuery = $dbHelper->dateQueryList(); |
| @@ -139,9 +144,10 @@ | ||
| 139 | 144 | |
| 140 | 145 | return trim($sql); |
| 141 | 146 | } |
| 142 | 147 | |
| 143 | - public function queryRecount($selectedMeta, $groupedCondition, $orderCondition, $all_values) { | |
| 148 | + public function queryRecount($selectedMeta, $groupedCondition, $orderCondition, $all_values) | |
| 149 | + { | |
| 144 | 150 | $entry_table = $this->app_db->prefix . 'bitforms_form_entries'; |
| 145 | 151 | $sql = 'SELECT count(*) as count FROM ('; |
| 146 | 152 | $sql .= "SELECT $selectedMeta FROM `$this->table_name` em"; |
| 147 | 153 | $sql .= " INNER JOIN $entry_table e on e.id = em.bitforms_form_entry_id "; |
| @@ -150,9 +156,10 @@ | ||
| 150 | 156 | $countResult = $this->execute($sql, $all_values)->getResult(); |
| 151 | 157 | return $countResult[0]->count; |
| 152 | 158 | } |
| 153 | 159 | |
| 154 | - public function selectedEntryMeta($formFields, $fieldCount) { | |
| 160 | + public function selectedEntryMeta($formFields, $fieldCount) | |
| 161 | + { | |
| 155 | 162 | $all_values = []; |
| 156 | 163 | $formFieldsNames = []; |
| 157 | 164 | $metaChecker = 0; |
| 158 | 165 | $selectedMeta = '`bitforms_form_entry_id` as entry_id,'; |
| @@ -185,13 +192,13 @@ | ||
| 185 | 192 | $selectedMeta .= ','; |
| 186 | 193 | } |
| 187 | 194 | //#unused code commented by me## |
| 188 | 195 | // if ( !empty( $filter['global'] ) ) { |
| 189 | - // $globalFilterString .= " `" . $fieldDetails['key'] . "` LIKE '%%" . $this->getFieldFormat( $filter['global'] ) . "%%' "; | |
| 190 | - // if ( $metaChecker < $fieldCount ) { | |
| 191 | - // $globalFilterString .= " OR "; | |
| 192 | - // } | |
| 193 | - // $globalFilterValues[] = $filter['global']; | |
| 196 | + // $globalFilterString .= " `" . $fieldDetails['key'] . "` LIKE '%%" . $this->getFieldFormat( $filter['global'] ) . "%%' "; | |
| 197 | + // if ( $metaChecker < $fieldCount ) { | |
| 198 | + // $globalFilterString .= " OR "; | |
| 199 | + // } | |
| 200 | + // $globalFilterValues[] = $filter['global']; | |
| 194 | 201 | // } |
| 195 | 202 | } |
| 196 | 203 | |
| 197 | 204 | return [ |
| @@ -200,9 +207,10 @@ | ||
| 200 | 207 | 'all_values' => $all_values, |
| 201 | 208 | ]; |
| 202 | 209 | } |
| 203 | 210 | |
| 204 | - public function groupedCondition($condition, $all_values, $fieldConditions) { | |
| 211 | + public function groupedCondition($condition, $all_values, $fieldConditions) | |
| 212 | + { | |
| 205 | 213 | $isFldCondition = false; |
| 206 | 214 | $formattedCondition = $this->getFormatedCondition($condition); |
| 207 | 215 | if ($formattedCondition) { |
| 208 | 216 | $groupedCondition = $formattedCondition['conditions'] . 'GROUP BY |
| @@ -214,40 +222,40 @@ | ||
| 214 | 222 | //#unused code commented by me## |
| 215 | 223 | //$isRecount = false; |
| 216 | 224 | |
| 217 | 225 | // if ( !empty( $filter['field'] ) ) { |
| 218 | - // $isRecount = true; | |
| 219 | - // $filterFieldCount = count( $filter['field'] ); | |
| 220 | - // $filterFieldChecker = 0; | |
| 221 | - // if ( $filterFieldCount > 0 ) { | |
| 222 | - // $groupedCondition .= " HAVING "; | |
| 223 | - // } | |
| 224 | - // foreach ( $filter['field'] as $filterFieldKey => $filterFieldDetails ) { | |
| 225 | - // $groupedCondition .= " `$filterFieldDetails->id` ='%%" . $this->getFieldFormat( $filterFieldDetails->value ) . "%%'"; | |
| 226 | - // $all_values[] = $filterFieldDetails->value; | |
| 227 | - // if ( $filterFieldChecker < $filterFieldCount ) { | |
| 228 | - // $groupedCondition .= " AND "; | |
| 229 | - // } | |
| 230 | - // } | |
| 226 | + // $isRecount = true; | |
| 227 | + // $filterFieldCount = count( $filter['field'] ); | |
| 228 | + // $filterFieldChecker = 0; | |
| 229 | + // if ( $filterFieldCount > 0 ) { | |
| 230 | + // $groupedCondition .= " HAVING "; | |
| 231 | + // } | |
| 232 | + // foreach ( $filter['field'] as $filterFieldKey => $filterFieldDetails ) { | |
| 233 | + // $groupedCondition .= " `$filterFieldDetails->id` ='%%" . $this->getFieldFormat( $filterFieldDetails->value ) . "%%'"; | |
| 234 | + // $all_values[] = $filterFieldDetails->value; | |
| 235 | + // if ( $filterFieldChecker < $filterFieldCount ) { | |
| 236 | + // $groupedCondition .= " AND "; | |
| 237 | + // } | |
| 238 | + // } | |
| 231 | 239 | // } |
| 232 | 240 | |
| 233 | 241 | // if ( !empty( $filter['global'] ) && !empty( $globalFilterString ) && !empty( $globalFilterValues ) ) { |
| 234 | - // $isRecount = true; | |
| 235 | - // if ( !empty( $filter['field'] ) ) { | |
| 236 | - // $groupedCondition .= " AND (" . $globalFilterString . ") "; | |
| 237 | - // } else { | |
| 238 | - // $groupedCondition .= " HAVING $globalFilterString "; | |
| 239 | - // } | |
| 240 | - // $offset = 0; | |
| 241 | - // $all_values = array_merge( $all_values, $globalFilterValues ); | |
| 242 | + // $isRecount = true; | |
| 243 | + // if ( !empty( $filter['field'] ) ) { | |
| 244 | + // $groupedCondition .= " AND (" . $globalFilterString . ") "; | |
| 245 | + // } else { | |
| 246 | + // $groupedCondition .= " HAVING $globalFilterString "; | |
| 247 | + // } | |
| 248 | + // $offset = 0; | |
| 249 | + // $all_values = array_merge( $all_values, $globalFilterValues ); | |
| 242 | 250 | // } |
| 243 | 251 | |
| 244 | 252 | // if ( !empty( $dateBetweenFilter ) && !empty( $dateBetweenFilter->start_date ) && !empty( $dateBetweenFilter->end_date ) ) { |
| 245 | - // if ( strpos( $groupedCondition, 'HAVING' ) !== false ) { | |
| 246 | - // $groupedCondition .= " AND `__created_at` BETWEEN '" . $dateBetweenFilter->start_date . "' AND '" . $dateBetweenFilter->end_date . "' "; | |
| 247 | - // } else { | |
| 248 | - // $groupedCondition .= " HAVING `__created_at` BETWEEN '" . $dateBetweenFilter->start_date . "' AND '" . $dateBetweenFilter->end_date . "' "; | |
| 249 | - // } | |
| 253 | + // if ( strpos( $groupedCondition, 'HAVING' ) !== false ) { | |
| 254 | + // $groupedCondition .= " AND `__created_at` BETWEEN '" . $dateBetweenFilter->start_date . "' AND '" . $dateBetweenFilter->end_date . "' "; | |
| 255 | + // } else { | |
| 256 | + // $groupedCondition .= " HAVING `__created_at` BETWEEN '" . $dateBetweenFilter->start_date . "' AND '" . $dateBetweenFilter->end_date . "' "; | |
| 257 | + // } | |
| 250 | 258 | // } |
| 251 | 259 | |
| 252 | 260 | $sqlQryByFldCondtion = $this->sqlQryGenerateByFldCondition($fieldConditions); |
| 253 | 261 | |
| @@ -265,9 +273,10 @@ | ||
| 265 | 273 | 'isFldCondition' => $isFldCondition, |
| 266 | 274 | ]; |
| 267 | 275 | } |
| 268 | 276 | |
| 269 | - public function orderCondition($formFieldsNames, $sortBy) { | |
| 277 | + public function orderCondition($formFieldsNames, $sortBy) | |
| 278 | + { | |
| 270 | 279 | $orderCondition = null; |
| 271 | 280 | if (!empty($sortBy)) { |
| 272 | 281 | $sortableFieldCount = count($sortBy); |
| 273 | 282 | $sortableFieldChecker = 0; |
| @@ -296,9 +305,10 @@ | ||
| 296 | 305 | $orderCondition .= empty($orderCondition) ? ' ORDER BY `bitforms_form_entry_id` DESC ' : ',`bitforms_form_entry_id` DESC '; |
| 297 | 306 | return $orderCondition; |
| 298 | 307 | } |
| 299 | 308 | |
| 300 | - public function isEntryMetaExist($conditions) { | |
| 309 | + public function isEntryMetaExist($conditions) | |
| 310 | + { | |
| 301 | 311 | $existMetaData = $this->get( |
| 302 | 312 | [ |
| 303 | 313 | 'meta_key', |
| 304 | 314 | 'meta_value', |
| @@ -310,9 +320,10 @@ | ||
| 310 | 320 | } |
| 311 | 321 | return false; |
| 312 | 322 | } |
| 313 | 323 | |
| 314 | - public function getEntryMeta($formFields, $entries, $limit = null, $offset = null, $filter = null, $sortBy = null, $fieldConditions = null, $dateBetweenFilter = null) { | |
| 324 | + public function getEntryMeta($formFields, $entries, $limit = null, $offset = null, $filter = null, $sortBy = null, $fieldConditions = null, $dateBetweenFilter = null) | |
| 325 | + { | |
| 315 | 326 | $entry_table = $this->app_db->prefix . 'bitforms_form_entries'; |
| 316 | 327 | $fieldCount = count($formFields); |
| 317 | 328 | $getSelectedMetaFldValue = $this->selectedEntryMeta($formFields, $fieldCount); |
| 318 | 329 | |
| @@ -383,9 +394,10 @@ | ||
| 383 | 394 | ]; |
| 384 | 395 | return $resultedEntries; |
| 385 | 396 | } |
| 386 | 397 | |
| 387 | - private function csvInjectionPrevent($value) { | |
| 398 | + private function csvInjectionPrevent($value) | |
| 399 | + { | |
| 388 | 400 | $formula = ['=', '-', '+', '@', "\t", "\r"]; |
| 389 | 401 | $valueFilter = preg_replace('/[\]["]/i', '', $value); |
| 390 | 402 | if (\in_array(substr($value, 0, 1), $formula, true)) { |
| 391 | 403 | $valueFilter = "'" . trim($valueFilter); |
| @@ -393,9 +405,10 @@ | ||
| 393 | 405 | |
| 394 | 406 | return $valueFilter; |
| 395 | 407 | } |
| 396 | 408 | |
| 397 | - public function getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit = null, $sortBy = null, $sortByField = null) { | |
| 409 | + public function getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit = null, $sortBy = null, $sortByField = null) | |
| 410 | + { | |
| 398 | 411 | $entry_table = $this->app_db->prefix . 'bitforms_form_entries'; |
| 399 | 412 | $selectedEntryMeta = '`bitforms_form_entry_id` as entry_id,'; |
| 400 | 413 | $selectedEntryMeta .= "e.user_id as '__user_id',"; |
| 401 | 414 | $selectedEntryMeta .= "e.status as '__entry_status',"; |