public static function find_by($where) { $results = AWPCP_Ad::find($where); if (!empty($results)) { return $results[0]; } return null; }
public static function delete($id, &$errors) { global $wpdb; $plan = self::find_by_id($id); if (is_null($plan)) { $errors[] = __("The Fee doesn't exist.", 'AWPCP'); return false; } $where = "adterm_id = %d AND payment_term_type = 'fee'"; $ads = AWPCP_Ad::find($wpdb->prepare($where, $id)); if (!empty($ads)) { $errors[] = __("The Fee can't be deleted because there are active Ads in the system that are associated with the Fee ID.", 'AWPCP'); return false; } $query = 'DELETE FROM ' . AWPCP_TABLE_ADFEES . ' WHERE adterm_id = %d'; $result = $wpdb->query($wpdb->prepare($query, $id)); return $result !== false; }
public function delete() { $id = awpcp_request_param('id', 0); $fee = AWPCP_Fee::find_by_id($id); if (is_null($fee)) { awpcp_flash(__("The specified Fee doesn't exists.", 'AWPCP'), 'error'); return $this->index(); } $errors = array(); if (AWPCP_Fee::delete($fee->id, $errors)) { awpcp_flash(__('The Fee was successfully deleted.', 'AWPCP')); } else { $where = sprintf("adterm_id = %d AND payment_term_type = 'fee'", $fee->id); $ads = AWPCP_Ad::find($where); if (empty($ads)) { foreach ($errors as $error) { awpcp_flash($error, 'error'); } } else { $fees = AWPCP_Fee::query(); if (count($fees) > 1) { $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. You need to switch the Ads to a different Fee before you can delete the plan.", "AWPCP"); awpcp_flash($message, 'error'); $params = array('fee' => $fee, 'fees' => $fees); $template = AWPCP_DIR . '/admin/templates/admin-panel-fees-delete.tpl.php'; echo $this->render($template, $params); return; } else { $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. Please create a new Fee and try the delete operation again. AWPCP will help you to switch existing Ads to the new fee.", "AWPCP"); awpcp_flash($message, 'error'); } } } return $this->index(); }
/** * @since 3.0.2 */ function awpcp_clean_up_non_verified_ads($listings, $settings) { global $wpdb; if (!$settings->get_option('enable-email-verification')) { return; } $resend_email_threshold = $settings->get_option('email-verification-first-threshold'); $delete_ads_threshold = $settings->get_option('email-verification-second-threshold'); // delete Ads that have been in a non-verified state for more than M days $conditions = AWPCP_Ad::get_where_conditions_for_successfully_paid_listings(array('verified = 0', $wpdb->prepare('ad_postdate < ADDDATE( NOW(), INTERVAL -%d DAY )', $delete_ads_threshold))); foreach (AWPCP_Ad::find(join(' AND ', $conditions)) as $ad) { $ad->delete(); } // re-send verificaiton email for Ads that have been in a non-verified state for more than N days $conditions = AWPCP_Ad::get_where_conditions_for_successfully_paid_listings(array('verified = 0', $wpdb->prepare('ad_postdate < ADDDATE( NOW(), INTERVAL -%d DAY )', $resend_email_threshold))); foreach (AWPCP_Ad::find(join(' AND ', $conditions)) as $ad) { if (intval(awpcp_get_ad_meta($ad->ad_id, 'verification_emails_sent', true)) <= 1) { $listings->send_verification_email($ad); } } }