/** * Constructor. */ public function __construct() { $editor = new Editor(Factory::make('itelic-renewal-reminder'), array('mustSelectItem' => __("You must select an item", Plugin::SLUG), 'selectTemplateTag' => __("Select Template Tag", Plugin::SLUG), 'templateTag' => __("Template Tag", Plugin::SLUG), 'selectATag' => __("Select a tag", Plugin::SLUG), 'insertTag' => __("Insert", Plugin::SLUG), 'cancel' => __("Cancel", Plugin::SLUG), 'insertTemplateTag' => __("Insert Template Tag", Plugin::SLUG))); add_action('admin_footer', function () use($editor) { $editor->thickbox(); unset($editor); }); }
/** * @dataProvider listeners_data_provider */ public function test_registered_listeners($listener) { $manager = \IronBound\WP_Notifications\Template\Factory::make('itelic-outdated-customers'); $this->assertNotInstanceOf('\\IronBound\\WP_Notifications\\Template\\Null_Listener', $manager->get_listener($listener)); }
/** * Send the notifications. * * @return Notification[] */ public function get_notifications() { $reminders = Reminder\CPT::get_reminders(); if (empty($reminders)) { return array(); } $date_to_reminder = array(); $table = Manager::get('itelic-keys'); $tn = $table->get_table_name($GLOBALS['wpdb']); // retrieve key information and just the date value ( no time ) of when the key expires $sql = "SELECT *, Date(`expires`) AS EXP_DAY FROM {$tn} WHERE "; // START manual first record $sql .= $this->convert_interval_to_between($reminders[0]->get_interval()); $date_to_reminder[$this->convert_interval_to_date($reminders[0]->get_interval())->format("Y-m-d")] = $reminders[0]; unset($reminders[0]); // END manual first record foreach ($reminders as $reminder) { $interval = $reminder->get_interval(); $date = $this->convert_interval_to_date($interval); // search for keys that expire any time during the day of the current reminder. $sql .= " OR " . $this->convert_datetime_to_between($date); // store a reference of that entire day to the reminder object for later use. $date_to_reminder[$date->format("Y-m-d")] = $reminder; } /* * SQL generated is similar to: * SELECT *, Date(`expires`) AS EXP_DAY FROM wp_itelic_keys WHERE * (`expires` BETWEEN '2015-03-08' AND '2015-03-08 23:59:59') OR * (`expires` BETWEEN '2017-03-01' AND '2017-03-01 23:59:59') */ $result = $GLOBALS['wpdb']->get_results($sql); if (empty($result)) { return array(); } $expire_to_key = array(); foreach ($result as $record) { $expire_to_key[$record->EXP_DAY] = itelic_get_key_from_data($record); } $notifications = array(); $manager = Factory::make('itelic-renewal-reminder'); foreach ($expire_to_key as $expire => $key) { $notification = $this->make_notification($date_to_reminder[$expire], $key, $manager); if ($notification) { $notifications[] = $notification; } } return $notifications; }
/** * Render the notification editor. * * @since 1.0 */ protected function render_notification_editor() { $editor = new Editor(Factory::make('itelic-outdated-customers'), array('mustSelectItem' => __("You must select an item", Plugin::SLUG), 'selectTemplateTag' => __("Select Template Tag", Plugin::SLUG), 'templateTag' => __("Template Tag", Plugin::SLUG), 'selectATag' => __("Select a tag", Plugin::SLUG), 'insertTag' => __("Insert", Plugin::SLUG), 'cancel' => __("Cancel", Plugin::SLUG), 'insertTemplateTag' => __("Insert Template Tag", Plugin::SLUG))); $editor->thickbox(); ?> <div class="spacing-wrapper hidden notifications-editor"> <h4><?php _e("Send Update Reminders", Plugin::SLUG); ?> </h4> <p class="description"> <?php printf(__('Email your customers who have not yet updated to version %1$s of %2$s.', Plugin::SLUG), $this->release->get_version(), $this->release->get_product()->post_title); ?> </p> <div class="notification-editor-fields-container"> <input type="text" id="notification-subject" placeholder="<?php esc_attr_e("Enter your subject", Plugin::SLUG); ?> "> <?php $editor->display_template_tag_button(); ?> <?php wp_editor('', 'notification-body', array('teeny' => true, 'media_buttons' => false, 'editor_height' => '250px')); ?> <p class="clearfix notification-buttons"> <a href="javascript:" class="button button-secondary" id="cancel-notification"> <?php _e("Cancel", Plugin::SLUG); ?> </a> <a href="javascript:" class="button button-primary" id="send-notification"> <?php _e("Send", Plugin::SLUG); ?> </a> </p> </div> </div> <?php }
/** * Get notifications. * * @since 1.0 * * @param Release $release * @param string $message * @param string $subject * * @return Notification[] */ public function get_notifications(Release $release, $message, $subject) { /** @var $wpdb \wpdb */ global $wpdb; $atn = Manager::get('itelic-activations')->get_table_name($wpdb); $ktn = Manager::get('itelic-keys')->get_table_name($wpdb); $rtn = Manager::get('itelic-releases')->get_table_name($wpdb); $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT k.customer FROM {$atn} a JOIN {$ktn} k ON ( a.lkey = k.lkey AND k.`product` = %d )\n\t\t\t WHERE a.status = %s AND a.release_id IN (\n\t\t\t SELECT r.ID FROM {$rtn} r WHERE r.product = %d AND r.`start_date` < %s )", $release->get_product()->ID, Activation::ACTIVE, $release->get_product()->ID, $release->get_start_date()->format('Y-m-d H:i:s'))); if (empty($results)) { return array(); } $notifications = array(); foreach ($results as $result) { $to = get_user_by('id', $result->customer); if (!$to instanceof \WP_User) { continue; } $notification = new Notification($to, Factory::make('itelic-outdated-customers'), $message, $subject); $notification->add_data_source($release); $notifications[] = $notification; } return $notifications; }