ActiveWAFL Crash Course

The WAFL Cones Ice Cream Shop, Version 1.0

3.4: Generate the models

Before you can generate the code for the models, you need to setup a connection to a database.

Edit your Settings.dev.syrp file and setup a DataStorage by adding the following syrup to the end of the file.

Append to Settings.dev.syrp file to enable the database connection
  1. DataStorage
  2.     Common
  3.         LoadBalanced        =   0   //0=none,   1=roundrobin
  4.  
  5.     Master
  6.         Uri                 =   192.168.1.20
  7.         Catalog             =   waflcones
  8.         Username            =   db-username
  9.         Password            =   db-password
  10.         CreateScript        =   Database/Sql/CreateDatabase.sq
  11.         UpdateScript        =   Database/Sql/NextUpdate.sql
  12.         ReplicationRole     =   Master
  13.         PersistModels       =   {true}
  14.         ModelGroup          =   WaflCones
  15.         RequiredLocation    =   Sessions
  16.         AccessScope         =   ReadWrite
  17.         EngineDriverPath    =   \\Wafl\\Extensions\\Storage\\Mysql
  18.         CharacterEncoding   =   utf8

UpdateDataModel

Use the application's Bin/UpdateDataModel utility to generate the WaflCone's Data Model and the Functional Model classes.

Output from the UpdateDataModel utility

C:\xampp\vhosts\shared\CrashCourse\WaflCones.dev\WaflCones\Bin>UpdateDataModel

C:\xampp\vhosts\shared\CrashCourse\WaflCones.dev\WaflCones\Bin>call WaflCliBoots
trap.bat
ActiveWAFL CLI...
ActiveWAFL environment is set to c:/xampp/vhosts/shared/Wafl/
Updating the data model...

ActiveWAFL Utilities

0.3.x - UpdateDataModel Utility
App Initialized
Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Employee.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Employee.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Employee.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Employee.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Flavor.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Flavor.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Flavor.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Flavor.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/SaleItem.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/SaleItem.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/SaleItem.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/SaleItem.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Sale.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Sale.php...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Da
taModel/Sale.js...
Done

Saving file c:/xampp/vhosts/shared/CrashCourse/WaflCones.dev/WaflCones\Models/Fu
nctionalModel/Sale.js...
Done

C:\xampp\vhosts\shared\CrashCourse\WaflCones.dev\WaflCones\Bin>
 

The Data Model and Functional Model classes have successfully been generated.

Back in section 3.3 of this tutorial, in the Extensions.syrp configuration file, we specified that the Employee class will be used to represent website users.

Extensions.syrp setting that specifies the class to be used to represent a website user
  1. UserClass   =   \\WaflCones\\FunctionalModel\\Employee

All website users need to implement the IActor interface so that resource permissions can be honored. We need to make a small modification to the generated Employee Functional Model so that Employees can be treated as "Actors".

In order to make Employees into Actors, edit the Functional Model file Models/FunctionalModel/Employee.php and implement IActor by replacing the contents with the following:

The Employee Functional Model, modified to implement the IActor interface.
  1. <?php
  2. namespace WaflCones\FunctionalModel;
  3.  
  4. /**
  5.  * Employee
  6.  * Represents a row in the database table Employees
  7.  */
  8. class Employee extends \WaflCones\DataModel\Employee implements \DblEj\Users\IUser
  9. {
  10.     public function Get_ActorId()
  11.     {
  12.         return "Employee".$this->_employeeId;
  13.     }
  14.  
  15.     public function Get_ActorTypeId()
  16.     {
  17.         return \DblEj\Resources\Resource::RESOURCE_TYPE_PERSON;
  18.     }
  19.  
  20.     public function Get_DisplayName()
  21.     {
  22.         return $this->_fullName;
  23.     }
  24.  
  25.     public function Get_UserId()
  26.     {
  27.         return $this->_employeeId;
  28.     }
  29.  
  30.     public function Get_Username()
  31.     {
  32.         return $this->_fullName;
  33.     }
  34.  
  35.     public function Set_Username($newUsername)
  36.     {
  37.         $this->_fullName = $newUsername;
  38.     }
  39.  
  40. }

The Data Model and Functional Model for both the server and client side are ready to go.
Next we'll create the Presentation Templates.