-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add First, Last, Pos, TotalItems and EvenOdd helpers #282
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added an idea.
Also note that we're in the process of updating the master branch for elemental v4 with some breaking changes. You may want to target the 3
branch
src/Models/BaseElement.php
Outdated
*/ | ||
public function isFirstElement() | ||
{ | ||
return !($this->Parent()->Elements()->filter('Sort:LessThan', $this->Sort)->exists()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you reckon about $this->Parent()->Elements()->first() === $this
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would $this
be robust enough? I'm just thinking of objects perhaps changing at runtime with something like fluent etc..
Perhaps $this->Parent()->Elements()->first()->ID === $this->ID
. ID is all that matters right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah give that a go. Your tests should be good enough to try it out =D
Related: #211 |
@robbieaverill What to you think like #211 should we do something at the ElementArea level or leave it as functions on |
@wilr I'm happy to follow your judgement =) they sound like useful methods either way |
Ok my judgement is consistently probably out weighs risk since the behaviour for all the options is going to be the same unless you start to do funky things like building your own Updated the code, tests and docs. Changed branch to 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor doc block comments
src/Models/BaseElement.php
Outdated
} | ||
|
||
/** | ||
* @return boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: should be int
src/Models/BaseElement.php
Outdated
/** | ||
* Returns the position of the current element. | ||
* | ||
* @return boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int
src/Models/BaseElement.php
Outdated
} | ||
|
||
/** | ||
* @return boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
if ($this->hasExtension(Versioned::class)) { | ||
$records = Versioned::get_by_stage(BaseElement::class, Versioned::DRAFT); | ||
} else { | ||
$records = BaseElement::get()->max('Sort'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review but it appears this is a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ScopeyNZ What seems to be the bug? I added this in as it was skipping draft version numbers and it was also using the global max rather than the local max.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$records = ...->max('Sort')
should return an int, but is treated like an object on the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yep, but only if versioned had been removed with is rare. I'll submit a fix to the 3 branch.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet 👍
When in an Element template the expected $First, $Last helpers aren't there so this replaces them with something.