| @@ -4,8 +4,24 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmEntriesHelper { |
| 7 | 7 | |
| 8 | + /** | |
| 9 | + * "Submitted" entry status. | |
| 10 | + * | |
| 11 | + * @since 6.4.2 | |
| 12 | + * @var int | |
| 13 | + */ | |
| 14 | + const SUBMITTED_ENTRY_STATUS = 0; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * "Draft" entry status. | |
| 18 | + * | |
| 19 | + * @since 6.4.2 | |
| 20 | + * @var int | |
| 21 | + */ | |
| 22 | + const DRAFT_ENTRY_STATUS = 1; | |
| 23 | + | |
| 8 | 24 | public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
| 9 | 25 | remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' ); |
| 10 | 26 | |
| 11 | 27 | $values = array( |
| @@ -692,8 +708,18 @@ | ||
| 692 | 708 | ), |
| 693 | 709 | 'icon' => 'frm_icon_font frm_email_icon', |
| 694 | 710 | ); |
| 695 | 711 | |
| 712 | + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) { | |
| 713 | + $actions['frm_download_pdf'] = array( | |
| 714 | + 'url' => '#', | |
| 715 | + 'label' => __( 'Download as PDF', 'formidable' ), | |
| 716 | + 'class' => 'frm_noallow', | |
| 717 | + 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ), | |
| 718 | + 'icon' => 'frm_icon_font frm_download_icon', | |
| 719 | + ); | |
| 720 | + } | |
| 721 | + | |
| 696 | 722 | $actions['frm_edit'] = array( |
| 697 | 723 | 'url' => '#', |
| 698 | 724 | 'label' => __( 'Edit Entry', 'formidable' ), |
| 699 | 725 | 'class' => 'frm_noallow', |
| @@ -708,8 +734,32 @@ | ||
| 708 | 734 | return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) ); |
| 709 | 735 | } |
| 710 | 736 | |
| 711 | 737 | /** |
| 738 | + * Gets data attributes for PDFs addon upgrade link. | |
| 739 | + * | |
| 740 | + * @param string $medium The source of the upgrade link used for analytics data. | |
| 741 | + * @return array | |
| 742 | + */ | |
| 743 | + private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) { | |
| 744 | + $data = array( | |
| 745 | + 'oneclick' => '', | |
| 746 | + 'requires' => '', | |
| 747 | + 'upgrade' => __( 'Forms to PDF', 'formidable' ), | |
| 748 | + 'medium' => $medium, | |
| 749 | + ); | |
| 750 | + | |
| 751 | + $upgrading = FrmAddonsController::install_link( 'pdfs' ); | |
| 752 | + if ( isset( $upgrading['url'] ) ) { | |
| 753 | + $data['oneclick'] = json_encode( $upgrading ); | |
| 754 | + } else { | |
| 755 | + $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 ); | |
| 756 | + } | |
| 757 | + | |
| 758 | + return $data; | |
| 759 | + } | |
| 760 | + | |
| 761 | + /** | |
| 712 | 762 | * @since 5.0.15 |
| 713 | 763 | * |
| 714 | 764 | * @param string|int $entry_id |
| 715 | 765 | * @return void |
| @@ -730,5 +780,81 @@ | ||
| 730 | 780 | return; |
| 731 | 781 | } |
| 732 | 782 | } |
| 733 | 783 | } |
| 784 | + | |
| 785 | + /** | |
| 786 | + * Return entry status based on is_draft column value. | |
| 787 | + * | |
| 788 | + * @since 6.5 | |
| 789 | + * | |
| 790 | + * @param int $status is_draft column. | |
| 791 | + * | |
| 792 | + * @return int | |
| 793 | + */ | |
| 794 | + public static function get_entry_status( $status ) { | |
| 795 | + $statuses = self::get_entry_statuses(); | |
| 796 | + | |
| 797 | + if ( array_key_exists( $status, $statuses ) ) { | |
| 798 | + return $status; | |
| 799 | + } | |
| 800 | + | |
| 801 | + if ( empty( $status ) ) { | |
| 802 | + return self::SUBMITTED_ENTRY_STATUS; // If the status is empty, let's default to 0. | |
| 803 | + } | |
| 804 | + | |
| 805 | + return self::DRAFT_ENTRY_STATUS; // If it has a value that isn't in the array, let's default to 1. There may be old entries that don't have a value for is_draft. | |
| 806 | + } | |
| 807 | + | |
| 808 | + /** | |
| 809 | + * Return entry status label based on passed value. | |
| 810 | + * | |
| 811 | + * @since 6.5 | |
| 812 | + * | |
| 813 | + * @param int $status is_draft column. | |
| 814 | + * | |
| 815 | + * @return string | |
| 816 | + */ | |
| 817 | + public static function get_entry_status_label( $status ) { | |
| 818 | + $statuses = self::get_entry_statuses(); | |
| 819 | + | |
| 820 | + return $statuses[ self::get_entry_status( $status ) ]; | |
| 821 | + } | |
| 822 | + | |
| 823 | + /** | |
| 824 | + * Get all entry statuses. | |
| 825 | + * | |
| 826 | + * @since 6.5 | |
| 827 | + * @since 6.6 function went from private to public. | |
| 828 | + * | |
| 829 | + * @return array<string> | |
| 830 | + */ | |
| 831 | + public static function get_entry_statuses() { | |
| 832 | + | |
| 833 | + $default_entry_statuses = array( | |
| 834 | + self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ), | |
| 835 | + self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ), | |
| 836 | + ); | |
| 837 | + | |
| 838 | + /** | |
| 839 | + * Register entry status. | |
| 840 | + * | |
| 841 | + * "2" is used in abandonment-addon and reserved for "In progress". | |
| 842 | + * "3" is used in abandonment-addon and reserved for "Abandoned". | |
| 843 | + * | |
| 844 | + * @since 6.5 | |
| 845 | + * | |
| 846 | + * @param array<string> $extended_entry_status Entry statuses. | |
| 847 | + */ | |
| 848 | + $extended_entry_status = apply_filters( 'frm_entry_statuses', array() ); | |
| 849 | + | |
| 850 | + if ( ! is_array( $extended_entry_status ) ) { | |
| 851 | + _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' ); | |
| 852 | + $extended_entry_status = array(); | |
| 853 | + } | |
| 854 | + | |
| 855 | + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status ); | |
| 856 | + | |
| 857 | + return $existing_entry_statuses; | |
| 858 | + } | |
| 859 | + | |
| 734 | 860 | } |