AliasController.php 1.81 KB
<?php
/**
 * Alias action handler
 */
 
class AliasController extends WRestController
{
    protected $_modelName = "alias";
    
    public function actions() //determine which of the standard actions will support the controller
    {
        
        return array(
            'list' => array( //use for get list of objects
                'class' => 'WRestListAction',
                'filterBy' => array(
                    'compare' => array(
                        'column' => array(
                            'alias' => 'query',
                            'recipient' => 'query',
                            'comment' => 'query'
                        ),
                        'partial' => true,
                        'operator' => 'OR'
                    )
                ),
                'limit' => 'limit',
                'page' => 'page',
                'order' => $this->getOrder(Yii::app()->request->getParam("sort"))
            ),
            'delete' => 'WRestDeleteAction',
            'get' => 'WRestGetAction',
            'create' => array(
                'class' => 'WRestCreateAction',
                'scenario' => 'update'
            ),
            'update' => array(
                'class' => 'WRestUpdateAction',
                'scenario' => 'update'
            )
        );
    }

    /**
     * Build order value
     */
    private function getOrder( $paramValue ) {
        if(!empty($paramValue) && ($jdecode = json_decode($paramValue))) {
            if(!is_array($jdecode)) {
                $jdecode = array($jdecode);
            }
            
            array_walk($jdecode, create_function('&$item, $key', '
                $item = sprintf("%s %s", $item->property, $item->direction);
            '));
            
            return $jdecode;
        }

        return $paramValue;
    }
}