| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Create a new entry with some differences depending on type |
| 23 | 23 | * |
| 24 | - * @param array $values | |
| 24 | + * @param array $values | |
| 25 | 25 | * @param string $type |
| 26 | 26 | * |
| 27 | 27 | * @return int | boolean $entry_id |
| 28 | 28 | */ |
| @@ -116,9 +116,9 @@ | ||
| 116 | 116 | |
| 117 | 117 | if ( $is_duplicate ) { |
| 118 | 118 | break; |
| 119 | 119 | } |
| 120 | - } | |
| 120 | + }//end foreach | |
| 121 | 121 | |
| 122 | 122 | $frm_vars['checking_duplicates'] = false; |
| 123 | 123 | |
| 124 | 124 | return $is_duplicate; |
| @@ -150,9 +150,9 @@ | ||
| 150 | 150 | * |
| 151 | 151 | * @since 2.0.23 |
| 152 | 152 | * |
| 153 | 153 | * @param array $values |
| 154 | - * @param int $duplicate_entry_time | |
| 154 | + * @param int $duplicate_entry_time | |
| 155 | 155 | * |
| 156 | 156 | * @return bool |
| 157 | 157 | */ |
| 158 | 158 | private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) { |
| @@ -212,9 +212,9 @@ | ||
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Update an entry (not via XML) |
| 215 | 215 | * |
| 216 | - * @param int $id | |
| 216 | + * @param int $id | |
| 217 | 217 | * @param array $values |
| 218 | 218 | * |
| 219 | 219 | * @return boolean|int $update_results |
| 220 | 220 | */ |
| @@ -228,9 +228,9 @@ | ||
| 228 | 228 | * Update an entry with some differences depending on the update type |
| 229 | 229 | * |
| 230 | 230 | * @since 2.0.16 |
| 231 | 231 | * |
| 232 | - * @param int $id | |
| 232 | + * @param int $id | |
| 233 | 233 | * @param array $values |
| 234 | 234 | * |
| 235 | 235 | * @return boolean|int $query_results |
| 236 | 236 | */ |
| @@ -260,9 +260,10 @@ | ||
| 260 | 260 | public static function destroy( $id ) { |
| 261 | 261 | global $wpdb; |
| 262 | 262 | $id = (int) $id; |
| 263 | 263 | |
| 264 | - $entry = self::getOne( $id, true ); // Item meta is required for conditional logic in actions with 'delete' events. | |
| 264 | + // Item meta is required for conditional logic in actions with 'delete' events. | |
| 265 | + $entry = self::getOne( $id, true ); | |
| 265 | 266 | if ( ! $entry ) { |
| 266 | 267 | $result = false; |
| 267 | 268 | return $result; |
| 268 | 269 | } |
| @@ -335,9 +336,9 @@ | ||
| 335 | 336 | |
| 336 | 337 | /** |
| 337 | 338 | * If $entry is numeric, get the entry object |
| 338 | 339 | * |
| 339 | - * @param int|object $entry by reference | |
| 340 | + * @param int|object $entry By reference. | |
| 340 | 341 | * |
| 341 | 342 | * @since 2.0.9 |
| 342 | 343 | */ |
| 343 | 344 | public static function maybe_get_entry( &$entry ) { |
| @@ -387,9 +388,10 @@ | ||
| 387 | 388 | return; |
| 388 | 389 | } |
| 389 | 390 | |
| 390 | 391 | FrmAppHelper::unserialize_or_decode( $entry->description ); |
| 391 | - $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output. | |
| 392 | + // TODO: Remove slashes on input only, not output. | |
| 393 | + $entry = wp_unslash( $entry ); | |
| 392 | 394 | } |
| 393 | 395 | |
| 394 | 396 | /** |
| 395 | 397 | * @since 4.02.03 |
| @@ -498,9 +500,9 @@ | ||
| 498 | 500 | $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 499 | 501 | unset( $query ); |
| 500 | 502 | |
| 501 | 503 | FrmDb::set_cache( $cache_key, $entries, 'frm_entry' ); |
| 502 | - } | |
| 504 | + }//end if | |
| 503 | 505 | |
| 504 | 506 | if ( ! $meta || ! $entries ) { |
| 505 | 507 | self::prepare_entries( $entries ); |
| 506 | 508 | return $entries; |
| @@ -577,13 +579,13 @@ | ||
| 577 | 579 | } |
| 578 | 580 | |
| 579 | 581 | // Pagination Methods |
| 580 | 582 | /** |
| 581 | - * @param int|array|string If int, use the form id. | |
| 583 | + * @param int|array|string $where If int, use the form id. | |
| 582 | 584 | */ |
| 583 | 585 | public static function getRecordCount( $where = '' ) { |
| 584 | 586 | global $wpdb; |
| 585 | - $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; | |
| 587 | + $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; | |
| 586 | 588 | |
| 587 | 589 | if ( is_numeric( $where ) ) { |
| 588 | 590 | $table_join = 'frm_items'; |
| 589 | 591 | $where = array( 'form_id' => $where ); |
| @@ -617,9 +619,9 @@ | ||
| 617 | 619 | * Prepare the data before inserting it into the database |
| 618 | 620 | * |
| 619 | 621 | * @since 2.0.16 |
| 620 | 622 | * |
| 621 | - * @param array $values | |
| 623 | + * @param array $values | |
| 622 | 624 | * @param string $type |
| 623 | 625 | * |
| 624 | 626 | * @return array $new_values |
| 625 | 627 | */ |
| @@ -661,9 +663,9 @@ | ||
| 661 | 663 | * Sanitize the POST values before we use them |
| 662 | 664 | * |
| 663 | 665 | * @since 2.0 |
| 664 | 666 | * |
| 665 | - * @param array $values The POST values by reference | |
| 667 | + * @param array $values The POST values by reference. | |
| 666 | 668 | */ |
| 667 | 669 | public static function sanitize_entry_post( &$values ) { |
| 668 | 670 | $sanitize_method = array( |
| 669 | 671 | 'form_id' => 'absint', |
| @@ -754,9 +756,13 @@ | ||
| 754 | 756 | * |
| 755 | 757 | * @return int |
| 756 | 758 | */ |
| 757 | 759 | private static function get_is_draft_value( $values ) { |
| 758 | - return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; | |
| 760 | + if ( isset( $values['frm_saving_draft'] ) && FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $values['frm_saving_draft'] ) { | |
| 761 | + return FrmEntriesHelper::DRAFT_ENTRY_STATUS; | |
| 762 | + } | |
| 763 | + | |
| 764 | + return isset( $values['is_draft'] ) ? absint( $values['is_draft'] ) : FrmEntriesHelper::SUBMITTED_ENTRY_STATUS; | |
| 759 | 765 | } |
| 760 | 766 | |
| 761 | 767 | /** |
| 762 | 768 | * Get the created_at value for a new entry |
| @@ -879,9 +885,9 @@ | ||
| 879 | 885 | * |
| 880 | 886 | * @since 2.0.16 |
| 881 | 887 | * |
| 882 | 888 | * @param array $values |
| 883 | - * @param int $entry_id | |
| 889 | + * @param int $entry_id | |
| 884 | 890 | * @return void |
| 885 | 891 | */ |
| 886 | 892 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 887 | 893 | if ( isset( $values['item_meta'] ) ) { |
| @@ -909,9 +915,10 @@ | ||
| 909 | 915 | * Trigger frm_after_create_entry hooks |
| 910 | 916 | * |
| 911 | 917 | * @since 2.0.16 |
| 912 | 918 | * |
| 913 | - * @param int $entry_id | |
| 919 | + * @param int $entry_id | |
| 920 | + * @param array $values | |
| 914 | 921 | * @param array $new_values |
| 915 | 922 | */ |
| 916 | 923 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
| 917 | 924 | // this is a child entry |
| @@ -927,9 +934,9 @@ | ||
| 927 | 934 | * @since 2.0.16 |
| 928 | 935 | * |
| 929 | 936 | * @param array $values |
| 930 | 937 | * @param array $new_values |
| 931 | - * @param int $entry_id | |
| 938 | + * @param int $entry_id | |
| 932 | 939 | */ |
| 933 | 940 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 934 | 941 | |
| 935 | 942 | self::add_new_entry_to_frm_vars( $entry_id ); |
| @@ -945,10 +952,10 @@ | ||
| 945 | 952 | * Perform some actions right before updating an entry |
| 946 | 953 | * |
| 947 | 954 | * @since 2.0.16 |
| 948 | 955 | * |
| 949 | - * @param int $id | |
| 950 | - * @param array $values | |
| 956 | + * @param int $id | |
| 957 | + * @param array $values | |
| 951 | 958 | * @param string $update_type |
| 952 | 959 | * |
| 953 | 960 | * @return boolean $update |
| 954 | 961 | */ |
| @@ -972,9 +979,9 @@ | ||
| 972 | 979 | * Package the entry data for updating |
| 973 | 980 | * |
| 974 | 981 | * @since 2.0.16 |
| 975 | 982 | * |
| 976 | - * @param int $id | |
| 983 | + * @param int $id | |
| 977 | 984 | * @param array $values |
| 978 | 985 | * |
| 979 | 986 | * @return array $new_values |
| 980 | 987 | */ |
| @@ -1015,11 +1022,11 @@ | ||
| 1015 | 1022 | * |
| 1016 | 1023 | * @since 2.0.16 |
| 1017 | 1024 | * |
| 1018 | 1025 | * @param boolean|int $query_results |
| 1019 | - * @param int $id | |
| 1020 | - * @param array $values | |
| 1021 | - * @param array $new_values | |
| 1026 | + * @param int $id | |
| 1027 | + * @param array $values | |
| 1028 | + * @param array $new_values | |
| 1022 | 1029 | */ |
| 1023 | 1030 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 1024 | 1031 | if ( $query_results ) { |
| 1025 | 1032 | self::clear_cache(); |
| @@ -1061,9 +1068,9 @@ | ||
| 1061 | 1068 | * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
| 1062 | 1069 | * |
| 1063 | 1070 | * @since 2.0.16 |
| 1064 | 1071 | * |
| 1065 | - * @param int $id | |
| 1072 | + * @param int $id | |
| 1066 | 1073 | * @param array $values |
| 1067 | 1074 | * |
| 1068 | 1075 | * @return int | boolean $updated |
| 1069 | 1076 | */ |
| @@ -1081,6 +1088,22 @@ | ||
| 1081 | 1088 | public static function get_id_by_key( $key ) { |
| 1082 | 1089 | $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
| 1083 | 1090 | |
| 1084 | 1091 | return (int) $entry_id; |
| 1092 | + } | |
| 1093 | + | |
| 1094 | + /** | |
| 1095 | + * Get entries count. | |
| 1096 | + * | |
| 1097 | + * @since 6.8 | |
| 1098 | + * | |
| 1099 | + * @return int | |
| 1100 | + */ | |
| 1101 | + public static function get_entries_count() { | |
| 1102 | + $args = array( | |
| 1103 | + 'or' => 1, | |
| 1104 | + 'parent_form_id' => null, | |
| 1105 | + 'parent_form_id <' => 1, | |
| 1106 | + ); | |
| 1107 | + return self::getRecordCount( $args ); | |
| 1085 | 1108 | } |
| 1086 | 1109 | } |