Raymond Geerts Posted October 31, 2014 Share Posted October 31, 2014 (edited) FieldtypePageWithDate & InputfieldPageWithDate Module for ProcessWire - Page Reference with Date Field - Field that stores one or more references to ProcessWire pages Modified version of the FieldtypePage module in ProcessWire with extra datetime field containing the date a page was added to the inputfield. Github URL Link: FieldtypePageWithDate To install Copy to /site/modules/ and go to Admin > Modules > Check for new modules. Requirement Requires: InputfieldPageWithDate (will be installed automaticly) Tested on ProcessWire 2.5.6 dev Setup in back-end install both modules:FieldtypePageWithDate InputfieldPageWithDate create a new field in ProcessWire and give it a nameeg. myfriends as type choose PageWithDate choose the right dereference for your needs (all 3 modes work fine with this field)Multiple pages (PageArray) (in this example we are using this) Single page (Page) or boolean false when none selected Single page (Page) or empty page (NullPage) when none selected assign a selector to the field, in this example we will use users Template of selectable page(s) (select the user template) choose a label field, since we are using users set it to name Label Field name set an input field type, depending if you are using dereference of multiple or a single pagefor this example we are using AsmSelect save the field and assign it to a template of choice Add some users/friends to the field by editing a page with this template Usage in front-end In you template you can acces the field as you usualy do with any FieldtypePage. In addition to this the new parameter "assigned" is available Multiple pages if (count($page->myfriends)) { foreach($page->myfriends as $friend) { echo "id: ".$friend->id."<br>"; echo "name: ".$friend->name."<br>"; echo "assigned on: ".$friend->assigned."<br><br>"; } } This will output something like: id: 1031name: johndoeassigned on: 2014-10-31 14:22:02id: 1032name: janedoeassigned on: 2013-04-15 23:16:38 Note: To use your own data/time formatting set $friend->of(false); to get a unix timestamp from the database Single page echo "id: ".$page->myfriends->id."<br>"; echo "name: ".$page->myfriends->name."<br>"; echo "assigned on: ".$page->myfriends->assigned."<br>";This will output something like: id: 1031name: johndoeassigned on: 2014-10-31 14:22:02 Note: To use your own data/time formatting set $page->myfriends->of(false); to get a unix timestamp from the database Edited: removed extra date() formatting since value is formatted by default. Set assigned datetime manuallyYou can set datetime manually by assigning it to the page you add $friend = $users->get('johndoe'); $friend->assigned = "2012-01-01 12:12:12"; $page->myfriends->add($friend); $page->of(false); $page->save(); Edited: Added information on manually setting the assigned to a datetime value. (if you previously installed this module you need to update atleast the FieldtypePageWithDate.module file) Edited November 11, 2014 by Raymond Geerts 11 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 31, 2014 Share Posted October 31, 2014 This is great, nice addition Raymond. 1 Link to comment Share on other sites More sharing options...
netcarver Posted November 7, 2014 Share Posted November 7, 2014 @Raymond Thanks for sharing this module. I'm thinking of using it in a project but need to know if the assigned value is API settable too - I'm presuming it is but want to be sure. Thanks in advance! 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted November 7, 2014 Share Posted November 7, 2014 @steve: I don't see 'assigned' back in the names array of ->getMatchQuery, so I doubt. One thing I know for sure: Raymond will be open for enhancement. 2 Link to comment Share on other sites More sharing options...
netcarver Posted November 8, 2014 Share Posted November 8, 2014 (edited) @Raymond I'm trying this out now and seem to have hit a problem. I can see that the assigned column is getting stored correctly in the DB but when I access the assigned time as per your example in the opening post I always get "1970-01-01 01:33:34" - which is obviously incorrect. Edited to add: I think your example code should be... if (count($page->myfriends)) { foreach($page->myfriends as $friend) { echo "id: ".$friend->id."<br>"; echo "name: ".$friend->name."<br>"; echo "assigned on: ".$friend->assigned."<br><br>"; } } ...as the assigned field is already formatted. Double-formatting it causes the problem (at least it does in my case.) Edited November 8, 2014 by netcarver 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted November 9, 2014 Author Share Posted November 9, 2014 Thanks for sharing this module. I'm thinking of using it in a project but need to know if the assigned value is API settable too - I'm presuming it is but want to be sure. This is something i havent tried yet, so at the moment i think its not possible. I will take a look at it and if it can be build in i will add it and update the module(s) I'm trying this out now and seem to have hit a problem. I can see that the assigned column is getting stored correctly in the DB but when I access the assigned time as per your example in the opening post I always get "1970-01-01 01:33:34" - which is obviously incorrect. You are right about that, somehow i messed it up, looking at my code i tested with i see i turned output filtering off so thats must be where it went wrong I have edited the instructions here and on github. Thanks for noticing Link to comment Share on other sites More sharing options...
Raymond Geerts Posted November 11, 2014 Author Share Posted November 11, 2014 Thanks for sharing this module. I'm thinking of using it in a project but need to know if the assigned value is API settable too - I'm presuming it is but want to be sure. I have added the ability to set the assigned datetime manually. This can be done by setting the assigned value to the page you going to add. For example: $friend = $users->get('johndoe'); $friend->assigned = "2012-01-01 12:12:12"; $page->myfriends->add($friend); $page->of(false); $page->save(); When you want to modify the value of an already assigned page you will have to remove it first and then add it again with a new assigned datetime value. $friend = $users->get('johndoe'); $page->myfriends->remove($friend); $page->of(false); $page->save(); $friend->assigned = "2012-01-01 12:12:12"; $page->myfriends->add($friend); $page->of(false); $page->save(); 5 Link to comment Share on other sites More sharing options...
netcarver Posted November 11, 2014 Share Posted November 11, 2014 Perfect, Raymond, thank you! 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 8, 2015 Share Posted February 8, 2015 I'm having an issue using this module.my code is this: if($input->post->addfriend && $user->isLoggedin()){ $page->of(false); $page->friends_waiting->add($user); $page->save(); } I get this error Warning: array_filter() expects parameter 1 to be array, null given in /home/public_html/site/modules/FieldtypePageWithDate/FieldtypePageWithDate.module on line 280 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted February 12, 2015 Author Share Posted February 12, 2015 I dont see where you set $user->assigned in your code. You could try the following, hoping that it will solve your problem. (note the move of $page->of(false); ) if ($input->post->addfriend && $user->isLoggedin()) { $user->assigned = date("Y-m-d H:i:s"); $page->friends_waiting->add($user); $page->of(false); $page->save(); } 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 15, 2015 Share Posted February 15, 2015 I'm sorry but the problem still persist. Strange thing is after the error has been displayed the code is executed and it works...just got that error and since I'm using ajax call to perform that code I stuck there because of the error.Edit: disabling debug mode on PW I get this working... Link to comment Share on other sites More sharing options...
Raymond Geerts Posted February 17, 2015 Author Share Posted February 17, 2015 I made a patch on GitHub. Could you take a look and let me know if it fixed the problem? https://github.com/Rayden/FieldtypePageWithDate/tree/Sevarf2-patch Only FieldtypePageWithDate.module has been modified. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 17, 2015 Share Posted February 17, 2015 Hi, tried right now. Now I get this Notice, better than the Warning Notice: Undefined offset: 0 in /home/public_html/site/modules/FieldtypePageWithDate/FieldtypePageWithDate.module on line 281 but still after the notice the code is executed correctly Link to comment Share on other sites More sharing options...
Raymond Geerts Posted February 17, 2015 Author Share Posted February 17, 2015 I will dive in tomorow, i think array_shift might solve it. At the moment i dont have a working example throwing the notice. Any chance you can send me an export of the files and database, so that i can install it here localy. Makes debuging a lot easier. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 17, 2015 Share Posted February 17, 2015 well, there is a huge amount of files and stuff here let me think about a solution, thanks for now Link to comment Share on other sites More sharing options...
Raymond Geerts Posted February 26, 2015 Author Share Posted February 26, 2015 @Sevarf2 The notice about the undefined index is fixed now in FieldtypePageWithDate v1.0.3 https://github.com/Rayden/FieldtypePageWithDate 4 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 27, 2015 Share Posted February 27, 2015 Great I will update the module asap, thanks Link to comment Share on other sites More sharing options...
arjen Posted April 24, 2015 Share Posted April 24, 2015 Finally got a use for your fieldtype Raymond. Works really nice. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now