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

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