PageRenderTime 89ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://logisticsouth.googlecode.com/
PHP | 362 lines | 217 code | 34 blank | 111 comment | 33 complexity | 02a08404465b2c7847544623854928cb MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * This is the "Meta" DataGrid class for the List functionality
  4. * of the Proveedor class. This code-generated class
  5. * contains a QDataGrid class which can be used by any QForm or QPanel,
  6. * listing a collection of Proveedor 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 ProveedorDataGridGen 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 Proveedor datagrid. The description of a column's
  40. * content can be either a text string description of a simple field name
  41. * in the Proveedor object, or it can be any QQNode extending from QQN::Proveedor().
  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 Proveedor 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 Proveedor
  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 ? '&' : '?').'intIdPROVEEDOR=<?=urlencode($_ITEM->IdPROVEEDOR)?>';
  178. break;
  179. case QMetaControlArgumentType::PathInfo:
  180. $strLinkUrl .= '/<?=urlencode($_ITEM->IdPROVEEDOR)?>';
  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->IdPROVEEDOR, 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 = Proveedor::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 Proveedor, given the clauses above
  231. $this->DataSource = Proveedor::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 Proveedor-based QQNode.
  237. * It will also verify that it is a proper Proveedor-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 == 'PROVEEDOR') {
  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 "PROVEEDOR".');
  259. } else if (is_string($mixContent)) switch ($mixContent) {
  260. case 'IdPROVEEDOR': return QQN::Proveedor()->IdPROVEEDOR;
  261. case 'Nombre': return QQN::Proveedor()->Nombre;
  262. case 'Direccion': return QQN::Proveedor()->Direccion;
  263. case 'Telefono': return QQN::Proveedor()->Telefono;
  264. case 'Email': return QQN::Proveedor()->Email;
  265. case 'PAISIdPAIS': return QQN::Proveedor()->PAISIdPAIS;
  266. case 'PAISIdPAISObject': return QQN::Proveedor()->PAISIdPAISObject;
  267. default: throw new QCallerException('Simple Property not found in ProveedorDataGrid content: ' . $mixContent);
  268. } else if ($mixContent instanceof QQAssociationNode)
  269. throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
  270. else
  271. throw new QCallerException('Invalid Content type');
  272. }
  273. /**
  274. * This will get the value of $strName
  275. *
  276. * @param string $strName Name of the property to get
  277. * @return mixed
  278. */
  279. public function __get($strName) {
  280. switch ($strName) {
  281. case 'AdditionalConditions':
  282. return $this->conAdditionalConditions;
  283. case 'AdditionalClauses':
  284. return $this->clsAdditionalClauses;
  285. default:
  286. try {
  287. return parent::__get($strName);
  288. } catch (QCallerException $objExc) {
  289. $objExc->IncrementOffset();
  290. throw $objExc;
  291. }
  292. }
  293. }
  294. /**
  295. * This will set the property $strName to be $mixValue
  296. *
  297. * @param string $strName Name of the property to set
  298. * @param string $mixValue New value of the property
  299. * @return mixed
  300. */
  301. public function __set($strName, $mixValue) {
  302. switch ($strName) {
  303. case 'AdditionalConditions':
  304. try {
  305. return ($this->conAdditionalConditions = QType::Cast($mixValue, 'QQCondition'));
  306. } catch (QCallerException $objExc) {
  307. $objExc->IncrementOffset();
  308. throw $objExc;
  309. }
  310. case 'AdditionalClauses':
  311. try {
  312. return ($this->clsAdditionalClauses = QType::Cast($mixValue, 'QQClause'));
  313. } catch (QCallerException $objExc) {
  314. $objExc->IncrementOffset();
  315. throw $objExc;
  316. }
  317. default:
  318. try {
  319. parent::__set($strName, $mixValue);
  320. break;
  321. } catch (QCallerException $objExc) {
  322. $objExc->IncrementOffset();
  323. throw $objExc;
  324. }
  325. }
  326. }
  327. }
  328. ?>