Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
4 layer model - business logic for selecting bus futures
Principles of Model - View - Controller example from a Well House Consultants training course
More on Principles of Model - View - Controller [link]

This example is described in the following article(s):
   • Real life PHP application using our course training MVC example - [link]

Source code: 4lm_business.inc Module: Q915

/* 4 layer model - business logic for selecting bus futures */

function load_base_data() {
        $base = array();
        $fh = fopen("choice.data",'r');
        while ($line = fgetcsv($fh,0,"\t")) {
                $key = array_shift($line);
                $base[$key] = $line;
        $_SESSION["choicedata"] = $base;

        $rows = array();
        $fh = fopen("row.data",'r');
        while ($line = fgets($fh)) {
                if (preg_match('/^(.):/',$line,$gotten)) {
                        $current = $gotten[1];
                        $rows[$current] = "";
                } else {
                        $rows[$current] .= $line;
        $_SESSION["rows"] = $rows;

        $cols = array();
        $fh = fopen("col.data",'r');
        while ($line = fgets($fh)) {
                if (preg_match('/^(.):/',$line,$gotten)) {
                        $current = $gotten[1];
                        $cols[$current] = "";
                } else {
                        $cols[$current] .= $line;
        $_SESSION["cols"] = $cols;

function checkphase2() {
        global $alert, $error;
        foreach (array_keys($_SESSION["cols"]) as $rowname) {
                $alert[$rowname] = chek_an_integer($rowname,1,10000);
                $_SESSION[$rowname] = ss($_POST[$rowname]);
        if (! $error) {
                $_SESSION[current] = 3;

function offer_weights() {
        global $alert, $fill;
        $fields = array(array("","<center><b>How important is it to you </b>...</center>",
                                "<center>Least ----- Most</centrer>","type"=>"label"));
        $fvals = "31|42|56|75|100|133|178|237|317";
        foreach (array_keys($_SESSION["cols"]) as $rowname) {
                if ($_POST[$rowname] == "") $_POST[$rowname] = 100;
        $fill[toptag] = "How important is each factor in this decision for you?";

        $fill[body] = "<p>Deciding the future direction for Wiltshire's Public Transport" .
                " Network is going to be a compromise between many factors, and the council" .
                " has a difficult decision to make with regards bus support for the 2017/18" .
                " year and beyond. This tool (prototype at the moment) is a tool to help you" .
                " understand the various elements that go towards making the decision, and" .
                " the way that priorities / importance will affect the outcome.<br /><br />" .
                "<b>We invite you to put yourself in the decision maker's shoes</b>. Select" .
                " a box to the right to add importance or to the left if they're not important" .
                " to you. When you are done, submit the form and we'll rank the eight options" .
                " we're aware of based on the relative importance you've given to each factor" .
                " in the choice. To call up the support page, go <a href=choice.html target=xyz>" .
        $fill[body] .= mkeform($fields);
        $fill[body] .= "</p>";

        $fill[result] = "Results will appear in this area";

function report_results() {
        global $fill;
        $fill[toptag] = "Thank you for your inputs";
        $fill[body] = "<p>Based on those weights, here are the options available and their scores<br />";
        $sortable = array();
        foreach (array_keys($_SESSION["choicedata"]) as $rowname) {
                $fillpart = "<br>Option $rowname ....<br />";
                $fillpart .= $_SESSION[rows][$rowname] . "<br />";
                $score = 0;
                $maxscore = 0;
                $values = $_SESSION["choicedata"][$rowname];
                $vp = 0;
                $vst = "";
                foreach (array_keys($_SESSION["cols"]) as $colname) {
                        $score += $_SESSION[$colname] * $values[$vp];
                        $maxscore += $_SESSION[$colname] * 100;
                        $vst .= $_SESSION[$colname] . "\t";
                $percent = sprintf("%.2f",100.0 * $score / $maxscore);
                $fillpart .= "scores $score out of $maxscore - <b>$percent%</b><br>";
                $sortable[$fillpart] = $score;

                # $fill[body] .= $fillpart;
        foreach (array_keys($sortable) as $record) {
                $fill[body] .= $record;
        $fill[body] .= "<br />If you would like to try different factors, select" .
                " <a href=choice.php>[here]</a>. If you would like to see the support" .
                " page for this application, see <a href=choice.html>[here]</a>";
        $fill[body] .= "</p>";
        $fh = fopen ("loggergame.text","a");
        $att = time();
        fputs($fh, "$vst$_SERVER[REMOTE_ADDR]\t$att\n");


Learn about this subject
This module and example are covered on the following public courses:
 * Ruby on Rails
 * %dj%
Also available on on site courses for larger groups

Books covering this topic
Yes. We have over 700 books in our library. Books covering all the subjects we teach are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "Principles of Model - View - Controller" training module. You'll find a description of the topic and some other closely related examples on the "Principles of Model - View - Controller" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Web site author
This web site is written and maintained by Well House Consultants.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb