From 2eecb6c3752e2f4d19e03728a58f179e74de2832 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 15 Mar 2019 18:43:06 -0600 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9Cis=20snoozable=E2=80=9D=20flag?= =?UTF-8?q?=20to=20WC=5FAdmin=5FNote.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../includes/class-wc-admin-install.php | 1 + .../includes/class-wc-admin-note.php | 20 ++++++++++++++++++ .../class-wc-admin-notes-data-store.php | 21 +++++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-install.php b/plugins/woocommerce-admin/includes/class-wc-admin-install.php index 2925e09cdf5..43679ad5ced 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-install.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-install.php @@ -168,6 +168,7 @@ class WC_Admin_Install { source varchar(200) NOT NULL, date_created datetime NOT NULL default '0000-00-00 00:00:00', date_reminder datetime NULL default null, + is_snoozable boolean DEFAULT 0 NOT NULL, PRIMARY KEY (note_id) ) $collate; CREATE TABLE {$wpdb->prefix}wc_admin_note_actions ( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-note.php b/plugins/woocommerce-admin/includes/class-wc-admin-note.php index a3000bdf8f0..60aa3d8883c 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-note.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-note.php @@ -48,6 +48,7 @@ class WC_Admin_Note extends WC_Data { 'source' => 'woocommerce', 'date_created' => '0000-00-00 00:00:00', 'date_reminder' => '', + 'is_snoozable' => false, 'actions' => array(), ); @@ -243,6 +244,16 @@ class WC_Admin_Note extends WC_Data { return $this->get_prop( 'date_reminder', $context ); } + /** + * Get note snoozability. + * + * @param string $context What the value is for. Valid values are 'view' and 'edit'. + * @return bool Whether or not the note can be snoozed. + */ + public function get_is_snoozable( $context = 'view' ) { + return $this->get_prop( 'is_snoozable', $context ); + } + /** * Get actions on the note (if any). * @@ -438,6 +449,15 @@ class WC_Admin_Note extends WC_Data { $this->set_date_prop( 'date_reminder', $date ); } + /** + * Set note snoozability. + * + * @param bool $is_snoozable Whether or not the note can be snoozed. + */ + public function set_is_snoozable( $is_snoozable ) { + return $this->set_prop( 'is_snoozable', $is_snoozable ); + } + /** * Clear actions from a note. */ diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php index 918e09fb73d..78946c24e0b 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php @@ -23,14 +23,15 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da global $wpdb; $note_to_be_inserted = array( - 'name' => $note->get_name(), - 'type' => $note->get_type(), - 'locale' => $note->get_locale(), - 'title' => $note->get_title(), - 'content' => $note->get_content(), - 'icon' => $note->get_icon(), - 'status' => $note->get_status(), - 'source' => $note->get_source(), + 'name' => $note->get_name(), + 'type' => $note->get_type(), + 'locale' => $note->get_locale(), + 'title' => $note->get_title(), + 'content' => $note->get_content(), + 'icon' => $note->get_icon(), + 'status' => $note->get_status(), + 'source' => $note->get_source(), + 'is_snoozable' => $note->get_is_snoozable(), ); $note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data() ); @@ -68,7 +69,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da if ( 0 !== $note_id || '0' !== $note_id ) { $note_row = $wpdb->get_row( $wpdb->prepare( - "SELECT name, type, locale, title, content, icon, content_data, status, source, date_created, date_reminder FROM {$wpdb->prefix}wc_admin_notes WHERE note_id = %d LIMIT 1", + "SELECT name, type, locale, title, content, icon, content_data, status, source, date_created, date_reminder, is_snoozable FROM {$wpdb->prefix}wc_admin_notes WHERE note_id = %d LIMIT 1", $note->get_id() ) ); @@ -97,6 +98,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da $note->set_source( $note_row->source ); $note->set_date_created( $note_row->date_created ); $note->set_date_reminder( $note_row->date_reminder ); + $note->set_is_snoozable( $note_row->is_snoozable ); $this->read_actions( $note ); $note->read_meta_data(); $note->set_object_read( true ); @@ -147,6 +149,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da 'source' => $note->get_source(), 'date_created' => $date_created_to_db, 'date_reminder' => $date_reminder_to_db, + 'is_snoozable' => $note->get_is_snoozable(), ), array( 'note_id' => $note->get_id() ) );