Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ all elements ]

Source for file AdminRecord.php

Documentation is available at AdminRecord.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * Class file.
  6.  *
  7.  * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  8.  * @copyright 2005, diemeisterei GmbH. All rights reserved.
  9.  * @author $Author: schmunk $
  10.  * @version $Revision: 601 $  $Date: 2007-02-24 23:49:30 +0100 (Sa, 24 Feb 2007) $
  11.  * @package Phundament.Packages
  12.  * @subpackage LContent
  13.  */
  14.  
  15. /**
  16.  * Interface for editing or creating a record in database
  17.  *
  18.  * @package Admin.Pages
  19.  * @subpackage LContent
  20.  */
  21.  
  22. class AdminRecord extends TPage
  23. {
  24.     private $Core;
  25.     public $Record;
  26.  
  27.     /**
  28.      * prepares layout
  29.      */
  30.     public function onInit($param)
  31.     {
  32.         parent :: onInit($param);
  33.         $this->Page->setViewState("BackUrl"$this->Request->itemAt("back_url"));
  34.         $this->Corenew LContentCore;
  35.     }
  36.  
  37.     /**
  38.      * prepares data
  39.      */
  40.     public function onLoad($param)
  41.     {
  42.         parent :: onLoad($param);
  43.         $this->prepareData();
  44.     }
  45.  
  46.     /**
  47.      * selects values
  48.      */
  49.     public function onPreRender($param)
  50.     {
  51.         $this->Type->setDataSource(LContentCore :: getConfiguration("AvailableTypes"));
  52.         $this->Category->setDataSource(LContentCore :: getConfiguration("AvailableCategories"));
  53.         if ($this->Record)
  54.         {
  55.             try
  56.             {
  57.                 $this->Type->SelectedValue$this->Record->getType();
  58.                 $this->Category->SelectedValue$this->Record->getCategory();
  59.             }
  60.             catch (Exception $e)
  61.             {
  62.                 Prado :: log($e->getMessage()8"Lithron.LContent");
  63.             }
  64.         }
  65.         try
  66.         {
  67.             $this->Type->dataBind();
  68.             $this->Category->dataBind();
  69.         }
  70.         catch (Exception $e)
  71.         {
  72.             Prado :: log($e->getMessage()8"Lithron.LContent");
  73.         }
  74.         parent :: onPreRender($param);
  75.     }
  76.  
  77.     /**
  78.      * @ignore
  79.      */
  80.     public function backClicked()
  81.     {
  82.         LContentCore :: redirectToList();
  83.     }
  84.  
  85.     /**
  86.      * @ignore
  87.      */
  88.     public function createClicked()
  89.     {
  90.         $recordnew LContent;
  91.         $this->setRecordValues($record);
  92.         LContentCore :: saveRecord($record);
  93.     }
  94.  
  95.     /**
  96.     * @ignore
  97.     */
  98.     public function updateClicked()
  99.     {
  100.         $record$this->getViewstate("Record");
  101.         $this->setRecordValues($record);
  102.         LContentCore :: saveRecord($record);
  103.     }
  104.  
  105.     /**
  106.      * Loads record data or sets default value and sets button visibility
  107.      */
  108.     private function prepareData()
  109.     {
  110.  
  111.         // edit mode
  112.         if (!$this->isPostBack && $id$this->Request->itemAt("l_content_id"))
  113.         {
  114.             Prado :: trace("L_CONTENT_ID found""Lithron.LContent");
  115.             $this->Record$this->Core->queryRecords($id);
  116.  
  117.             if (LRightsManager :: getRights($this->RecordLPermissions :: EDIT)
  118.             {
  119.                 // permissions OK
  120.             }
  121.             else
  122.             {
  123.                 $this->Application->getModule("user_message")->add("Not allowed.""ERROR");
  124.                 $this->Core->redirectToList();
  125.             }
  126.             $this->setViewstate("Record"$this->Record);
  127.             try
  128.             {
  129.                 $this->dataBind();
  130.             }
  131.             catch (Exception $e)
  132.             {
  133.                 Prado :: log("Error while preparing data: " $e->getMessage()8"Lithron.LContent");
  134.             }
  135.         }
  136.  
  137.         // postback
  138.         elseif ($this->getViewstate("Record"!== null || $this->isPostBack)
  139.         {
  140.             $this->Record$this->getViewstate("Record");
  141.             #$this->dataBind();
  142.         }
  143.         else
  144.         {
  145.             $this->Culture->setText($this->Application->Globalization->getCulture());
  146.             $this->StartDate->setDate(date("m/d/y"));
  147.             $this->Buttons->dataBind();
  148.         }
  149.  
  150.     }
  151.     /**
  152.      * Sets values from template in propel object
  153.      */
  154.     private function setRecordValues($record)
  155.     {
  156.         $record->setAlias($this->Alias->getText());
  157.  
  158.         $record->setCulture(strtoupper($this->Culture->getText()));
  159.         $record->setRank($this->Rank->getText());
  160.         $record->setType($this->Type->getText());
  161.         $record->setOptions($this->Options->getText());
  162.         $record->setCategory($this->Category->getText());
  163.  
  164.         if ($this->CleanStartDate->getChecked(== true)
  165.             $record->setStartDate(null);
  166.         elseif ($this->StartDate->getText()) $record->setStartDate(strtotime($this->StartDate->getText()));
  167.  
  168.         if ($this->CleanEndDate->getChecked(== true)
  169.             $record->setEndDate(null);
  170.         elseif ($this->EndDate->getText()) $record->setEndDate(strtotime($this->EndDate->getText()));
  171.  
  172.         $record->setPreStart($this->PreStart->getText());
  173.         $record->setPostEnd($this->PostEnd->getText());
  174.  
  175.         $record->setStatus($this->Status->getSelectedValue());
  176.  
  177.         $record->setHeadline($this->Headline->getText());
  178.         $record->setSubline($this->Subline->getText());
  179.         $record->setText($this->Text->getText());
  180.  
  181.         $record->setLastEdit(time());
  182.  
  183.         LRightsManager :: setRights($record$this->RightsPanel);
  184.         $record->save($this->Application->getModule("database")->getConnection("l_content""propel"));
  185.  
  186.         $record->setLMetaData($this->MetaData)// has to be done after save, otherwise not id available
  187.  
  188.     }
  189. }
  190. ?>

Documentation generated on Sun, 25 Feb 2007 16:09:34 +0100 by phpDocumentor 1.3.1