Source for file InstallController.php

Documentation is available at InstallController.php

  1. <?php
  2. /* -------------------------------------------------------------------------- */
  3. /* Module      : InstallController                                            */
  4. /*                                                                            */
  5. /* Version History :                                                          */
  6. /*                                                                            */
  7. /* Date        Vsn     Author          Description                            */
  8. /* -------------------------------------------------------------------------- */
  9. /* 04/02/09    1.0     S.Lindo         Initial version.                       */
  10. /* -------------------------------------------------------------------------- */
  11. /**
  12.  * Handles the actions for installation of the online booking system.
  13.  * 
  14.  * @package Default
  15.  */
  16. class InstallController extends Zend_Controller_Action 
  17. {
  18.     public function init(){
  19.         parent::init();
  20.         // Shared behaviour should be placed here.
  21.     }
  22.  
  23.     /**
  24.      * The default action for all controllers.
  25.      *
  26.      * This controls all installation activites
  27.      *
  28.      * @return void 
  29.      */
  30.     public function indexAction(
  31.     {
  32.         $tab='&nbsp;&nbsp;&nbsp;&nbsp;';
  33.  
  34.         $this->_helper->layout->setLayout('website');
  35.         $this->view->pageTitle='Install';
  36.  
  37.         $this->view->pageSkillSet null;
  38.  
  39.         $this->installReferenceData($tab);
  40.         $this->installClients($tab);
  41.     }
  42.  
  43.     /**
  44.      * Populate the database with all demo clients (and root)
  45.      *
  46.      * @return void 
  47.      */
  48.     private function installClients($tab
  49.     {
  50.         echo '<br /><br />-------------------------------------------------------------------';
  51.         echo '<br />Installing CLIENTS<br />';
  52.         $property_id 0;
  53.         $accomm_id 0;
  54.  
  55.  
  56.         $clientIdsArray array();
  57.         $clientIdsArray['CLIENT_ROOT'array
  58.                            (
  59.                                'client_id' => CLIENT_ROOT,
  60.                                'user_id'   => LOGIN_NAME_ROOT,
  61.                                'perm_id'   => PERM_ROOT
  62.                            );
  63.         $clientIdsArray['CLIENT_DEMO_VILLA'array
  64.                            (
  65.                                'client_id' => CLIENT_DEMO_VILLA,
  66.                                'user_id'   => LOGIN_NAME_DEMO_VILLA,
  67.                                'perm_id'   => PERM_CLIENT_PREMIUM
  68.                            );
  69.         $clientIdsArray['CLIENT_DEMO_BandB'array
  70.                            (
  71.                                'client_id' => CLIENT_DEMO_BandB,
  72.                                'user_id'   => LOGIN_NAME_DEMO_BandB,
  73.                                'perm_id'   => PERM_CLIENT_PREMIUM
  74.                            );
  75.  
  76.         $clientTypeArray array
  77.                            (
  78.                                'CLIENT_TYPE_WEBSITE'  => CLIENT_TYPE_WEBSITE,
  79.                                'CLIENT_TYPE_OWNER'    => CLIENT_TYPE_OWNER,
  80.                                'CLIENT_TYPE_ROOT'     => CLIENT_TYPE_ROOT
  81.                            );
  82.  
  83.         $paymentMethodsArray array
  84.                            (
  85.                                'PYT_CARD'   => PYT_CARD,
  86.                                'PYT_CHEQUE' => PYT_CHEQUE,
  87.                                'PYT_PHONE'  => PYT_PHONE
  88.                            );
  89.  
  90.         $seasonsArray array
  91.                         (
  92.                             'SEASON_DEFAULT'  => SEASON_DEFAULT
  93.                         );
  94.         $bookableDetailsArray array
  95.                                 (
  96.                                     'BOOKABLE_ADULT'  => 1,
  97.                                     'BOOKABLE_CHILD'  => 2,
  98.                                     'BOOKABLE_INFANT' => 3,
  99.                                     'BOOKABLE_COT'    => 4,
  100.                                     'BOOKABLE_PET'    => 5,
  101.                                     'BOOKABLE_RQT'    => 6
  102.                                 );
  103.  
  104.         $path=APPLICATION_PATH '/config/install/clients';
  105.         if ($handle opendir($path))
  106.         {
  107.             $client new Client ();
  108.             $user new User ();
  109.             $contactDetails new ContactDetails ();
  110.             $clientPayment new ClientPayment ();
  111.             $clientDeposit new ClientDeposit ();
  112.             $clientSeason new ClientSeason ();
  113.             $clientProperty new ClientProperty ();
  114.             $property new Property ();
  115.             $propertyOffers new PropertyOffers ();
  116.             $propertyConditions new PropertyConditions ();
  117.             $accommodation new Accommodation ();
  118.             $accommDetails new AccommDetails ();
  119.             $durationPrice new DurationPrice ();
  120.  
  121.             // Loop over the client configuration files directory
  122.             while (false !== ($file readdir($handle)))
  123.             {
  124.                 if (!is_dir($file))
  125.                 {
  126.                     $filenameAsArray explode('.'$file);
  127.                     if (count($filenameAsArray1)
  128.                     {
  129.                         if ($filenameAsArray[1== 'xml')
  130.                         {
  131.                             $fullPath $path '/' $file;
  132.                             $config new Zend_Config_Xml ($fullPath);
  133.  
  134.                             echo '<br /><br />-------------------------------------------------------------------';
  135.  
  136.  
  137.                             // CLIENT
  138.                             $clientRow null;
  139.                             $clientRow $client->createRow($config->client->toArray());
  140.                             $constants $clientIdsArray[$clientRow->client_id];
  141.                             $clientRow->client_id $constants['client_id'];
  142.                             $clientRow->client_type $clientTypeArray[$config->client->client_type];
  143.                             if ($clientRow->cheques_to == null)
  144.                             {
  145.                                 $clientRow->cheques_to $clientRow->company_name;
  146.                             }
  147.                             echo '<br />Installing client ' $clientRow->client_id;
  148.                             $client->delete('client_id=' $clientRow->client_id);
  149.                             $client->insert($clientRow->toArray());
  150.  
  151.                             // USER
  152.                             echo '<br />Installing user ' $config->client->user->last_name;
  153.                             $userRow null;
  154.                             $userRow $user->createRow($config->client->user->toArray());
  155.                             $userRow->client_id $clientRow->client_id;
  156.                             $userRow->user_id $constants['user_id'];
  157.                             $userRow->perm_id $constants['perm_id'];
  158.                             $userRow->create_date DATE_TODAY;
  159.                             $user->delete('client_id=' $clientRow->client_id " AND user_id='" $userRow->user_id "'");
  160.                             $user->insert($userRow->toArray());
  161.  
  162.                             // CONTACT DETAILS
  163.                             echo '<br />Installing contact details';
  164.                             $contactDetailsRow null;
  165.                             $contactDetailsRow =  $contactDetails->createRow($config->client->user->contact_details->toArray());
  166.                             $contactDetailsRow->user_id $userRow->user_id;
  167.                             $contactDetails->delete("user_id='" $contactDetailsRow->user_id "'");
  168.                             $contactDetails->insert($contactDetailsRow->toArray());
  169.  
  170.                             // CLIENT PAYMENTS
  171.                             if ($config->client->client_payments != null)
  172.                             {
  173.                                 echo '<br />Installing client payment methods' $clientRow->client_id;
  174.                                 $clientPayment->delete('client_id=' $clientRow->client_id);
  175.                                 foreach ($config->client->client_payments as $paymentDefinition)
  176.                                 {
  177.                                     $clientPaymentRow null;
  178.                                     $clientPaymentRow =  $clientPayment->createRow($paymentDefinition->toArray());
  179.                                     $clientPaymentRow->client_id $clientRow->client_id;
  180.                                     $clientPaymentRow->method_id  $paymentMethodsArray[$paymentDefinition->method_id];
  181.                                     $clientPayment->insert($clientPaymentRow->toArray());
  182.                                 }
  183.                             else {
  184.                                 echo '<br />** No client payment methods to install** ';
  185.                             }
  186.  
  187.                             // CLIENT DEPOSIT
  188.                             if ($config->client->client_deposit != null)
  189.                             {
  190.                                 echo '<br />Installing client deposit' $clientRow->client_id;
  191.                                 $clientDepositRow null;
  192.                                 $clientDepositRow =  $clientDeposit->createRow($config->client->client_deposit->toArray());
  193.                                 $clientDepositRow->client_id $clientRow->client_id;
  194.                                 $clientDeposit->delete('client_id=' $clientDepositRow->client_id);
  195.                                 $clientDeposit->insert($clientDepositRow->toArray());
  196.                             else {
  197.                                 echo '<br />** No client deposit to install** ';
  198.                             }
  199.  
  200.                             // CLIENT SEASONS
  201.                             if ($config->client->client_seasons != null)
  202.                             {
  203.                                 $clientSeason->delete('client_id=' $clientRow->client_id);
  204.                                 foreach ($config->client->client_seasons as $seasonDefinition)
  205.                                 {
  206.                                     echo '<br />Installing client season' $clientRow->client_id;
  207.                                     $clientSeasonRow null;
  208.                                     $clientSeasonRow =  $clientSeason->createRow($seasonDefinition->toArray());
  209.                                     $clientSeasonRow->client_id $clientRow->client_id;
  210.                                     $clientSeasonRow->season_id  $seasonsArray[$seasonDefinition->season_id];
  211.                                     $clientSeason->insert($clientSeasonRow->toArray());
  212.                                 }
  213.                             else {
  214.                                 echo '<br />** No client seasons to install** ';
  215.                             }
  216.  
  217.  
  218.                             // 'Root' clients does not have properties
  219.                             if ($config->client->client_property != null)
  220.                             {
  221.                                 $clientProperty->delete('client_id=' $clientRow->client_id);
  222.                                 // PROPERTIES
  223.                                 foreach ($config->client->client_property as $propertyDefinition)
  224.                                 {
  225.                                     // CLIENT_PROPERTY
  226.                                     $property_id++;
  227.                                     $clientPropertyRow null;
  228.                                     $clientPropertyRow $clientProperty->createRow();
  229.                                     $clientPropertyRow->client_id $clientRow->client_id;
  230.                                     $clientPropertyRow->property_id $property_id;
  231.                                     echo '<br />Installing client property ' $clientPropertyRow->property_id;
  232.                                     $clientProperty->insert($clientPropertyRow->toArray());
  233.                                     // PROPERTY
  234.                                     $propertyRow null;
  235.                                     $propertyRow $property->createRow();
  236.                                     $propertyRow->property_id $clientPropertyRow->property_id;
  237.                                     $propertyRow->description $propertyDefinition->description;
  238.                                     $propertyRow->main $propertyDefinition->main;
  239.                                     $propertyRow->single_unit $propertyDefinition->single_unit;
  240.  
  241.                                     echo '<br />' $tab 'Installing property ' $propertyRow->property_id ' - ' $propertyDefinition->description;
  242.                                     $property->delete('property_id=' $propertyRow->property_id);
  243.                                     $property->insert($propertyRow->toArray());
  244.  
  245.                                     // PROPERTY CONDITIONS
  246.                                     echo '<br />' $tab $tab 'Installing booking conditions ';
  247.                                     $propertyConditionsRow null;
  248.                                     $propertyConditionsRow $propertyConditions->createRow();
  249.                                     $propertyConditionsRow->property_id $propertyRow->property_id;
  250.                                     $propertyConditionsRow->description $propertyDefinition->conditions;
  251.                                     $propertyConditions->delete('property_id=' $propertyConditionsRow->property_id);
  252.                                     $propertyConditions->insert($propertyConditionsRow->toArray());
  253.  
  254.  
  255.                                     // PROPERTY OFFERS
  256.                                     echo '<br />' $tab $tab 'Installing special offers ';
  257.                                     $propertyOffersRow null;
  258.                                     $propertyOffersRow $propertyOffers->createRow();
  259.                                     $propertyOffersRow->property_id $propertyRow->property_id;
  260.                                     $propertyOffersRow->description $propertyDefinition->offers;
  261.                                     $propertyOffers->delete('property_id=' $propertyConditionsRow->property_id);
  262.                                     $propertyOffers->insert($propertyOffersRow->toArray());
  263.  
  264.                                     $accommodation->delete('property_id=' $propertyRow->property_id);
  265.                                     foreach ($propertyDefinition->accommodations as $accommodationDefinition)
  266.                                     {
  267.                                         $accomm_id++;
  268.                                         echo '<br />' $tab $tab 'Installing accommodation ' $accomm_id ' - ' $accommodationDefinition->description;
  269.  
  270.                                         $accommodationRow null;
  271.                                         $accommodationRow $accommodation->createRow();
  272.                                         $accommodationRow->accomm_id $accomm_id;
  273.                                         $accommodationRow->property_id $propertyRow->property_id;
  274.                                         $accommodationRow->description $accommodationDefinition->description;
  275.                                         $accommodationRow->max_occupancy $accommodationDefinition->max_occupancy;
  276.                                         $accommodationRow->full_pyt_deadline $accommodationDefinition->full_pyt_deadline;
  277.                                         $accommodationRow->url $accommodationDefinition->url;
  278.                                         $accommodationRow->notes $accommodationDefinition->notes;
  279.                                         $accommodationRow->live_flag $accommodationDefinition->live_flag;
  280.                                         $accommodation->insert($accommodationRow->toArray());
  281.  
  282.                                         // ACCOMMODATION DETAILS
  283.                                         $accommDetails->delete('accomm_id=' $accommodationRow->accomm_id);
  284.                                         foreach ($accommodationDefinition->accommodation_details as $detailsDefinition)
  285.                                         {
  286.                                             echo '<br />' $tab $tab 'Installing detail ' $detailsDefinition->detail_id;
  287.                                             $accommDetailsRow null;
  288.                                             $accommDetailsRow $accommDetails->createRow();
  289.                                             $accommDetailsRow->detail_id  $bookableDetailsArray[$detailsDefinition->detail_id];
  290.                                             $accommDetailsRow->accomm_id  $accommodationRow->accomm_id;
  291.                                             $accommDetailsRow->cost       $detailsDefinition->cost;
  292.                                             $accommDetailsRow->max_no     $detailsDefinition->max_no;
  293.                                             $accommDetailsRow->start_date DATE_TODAY;
  294.                                             $accommDetailsRow->end_date   null;
  295.                                             $accommDetails->insert($accommDetailsRow->toArray());
  296.                                         }
  297.  
  298.                                         // DURATION PRICE
  299.                                         $durationPrice->delete('accomm_id=' $accommodationRow->accomm_id);
  300.                                         foreach ($accommodationDefinition->duration_prices as $pricesDefinition)
  301.                                         {
  302.                                             echo '<br />' $tab $tab 'Installing duration_price ' $pricesDefinition->detail_id;
  303.                                             $durationPriceRow null;
  304.                                             $durationPriceRow $durationPrice->createRow();
  305.                                             $durationPriceRow->accomm_id  $accommodationRow->accomm_id;
  306.                                             $durationPriceRow->client_season_id  $pricesDefinition->client_season_id;
  307.                                             $durationPriceRow->duration  $pricesDefinition->duration;
  308.                                             $durationPriceRow->start_date  DATE_TODAY;
  309.                                             $durationPriceRow->end_date  null;
  310.                                             $durationPriceRow->changeover_day  $pricesDefinition->changeover_day;
  311.                                             $durationPriceRow->cost  $pricesDefinition->cost;
  312.                                             $durationPriceRow->daily_rate_flag  $pricesDefinition->daily_rate_flag;
  313.                                             $durationPrice->insert($durationPriceRow->toArray());
  314.                                         }
  315.                                     }
  316.                                 }
  317.  
  318.                             else {
  319.                                 echo '<br />' $tab '** No property to install** ';
  320.                             }
  321.                         }
  322.                     }
  323.                 }
  324.             }
  325.             closedir($handle);
  326.         }
  327.  
  328.  
  329. /*
  330.         $db = Zend_Db_Table::getDefaultAdapter();
  331.         // Set up demo CLIENTS;
  332.         $clientArray = $this->clients(); //array (
  333.         $client = new Client();
  334.         $user = new User();
  335.         foreach ($clientArray as $clientDetails)
  336.         {
  337.             // CLIENT
  338.             $row = $client->createRow();
  339.             $row->setFromArray($clientDetails);
  340.             $client->delete('client_id='.$row->client_id);
  341.             $row->save();
  342.  
  343.             // USER
  344.             $row = $user->createRow();
  345.             $row->client_id = $clientDetails['client_id'];
  346.             $row->setFromArray($clientDetails['userDetails']);
  347.             $user->delete('user_id='.$row->user_id);
  348.             $row->save();
  349.         }
  350. */
  351.  
  352.     }
  353.  
  354.     /**
  355.      * Populate the database with all reference/lookup data.
  356.      *
  357.      * @return void 
  358.      */
  359.     private function installReferenceData($tab
  360.     {
  361.         echo '<br /><br />-------------------------------------------------------------------';
  362.         echo '<br />Installing REFERENCE DATA<br />';
  363.         $path=APPLICATION_PATH '/config/install/reference_data';
  364.         if ($handle opendir($path))
  365.         {
  366.  
  367.             // Loop over the ref data configuration files directory
  368.             while (false !== ($file readdir($handle)))
  369.             {
  370.                 if (!is_dir($file))
  371.                 {
  372.                     $filenameAsArray explode('.'$file);
  373.                     if (count($filenameAsArray1)
  374.                     {
  375.                         if ($filenameAsArray[1!= 'xml')
  376.                         {
  377.                             continue;
  378.                         }
  379.                         $tableName $filenameAsArray[0];
  380.                         echo '<br />' $tab 'Installing ' $tableName;
  381.                         $fullPath $path '/' $file;
  382.                         $config new Zend_Config_Xml ($fullPath);
  383.  
  384.                         $where $config->delete_where_clause;
  385.                         if ($where == '')
  386.                         {
  387.                             echo "<br /><br />** " $tableName " FAILED! No 'where' clause supplied for the delete. **<br />";
  388.                             exit;
  389.                         else {
  390.                             $table new $tableName ();
  391.                             $table->delete($where);
  392.                         }
  393.                         foreach ($config->rows as $dataDefinition)
  394.                         {
  395.                             $row $table->createRow($dataDefinition->toArray());
  396.                             $table->insert($row->toArray());
  397.                         }
  398.                     }
  399.                 }
  400.             }
  401.             $this->installCalendar($tab);
  402.         }
  403.     }
  404.  
  405.     /**
  406.      * Populate the calendar table with 5 years worth of dates.
  407.      *
  408.      * @return void 
  409.      */
  410.     private function installCalendar($tab
  411.     {
  412.         // INSERT 5 years worth of dates.
  413.         $db Zend_Db_Table::getDefaultAdapter();
  414.  
  415.         // Get the start of the current month
  416.         $startCurrMonth date("Y-m-01",strtotime(DATE_TODAY));
  417.         // Get start of previous month - final calendar display needs this
  418.         $query="SELECT DATE_SUB('" $startCurrMonth "', INTERVAL 1 month) as startDate";
  419.         $row=$db->fetchRow($query);
  420.         $startDate=$row['startDate'];
  421.  
  422.         // Get the date 'n' years on from that.
  423.         $years=5;
  424.         $query="SELECT DATE_ADD('" $startDate ."', INTERVAL $years year) as endDate";
  425.         $row=$db->fetchRow($query);
  426.         $endDate=$row['endDate'];
  427.  
  428.         // HOW MANY DAYS BETWEEN NOW AND THEN?
  429.         $query="SELECT DATEDIFF('" $endDate "','" $startDate "') as days";
  430.         $row=$db->fetchRow($query);
  431.         $days=$row['days'];
  432.  
  433.  
  434.         echo '<br />Inserting ' $years ' years worth of dates from ' $startDate;
  435.  
  436.         $db->delete('Calendar');
  437.  
  438.         for($i=0;$i<$days;$i++)
  439.         {
  440.             $result $db->getConnection()->exec("INSERT INTO Calendar (date) VALUES (date_add('".  $startDate ."' ,INTERVAL " $i " DAY))" );
  441.         }
  442.     }
  443. }

Documentation generated on Fri, 27 Mar 2009 13:48:37 +0000 by phpDocumentor 1.4.1