About Page Reference with Date Field

Field that stores one or more references to ProcessWire pages

Category 1Field Types
Fieldtype modules that represent a data type used by fields.
Category 2Input Fields
Inputfield modules that provide a UI input widget in the ProcessWire admin.
Release StateStable
Should be safe for use in production environments. *
Authorraymond-geerts
Module Version1.0.3
Class NameFieldtypePageWithDate
Compatibility2.5, 2.6, 2.7
Date AddedOctober 31, 2014
Last UpdatedNovember 11, 2015
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/FieldtypePageWithDate/
How to install or uninstall modules

README

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.

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 name
    • eg. 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 page
    • for 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: 1031
name: johndoe
assigned on: 2014-10-31 14:22:02

id: 1032
name: janedoe
assigned 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: 1031
name: johndoe
assigned 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

Set assigned datetime manually

You 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();

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.