/sgl/includes/meta_controls/generated/LicenciaDataGridGen.class.php

http://logisticsouth.googlecode.com/ · PHP · 373 lines · 228 code · 34 blank · 111 comment · 33 complexity · 065a30ce47952068168876f780233fec MD5 · raw file

  1. <?php
  2. /**
  3. * This is the "Meta" DataGrid class for the List functionality
  4. * of the Licencia class. This code-generated class
  5. * contains a QDataGrid class which can be used by any QForm or QPanel,
  6. * listing a collection of Licencia objects. It includes
  7. * functionality to perform pagination and sorting on columns.
  8. *
  9. * To take advantage of some (or all) of these control objects, you
  10. * must create an instance of this DataGrid in a QForm or QPanel.
  11. *
  12. * Any and all changes to this file will be overwritten with any subsequent re-
  13. * code generation.
  14. *
  15. * @package My QCubed Application
  16. * @property QQCondition $AdditionalConditions Any conditions to use during binding
  17. * @property QQClause $AdditionalClauses Any clauses to use during binding
  18. * @subpackage MetaControls
  19. *
  20. */
  21. class LicenciaDataGridGen extends QDataGrid {
  22. protected $conAdditionalConditions;
  23. protected $clsAdditionalClauses;
  24. protected $blnShowFilter = true;
  25. /**
  26. * Standard DataGrid constructor which also pre-configures the DataBinder
  27. * to its own SimpleDataBinder. Also pre-configures UseAjax to true.
  28. *
  29. * @param mixed $objParentObject either a QPanel or QForm which would be this DataGrid's parent
  30. * @param string $strControlId optional explicitly-defined ControlId for this DataGrid
  31. */
  32. public function __construct($objParentObject, $strControlId = null) {
  33. parent::__construct($objParentObject, $strControlId);
  34. $this->SetDataBinder('MetaDataBinder', $this);
  35. $this->UseAjax = true;
  36. }
  37. /**
  38. * Given the description of the Column's contents, this is a simple, express
  39. * way of adding a column to this Licencia datagrid. The description of a column's
  40. * content can be either a text string description of a simple field name
  41. * in the Licencia object, or it can be any QQNode extending from QQN::Licencia().
  42. *
  43. * MetaAddColumn will automatically pre-configure the column with the name, html
  44. * and sort rules given the content being specified.
  45. *
  46. * Any of these things can be overridden with OverrideParameters.
  47. *
  48. * Finally, $mixContents can also be an array of contents, if displaying and/or
  49. * sorting using two fields from the Licencia object.
  50. *
  51. * @param mixed $mixContents
  52. * @param string $objOverrideParameters[]
  53. * @return QDataGridColumn
  54. */
  55. public function MetaAddColumn($mixContent, $objOverrideParameters = null) {
  56. if (is_array($mixContent)) {
  57. $objNodeArray = array();
  58. try {
  59. foreach ($mixContent as $mixItem) {
  60. $objNodeArray[] = $this->ResolveContentItem($mixItem);
  61. }
  62. } catch (QCallerException $objExc) {
  63. $objExc->IncrementOffset();
  64. throw $objExc;
  65. }
  66. if (count($objNodeArray) == 0)
  67. throw new QCallerException('No content specified');
  68. // Create Various Arrays to be used by DGC
  69. $strNameArray = '';
  70. $strHtmlArray = '';
  71. $objSort = array();
  72. $objSortDescending = array();
  73. foreach ($objNodeArray as $objNode) {
  74. $strNameArray[] = QApplication::Translate(QConvertNotation::WordsFromCamelCase($objNode->_PropertyName));
  75. $strHtmlArray[] = $objNode->GetDataGridHtml();
  76. $objSort[] = $objNode->GetDataGridOrderByNode();
  77. $objSortDescending[] = $objNode->GetDataGridOrderByNode();
  78. $objSortDescending[] = false;
  79. }
  80. $objNewColumn = new QDataGridColumn(
  81. implode(', ', $strNameArray),
  82. '<?=' . implode(' . ", " . ', $strHtmlArray) . '?>',
  83. array(
  84. 'OrderByClause' => new QQOrderBy($objNodeArray),
  85. 'ReverseOrderByClause' => new QQOrderBy($objSortDescending)
  86. )
  87. );
  88. } else {
  89. try {
  90. $objNode = $this->ResolveContentItem($mixContent);
  91. } catch (QCallerException $objExc) {
  92. $objExc->IncrementOffset();
  93. throw $objExc;
  94. }
  95. $objNewColumn = new QDataGridColumn(
  96. QApplication::Translate(QConvertNotation::WordsFromCamelCase($objNode->_PropertyName)),
  97. '<?=' . $objNode->GetDataGridHtml() . '?>',
  98. array(
  99. 'OrderByClause' => QQ::OrderBy($objNode->GetDataGridOrderByNode()),
  100. 'ReverseOrderByClause' => QQ::OrderBy($objNode->GetDataGridOrderByNode(), false)
  101. )
  102. );
  103. }
  104. $objNode->SetFilteredDataGridColumnFilter($objNewColumn);
  105. $objOverrideArray = func_get_args();
  106. if (count($objOverrideArray) > 1)
  107. try {
  108. unset($objOverrideArray[0]);
  109. $objNewColumn->OverrideAttributes($objOverrideArray);
  110. } catch (QCallerException $objExc) {
  111. $objExc->IncrementOffset();
  112. throw $objExc;
  113. }
  114. $this->AddColumn($objNewColumn);
  115. return $objNewColumn;
  116. }
  117. /**
  118. * Similar to MetaAddColumn, except it creates a column for a Type-based Id. You MUST specify
  119. * the name of the Type class that this will attempt to use $NameArray against.
  120. *
  121. * Also, $mixContent cannot be an array. Only a single field can be specified.
  122. *
  123. * @param mixed $mixContent string or QQNode from Licencia
  124. * @param string $strTypeClassName the name of the TypeClass to use $NameArray against
  125. * @param mixed $objOverrideParameters
  126. */
  127. public function MetaAddTypeColumn($mixContent, $strTypeClassName, $objOverrideParameters = null) {
  128. // Validate TypeClassName
  129. if (!class_exists($strTypeClassName) || !property_exists($strTypeClassName, 'NameArray'))
  130. throw new QCallerException('Invalid TypeClass Name: ' . $strTypeClassName);
  131. // Validate Node
  132. try {
  133. $objNode = $this->ResolveContentItem($mixContent);
  134. } catch (QCallerException $objExc) {
  135. $objExc->IncrementOffset();
  136. throw $objExc;
  137. }
  138. // Create the Column
  139. $strName = QConvertNotation::WordsFromCamelCase($objNode->_PropertyName);
  140. if (strtolower(substr($strName, strlen($strName) - 3)) == ' id')
  141. $strName = substr($strName, 0, strlen($strName) - 3);
  142. $strProperty = $objNode->GetDataGridHtml();
  143. $objNewColumn = new QDataGridColumn(
  144. QApplication::Translate($strName),
  145. sprintf('<?=(%s) ? %s::$NameArray[%s] : null;?>', $strProperty, $strTypeClassName, $strProperty),
  146. array(
  147. 'OrderByClause' => QQ::OrderBy($objNode),
  148. 'ReverseOrderByClause' => QQ::OrderBy($objNode, false)
  149. )
  150. );
  151. // Perform Overrides
  152. $objOverrideArray = func_get_args();
  153. if (count($objOverrideArray) > 2)
  154. try {
  155. unset($objOverrideArray[0]);
  156. unset($objOverrideArray[1]);
  157. $objNewColumn->OverrideAttributes($objOverrideArray);
  158. } catch (QCallerException $objExc) {
  159. $objExc->IncrementOffset();
  160. throw $objExc;
  161. }
  162. $this->AddColumn($objNewColumn);
  163. return $objNewColumn;
  164. }
  165. /**
  166. * Will add an "edit" link-based column, using a standard HREF link to redirect the user to a page
  167. * that must be specified.
  168. *
  169. * @param string $strLinkUrl the URL to redirect the user to
  170. * @param string $strLinkHtml the HTML of the link text
  171. * @param string $strColumnTitle the HTML of the link text
  172. * @param string $intArgumentType the method used to pass information to the edit page (defaults to PathInfo)
  173. */
  174. public function MetaAddEditLinkColumn($strLinkUrl, $strLinkHtml = 'Edit', $strColumnTitle = 'Edit', $intArgumentType = QMetaControlArgumentType::PathInfo) {
  175. switch ($intArgumentType) {
  176. case QMetaControlArgumentType::QueryString:
  177. $strLinkUrl .= (strpos($strLinkUrl, '?') !== false ? '&' : '?').'intIdLICENCIA=<?=urlencode($_ITEM->IdLICENCIA)?>';
  178. break;
  179. case QMetaControlArgumentType::PathInfo:
  180. $strLinkUrl .= '/<?=urlencode($_ITEM->IdLICENCIA)?>';
  181. break;
  182. default:
  183. throw new QCallerException('Unable to pass arguments with this intArgumentType: ' . $intArgumentType);
  184. }
  185. $strHtml = '<a href="' . $strLinkUrl . '">' . $strLinkHtml . '</a>';
  186. $colEditColumn = new QDataGridColumn($strColumnTitle, $strHtml, 'HtmlEntities=False');
  187. $this->AddColumn($colEditColumn);
  188. return $colEditColumn;
  189. }
  190. /**
  191. * Will add an "edit" control proxy-based column, calling any actions on a given control proxy
  192. * that must be specified.
  193. *
  194. * @param QControlProxy $pxyControl the control proxy to use
  195. * @param string $strLinkHtml the HTML of the link text
  196. * @param string $strColumnTitle the HTML of the link text
  197. */
  198. public function MetaAddEditProxyColumn(QControlProxy $pxyControl, $strLinkHtml = 'Edit', $strColumnTitle = 'Edit') {
  199. $strHtml = '<a href="#" <?= $_FORM->GetControl("' . $pxyControl->ControlId . '")->RenderAsEvents($_ITEM->IdLICENCIA, false); ?>>' . $strLinkHtml . '</a>';
  200. $colEditColumn = new QDataGridColumn($strColumnTitle, $strHtml, 'HtmlEntities=False');
  201. $this->AddColumn($colEditColumn);
  202. return $colEditColumn;
  203. }
  204. /**
  205. * Default / simple DataBinder for this Meta DataGrid. This can easily be overridden
  206. * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice.
  207. *
  208. * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used.
  209. * It will also perform any sorting (if applicable).
  210. */
  211. public function MetaDataBinder() {
  212. $objConditions = $this->Conditions;
  213. if(null !== $this->conAdditionalConditions)
  214. $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions);
  215. // Setup the $objClauses Array
  216. $objClauses = array();
  217. if(null !== $this->clsAdditionalClauses)
  218. $objClauses = $this->clsAdditionalClauses;
  219. // Remember! We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
  220. if ($this->Paginator) {
  221. $this->TotalItemCount = Licencia::QueryCount($objConditions);
  222. }
  223. // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
  224. // the OrderByClause to the $objClauses array
  225. if ($objClause = $this->OrderByClause)
  226. array_push($objClauses, $objClause);
  227. // Add the LimitClause information, as well
  228. if ($objClause = $this->LimitClause)
  229. array_push($objClauses, $objClause);
  230. // Set the DataSource to be a Query result from Licencia, given the clauses above
  231. $this->DataSource = Licencia::QueryArray($objConditions, $objClauses);
  232. }
  233. /**
  234. * Used internally by the Meta-based Add Column tools.
  235. *
  236. * Given a QQNode or a Text String, this will return a Licencia-based QQNode.
  237. * It will also verify that it is a proper Licencia-based QQNode, and will throw an exception otherwise.
  238. *
  239. * @param mixed $mixContent
  240. * @return QQNode
  241. */
  242. protected function ResolveContentItem($mixContent) {
  243. if ($mixContent instanceof QQNode) {
  244. if (!$mixContent->_ParentNode)
  245. throw new QCallerException('Content QQNode cannot be a Top Level Node');
  246. if ($mixContent->_RootTableName == 'LICENCIA') {
  247. if (($mixContent instanceof QQReverseReferenceNode) && !($mixContent->_PropertyName))
  248. throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
  249. $objCurrentNode = $mixContent;
  250. while ($objCurrentNode = $objCurrentNode->_ParentNode) {
  251. if (!($objCurrentNode instanceof QQNode))
  252. throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
  253. if (($objCurrentNode instanceof QQReverseReferenceNode) && !($objCurrentNode->_PropertyName))
  254. throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
  255. }
  256. return $mixContent;
  257. } else
  258. throw new QCallerException('Content QQNode has a root table of "' . $mixContent->_RootTableName . '". Must be a root of "LICENCIA".');
  259. } else if (is_string($mixContent)) switch ($mixContent) {
  260. case 'IdLICENCIA': return QQN::Licencia()->IdLICENCIA;
  261. case 'EMPRESAIdEMPRESA': return QQN::Licencia()->EMPRESAIdEMPRESA;
  262. case 'EMPRESAIdEMPRESAObject': return QQN::Licencia()->EMPRESAIdEMPRESAObject;
  263. case 'PROVEEDORIdPROVEEDOR': return QQN::Licencia()->PROVEEDORIdPROVEEDOR;
  264. case 'PROVEEDORIdPROVEEDORObject': return QQN::Licencia()->PROVEEDORIdPROVEEDORObject;
  265. case 'FechaInicio': return QQN::Licencia()->FechaInicio;
  266. case 'FechaFin': return QQN::Licencia()->FechaFin;
  267. case 'FechaFinEstimada': return QQN::Licencia()->FechaFinEstimada;
  268. case 'NumeroProforma': return QQN::Licencia()->NumeroProforma;
  269. case 'NumeroCNP': return QQN::Licencia()->NumeroCNP;
  270. case 'VencimientoCNP': return QQN::Licencia()->VencimientoCNP;
  271. case 'Status': return QQN::Licencia()->Status;
  272. case 'FormaPago': return QQN::Licencia()->FormaPago;
  273. case 'Tipo': return QQN::Licencia()->Tipo;
  274. case 'Flete': return QQN::Licencia()->Flete;
  275. case 'Seguro': return QQN::Licencia()->Seguro;
  276. case 'PROCESOIdPROCESO': return QQN::Licencia()->PROCESOIdPROCESO;
  277. case 'PROCESOIdPROCESOObject': return QQN::Licencia()->PROCESOIdPROCESOObject;
  278. default: throw new QCallerException('Simple Property not found in LicenciaDataGrid content: ' . $mixContent);
  279. } else if ($mixContent instanceof QQAssociationNode)
  280. throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
  281. else
  282. throw new QCallerException('Invalid Content type');
  283. }
  284. /**
  285. * This will get the value of $strName
  286. *
  287. * @param string $strName Name of the property to get
  288. * @return mixed
  289. */
  290. public function __get($strName) {
  291. switch ($strName) {
  292. case 'AdditionalConditions':
  293. return $this->conAdditionalConditions;
  294. case 'AdditionalClauses':
  295. return $this->clsAdditionalClauses;
  296. default:
  297. try {
  298. return parent::__get($strName);
  299. } catch (QCallerException $objExc) {
  300. $objExc->IncrementOffset();
  301. throw $objExc;
  302. }
  303. }
  304. }
  305. /**
  306. * This will set the property $strName to be $mixValue
  307. *
  308. * @param string $strName Name of the property to set
  309. * @param string $mixValue New value of the property
  310. * @return mixed
  311. */
  312. public function __set($strName, $mixValue) {
  313. switch ($strName) {
  314. case 'AdditionalConditions':
  315. try {
  316. return ($this->conAdditionalConditions = QType::Cast($mixValue, 'QQCondition'));
  317. } catch (QCallerException $objExc) {
  318. $objExc->IncrementOffset();
  319. throw $objExc;
  320. }
  321. case 'AdditionalClauses':
  322. try {
  323. return ($this->clsAdditionalClauses = QType::Cast($mixValue, 'QQClause'));
  324. } catch (QCallerException $objExc) {
  325. $objExc->IncrementOffset();
  326. throw $objExc;
  327. }
  328. default:
  329. try {
  330. parent::__set($strName, $mixValue);
  331. break;
  332. } catch (QCallerException $objExc) {
  333. $objExc->IncrementOffset();
  334. throw $objExc;
  335. }
  336. }
  337. }
  338. }
  339. ?>