Giter Club home page Giter Club logo

cakephp-sequence's People

Contributors

adayth avatar admad avatar areveron avatar bravo-kernel avatar curtisgibby avatar dakota avatar josegonzalez avatar lordsimal avatar lorenzo avatar veganista 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

Watchers

 avatar  avatar  avatar  avatar

cakephp-sequence's Issues

Randomly ordered Entities

I've started using this plugin, when users already had order field in place within qobo/cakephp-survey plugin.

As a result, some of the entities had following order sequence within defined survey questions scope:

[
  'question_1' => 1,
  'question_2' => 2, 
  'question_3' => 5,
];

The UI has a wrapper for moveUp() and moveDown() methods of the behaviour, and everything works fine, but when the user has to swap question_2 and question_3, the first one has to be clicked multiple times to reach 4 <-> 5 swap.

Moving question_3 up, the user still has to click multiple times.

I could look into slightly changing _movePosition() method to look for closest neighbour entity (depending whether its up/down direction) and re-calculate its position fields, to get rid off possible gaps.

Restart sequence

  1. Is there possible to restart sequence
    13,15,14,16 => 1,3,2,4

  2. Or ideally keep the sequence to always start with start value
    start, start+1, start+2, ...

Improve setOrder method

I detected that setOrder method fails hard with protected fields ($_accesible Entity definition). With some validation rules, saving entity will fail. I added this line to overcome this issue, but I'm not sure if this is really safe for all types of models (in my app works OK):

$entities = $table->newEntities($data, ['accessibleFields' => ['*' => true]]);

This method could also accept an array of entities, so we don't need to convert our entities to an array of data to use setOrder.

Another suggestion. We can add another method to fix list order numbers (CakeDC List has some method like that) based in passed where conditions. For example, if you have positions 1,2,3,4 and move down 1, the result list will be 0,2,3,4 and I prefer it to be 1,2,3,4. This happen with list upper limit too. Right now I'm using setOrder for this, but I need to get entities, convert to array, pass to setOrder...

I can PR some of this changes if you want.

contains duplicate method "moveup"

I have already used Tree Behavior and if i am going to add Sequence Behavior then coming below error:

ADmad\Sequence\Model\Behavior\SequenceBehavior contains duplicate method "moveup" which is already provided by "Tree"

error

Composer insatll instructions are incorrect

The readme says to run composer require admad/sequence:dev-master to install via composer but you actually need to run composer require admad/cakephp-sequence:dev-master

Problem when using MySQL reserved words

If you use a reserved word as the order field the the generated SQL does not get properly escaped when quoteIdentifiers is set to true.

Not sure if this is a bug with Cake or not.

Example

$this->addBehavior('Sequence.Sequence', [
    'order' => 'order',
    'start' => 0,
    'scope' => 'course_id'
]);

Then the following SQL is created:

UPDATE course_modules SET `order` = (order - 1) WHERE (`order` > :c0 AND `course_id` = :c1)

You can see the order is not getting escaped. It's caused by these lines

$this->_table->query()->newExpr()->add("$orderField + 1")

Issue when using the behavior with belongsToMany with has through option

Main issue is here as i think this is cake related.

The work around seems to be to comment out the beforeFind in the Behavior and and add this to clause to the 'sort' option when creating your association.

        $this->belongsToMany('Modules', [
            'through' => 'course_modules',
            'sort' => ['position' => 'ASC']
        ]);

Until the union problem is fixed this is the only way I've found to use the Behavior with it's intended behavior ( no pun intended )

Problems with virtual fields

I encountered an problem using virtual fields when editing data:
The method "_getOldValue" adds virtual fields to the $values-array (called in line 175). These are later on passed to the database which results in an error - fields not found...

I created an patch which solves this bug for me.

avoidVirtualFields.txt

Field 'position' doesn't have a default value

Hi,

After using successfuly Behavior on a Table having belongsToMany relation and grouping with 'scope' field, I currently trying to use the Behavior on a Table having hasMnay relation. In this case, I don't have to use 'scope' field, I simply want to handle position of each table's record.

I get an SQL error :

"Error: SQLSTATE[HY000]: General error: 1364 Field 'position' doesn't have a default value"
"INSERT INTO gallerycategories (name, slug) VALUES (:c0, :c1)"

Of course, 'position' field has any default value in my SQL settings.
I don't need it assuming Behavior handles 'position' property in Entity.

I debugged Entity in beforeSave method within Behavior and Entity's got 'position' property.
So, I assumed the Behavior was working as expecded... Then, I tryed to set a default value to my 'position' field in SQL Database and I figured out that 'position' field wasn't set into SQL Database, but 'position' default value was setting in instead.

This is running me crazy, because I successfuly used this great Behavior once. By my side, I checked all I do without any success. The only one difference that I got between my successful use case and now, is not having use 'scope' Behavior setting.

Have you got some ideas ?

Add ability to move up/down in list

Sometimes you don't really care to reorder the entire list but just one or two entities, and having a helper method for this would be useful.

Using two (or more) ordering columns

Hey, thanks for your work on this

I have a case where I wanted to keep two columns storing the order.
Is there anyway to accomplish that with the plugin? maybe a workaround?

The case is like a voting system with two phases. I have an order for the first phase and an order for the second phase, they can both be edited.

Plugin namespace

There seems to be some discrepancy between the Admad/Sequence namespace used in the readme and the plain Sequence one the plugin is actually using. Which PR do you prefer?

CakePHP 4.5 deprecations

Deprecated: As of 4.5.0 using query() is deprecated. Instead use insertQuery(), deleteQuery(), selectQuery() or updateQuery() in vendor/admad/cakephp-sequence/src/Model/Behavior/SequenceBehavior.php, line: 555

Modifying lists? insertAt(), moveTo()?

It looks like this behavior is just supporting generating a list on insert but there is no way to modify the list order or insert at a certain position?

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.