Code Duplication    Length = 47-47 lines in 2 locations

admin_pages/events/Events_Admin_Page.core.php 1 location

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

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