Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ranshoshani34 committed Aug 25, 2021
1 parent 24c5d4c commit dfd08c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
21 changes: 10 additions & 11 deletions includes/calendar-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ function ( $event ) use ( $current_date ) {
/**
* Method to generate the necessary html to render the calendar.
*
* @param int $month the month to display.
* @param int $year the year to dispaly.
* @param int $date timestamp of the date to display.
*
* @return string
*/
public static function generate_calendar_html(int $date) : string {
return self::generate_month_picker($date) . self::generate_calendar_header_html($date) . '<br><br><div id="event_plugin_calendar">' . self::draw_calendar( gmdate( 'm' , $date), gmdate( 'Y' , $date) ) . '</div>';
public static function generate_calendar_html( int $date ) : string {
return self::generate_month_picker( $date ) . self::generate_calendar_header_html( $date ) . '<br><br><div id="event_plugin_calendar">' . self::draw_calendar( gmdate( 'm', $date ), gmdate( 'Y', $date ) ) . '</div>';
}

/**
Expand Down Expand Up @@ -144,24 +143,24 @@ public static function respond_with_calendar() {
/**
* Method to render a header with month and year information.
*
* @param int $date the date to render
* @param int $date the date to render.
*
* @return string
*/
public static function generate_calendar_header_html(int $date) : string {
return '<h2>' . gmdate( 'F' , $date) . ' ' . gmdate( 'Y' , $date) . '</>';
public static function generate_calendar_header_html( int $date ) : string {
return '<h2>' . gmdate( 'F', $date ) . ' ' . gmdate( 'Y', $date ) . '</>';
}

/**
* Method to return the html string for the month picker that changes the month in the calendar dynamically.
*
* @param int $date the date to render
* @param int $date the date to render.
*
* @return string the html for the month picker.
*/
private static function generate_month_picker(int $date) : string {
$month = gmdate( 'm' , $date);
$year = gmdate( 'Y' , $date);
private static function generate_month_picker( int $date ) : string {
$month = gmdate( 'm', $date );
$year = gmdate( 'Y', $date );
$current_time = $year . '-' . $month;
return '<form class="event_plugin_month_picker"><input type="month" id="event_plugin_month" name="event_plugin_month" value="' . $current_time . '"><input type="submit" value="Change month"></form>';
}
Expand Down
18 changes: 0 additions & 18 deletions includes/event-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,6 @@ public function init_widgets() {
Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Event_Creator_Widget() );
}

/**
* Init Controls
* Include controls files and register them
*
* @since 1.0.0
* @access public
*/
public function init_controls() {

// Include Control files.
// todo
// require_once __DIR__ . '/controls/test-control.php';.

// Register control.
// todo
// \Elementor\Plugin::$instance->controls_manager->register_control( 'control-type-', new \Test_Control() );.
}

/**
* Admin notice
* Warning when the site doesn't have Elementor installed or activated.
Expand Down
22 changes: 11 additions & 11 deletions widgets/calendar-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ protected function render() {
require_once WP_PLUGIN_DIR . '/event-plugin/includes/calendar-creator.php';

$settings = $this->get_settings_for_display();
if ('yes' === $settings['current_month']){
if ( 'yes' === $settings['current_month'] ) {
$default_date = time();
} else {
$default_date = strtotime( $settings[ 'default_month' ] );
$default_date = strtotime( $settings['default_month'] );
}

echo Calendar_Creator::generate_calendar_html($default_date); //phpcs:ignore
}

protected function _register_controls() {
protected function _register_controls() { //phpcs:ignore

$this->start_controls_section(
'default_section',
Expand All @@ -71,11 +71,11 @@ protected function _register_controls() {
$this->add_control(
'default_month',
[
'label' => __( 'Default Month', 'event-plugin' ),
'type' => Elementor\Controls_Manager::DATE_TIME,
'description' => 'Pick any day of the month you want to be the default month',
'picker_options' => [
'enableTime' => 'false',
'label' => __( 'Default Month', 'event-plugin' ),
'type' => Elementor\Controls_Manager::DATE_TIME,
'description' => 'Pick any day of the month you want to be the default month',
'picker_options' => [
'enableTime' => 'false',
'monthSelectorType' => 'dropdown',
],
]
Expand All @@ -84,9 +84,9 @@ protected function _register_controls() {
$this->add_control(
'current_month',
[
'label' => __( 'Default month as current month?', 'event-plugin' ),
'type' => Elementor\Controls_Manager::SWITCHER,
'description' => 'If this is on, the default month is irrelevant and will always display the current month as the default ',
'label' => __( 'Default month as current month?', 'event-plugin' ),
'type' => Elementor\Controls_Manager::SWITCHER,
'description' => 'If this is on, the default month is irrelevant and will always display the current month as the default ',
]
);

Expand Down

0 comments on commit dfd08c5

Please sign in to comment.