models/Vote.php
public static function process(ActiveRecord $model, $type)
    {
        $value = self::value($type);

        if (isset($model['votes'])) {
            $model['votes'] += $value;

            $vote = new self([
                'entity_id' => $model['id'],
                'vote' => $value,
                'entity' => self::modelEntityType($model)
            ]);

            if ($vote->save() && $model->save()) {
                return $model;
            }
        }

        return false;
    }
public static function process(ActiveRecord $model, $type)
    {
        $value = self::value($type);

        if (isset($model['votes'])) {
            $model['votes'] += $value;

            $vote = new self([
                'entity_id' => $model['id'],
                'vote' => $value,
                'entity' => self::modelEntityType($model)
            ]);

            if ($vote->save() && $model->save()) {
                return $model;
            }
        }

        return false;
    }
public static function process ( ActiveRecord $ model , $ type ) { $ value = self :: value ( $ type ) ; if ( isset ( $ model [ 'votes' ] ) ) { $ model [ 'votes' ] += $ value ; $ vote = new self ( [ 'entity_id' => $ model [ 'id' ] , 'vote' => $ value , 'entity' => self :: modelEntityType ( $ model ) ] ) ; if ( $ vote -> save ( ) && $ model -> save ( ) ) { return $ model ; } } return false ; }
Increment votes for given model
@param ActiveRecord $model
@param string $type of vote, up or down
@return ActiveRecord
Increment votes for given model