class-batch-export-donors.php
7 years ago
class-batch-export-forms.php
8 years ago
class-batch-export.php
8 years ago
class-core-settings-export.php
8 years ago
class-export-earnings.php
8 years ago
class-export.php
8 years ago
class-give-export-donations.php
8 years ago
export-actions.php
8 years ago
export-functions.php
8 years ago
give-export-donations-exporter.php
7 years ago
give-export-donations-functions.php
7 years ago
pdf-reports.php
7 years ago
class-give-export-donations.php
377 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Give Export Donations Settings |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Classes/Give_Settings_Data |
| 7 | * @copyright Copyright (c) 2016, WordImpress |
| 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | * @since 2.1 |
| 10 | */ |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly |
| 14 | } |
| 15 | |
| 16 | if ( ! class_exists( 'Give_Export_Donations' ) ) { |
| 17 | |
| 18 | /** |
| 19 | * Give_Settings_CSV. |
| 20 | * |
| 21 | * @sine 2.1 |
| 22 | */ |
| 23 | final class Give_Export_Donations { |
| 24 | /** |
| 25 | * Importer type |
| 26 | * |
| 27 | * @since 2.1 |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | private $exporter_type = 'export_donations'; |
| 32 | |
| 33 | /** |
| 34 | * Instance. |
| 35 | * |
| 36 | * @since 2.1 |
| 37 | */ |
| 38 | static private $instance; |
| 39 | |
| 40 | /** |
| 41 | * Singleton pattern. |
| 42 | * |
| 43 | * @since 2.1 |
| 44 | * |
| 45 | * @access private |
| 46 | */ |
| 47 | private function __construct() { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get instance. |
| 52 | * |
| 53 | * @since 2.1 |
| 54 | * |
| 55 | * @access public |
| 56 | * |
| 57 | * @return static |
| 58 | */ |
| 59 | public static function get_instance() { |
| 60 | if ( null === static::$instance ) { |
| 61 | self::$instance = new static(); |
| 62 | } |
| 63 | |
| 64 | return self::$instance; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Setup |
| 69 | * |
| 70 | * @since 2.1 |
| 71 | * |
| 72 | * @return void |
| 73 | */ |
| 74 | public function setup() { |
| 75 | $this->setup_hooks(); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * Setup Hooks. |
| 81 | * |
| 82 | * @since 2.1 |
| 83 | * |
| 84 | * @return void |
| 85 | */ |
| 86 | private function setup_hooks() { |
| 87 | if ( ! $this->is_donations_export_page() ) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // Do not render main export tools page. |
| 92 | remove_action( 'give_admin_field_tools_export', array( |
| 93 | 'Give_Settings_Export', |
| 94 | 'render_export_field' |
| 95 | ), 10 ); |
| 96 | |
| 97 | // Render donation export page |
| 98 | add_action( 'give_admin_field_tools_export', array( $this, 'render_page' ) ); |
| 99 | |
| 100 | // Print the HTML. |
| 101 | add_action( 'give_tools_export_donations_form_start', array( $this, 'html' ) ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Filter to modity the Taxonomy args |
| 106 | * |
| 107 | * @since 2.1 |
| 108 | * |
| 109 | * @param array $args args for Taxonomy |
| 110 | * |
| 111 | * @return array args for Taxonomy |
| 112 | */ |
| 113 | function give_forms_taxonomy_dropdown( $args ) { |
| 114 | $args['number'] = 30; |
| 115 | |
| 116 | return $args; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Print the HTML for core setting exporter. |
| 121 | * |
| 122 | * @since 2.1 |
| 123 | */ |
| 124 | public function html() { |
| 125 | ?> |
| 126 | <section id="give-export-donations"> |
| 127 | <table class="widefat export-options-table give-table"> |
| 128 | <tbody> |
| 129 | <tr class="top"> |
| 130 | <td colspan="2"> |
| 131 | <h2 id="give-export-title"><?php _e( 'Export Donation History and Custom Fields to CSV', 'give' ) ?></h2> |
| 132 | <p class="give-field-description"><?php _e( 'Download an export of donors for specific donation forms with the option to include custom fields.', 'give' ) ?></p> |
| 133 | </td> |
| 134 | </tr> |
| 135 | |
| 136 | <?php |
| 137 | if ( give_is_setting_enabled( give_get_option( 'categories' ) ) ) { |
| 138 | add_filter( 'give_forms_category_dropdown', array( $this, 'give_forms_taxonomy_dropdown' ) ); |
| 139 | ?> |
| 140 | <tr> |
| 141 | <td scope="row" class="row-title"> |
| 142 | <label |
| 143 | for="give_forms_categories"><?php _e( 'Filter by Categories:', 'give' ); ?></label> |
| 144 | </td> |
| 145 | <td class="give-field-wrap"> |
| 146 | <div class="give-clearfix"> |
| 147 | <?php |
| 148 | echo Give()->html->category_dropdown( |
| 149 | 'give_forms_categories[]', |
| 150 | 0, |
| 151 | array( |
| 152 | 'id' => 'give_forms_categories', |
| 153 | 'class' => 'give_forms_categories', |
| 154 | 'chosen' => true, |
| 155 | 'multiple' => true, |
| 156 | 'selected' => array(), |
| 157 | 'show_option_all' => false, |
| 158 | 'placeholder' => __( 'Choose one or more from categories', 'give' ), |
| 159 | 'data' => array( 'search-type' => 'categories' ), |
| 160 | ) |
| 161 | ); |
| 162 | ?> |
| 163 | </div> |
| 164 | </td> |
| 165 | </tr> |
| 166 | <?php |
| 167 | remove_filter( 'give_forms_category_dropdown', array( $this, 'give_forms_taxonomy_dropdown' ) ); |
| 168 | } |
| 169 | |
| 170 | if ( give_is_setting_enabled( give_get_option( 'tags' ) ) ) { |
| 171 | add_filter( 'give_forms_tag_dropdown', array( $this, 'give_forms_taxonomy_dropdown' ) ); |
| 172 | ?> |
| 173 | <tr> |
| 174 | <td scope="row" class="row-title"> |
| 175 | <label |
| 176 | for="give_forms_tags"><?php _e( 'Filter by Tags:', 'give' ); ?></label> |
| 177 | </td> |
| 178 | <td class="give-field-wrap"> |
| 179 | <div class="give-clearfix"> |
| 180 | <?php |
| 181 | echo Give()->html->tags_dropdown( |
| 182 | 'give_forms_tags[]', |
| 183 | 0, |
| 184 | array( |
| 185 | 'id' => 'give_forms_tags', |
| 186 | 'class' => 'give_forms_tags', |
| 187 | 'chosen' => true, |
| 188 | 'multiple' => true, |
| 189 | 'selected' => array(), |
| 190 | 'show_option_all' => false, |
| 191 | 'placeholder' => __( 'Choose one or more from tags', 'give' ), |
| 192 | 'data' => array( 'search-type' => 'tags' ), |
| 193 | ) |
| 194 | ); |
| 195 | ?> |
| 196 | </div> |
| 197 | </td> |
| 198 | </tr> |
| 199 | <?php |
| 200 | remove_filter( 'give_forms_tag_dropdown', array( $this, 'give_forms_taxonomy_dropdown' ) ); |
| 201 | } |
| 202 | ?> |
| 203 | |
| 204 | <tr class="give-export-donation-form"> |
| 205 | <td scope="row" class="row-title"> |
| 206 | <label |
| 207 | for="give_payment_form_select"><?php _e( 'Filter by Donation Form:', 'give' ); ?></label> |
| 208 | </td> |
| 209 | <td class="give-field-wrap"> |
| 210 | <div class="give-clearfix"> |
| 211 | <?php |
| 212 | $args = array( |
| 213 | 'name' => 'forms', |
| 214 | 'id' => 'give-payment-form-select', |
| 215 | 'chosen' => true, |
| 216 | 'placeholder' => __( 'All Forms', 'give' ), |
| 217 | 'data' => array( 'no-form' => __( 'No donation forms found', 'give' ), ), |
| 218 | ); |
| 219 | echo Give()->html->forms_dropdown( $args ); |
| 220 | ?> |
| 221 | |
| 222 | <input type="hidden" name="form_ids" class="form_ids" /> |
| 223 | </div> |
| 224 | </td> |
| 225 | </tr> |
| 226 | |
| 227 | <tr> |
| 228 | <td scope="row" class="row-title"> |
| 229 | <label for="give-payment-export-start"><?php _e( 'Filter by Date:', 'give' ); ?></label> |
| 230 | </td> |
| 231 | <td class="give-field-wrap"> |
| 232 | <div class="give-clearfix"> |
| 233 | <?php |
| 234 | $args = array( |
| 235 | 'id' => 'give-payment-export-start', |
| 236 | 'name' => 'start', |
| 237 | 'placeholder' => __( 'Start date', 'give' ), |
| 238 | ); |
| 239 | echo Give()->html->date_field( $args ); ?> |
| 240 | <?php |
| 241 | $args = array( |
| 242 | 'id' => 'give-payment-export-end', |
| 243 | 'name' => 'end', |
| 244 | 'placeholder' => __( 'End date', 'give' ), |
| 245 | ); |
| 246 | echo Give()->html->date_field( $args ); ?> |
| 247 | </div> |
| 248 | </td> |
| 249 | </tr> |
| 250 | |
| 251 | <tr> |
| 252 | <td scope="row" class="row-title"> |
| 253 | <label |
| 254 | for="give-export-donations-status"><?php _e( 'Filter by Status:', 'give' ); ?></label> |
| 255 | </td> |
| 256 | <td> |
| 257 | <div class="give-clearfix"> |
| 258 | <select name="status" id="give-export-donations-status"> |
| 259 | <option value="any"><?php _e( 'All Statuses', 'give' ); ?></option> |
| 260 | <?php |
| 261 | $statuses = give_get_payment_statuses(); |
| 262 | foreach ( $statuses as $status => $label ) { |
| 263 | echo '<option value="' . $status . '">' . $label . '</option>'; |
| 264 | } |
| 265 | ?> |
| 266 | </select> |
| 267 | </div> |
| 268 | </td> |
| 269 | </tr> |
| 270 | |
| 271 | <?php |
| 272 | /** |
| 273 | * Add fields columns that are going to be exported when exporting donations |
| 274 | * |
| 275 | * @since 2.1 |
| 276 | */ |
| 277 | do_action( 'give_export_donation_fields' ); |
| 278 | ?> |
| 279 | |
| 280 | <tr class="end"> |
| 281 | <td> |
| 282 | </td> |
| 283 | <td> |
| 284 | <?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?> |
| 285 | <input type="hidden" name="give-export-class" value="Give_Export_Donations_CSV"/> |
| 286 | <input type="submit" value="<?php _e( 'Generate CSV', 'give' ) ?>" class="give-export-donation-button button button-primary"> |
| 287 | <div class="add-notices"></div> |
| 288 | </td> |
| 289 | </tr> |
| 290 | </tbody> |
| 291 | </table> |
| 292 | </section> |
| 293 | <?php |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Render donations export page |
| 298 | * |
| 299 | * @since 2.1 |
| 300 | */ |
| 301 | public function render_page() { |
| 302 | /** |
| 303 | * Fires before displaying the export div tools. |
| 304 | * |
| 305 | * @since 2.1 |
| 306 | */ |
| 307 | do_action( 'give_tools_export_donations_main_before' ); |
| 308 | ?> |
| 309 | <div id="poststuff"> |
| 310 | <div class="postbox"> |
| 311 | <h1 class="give-export-h1" align="center"><?php _e( 'Export Donations', 'give' ); ?></h1> |
| 312 | <div class="inside give-tools-setting-page-export give-export_donations"> |
| 313 | <?php |
| 314 | /** |
| 315 | * Fires before from start. |
| 316 | * |
| 317 | * @since 2.1 |
| 318 | */ |
| 319 | do_action( 'give_tools_export_donations_form_before_start' ); |
| 320 | ?> |
| 321 | <form method="post" id="give-export_donations-form" |
| 322 | class="give-export-form tools-setting-page-export tools-setting-page-export" |
| 323 | enctype="multipart/form-data"> |
| 324 | |
| 325 | <?php |
| 326 | /** |
| 327 | * Fires just after form start. |
| 328 | * |
| 329 | * @since 2.1 |
| 330 | */ |
| 331 | do_action( 'give_tools_export_donations_form_start' ); |
| 332 | ?> |
| 333 | |
| 334 | <?php |
| 335 | /** |
| 336 | * Fires just after before form end. |
| 337 | * |
| 338 | * @since 2.1 |
| 339 | */ |
| 340 | do_action( 'give_tools_export_donations_form_end' ); |
| 341 | ?> |
| 342 | </form> |
| 343 | <?php |
| 344 | /** |
| 345 | * Fires just after form end. |
| 346 | * |
| 347 | * @since 2.1 |
| 348 | */ |
| 349 | do_action( 'give_tools_iexport_donations_form_after_end' ); |
| 350 | ?> |
| 351 | </div><!-- .inside --> |
| 352 | </div><!-- .postbox --> |
| 353 | </div><!-- #poststuff --> |
| 354 | <?php |
| 355 | /** |
| 356 | * Fires after displaying the export div tools. |
| 357 | * |
| 358 | * @since 2.1 |
| 359 | */ |
| 360 | do_action( 'give_tools_export_donations_main_after' ); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Get if current page export donations page or not |
| 365 | * |
| 366 | * @since 2.1 |
| 367 | * |
| 368 | * @return bool |
| 369 | */ |
| 370 | private function is_donations_export_page() { |
| 371 | return 'export' === give_get_current_setting_tab() && isset( $_GET['type'] ) && $this->exporter_type === give_clean( $_GET['type'] ); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | Give_Export_Donations::get_instance()->setup(); |
| 376 | } |
| 377 |