id = $id; } $this->active_from = $this->get_formatted_date( 'now' ); if ( $this->interval > 0 ) { $this->active_until = $this->get_formatted_date( '+' . $this->interval . ' day' ); } else { $this->active_until = $this->get_formatted_date( '+1 day' ); } if ( ! empty( $this->id ) ) { // Register notification in event runner userfeedback_notification_event_runner()->register_notification( $this ); } } /** * Helper function for dates * * @param $readable_time * @return false|string */ public function get_formatted_date( $readable_time ) { return gmdate( 'm/d/Y g:i a', strtotime( $readable_time ) ); } /** * Check notification types against installation type * * @return bool */ public function license_type_check() { $active_type = UserFeedback()->license->get_license_type() ?: 'lite'; return in_array( $active_type, $this->license_types ); } /** * Check if notification should be displayed based on its dates range * * @return bool */ public function date_range_check() { $now = $this->get_formatted_date( 'now' ); if ( ! empty( $this->active_from ) && $now < $this->active_from ) { return false; } // Ignore if expired. if ( ! empty( $this->active_until ) && $now > $this->active_until ) { return false; } return true; } /** * Determine if notification should appear or not * Child class can (and probably should) extend this function * * @return boolean */ public function should_display() { return $this->date_range_check() && $this->license_type_check(); } /** * Add notification action * * @param $text * @param $name * @return void */ protected function add_action( $text, $name ) { $this->buttons[] = array( 'type' => 'action', 'class' => get_called_class(), 'action' => $name, 'text' => $text, ); } /** * Prepare notification data * * @return null|UserFeedback_Notification_Event */ public function prepare() { return $this; } }