rule = $rule;
$this->group_id = $group_id;
$this->rule_id = $rule_id;
$this->value = $value;
}
/*
* Get field html markup
* @param $type string Field type
* @return string
*/
public function get_field( $type ) {
$this->field_name = "awl_label_params[conditions][group_{$this->group_id}][rule_{$this->rule_id}][{$type}]";
return call_user_func( array( $this, 'get_rule_' . $type ) );
}
/*
* Rule html
* @return string
*/
public function get_rule() {
$params_html = $this->get_field( 'param' );
$operators_html = $this->get_field( 'operator' );
$values_html = $this->get_field( 'value' );
$suboptions_html = $this->get_field( 'suboption' );
$class = $suboptions_html ? ' adv' : '';
$rule_html = '';
$rule_html .= '
';
$rule_html .= '| ';
$rule_html .= $params_html . $suboptions_html;
$rule_html .= ' | ';
$rule_html .= '';
$rule_html .= $operators_html;
$rule_html .= ' | ';
$rule_html .= '';
$rule_html .= $values_html;
$rule_html .= ' | ';
$rule_html .= '';
$rule_html .= '' . __( 'and', 'advanced-woo-labels' ) . '';
$rule_html .= ' | ';
$rule_html .= '';
$rule_html .= '';
$rule_html .= ' | ';
$rule_html .= '
';
return $rule_html;
}
/*
* Rules params html
* @param $rule array Rule
* @return string
*/
private function get_rule_param() {
$rules = AWL_Admin_Options::include_rules();
$val = ( $this->value && is_array( $this->value ) && isset( $this->value['param'] ) ) ? $this->value['param'] : '';
$rules_html = '';
return $rules_html;
}
/*
* Rules suboptions html
* @return string
*/
private function get_rule_suboption() {
$val = ( $this->value && is_array( $this->value ) && isset( $this->value['suboption'] ) ) ? $this->value['suboption'] : '';
$rules_html = '';
if ( isset( $this->rule['suboption'] ) && isset( $this->rule['suboption']['callback'] ) && isset( $this->rule['suboption']['params'] ) ) {
$values_callback = self::get_rule_callback_options( $this->rule['suboption']['callback'], $this->rule['suboption']['params'], $val );
if ( $values_callback ) {
$rules_html = '';
} else {
$rules_html = '';
}
}
return $rules_html;
}
/*
* Rules values html markup
* @return string
*/
private function get_rule_value() {
$val = ( $this->value && is_array( $this->value ) && isset( $this->value['value'] ) ) ? $this->value['value'] : '';
$sub_val = ( $this->value && is_array( $this->value ) && isset( $this->value['suboption'] ) ) ? $this->value['suboption'] : '';
$values = '';
switch( $this->rule['type'] ) {
case 'callback';
$callback_function = $this->rule['choices']['callback'];
$callback_params = $sub_val ? array( $sub_val ) : $this->rule['choices']['params'];
if ( isset( $this->rule['suboption'] ) && empty( $callback_params ) ) {
$values_suboption = call_user_func_array( $this->rule['suboption']['callback'], $this->rule['suboption']['params'] );
if ( $values_suboption && is_array( $values_suboption ) && ! empty( $values_suboption ) ) {
foreach ( $values_suboption as $values_val => $values_name ) {
if ( is_array( $values_name ) && isset( $values_name['value'] ) ) {
$values_val = $values_name['value'];
}
$callback_params = array( $values_val );
break;
}
}
}
$values_callback = $this->get_rule_callback_options( $callback_function, $callback_params, $val );
if ( $values_callback ) {
if ( isset( $this->rule['suboption'] ) ) {
$values_callback = '' . $values_callback;
}
$values = '';
} else {
$values = '';
}
break;
case 'bool';
$values .= '';
break;
case 'number';
$step = isset( $this->rule['step'] ) ? 'step="' . esc_attr( $this->rule['step'] ) . '"' : '';
$values .= '';
break;
case 'text';
$placeholder = $this->rule['placeholder'] ? $this->rule['placeholder'] : '';
$values .= '';
break;
}
return $values;
}
/*
* Rules operators html markup
* @return string
*/
private function get_rule_operator() {
$val = ( $this->value && is_array( $this->value ) && isset( $this->value['operator'] ) ) ? $this->value['operator'] : '';
$operators = AWL_Admin_Options::get_rule_operators( $this->rule['operators'] );
$operators_html = '';
return $operators_html;
}
/*
* Rules callback options
* @param $callback string Function name
* @param $params array Function parameters
* @return string
*/
private function get_rule_callback_options( $callback, $params, $value = false ) {
$values = '';
$values_arr = call_user_func_array( $callback, $params );
if ( $values_arr && is_array( $values_arr ) && ! empty( $values_arr ) ) {
foreach ( $values_arr as $values_val => $values_name ) {
if ( is_array( $values_name ) && isset( $values_name['name'] ) && isset( $values_name['value'] ) ) {
$values_val = $values_name['value'];
$values_name = $values_name['name'];
}
$values .= '';
}
}
return $values;
}
}
endif;