Add “is snoozable” flag to WC_Admin_Note.

This commit is contained in:
Jeff Stieler 2019-03-15 18:43:06 -06:00
parent f08fda5271
commit 2eecb6c375
3 changed files with 33 additions and 9 deletions

View File

@ -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 (

View File

@ -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.
*/

View File

@ -31,6 +31,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
'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() )
);