Skip to content
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

New field type - unique value #2160

Closed
jonmagne opened this issue May 3, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@jonmagne
Copy link

commented May 3, 2014

I wish there would be a plain text field type called "unique value" or something similar, where upon saving the post, the value/string would be compared to the values from the same field in other posts, and if a post with the same value/string already exists, the user would be told to change the text in this field to something unique.

This would be very helpful when using Pods for shops, inventories and collections where each object (post) has a unique identifier, SKU, ISBN, barcode or similar, and where it would be helpful to avoid registering something with an ID that already exists.

I tried finding out how to do this, but all I found was lots of forum posts from people needing the same thing. I need this for a museum collection web site I am planning.

@Shelob9 Shelob9 modified the milestones: Pods-related Plugins, Pods Future Release May 4, 2014

@Shelob9

This comment has been minimized.

Copy link
Contributor

commented May 4, 2014

A user said they were going to work on a plugin for this and forked the Pods plugin starter plugin. They haven't pushed and changes to the repo, but that doesn't mean they haven't made any progress. Maybe you can contact that user and see if they want to work together on this.

https://github.com/Whirl3d/pods-fieldtype-incr

@sc0ttkclark

This comment has been minimized.

Copy link
Member

commented May 4, 2014

This is available for Advanced Content Types as the "Unique" option.
Support for other content types has not yet been added, so this would be a
duplicate of that.

On Saturday, 3 May 2014, Josh Pollock notifications@github.com wrote:

A user said they were going to work on a plugin for this and forked the
Pods plugin starter plugin. They haven't pushed and changes to the repo,
but that doesn't mean they haven't made any progress. Maybe you can contact
that user and see if they want to work together on this.

https://github.com/Whirl3d/pods-fieldtype-incr

Reply to this email directly or view it on GitHubhttps://github.com//issues/2160#issuecomment-42120753
.

Best Regards,

Scott Kingsley Clark
Developer


E-mail: lol@scottkclark.com
Website: http://scottkclark.com/
Phone: 214.233.4048

Google / iMessage: lol@scottkclark.com
Skype / Yahoo: sc0ttkclark

IRC: sc0ttkclark / irc.freenode.net

@jonmagne

This comment has been minimized.

Copy link
Author

commented May 5, 2014

Oh sorry, I have no clue how I could miss that it was possible for Advanced Content Types (I'm usually quite good at finding information so this surprises me). I tested it and it works, so right now I'm probably going to use ACT to solve this, but I'm also going to wait for (the UI for) field groups for ACT in 3.0 (when is that due anyway?) because what I'm planning requires lots and lots of fields.

I still feel that this perhaps should be possible for an ordinary plain text field, without having to resort to ACT. I closed this, but you may open it as you see fit... not used to how things are done on GitHub, sorry...

@jonmagne jonmagne closed this May 5, 2014

@Shelob9

This comment has been minimized.

Copy link
Contributor

commented May 5, 2014

@jonmagne Here is a simple way to create this without using an ACT:

  • Add an option to the database to house the last used unique number and set its value to the first number.
  • Add number or plain text field to the Pod.
  • Add a pre_save filter that checks for new items and if so it would get the value of the unique number option, change it to the next number (by adding 1, for example,) and than save that value to both the field in the Pod and the option in the DB.
@mastef

This comment has been minimized.

Copy link
Contributor

commented May 5, 2014

Something a bit related.. populate pods fields with unique values :

add_filter("pods_api_pre_save_pod_item_mypod", "generate_api_key_if_empty", 10, 2);

function generate_api_key_if_empty($pieces=null, $is_new_item=null){

    if(empty($pieces[ 'fields' ][ 'api_token' ][ 'value' ])){
        $new_token = generate_api_token_from_wordlist(); // spits out a random token
        while(api_token_exists($new_token)){
            $new_token = generate_api_token_from_wordlist();
        }
        $pieces[ 'fields' ][ 'api_token' ][ 'value' ] = $new_token;
    }
    return $pieces;
}

function api_token_exists($token){
    if(pods('mypod')->find(null, -1, 'api_token="'.$token.'"')->total_found() > 0){
        return true;
    }
    return false;
}

We use this to generate random tokens when the value is empty on pods save.

@jonmagne

This comment has been minimized.

Copy link
Author

commented May 5, 2014

@mastef Hey thanks, I guess I could make a similar function to api_token_exists to see if the unique text already exists, but I prefer it to be built in with the plugin. That way it is more secure for updates etc.

I thank you for the effort, @Shelob9, but the user has to assign the text himself, and not necessarily in sequence. Most museums already have unique identification numbers or codes associated with their items. Seeing as most of the items got their numbers long before computers were an ordinary thing, the systems usually are not completely straight forward with lots (and I do mean lots) of exceptions and thus, as said, requires manual input. The paper archives from the past, which to a great extent haven't yet been transferred to digital form, are also usually not digitized in sequence.

Like I said, I just need to check that anything the user enters doesn't already exist, because that would indicate that either the user made a mistake (most likely), or there is a mistake in the paper archives (of which there must surely be quite a few). The option "Unique" for a plain text field in an ACT works the way I want it to. I'm sure there are lots of libraries, shops etc. that already have numbers for their books, products etc. that they want to fill in manually as well, that could use that function.

@sc0ttkclark sc0ttkclark self-assigned this Dec 29, 2015

@sc0ttkclark sc0ttkclark modified the milestones: Pods Future Release, Pods 3.0 Dec 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.