Quick search:

2. Hours registration

This application is situated in the example2 folder. To run it on your own server you need to create its table and data by executing the SQL in the file 'examples.sql/example2.sql'. To try it out on the phpPeanuts website click here.

It extends a copy from example 1 with hours registration. To do this we added the class Hours to the example2 class folder, and a multi value property 'hours' to the example2.Employee::initPropertyDescriptors method.

The multi value property 'hours' adds navigation over the relationship between Employee and Hours. To do that it uses the Hours>>employeeId property as a foreign key. Calling get('hours') on an Employee instance will return an Array holding the hours instances related to the Employee instance. The other way around the derived property Hours>>employee adds navigation back from the Hours instances to their Employee instance.

This relationship could be broken if an Employee was deleted while it still had hours: the hours would be left referencing an Employee that no longer exists. To prevent this initPropertyDescriptors calls setOnDelete with a 'c'. c stands for 'check' and will make PntDbObject::getDeleteErrorMessages return an array with an error if an Employees property 'hours' is not empty. Alternatively we could have overriden getDeleteErrorMessages on Employee, or set onDelete to 'd' to have the hours of the Employee deleted recursively by PntDbObject::delete.

The availability of the Employee>>hours property leads to an 'hours' button when viewing an instance of Employee in the user interface. When you click the button a table shows up with rows for the Hours instances related to the Employee instance. This is the PropertyPage for the multi value property 'hours'.

From the PropertyPage you can navigate further to an Hours instance by clicking its row. Now you get another EditDetailsPage with a form for editing the properties of the Hours instance.  A value for the property 'employee' can be selected from a list. Its label is a hyperlink back to the EditDetailsPage for the selected Employee instance. The folder icon in between is a hyperlink back to the 'hours' PropertyPage.

If you are using 1.2 or higher, you will notice that most of the properties in the EditDetailsPage have an asterisk behind the label. This means that these properties are compulsory: the user must fill them. This is because the minLength of these properties is larger then 0. In 1.1 and below these properties also had a minLength > 0, but it was not shown in the EditDetailsPage.

To the skinSubmenu.php in the example2 folder we added hyperlink 'Hours'. Its urls is  'example2/index.php?pntType=Hours&pntHandler=SearchPage'. It leads to a SearchPage by which you can search for instances of Hours. In this SearchPage you can click on the hyperlink 'advanced'. A Query By Example form shows up with search options (filters). With these you can search by values of one of the persistent properties of Hours or one of the persistent properties of related classes.

Finally we want to ask your attention for the initial values set when an instance of Hours is created. These are the variable declarations at the top of the page, and the 'set' call in the constructor. The last also shows how to format a date according to the internal date format, which is retrieved from the ValueValidator class. This class defines the formats used internally by all peanuts in the domain model. Its instances take care of validation of property values against propertyDescriptor settings.