Nooku Server is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-server

Commit 1619

User picture
  • Author: JohnBell
  • 2011-06-07 04:38 (almost 3 years ago)

Re #90 #100 updeated orderable behavior to be re-usable

Files Affected

 
16181619
23
    public function _initialize(KConfig $config)
23
    public function _initialize(KConfig $config)
24
    {
24
    {
25
        $sluggable = KDatabaseBehavior::factory('sluggable', array('columns' => array('name')));
25
        $sluggable = KDatabaseBehavior::factory('sluggable', array('columns' => array('name')));
26
            
26
        $orderable = Kfactory::get('admin::com.categories.database.behavior.orderable', array('parent_column' => 'catid'));
 
 
27
 
27
        $config->append(array(
28
        $config->append(array(
28
            'identity_column'    => 'bid',
29
            'identity_column'    => 'bid',
29
            'base'               => 'banner',
30
            'base'               => 'banner',
30
            'name'               => 'banner',
31
            'name'               => 'banner',
31
            'behaviors'             => array('creatable', 'lockable', $sluggable, 'orderable', 'hittable'),
32
            'behaviors'             => array('creatable', 'lockable', $sluggable, $orderable, 'hittable'),
32
            'column_map'         => array(
33
            'column_map'         => array(
33
                'enabled'    => 'showBanner',
34
                'enabled'    => 'showBanner',
34
                'created_on' => 'date',
35
                'created_on' => 'date',
16181619
21
{
21
{
22
    protected $_parent;
22
    protected $_parent;
23
 
23
 
 
 
24
    /**
 
 
25
     * The parent column name
 
 
26
     *
 
 
27
     * @var string
 
 
28
     */
 
 
29
    protected $_parent_column;
 
 
30
 
 
 
31
 
 
 
32
    public function __construct( KConfig $config = null)
 
 
33
    {
 
 
34
        $config->append(array('parent_column' => null));
 
 
35
        $this->_parent_column = $config->parent_column;
 
 
36
 
 
 
37
        parent::__construct($config);
 
 
38
    }
 
 
39
 
24
    public function _buildQueryWhere(KDatabaseQuery $query)
40
    public function _buildQueryWhere(KDatabaseQuery $query)
25
    {
41
    {
26
        //Implement your where query here depending on your conditions
42
        if ($this->_parent_column)
27
        $section = $this->_parent ? $this->_parent : $this->section;    
43
        {
28
        $query->where('section', '=', $section);
44
            $parent = $this->_parent ? $this->_parent : $this->{$this->_parent_column};   
 
 
45
            $query->where($this->_parent_column, '=', $parent);
 
 
46
        }
29
    }
47
    }
30
 
48
 
31
    /**
49
    /**
...
 
...
 
43
            if (isset($this->order))
61
            if (isset($this->order))
44
            {
62
            {
45
                unset($this->old_parent);
63
                unset($this->old_parent);
46
                //default action
64
                //default action               
47
                parent::_beforeTableUpdate($context);
65
                $this->order($this->order);
48
                
 
 
49
            } 
66
            } 
50
            elseif (isset($this->old_parent)) 
67
            elseif (isset($this->old_parent)) 
51
            {
68
            {
...
 
...
 
67
     */
84
     */
68
    protected function _afterTableUpdate(KCommandContext $context)
85
    protected function _afterTableUpdate(KCommandContext $context)
69
    {
86
    {
70
        if (isset($this->old_parent) && $this->old_parent != $this->section )
87
        if (isset($this->old_parent) && $this->old_parent != $this->{$this->_parent_column} )
71
        {
88
        {
72
            //section has changed,
89
            //section has changed,
73
            //tidy up the old section
90
            //tidy up the old section
16181619
22
    public function  _initialize(KConfig $config) 
22
    public function  _initialize(KConfig $config) 
23
    {
23
    {
24
        $config->identity_column = 'id';
24
        $config->identity_column = 'id';
25
        
25
        $orderable = Kfactory::get('admin::com.categories.database.behavior.orderable', array('parent_column' => 'section'));
 
 
26
                    
26
        $config->append(array(
27
        $config->append(array(
27
            'name'       => 'categories',
28
            'name'       => 'categories',
28
            'behaviors'  => array('lockable', 'orderable', 'sluggable', 'cascadable'),
29
            'behaviors'  => array('lockable',$orderable, 'sluggable', 'cascadable'),
29
            'column_map' => array(
30
            'column_map' => array(
30
                'enabled'      => 'published',
31
                'enabled'      => 'published',
31
                'locked_on'    => 'checked_out_time',
32
                'locked_on'    => 'checked_out_time',