Plugin Directory

Changeset 1785773


Ignore:
Timestamp:
12/12/2017 09:14:07 PM (8 years ago)
Author:
MaartenM
Message:
  • Components are registered by instance id instead of class name.
Location:
widget-display-conditions/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • widget-display-conditions/trunk/includes/admin.php

    r1777132 r1785773  
    161161                    <optgroup label="<?php echo esc_attr( $category['title'] ); ?>">
    162162                        <?php foreach ( $conditions as $condition ) : ?>
    163                         <option value="<?php echo esc_attr( get_class( $condition ) ); ?>"><?php echo esc_html( $condition->get_title() ); ?></option>
     163                        <option value="<?php echo esc_attr( $condition->get_id() ); ?>"><?php echo esc_html( $condition->get_title() ); ?></option>
    164164                        <?php endforeach; ?>
    165165                    </optgroup>
     
    199199    }
    200200
    201     $param_id = isset( $_POST['param'] ) ? $_POST['param'] : '';
     201    $param = isset( $_POST['param'] ) ? $_POST['param'] : '';
    202202
    203203    $items = array();
    204204
    205     if ( ! empty( $param_id ) )
    206     {
    207         foreach ( (array) $param_id as $class )
     205    if ( ! empty( $param ) )
     206    {
     207        foreach ( (array) $param as $condition_id )
    208208        {
    209             $condition = WDC_API::get_condition( $class );
     209            $condition = WDC_API::get_condition( $condition_id );
    210210
    211211            if ( ! $condition )
     
    227227                $operator_choices[] = array
    228228                (
    229                     'id'   => get_class( $operator ),
     229                    'id'   => $operator->get_id(),
    230230                    'text' => $operator->get_title()
    231231                );
     
    241241            /* ---------------------------------------------------- */
    242242           
    243             $items[ $class ] = array
     243            $items[ $condition_id ] = array
    244244            (
    245245                'operators' => $operator_choices,
  • widget-display-conditions/trunk/js/main.js

    r1777230 r1785773  
    314314            success : function( response )
    315315            {
     316                console.log( response );
     317
    316318                var items = response.data;
    317319
  • widget-display-conditions/trunk/src/WDC/API.php

    r1776540 r1785773  
    1616    }
    1717
    18     static public function get_condition( $class )
     18    static public function get_condition( $id )
    1919    {
    2020        $manager = WDC_Manager_Condition::get_instance();
    2121
    22         return $manager->get( $class );
     22        return $manager->get( $id );
    2323    }
    2424
     
    3030    }
    3131
    32     static public function unregister_condition( $class )
     32    static public function unregister_condition( $id )
    3333    {
    3434        $manager = WDC_Manager_Condition::get_instance();
    3535
    36         $manager->remove( $class );
     36        $manager->remove( $id );
    3737    }
    3838
     
    8585    }
    8686
    87     static public function get_operator( $class )
     87    static public function get_operator( $id )
    8888    {
    8989        $manager = WDC_Manager_Operator::get_instance();
    9090
    91         return $manager->get( $class );
     91        return $manager->get( $id );
    9292    }
    9393
     
    9999    }
    100100
    101     static public function unregister_operator( $class )
     101    static public function unregister_operator( $id )
    102102    {
    103103        $manager = WDC_Manager_Operator::get_instance();
    104104
    105         $manager->remove( $class );
     105        $manager->remove( $id );
    106106    }
    107107}
  • widget-display-conditions/trunk/src/WDC/Condition/Base.php

    r1778990 r1785773  
    33class WDC_Condition_Base extends WDC_Registrable_Base
    44{
    5     protected $id        = null;
    65    protected $title     = null;
    76    protected $category  = null;
     
    109    public function __construct( $id, $title, $args = null )
    1110    {
    12         parent::__construct();
     11        parent::__construct( $id );
    1312
    1413        $defaults = array
     
    1716            'operators' => apply_filters( 'wdc_default_operators', array
    1817            (
    19                 'WDC_Operator_IsEqualTo',
    20                 'WDC_Operator_IsNotEqualTo'
     18                '==',
     19                '!='
    2120            ))
    2221        );
     
    2625        extract( $args, EXTR_SKIP );
    2726
    28         $this->id        = $id;
    2927        $this->title     = $title;
    3028        $this->category  = $category;
    3129        $this->operators = (array) $operators;
    32     }
    33 
    34     public function get_id()
    35     {
    36         return $this->id;
    3730    }
    3831
  • widget-display-conditions/trunk/src/WDC/Manager/Base.php

    r1776540 r1785773  
    1515    }
    1616
    17     public function get( $class )
     17    public function get( $id )
    1818    {
    19         if ( isset( $this->objects[ $class ] ) )
     19        if ( isset( $this->objects[ $id ] ) )
    2020        {
    21             return $this->objects[ $class ];
     21            return $this->objects[ $id ];
    2222        }
    2323
     
    3434        }
    3535
    36         $this->objects[ $class ] = new $class();
     36        $instance = new $class();
     37
     38        $this->objects[ $instance->get_id() ] = $instance;
    3739    }
    3840
    39     public function remove( $class )
     41    public function remove( $id )
    4042    {
    41         if ( isset( $this->objects[ $class ] ) )
     43        if ( isset( $this->objects[ $id ] ) )
    4244        {
    43             unset( $this->objects[ $class ] );
     45            unset( $this->objects[ $id ] );
    4446        }
    4547
  • widget-display-conditions/trunk/src/WDC/Manager/Condition.php

    r1776540 r1785773  
    4343        $conditions = array();
    4444
    45         foreach ( $this->objects as $class => $condition )
     45        foreach ( $this->objects as $id => $condition )
    4646        {
    4747            if ( $condition->get_category() == $category )
    4848            {
    49                 $conditions[ $class ] = $condition;
     49                $conditions[ $id ] = $condition;
    5050            }
    5151        }
  • widget-display-conditions/trunk/src/WDC/Operator/Base.php

    r1776540 r1785773  
    33class WDC_Operator_Base extends WDC_Registrable_Base
    44{
    5     protected $id    = null;
    65    protected $title = null;
    76
    87    public function __construct( $id, $title )
    98    {
    10         parent::__construct();
     9        parent::__construct( $id );
    1110
    12         $this->id    = $id;
    1311        $this->title = $title;
    14     }
    15 
    16     public function get_id()
    17     {
    18         return $this->id;
    1912    }
    2013
  • widget-display-conditions/trunk/src/WDC/Registrable/Base.php

    r1776540 r1785773  
    33class WDC_Registrable_Base extends WDC_Base
    44{
    5     public function __construct()
     5    protected $id = null;
     6
     7    public function __construct( $id )
    68    {
    79        parent::__construct();
     10
     11        $this->id = $id;
     12    }
     13
     14    public function get_id()
     15    {
     16        return $this->id;
    817    }
    918}
Note: See TracChangeset for help on using the changeset viewer.