Skip to content

Commit

Permalink
Merge pull request #158 from sugarcalendar/release/2.1.4
Browse files Browse the repository at this point in the history
Release/2.1.4
  • Loading branch information
JJJ authored Jan 15, 2021
2 parents a012288 + 0d83a89 commit 8f294c4
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sugar-calendar",
"version": "2.1.3",
"version": "2.1.4",
"description": "A calendar with a sweet disposition.",
"private": true,
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Tags: simple calendar, event calendar, event management, event list
Requires PHP: 5.6.20
Requires at least: 5.1
Tested up to: 5.6
Stable tag: 2.1.3
Stable tag: 2.1.4

You can easily manage events with this lightweight calendar. No complicated configuration. Simple to use. Sweeeet!

Expand Down
2 changes: 1 addition & 1 deletion sugar-calendar-lite.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Domain Path: /sugar-calendar/includes/languages/
* Requires PHP: 5.6.20
* Requires at least: 5.1
* Version: 2.1.3
* Version: 2.1.4
*/

// Exit if accessed directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ protected function set_view( $start = '', $end = '' ) {
$end_time = strtotime( $end );

// Set view boundaries
$this->view_start = min( $start, $end );
$this->view_end = max( $start, $end );
$this->view_start = ( $end_time > $start_time ) ? $start : $end;
$this->view_end = ( $end_time < $start_time ) ? $start : $end;
$this->view_duration = ( $end_time - $start_time );

// Set view time zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct( $args = array() ) {
$view_start = "{$this->year}-{$this->month}-01 00:00:00";

// Month boundaries
$this->grid_start = mysql2date( 'U', $view_start );
$this->grid_start = strtotime( $view_start );
$this->grid_end = strtotime( '+1 month -1 second', $this->grid_start );

// View end
Expand Down
127 changes: 85 additions & 42 deletions sugar-calendar/includes/classes/database/engine/class-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1127,16 +1127,14 @@ private function parse_query( $query = array() ) {
/**
* Parse the where clauses for all known columns
*
* @todo split this method into smaller parts
*
* @since 1.0.0
*/
private function parse_where() {

// Defaults
$where = $join = $searchable = $date_query = array();
$and = '/^\s*AND\s*/';

// Set the table right away
$table = $this->apply_prefix( $this->item_name );

// Loop through columns
foreach ( $this->columns as $column ) {
Expand Down Expand Up @@ -1276,11 +1274,18 @@ private function parse_where() {
$where['search'] = $this->get_search_sql( $this->query_vars['search'], $search_columns );
}

/** Query Classes *****************************************************/

// Get the primary column & table
$primary = $this->get_primary_column_name();
$table = $this->get_meta_type();
$and = '/^\s*AND\s*/';

// Maybe perform a meta query.
$meta_query = $this->query_vars['meta_query'];
if ( ! empty( $meta_query ) && is_array( $meta_query ) ) {
$this->meta_query = $this->get_meta_query( $meta_query );
$clauses = $this->meta_query->get_sql( $table, $this->table_alias, $this->get_primary_column_name(), $this );
$clauses = $this->meta_query->get_sql( $table, $this->table_alias, $primary, $this );

// Not all objects have meta, so make sure this one exists
if ( false !== $clauses ) {
Expand All @@ -1299,11 +1304,16 @@ private function parse_where() {
$compare_query = $this->query_vars['compare_query'];
if ( ! empty( $compare_query ) && is_array( $compare_query ) ) {
$this->compare_query = $this->get_compare_query( $compare_query );
$clauses = $this->compare_query->get_sql( $table, $this->table_alias, $this->get_primary_column_name(), $this );
$clauses = $this->compare_query->get_sql( $table, $this->table_alias, $primary, $this );

// Not all objects can compare, so make sure this one exists
if ( false !== $clauses ) {

// Set join
if ( ! empty( $clauses['join'] ) ) {
$join['compare_query'] = $clauses['join'];
}

// Remove " AND " from query where clause.
$where['compare_query'] = preg_replace( $and, '', $clauses['where'] );
}
Expand All @@ -1317,11 +1327,16 @@ private function parse_where() {
// Maybe perform a date query
if ( ! empty( $date_query ) && is_array( $date_query ) ) {
$this->date_query = $this->get_date_query( $date_query );
$clauses = $this->date_query->get_sql( $table, $this->table_alias, $this->get_primary_column_name(), $this );
$clauses = $this->date_query->get_sql( $this->table_name, $this->table_alias, $primary, $this );

// Not all objects are dates, so make sure this one exists
if ( false !== $clauses ) {

// Set join
if ( ! empty( $clauses['join'] ) ) {
$join['date_query'] = $clauses['join'];
}

// Remove " AND " from query where clause.
$where['date_query'] = preg_replace( $and, '', $clauses['where'] );
}
Expand Down Expand Up @@ -2196,16 +2211,16 @@ protected function add_item_meta( $item_id = 0, $meta_key = '', $meta_value = ''
return false;
}

// Get meta table name
$table = $this->apply_prefix( $this->item_name );

// Bail if no meta table exists
if ( empty( $table ) ) {
if ( false === $this->get_meta_table_name() ) {
return false;
}

// Return results of get meta data
return add_metadata( $table, $item_id, $meta_key, $meta_value, $unique );
// Get meta type
$meta_type = $this->get_meta_type();

// Return results of adding meta data
return add_metadata( $meta_type, $item_id, $meta_key, $meta_value, $unique );
}

/**
Expand All @@ -2226,16 +2241,16 @@ protected function get_item_meta( $item_id = 0, $meta_key = '', $single = false
return false;
}

// Get meta table name
$table = $this->apply_prefix( $this->item_name );

// Bail if no meta table exists
if ( empty( $table ) ) {
if ( false === $this->get_meta_table_name() ) {
return false;
}

// Return results of get meta data
return get_metadata( $table, $item_id, $meta_key, $single );
// Get meta type
$meta_type = $this->get_meta_type();

// Return results of getting meta data
return get_metadata( $meta_type, $item_id, $meta_key, $single );
}

/**
Expand All @@ -2257,16 +2272,16 @@ protected function update_item_meta( $item_id = 0, $meta_key = '', $meta_value =
return false;
}

// Get meta table name
$table = $this->apply_prefix( $this->item_name );

// Bail if no meta table exists
if ( empty( $table ) ) {
if ( false === $this->get_meta_table_name() ) {
return false;
}

// Return results of get meta data
return update_metadata( $table, $item_id, $meta_key, $meta_value, $prev_value );
// Get meta type
$meta_type = $this->get_meta_type();

// Return results of updating meta data
return update_metadata( $meta_type, $item_id, $meta_key, $meta_value, $prev_value );
}

/**
Expand All @@ -2288,16 +2303,16 @@ protected function delete_item_meta( $item_id = 0, $meta_key = '', $meta_value =
return false;
}

// Get meta table name
$table = $this->apply_prefix( $this->item_name );

// Bail if no meta table exists
if ( empty( $table ) ) {
if ( false === $this->get_meta_table_name() ) {
return false;
}

// Return results of get meta data
return delete_metadata( $table, $item_id, $meta_key, $meta_value, $delete_all );
// Get meta type
$meta_type = $this->get_meta_type();

// Return results of deleting meta data
return delete_metadata( $meta_type, $item_id, $meta_key, $meta_value, $delete_all );
}

/**
Expand All @@ -2312,7 +2327,7 @@ protected function delete_item_meta( $item_id = 0, $meta_key = '', $meta_value =
private function get_registered_meta_keys( $object_subtype = '' ) {

// Get the object type
$object_type = $this->apply_prefix( $this->item_name );
$object_type = $this->get_meta_type();

// Return the keys
return get_registered_meta_keys( $object_type, $object_subtype );
Expand All @@ -2333,11 +2348,8 @@ private function save_extra_item_meta( $item_id = 0, $meta = array() ) {
return;
}

// Get meta table name
$table = $this->get_meta_table_name();

// Bail if no meta table exists
if ( empty( $table ) ) {
if ( false === $this->get_meta_table_name() ) {
return;
}

Expand Down Expand Up @@ -2395,26 +2407,57 @@ private function delete_all_item_meta( $item_id = 0 ) {
return;
}

// Get the meta type
$meta_type = $this->get_meta_type();

// Delete all meta data for this item ID
foreach ( $meta_ids as $mid ) {
delete_metadata_by_mid( $this->item_name, $mid );
delete_metadata_by_mid( $meta_type, $mid );
}
}

/**
* Return meta table
* Get the meta table for this query
*
* Forked from WordPress\_get_meta_table() so it can be more accurately
* predicted in a future iteration and default to returning false.
*
* @since 1.0.0
*
* @return mixed Table name if exists, False if not
*/
private function get_meta_table_name() {

// Maybe apply table prefix
$table = $this->apply_prefix( $this->item_name );
// Get the meta-type
$type = $this->get_meta_type();

// Append "meta" to end of meta-type
$table_name = "{$type}meta";

// Return table if exists, or false if not
return _get_meta_table( $table );
// Variable'ize the database interface, to use inside empty()
$db = $this->get_db();

// If not empty, return table name
if ( ! empty( $db->{$table_name} ) ) {
return $table_name;
}

// Default return false
return false;
}

/**
* Get the meta type for this query
*
* This method exists to reduce some duplication for now. Future iterations
* will likely use Column::relationships to
*
* @since 1.1.0
*
* @return string
*/
private function get_meta_type() {
return $this->apply_prefix( $this->item_name );
}

/** Cache *****************************************************************/
Expand Down
Loading

0 comments on commit 8f294c4

Please sign in to comment.