Skip to content

Commit

Permalink
Fix getter/setter to fix overloaded property issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkatz committed Jun 20, 2014
1 parent bd25e60 commit c15266a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
10 changes: 5 additions & 5 deletions includes/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function field_class( $field, $form = NULL, $entry = NULL ) {
}

if(!empty($field['id'])) {
$form_id = $gravityview_view->__get('form_id');
$form_id = $gravityview_view->form_id;
$form_id = empty($form_id) ? '' : '-'.$form_id;
$classes[] = 'gv-field'.$form_id.'-'.$field['id'];
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function field_value( $entry, $field_settings, $format = 'html') {
GravityView_Plugin::log_debug( sprintf('[field_value] Using template at %s', $field_exists) );

// Set the field data to be available in the templates
$gravityview_view->__set('field_data', array(
$gravityview_view->field_data = array(
'form' => $form,
'field_id' => $field_id,
'field' => $field,
Expand All @@ -123,7 +123,7 @@ public static function field_value( $entry, $field_settings, $format = 'html') {
'display_value' => $display_value,
'format' => $format,
'entry' => $entry,
));
);

ob_start();

Expand All @@ -148,7 +148,7 @@ public static function field_value( $entry, $field_settings, $format = 'html') {
$output = apply_filters( 'gravityview_field_entry_value', $output, $entry, $field_settings );

// Free up the memory
$gravityview_view->__unset('field_data');
unset( $gravityview_view->field_data );

return $output;
}
Expand All @@ -163,7 +163,7 @@ public static function no_results($wpautop = true) {

$is_search = false;

if($gravityview_view->__get('curr_start') || $gravityview_view->__get('curr_end') || $gravityview_view->__get('curr_search')) {
if($gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search) {
$is_search = true;
}

Expand Down
26 changes: 12 additions & 14 deletions includes/class-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

class GravityView_View extends Gamajo_Template_Loader {

protected $vars = array();

// Prefix for filter names.
protected $filter_prefix = 'gravityview';

Expand All @@ -32,7 +30,7 @@ class GravityView_View extends Gamajo_Template_Loader {

/**
* Construct the view object
* @param array $atts Associative array to set as vars
* @param array $atts Associative array to set the data of
*/
function __construct( $atts = array() ) {

Expand All @@ -45,25 +43,25 @@ function __construct( $atts = array() ) {
) );

foreach ($atts as $key => $value) {
$this->vars[ $key ] = $value;
$this->{$key} = $value;
}

// widget logic
add_action( 'gravityview_before', array( $this, 'render_widget_hooks' ) );
add_action( 'gravityview_after', array( $this, 'render_widget_hooks' ) );
}

// Magic methods
public function __set( $name, $value ) {
$this->vars[ $name ] = $value;
}

/**
* Magic Method: Instead of throwing an errow when a variable isn't set, return null.
* @param string $name Key for the data retrieval.
* @return mixed|null The stored data.
*/
public function __get( $name ) {
return isset($this->vars[ $name ]) ? $this->vars[ $name ] : NULL;
}

public function __unset( $name ) {
unset($this->vars[ $name ]);
if( isset( $this->{$name} ) ) {
return $this->{$name};
} else {
return NULL;
}
}

// Load the template
Expand Down
14 changes: 7 additions & 7 deletions includes/default-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ public function render_frontend( $widget_args ) {
global $gravityview_view;

// get configured search filters (fields)
$gravityview_view->__set('search_fields', $this->render_search_fields() );
$gravityview_view->search_fields = $this->render_search_fields();

$search_date = !empty( $widget_args['search_date'] );

$gravityview_view->__set('search_free', !empty( $widget_args['search_free'] ) );
$gravityview_view->__set('search_date', $search_date );
$gravityview_view->search_free = !empty( $widget_args['search_free'] );
$gravityview_view->search_date = $search_date;

if($search_date) {

Expand All @@ -207,13 +207,13 @@ public function render_frontend( $widget_args ) {
wp_enqueue_script( 'gform_datepicker_init' );

$datepicker_class = apply_filters( 'gravityview_search_datepicker_class', 'gv-datepicker datepicker ymd-dash' );
$gravityview_view->__set('datepicker_class', $datepicker_class );
$gravityview_view->datepicker_class = $datepicker_class;
}

// Search box and filters
$gravityview_view->__set('curr_search', esc_attr(rgget('gv_search')) );
$gravityview_view->__set('curr_start', esc_attr(rgget('gv_start')) );
$gravityview_view->__set('curr_end', esc_attr(rgget('gv_end')) );
$gravityview_view->curr_search = esc_attr(rgget('gv_search'));
$gravityview_view->curr_start = esc_attr(rgget('gv_start'));
$gravityview_view->curr_end = esc_attr(rgget('gv_end'));

$gravityview_view->render('widget', 'search');
}
Expand Down
2 changes: 1 addition & 1 deletion templates/list-body.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package GravityView
*/

if((int)$this->__get('total_entries') === 0) {
if((int)$this->total_entries === 0) {

echo '<div class="gv-list-view gv-no-results"><div class="gv-list-view-title"><h3>'.gv_no_results().'</h3></div></div>';

Expand Down
2 changes: 1 addition & 1 deletion templates/table-body.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tbody>
<?php
if((int)$this->__get('total_entries') === 0) {
if((int)$this->total_entries === 0) {
?>
<tr>
<td colspan="<?php echo sizeof($this->fields['directory_table-columns']); ?>" class="gv-no-results">
Expand Down
12 changes: 6 additions & 6 deletions templates/widget-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

<div class="gv-search-box">

<?php if( $gravityview_view->__get('search_free') ): ?>
<?php if( $gravityview_view->search_free ): ?>
<div class="gv-search">
<label for="gv_search_<?php echo $view_id; ?>"><?php esc_html_e( 'Search Entries:', 'gravity-view' ); ?></label>
<p><input type="text" name="gv_search" id="gv_search_<?php echo $view_id; ?>" value="<?php echo $gravityview_view->__get('curr_search'); ?>" /></p>
<p><input type="text" name="gv_search" id="gv_search_<?php echo $view_id; ?>" value="<?php echo $gravityview_view->curr_search; ?>" /></p>
</div>
<?php endif; ?>

<?php if( $gravityview_view->__get('search_date') ): ?>
<?php if( $gravityview_view->search_date ): ?>
<div class="gv-search-date">
<label for="gv_start_date_<?php echo $view_id; ?>"><?php esc_html_e('Filter by date:', 'gravity-view' ); ?></label>
<p>
<input name="gv_start" id="gv_start_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_html($gravityview_view->__get('datepicker_class')); ?>" placeholder="<?php esc_attr_e('Start date', 'gravity-view' ); ?>" value="<?php echo $gravityview_view->__get('curr_start'); ?>">
<input name="gv_end" id="gv_end_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_html($gravityview_view->__get('datepicker_class')); ?>" placeholder="<?php esc_attr_e('End date', 'gravity-view' ); ?>" value="<?php echo $gravityview_view->__get('curr_end'); ?>">
<input name="gv_start" id="gv_start_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_html($gravityview_view->datepicker_class); ?>" placeholder="<?php esc_attr_e('Start date', 'gravity-view' ); ?>" value="<?php echo $gravityview_view->curr_start; ?>">
<input name="gv_end" id="gv_end_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_html($gravityview_view->datepicker_class); ?>" placeholder="<?php esc_attr_e('End date', 'gravity-view' ); ?>" value="<?php echo $gravityview_view->curr_end; ?>">
</p>
</div>
<?php endif; ?>
</div>

<?php
// search filters (fields)
echo $gravityview_view->__get('search_fields');
echo $gravityview_view->search_fields;
?>

<div>
Expand Down

0 comments on commit c15266a

Please sign in to comment.