yii2tech / ar-position Goto Github PK
View Code? Open in Web Editor NEWActiveRecord behavior, which provides ability for custom records order setup
License: Other
ActiveRecord behavior, which provides ability for custom records order setup
License: Other
Please add feature to check if model is first or last in position
isFirst and isLast methods
I have checked the code for PositionBehavior::beforeDelete and the idea (moveLast()) is great, but it seems not to be working.
Delete a record
Position of other elementos to be updated
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.
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 |
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.
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).
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:
ar-position/PositionBehavior.php
Line 430 in 0822f8b
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;
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.