Yii Sortable Model Class Reference. Yii Framework

AjaxSortingAction

Package Yii Sortable Model
Inheritance class AjaxSortingAction » CAction » CComponent
Implements IAction
Since 1.0
Source Code extensions//actions/AjaxSortingAction.php
This action is triggered by SortableCGridView widget to store in the background the new records order.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
controller CController the controller who owns this action. CAction
id string id of this action CAction

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CAction
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getController() Returns the controller who owns this action. CAction
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns id of this action CAction
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
run() AjaxSortingAction
runWithParams() Runs the action with the supplied request parameters. CAction

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
runWithParamsInternal() Executes a method of an object with the supplied named parameters. CAction

Method Details

run() method
public void run()
Source Code: extensions//actions/AjaxSortingAction.php#L30 (show)
   public function run()
   {
  if (isset(
$_POST))
  {
     
$order_field $_POST['order_field'];
     
$model call_user_func(array($_POST['model'], 'model'));
     
$dragged_entry $model->findByPk($_POST['dragged_item_id']);
     
/*load dragged entry before changing orders*/
     
$prev $dragged_entry->{$order_field};
     
$new $model->findByPk($_POST['replacement_item_id'])->{$order_field};
     
/*update order only for the affected records*/
     
if ($prev $new)
     {
        for (
$i $prev 1;$i <= $new$i++)
        {
           
$entry $model->findByAttributes(array($order_field => $i));
           
$entry->{$order_field} = $entry->{$order_field} - 1;
           
$entry->update();
        }
     }
     elseif (
$prev $new)
     {
        for (
$i $prev 1;$i >= $new$i--)
        {
           
$entry $model->findByAttributes(array($order_field => $i));
           
$entry->{$order_field} = $entry->{$order_field} + 1;
           
$entry->update();
        }
     }
     
/*dragged entry order is changed at last, to not interfere during the changing orders loop*/
     
$dragged_entry->{$order_field} = $new;
     
$dragged_entry->update();
  }
   }

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.