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