Lithron.LContent
[ class tree: Lithron.LContent ] [ index: Lithron.LContent ] [ 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: 270 $ $Date: 2006-06-12 23:41:45 +0200 (Mo, 12 Jun 2006) $
  11. * @package Lithron.LContent
  12. * @subpackage Pages
  13. */
  14.  
  15. /**
  16. * Interface for editing or creating a record in database
  17. *
  18. * @package Lithron.LContent
  19. * @subpackage Pages
  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. $this->Page->setViewState("BackUrl", $this->Request->itemAt("back_url"));
  33. $this->Master->enlargeContent();
  34. $this->Core= new LContentCore;
  35. parent :: onInit($param);
  36. }
  37.  
  38. /**
  39. * prepares data
  40. */
  41. public function onLoad($param)
  42. {
  43. $this->prepareData();
  44. parent :: onLoad($param);
  45. }
  46.  
  47. /**
  48. * selects values
  49. */
  50. public function onPreRender($param)
  51. {
  52. $this->Type->setDataSource(LContentCore :: getConfiguration("AvailableTypes"));
  53. $this->Category->setDataSource(LContentCore :: getConfiguration("AvailableCategories"));
  54. if ($this->Record) // TODO TODO !!!
  55. {
  56. try
  57. {
  58. $this->Type->SelectedValue= $this->Record->getType();
  59. $this->Category->SelectedValue= $this->Record->getCategory();
  60. }
  61. catch (Exception $e)
  62. {
  63. echo $e->getMessage();
  64. }
  65. }
  66. try
  67. {
  68. $this->Type->dataBind();
  69. $this->Category->dataBind();
  70. }
  71. catch (Exception $e)
  72. {
  73. echo $e->getMessage();
  74. }
  75. parent :: onPreRender($param);
  76. }
  77.  
  78. /**
  79. * @ignore
  80. */
  81. public function backClicked()
  82. {
  83. LContentCore :: redirectToList();
  84. }
  85.  
  86. /**
  87. * @ignore
  88. */
  89. public function createClicked()
  90. {
  91. $record= new LContent;
  92. $this->setRecordValues($record);
  93. LContentCore :: saveRecord($record);
  94. }
  95.  
  96. /**
  97. * @ignore
  98. */
  99. public function updateClicked()
  100. {
  101. $record= $this->getViewstate("Record");
  102. $this->setRecordValues($record);
  103. LContentCore :: saveRecord($record);
  104. }
  105.  
  106. /**
  107. * Loads record data or sets default value and sets button visibility
  108. */
  109. private function prepareData()
  110. {
  111. if (!$this->isPostBack && $id= $this->Request->itemAt("l_content_id"))
  112. {
  113. Prado :: trace("L_CONTENT_ID found", "Lithron.LContent");
  114. $this->Record= $this->Core->queryRecords($id);
  115. $this->setViewstate("Record", $this->Record);
  116. try
  117. {
  118. $this->dataBind();
  119. }
  120. catch (Exception $e)
  121. {
  122. echo $e->getMessage();
  123. }
  124. }
  125. elseif ($this->getViewstate("Record") !== null)
  126. {
  127. $this->Record= $this->getViewstate("Record");
  128. #$this->dataBind();
  129. }
  130. else
  131. {
  132. $this->Culture->setText($this->Application->Globalization->getCulture());
  133. $this->Buttons->dataBind();
  134. }
  135.  
  136. }
  137. /**
  138. * Sets values from template in propel object
  139. */
  140. private function setRecordValues($record)
  141. {
  142. #$metaData= $this->MetaData->toArray(); // TODO dual
  143. #$record->setMetaData($metaData);
  144.  
  145. $record->setCulture(strtoupper($this->Culture->getText()));
  146. $record->setRank($this->Rank->getText());
  147. $record->setType($this->Type->getText());
  148. $record->setOptions($this->Options->getText());
  149. $record->setCategory($this->Category->getText());
  150.  
  151. if ($this->StartDate->getText())
  152. $record->setStartDate(strtotime($this->StartDate->getText()));
  153. if ($this->EndDate->getText())
  154. $record->setEndDate(strtotime($this->EndDate->getText()));
  155.  
  156. $record->setPreStart($this->PreStart->getText());
  157. $record->setPostEnd($this->PostEnd->getText());
  158.  
  159. $record->setStatus($this->Status->getSelectedValue());
  160.  
  161. $record->setHeadline($this->Headline->getText());
  162. $record->setSubline($this->Subline->getText());
  163. $record->setText($this->Text->getText());
  164.  
  165. $record->setLastEdit(time());
  166.  
  167. $ownerClass= "LContent";
  168. $ownerId= $record->getPrimaryKey();
  169.  
  170. $record->save($this->Application->getModule("database")->getConnection("l_content", "propel"));
  171. #$this->Core->saveRecord($record); // TODO dual
  172. $record->setLMetaData($this->MetaData); // TODO dual
  173.  
  174. }
  175.  
  176. }
  177. ?>

Documentation generated on Tue, 20 Jun 2006 05:14:56 +0200 by phpDocumentor 1.3.0RC4