PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/Pages/System/PropertyPortlet.php

http://pradoportal.googlecode.com/
PHP | 323 lines | 256 code | 49 blank | 18 comment | 24 complexity | d4c509328116eb709e65a6c3e2a7c69f MD5 | raw file
  1. <?php
  2. /**
  3. * Prado Portal.
  4. *
  5. * @author Steen Rabol <steen.rabol@gmail.com>
  6. * @link http://www.pradoportal.dk/
  7. * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
  8. * @license http://www.pradoportal.dk
  9. * @version $Id: PropertyPortlet.php 425 2011-01-05 10:30:30Z steen.rabol $
  10. *
  11. */
  12. Prado::using('Application.Common.Data.PortalConfigRecord');
  13. Prado::using('System.Web.UI.WebControls.TDropDownList');
  14. /*
  15. * Property of pportlet
  16. */
  17. class PropertyPortlet extends PortalSystemPage
  18. {
  19. private $_pagename = '';
  20. private $_controlname = '';
  21. private $_portletname = '';
  22. private $_recid = 0;
  23. public function onInit($param)
  24. {
  25. parent::onInit($param);
  26. if(!$this->User)
  27. {
  28. $this->reportError(1,Prado::localize("You need to be logged in to use this page"));
  29. }
  30. if($this->User->RoleId != $this->Application->Parameters['AdminRole'])
  31. {
  32. $this->reportError(1,Prado::localize("You need to be logged in to use this page"));
  33. }
  34. if(($pid=$this->Request['pid'])!==null)
  35. {
  36. $this->pid->Value = $pid;
  37. $this->PageName = $pid;
  38. }
  39. if(($cid=$this->Request['cid'])!==null)
  40. {
  41. $this->cid->Value = $cid;
  42. $this->_controlname = $cid;
  43. }
  44. if(($poid=$this->Request['poid'])!==null)
  45. {
  46. $this->rid->Value = $poid;
  47. $this->_recid = $poid;
  48. }
  49. if(($pname = $this->Request['pname'])!==null)
  50. {
  51. $this->PortletName = $pname;
  52. }
  53. // Get Portlet properties
  54. $pCommonClassName = $this->PortletName . 'Common';
  55. if(!class_exists($pCommonClassName,false))
  56. {
  57. $incFile = 'Application.Portlets.' . $this->PortletName . '.Common.' . $pCommonClassName;
  58. Prado::using($incFile);
  59. }
  60. if(method_exists($pCommonClassName,'getCustomProperties'))
  61. {
  62. $pProperties = call_user_func($pCommonClassName . '::getCustomProperties');
  63. if(is_array($pProperties) && count($pProperties) > 0)
  64. {
  65. $this->tblCustomProperties->Visible = true;
  66. $this->tblCustomProperties->Enabled = true;
  67. // get values...
  68. $config = PortalConfigRecord::finder()->findByname($this->ConfigName);
  69. if($config)
  70. {
  71. $pVal = Prado::unserialize($config->value);
  72. }
  73. else
  74. {
  75. $pVal = array();
  76. }
  77. foreach($pProperties as $property)
  78. {
  79. $row = new TTableRow;
  80. $cell = new TTableCell;
  81. $cell->Text = $property['title'];
  82. $row->Cells->add($cell);
  83. $cell = new TTableCell;
  84. $value = null;
  85. $ctrl = $this->buildPropertyControl($property,$pVal);
  86. if($ctrl !== null)
  87. {
  88. $cell->Controls[] = $ctrl;
  89. }
  90. else
  91. {
  92. $cell->Text = "&nbsp;";
  93. }
  94. $row->Cells->add($cell);
  95. $this->tblCustomProperties->Rows->add($row);
  96. }
  97. }
  98. else
  99. {
  100. $this->tblCustomProperties->Visible = false;
  101. $this->tblCustomProperties->Enabled = false;
  102. }
  103. }
  104. }
  105. public function onLoad($param)
  106. {
  107. $this->Title = $this->Application->Parameters['SiteTitle'] . " - " . Prado::localize("Element properties");
  108. if(!$this->IsPostBack)
  109. {
  110. $row = $this->DataAccess->createCommand("select * from tblpagecontent where id=" . $this->_recid)->queryRow();
  111. $this->LoginRequired->Checked = TPropertyValue::ensureBoolean($row['needlogin']);
  112. $this->ShowWhenLoggedin->Checked = TPropertyValue::ensureBoolean($row['showafterlogin']);
  113. $this->Active->Checked = TPropertyValue::ensureBoolean($row['active']);
  114. // Get Portlet properties
  115. $pCommonClassName = $this->PortletName . 'Common';
  116. if(!class_exists($pCommonClassName,false))
  117. {
  118. $incFile = 'Application.Portlets.' . $this->PortletName . '.Common.' . $pCommonClassName;
  119. Prado::using($incFile);
  120. }
  121. if(!method_exists($pCommonClassName,'getCustomProperties'))
  122. {
  123. $this->tblCustomProperties->Visible = false;
  124. $this->tblCustomProperties->Enabled = false;
  125. }
  126. }
  127. }
  128. private function buildPropertyControl($prop,$savedValues)
  129. {
  130. $type = $prop['type'];
  131. $id = $prop['name'];
  132. $value = (isset($savedValues[$id]) ? $savedValues[$id] : null);
  133. $ctrl = null;
  134. switch($type)
  135. {
  136. case 'colorpick':
  137. $ctrl = new TColorPicker();
  138. $ctrl->Id = $id;
  139. $ctrl->Mode ='Basic';
  140. if($value !== null)
  141. {
  142. $ctrl->Text = $value;
  143. }
  144. break;
  145. case 'text':
  146. case 'number':
  147. $ctrl = new TTextBox();
  148. $ctrl->Id = $id;
  149. if($value !== null)
  150. {
  151. $ctrl->Text = $value;
  152. }
  153. break;
  154. case 'droplist':
  155. $ctrl = new TDropDownList();
  156. $ctrl->Id = $id;
  157. $dlvalues = $prop['values'];
  158. $ctrl->DataSource = $dlvalues;
  159. $ctrl->DataTextField = "name";
  160. $ctrl->DataValueField = "value";
  161. $ctrl->PromptText = Prado::localize("Select");
  162. $ctrl->PromptValue = "";
  163. $ctrl->dataBind();
  164. if($value)
  165. {
  166. try
  167. {
  168. $ctrl->SelectedValue = $value;
  169. }
  170. catch(Exception $e) {}
  171. }
  172. break;
  173. case 'tablepick':
  174. $selecttable = $prop['values'][0];
  175. $selectfields = $prop['values'][1];
  176. $selectvalue = $prop['values'][2];
  177. $where = $prop['values'][3];
  178. $dlvalues = $this->DataAccess->createCommand(ltrim(rtrim("select $selectfields from $selecttable $where")))->query();
  179. $ctrl = new TDropDownList();
  180. $ctrl->Id = $id;
  181. $ctrl->DataSource = $dlvalues;
  182. $ctrl->DataTextField = $selectfields;
  183. $ctrl->DataValueField = $selectvalue;
  184. $ctrl->PromptText = Prado::localize("Select");
  185. $ctrl->PromptValue = "";
  186. $ctrl->dataBind();
  187. break;
  188. }
  189. return $ctrl;
  190. }
  191. public function getPortletName()
  192. {
  193. return $this->_portletname;
  194. }
  195. public function setPortletName($value)
  196. {
  197. $this->_portletname = $value;
  198. }
  199. public function saveButtonClicked($sender,$param)
  200. {
  201. $rid = $this->rid->Value;
  202. $needlogin = TPropertyValue::ensureInteger($this->LoginRequired->Checked);
  203. $showafterlogin = TPropertyValue::ensureInteger($this->ShowWhenLoggedin->Checked);
  204. $active = TPropertyValue::ensureInteger($this->Active->Checked);
  205. $sql = "update tblpagecontent set needlogin='$needlogin',showafterlogin='$showafterlogin',active='$active' where id=$rid";
  206. $this->DataAccess->createCommand($sql)->execute();
  207. // Get Portlet properties
  208. $pCommonClassName = $this->PortletName . 'Common';
  209. if(!class_exists($pCommonClassName,false))
  210. {
  211. $incFile = 'Application.Portlets.' . $this->PortletName . '.Common.' . $pCommonClassName;
  212. Prado::using($incFile);
  213. }
  214. if(method_exists($pCommonClassName,'getCustomProperties'))
  215. {
  216. $pProperties = call_user_func($pCommonClassName . '::getCustomProperties');
  217. if(is_array($pProperties) && count($pProperties) > 0)
  218. {
  219. $pVal = array();
  220. foreach($pProperties as $property)
  221. {
  222. $ctrl = $this->tblCustomProperties->findControl($property['name']);
  223. switch($property['type'])
  224. {
  225. case 'colorpick':
  226. case 'text':
  227. case 'number':
  228. $pVal[$property['name']] = $ctrl->Text;
  229. break;
  230. case 'droplist':
  231. $pVal[$property['name']] = $ctrl->SelectedValue;
  232. break;
  233. }
  234. }
  235. // Save
  236. $config = PortalConfigRecord::finder()->findByname($this->ConfigName);
  237. if(!$config)
  238. {
  239. $config = new PortalConfigRecord();
  240. $config->name = $this->ConfigName;
  241. }
  242. $config->value = Prado::serialize($pVal);
  243. $config->save();
  244. }
  245. }
  246. $this->gotoPage($this->pid->Value,array("PageMode" => $this->Page->EditMode));
  247. }
  248. public function cancelButtonClicked($sender,$param)
  249. {
  250. $rid = $this->rid->Value;
  251. $this->gotoPage($this->pid->Value,array("PageMode" => $this->Page->EditMode));
  252. }
  253. public function getPageName()
  254. {
  255. return $this->_pagename;
  256. }
  257. public function setPageName($value)
  258. {
  259. $this->_pagename = $value;
  260. }
  261. public function ControlName()
  262. {
  263. return $this->_controlname;
  264. }
  265. public function ElementName()
  266. {
  267. return $this->_portletname;
  268. }
  269. public function getConfigName()
  270. {
  271. return 'prop_' . $this->PortletName . '_' . $this->PageName . '_' . $this->_recid;
  272. }
  273. }
  274. ?>