Code Duplication    Length = 47-47 lines in 2 locations

admin_pages/venues/Venues_Admin_Page.core.php 1 location

@@ 1011-1057 (lines=47) @@
1008
     * @param  string $venue_status
1009
     * @return void
1010
     */
1011
    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1012
    {
1013
        // grab venue id
1014
        if (! $VNU_ID) {
1015
            $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1016
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1017
            return false;
1018
        }
1019
1020
        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1021
1022
        // clean status
1023
        $venue_status = sanitize_key($venue_status);
1024
        // grab status
1025
        if (! $venue_status) {
1026
            $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso');
1027
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1028
            return false;
1029
        }
1030
1031
        // was event trashed or restored ?
1032
        switch ($venue_status) {
1033
            case 'draft':
1034
                $action = 'restored from the trash';
1035
                $hook = 'AHEE_venue_restored_from_trash';
1036
                break;
1037
            case 'trash':
1038
                $action = 'moved to the trash';
1039
                $hook = 'AHEE_venue_moved_to_trash';
1040
                break;
1041
            default:
1042
                $action = 'updated';
1043
                $hook = false;
1044
        }
1045
        // use class to change status
1046
        $this->_cpt_model_obj->set_status($venue_status);
1047
        $success = $this->_cpt_model_obj->save();
1048
1049
        if ($success === false) {
1050
            $msg = sprintf(__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1051
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1052
            return false;
1053
        }
1054
        if ($hook) {
1055
            do_action($hook);
1056
        }
1057
        return true;
1058
    }
1059
1060

admin_pages/events/Events_Admin_Page.core.php 1 location

@@ 2030-2076 (lines=47) @@
2027
     * @param  string $event_status
2028
     * @return bool
2029
     */
2030
    private function _change_event_status($EVT_ID = 0, $event_status = '')
2031
    {
2032
        // grab event id
2033
        if (! $EVT_ID) {
2034
            $msg = esc_html__(
2035
                'An error occurred. No Event ID or an invalid Event ID was received.',
2036
                'event_espresso'
2037
            );
2038
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2039
            return false;
2040
        }
2041
        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2042
        // clean status
2043
        $event_status = sanitize_key($event_status);
2044
        // grab status
2045
        if (empty($event_status)) {
2046
            $msg = esc_html__(
2047
                'An error occurred. No Event Status or an invalid Event Status was received.',
2048
                'event_espresso'
2049
            );
2050
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2051
            return false;
2052
        }
2053
        // was event trashed or restored ?
2054
        switch ($event_status) {
2055
            case 'draft':
2056
                $action = 'restored from the trash';
2057
                $hook = 'AHEE_event_restored_from_trash';
2058
                break;
2059
            case 'trash':
2060
                $action = 'moved to the trash';
2061
                $hook = 'AHEE_event_moved_to_trash';
2062
                break;
2063
            default:
2064
                $action = 'updated';
2065
                $hook = false;
2066
        }
2067
        // use class to change status
2068
        $this->_cpt_model_obj->set_status($event_status);
2069
        $success = $this->_cpt_model_obj->save();
2070
        if ($success === false) {
2071
            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2072
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2073
            return false;
2074
        }
2075
        if ($hook) {
2076
            do_action($hook);
2077
        }
2078
        return true;
2079
    }