GithubHelp home page GithubHelp logo

yii2tech / ar-position Goto Github PK

View Code? Open in Web Editor NEW
115.0 10.0 15.0 22 KB

ActiveRecord behavior, which provides ability for custom records order setup

License: Other

PHP 100.00%
yii yii2 yii2-extension activerecord position custom order sort

ar-position's People

Contributors

klimov-paul avatar ondrejvasicek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ar-position's Issues

Position is not updated when deleting the record

I have checked the code for PositionBehavior::beforeDelete and the idea (moveLast()) is great, but it seems not to be working.

What steps will reproduce the problem?

Delete a record

What is the expected result?

Position of other elementos to be updated

What do you get instead?

Elements that were after the deleted record keeps their position. I have elements in positions 1 to 10, if deleting the 2nd the third should become 2nd and the same for the rest.

Additional info

Q A
This Package Version "yii2tech/ar-position": "^1.0"
Yii Framework Version "yiisoft/yii2": "~2.0.6",
PHP version PHP 7.2.19-0ubuntu0.19.04.2 (cli) (built: Aug 13 2019 11:45:23) ( NTS )
Operating system Linux Ubuntu 19.04 5.3.0-050300rc7-generic #201909021831 SMP Mon Sep 2 18:33:34 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Allow to set group attribute value directry

We are facing problem when using PositionBehavior in couple with SoftDeleteBehavior.

We want to exclude deleted records from updateAllCounters update:

public function behaviors() {
    return [
        'softDelete' => [
            'class' => SoftDeleteBehavior::className(),
            'softDeleteAttributeValues' => [
                'isDeleted' => true,
            ],
        ],
        'position' => [
            'class' => PositionBehavior::className(),
            'positionAttribute' => 'position',
            'groupAttributes' => [
                'albumListId',
                'isDeleted',
            ],
        ],
    ];
}

But this causes that PositionBehavior updates only deleted records. Yes, I know that changing behaviors order may solve this problem, but this is not a good idea.

I propose adding ability to set a value into groupAttributes like that:

'groupAttributes' => [
    'albumListId',
    'isDeleted' => false,
]

Thank you.

[ENH] Add new property `insertDefaultPosition`

As I undestand all new records are appended to the end of list when positionAttribute is empty in insert scenario.
Is it a good idea to add a new property (for example insertDefaultPosition) when we can choose default inserting position (first or last or even exactly integer position).

Update groupAttribute

When I update groupAttribute behavior put old position to $this->positionOnSave in beforeUpdate event and then saves it in afterSave event instead of keeping the new calculated position (line 435).
I believe there is a wrong unnecessary line:

$this->positionOnSave = $this->owner->$positionAttribute;

Weird random positioning in group when categoryId is null

When trying to position in a null category group I'm getting the following result:

Initial position:
Item 1 -> position 1

After adding item 2:
Item 1 -> position 0
Item 2 -> position 1

Update item 2 for the first time:
Item 1 -> position 0
Item 2 -> position 2

Update item 2 for the second time:
Item 1 -> position 0
Item 2 -> position 0

Solved this issue by changing the line 256 of PositionBehavior.php to this code:

$condition[$attribute] = empty($this->owner->$attribute)?null:$this->owner->$attribute;

Cant use method movePrev in "position in group"

model source:

public function movePre($position)
{
      $model = new PositionBehavior();
      $model->positionAttribute = $position;
      $model->groupAttributes = ['project_id'];
      $model->movePrev();
  }

controller source:

public function actionMove($id)
    {
        $position = $this->findModel($id)->position;
        $model = new Projectparts();
        $model->movePre($position);
        return $this->redirect(['projects/index']);
    }

return this: Call to a member function find() on null

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.