A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

561 lines
25 KiB

  1. <?php
  2. /**
  3. * This is a MetaControl class, providing a QForm or QPanel access to event handlers
  4. * and QControls to perform the Create, Edit, and Delete functionality
  5. * of the Usergroup class. This code-generated class
  6. * contains all the basic elements to help a QPanel or QForm display an HTML form that can
  7. * manipulate a single Usergroup object.
  8. *
  9. * To take advantage of some (or all) of these control objects, you
  10. * must create a new QForm or QPanel which instantiates a UsergroupMetaControl
  11. * class.
  12. *
  13. * Any and all changes to this file will be overwritten with any subsequent
  14. * code re-generation.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage MetaControls
  18. * property-read Usergroup $Usergroup the actual Usergroup data class being edited
  19. * property QLabel $IdControl
  20. * property-read QLabel $IdLabel
  21. * property QTextBox $NameControl
  22. * property-read QLabel $NameLabel
  23. * property QListBox $ContentItemControl
  24. * property-read QLabel $ContentItemLabel
  25. * property QListBox $PageControl
  26. * property-read QLabel $PageLabel
  27. * property QListBox $PersonControl
  28. * property-read QLabel $PersonLabel
  29. * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
  30. * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
  31. */
  32. class UsergroupMetaControlGen extends QBaseClass {
  33. // General Variables
  34. protected $objUsergroup;
  35. protected $objParentObject;
  36. protected $strTitleVerb;
  37. protected $blnEditMode;
  38. // Controls that allow the editing of Usergroup's individual data fields
  39. protected $lblId;
  40. protected $txtName;
  41. // Controls that allow the viewing of Usergroup's individual data fields
  42. protected $lblName;
  43. // QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References
  44. protected $lstContentItems;
  45. protected $lstPages;
  46. protected $lstPeople;
  47. // QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References
  48. protected $lblContentItems;
  49. protected $lblPages;
  50. protected $lblPeople;
  51. /**
  52. * Main constructor. Constructor OR static create methods are designed to be called in either
  53. * a parent QPanel or the main QForm when wanting to create a
  54. * UsergroupMetaControl to edit a single Usergroup object within the
  55. * QPanel or QForm.
  56. *
  57. * This constructor takes in a single Usergroup object, while any of the static
  58. * create methods below can be used to construct based off of individual PK ID(s).
  59. *
  60. * @param mixed $objParentObject QForm or QPanel which will be using this UsergroupMetaControl
  61. * @param Usergroup $objUsergroup new or existing Usergroup object
  62. */
  63. public function __construct($objParentObject, Usergroup $objUsergroup) {
  64. // Setup Parent Object (e.g. QForm or QPanel which will be using this UsergroupMetaControl)
  65. $this->objParentObject = $objParentObject;
  66. // Setup linked Usergroup object
  67. $this->objUsergroup = $objUsergroup;
  68. // Figure out if we're Editing or Creating New
  69. if ($this->objUsergroup->__Restored) {
  70. $this->strTitleVerb = QApplication::Translate('Edit');
  71. $this->blnEditMode = true;
  72. } else {
  73. $this->strTitleVerb = QApplication::Translate('Create');
  74. $this->blnEditMode = false;
  75. }
  76. }
  77. /**
  78. * Static Helper Method to Create using PK arguments
  79. * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  80. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  81. * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to
  82. * edit, or if we are also allowed to create a new one, etc.
  83. *
  84. * @param mixed $objParentObject QForm or QPanel which will be using this UsergroupMetaControl
  85. * @param integer $intId primary key value
  86. * @param QMetaControlCreateType $intCreateType rules governing Usergroup object creation - defaults to CreateOrEdit
  87. * @return UsergroupMetaControl
  88. */
  89. public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  90. // Attempt to Load from PK Arguments
  91. if (strlen($intId)) {
  92. $objUsergroup = Usergroup::Load($intId);
  93. // Usergroup was found -- return it!
  94. if ($objUsergroup)
  95. return new UsergroupMetaControl($objParentObject, $objUsergroup);
  96. // If CreateOnRecordNotFound not specified, throw an exception
  97. else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
  98. throw new QCallerException('Could not find a Usergroup object with PK arguments: ' . $intId);
  99. // If EditOnly is specified, throw an exception
  100. } else if ($intCreateType == QMetaControlCreateType::EditOnly)
  101. throw new QCallerException('No PK arguments specified');
  102. // If we are here, then we need to create a new record
  103. return new UsergroupMetaControl($objParentObject, new Usergroup());
  104. }
  105. /**
  106. * Static Helper Method to Create using PathInfo arguments
  107. *
  108. * @param mixed $objParentObject QForm or QPanel which will be using this UsergroupMetaControl
  109. * @param QMetaControlCreateType $intCreateType rules governing Usergroup object creation - defaults to CreateOrEdit
  110. * @return UsergroupMetaControl
  111. */
  112. public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  113. $intId = QApplication::PathInfo(0);
  114. return UsergroupMetaControl::Create($objParentObject, $intId, $intCreateType);
  115. }
  116. /**
  117. * Static Helper Method to Create using QueryString arguments
  118. *
  119. * @param mixed $objParentObject QForm or QPanel which will be using this UsergroupMetaControl
  120. * @param QMetaControlCreateType $intCreateType rules governing Usergroup object creation - defaults to CreateOrEdit
  121. * @return UsergroupMetaControl
  122. */
  123. public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
  124. $intId = QApplication::QueryString('intId');
  125. return UsergroupMetaControl::Create($objParentObject, $intId, $intCreateType);
  126. }
  127. ///////////////////////////////////////////////
  128. // PUBLIC CREATE and REFRESH METHODS
  129. ///////////////////////////////////////////////
  130. /**
  131. * Create and setup QLabel lblId
  132. * @param string $strControlId optional ControlId to use
  133. * @return QLabel
  134. */
  135. public function lblId_Create($strControlId = null) {
  136. $this->lblId = new QLabel($this->objParentObject, $strControlId);
  137. $this->lblId->Name = QApplication::Translate('Id');
  138. if ($this->blnEditMode)
  139. $this->lblId->Text = $this->objUsergroup->Id;
  140. else
  141. $this->lblId->Text = 'N/A';
  142. return $this->lblId;
  143. }
  144. /**
  145. * Create and setup QTextBox txtName
  146. * @param string $strControlId optional ControlId to use
  147. * @return QTextBox
  148. */
  149. public function txtName_Create($strControlId = null) {
  150. $this->txtName = new QTextBox($this->objParentObject, $strControlId);
  151. $this->txtName->Name = QApplication::Translate('Name');
  152. $this->txtName->Text = $this->objUsergroup->Name;
  153. $this->txtName->MaxLength = Usergroup::NameMaxLength;
  154. return $this->txtName;
  155. }
  156. /**
  157. * Create and setup QLabel lblName
  158. * @param string $strControlId optional ControlId to use
  159. * @return QLabel
  160. */
  161. public function lblName_Create($strControlId = null) {
  162. $this->lblName = new QLabel($this->objParentObject, $strControlId);
  163. $this->lblName->Name = QApplication::Translate('Name');
  164. $this->lblName->Text = $this->objUsergroup->Name;
  165. return $this->lblName;
  166. }
  167. /**
  168. * Create and setup QListBox lstContentItems
  169. * @param string $strControlId optional ControlId to use
  170. * @return QListBox
  171. */
  172. public function lstContentItems_Create($strControlId = null) {
  173. $this->lstContentItems = new QListBox($this->objParentObject, $strControlId);
  174. $this->lstContentItems->Name = QApplication::Translate('Content Items');
  175. $this->lstContentItems->SelectionMode = QSelectionMode::Multiple;
  176. $objAssociatedArray = $this->objUsergroup->GetContentItemArray();
  177. $objContentItemArray = ContentItem::LoadAll();
  178. if ($objContentItemArray) foreach ($objContentItemArray as $objContentItem) {
  179. $objListItem = new QListItem($objContentItem->__toString(), $objContentItem->Id);
  180. foreach ($objAssociatedArray as $objAssociated) {
  181. if ($objAssociated->Id == $objContentItem->Id)
  182. $objListItem->Selected = true;
  183. }
  184. $this->lstContentItems->AddItem($objListItem);
  185. }
  186. return $this->lstContentItems;
  187. }
  188. /**
  189. * Create and setup QLabel lblContentItems
  190. * @param string $strControlId optional ControlId to use
  191. * @param string $strGlue glue to display in between each associated object
  192. * @return QLabel
  193. */
  194. public function lblContentItems_Create($strControlId = null, $strGlue = ', ') {
  195. $this->lblContentItems = new QLabel($this->objParentObject, $strControlId);
  196. $this->lblContentItems->Name = QApplication::Translate('Content Items');
  197. $objAssociatedArray = $this->objUsergroup->GetContentItemArray();
  198. $strItems = array();
  199. foreach ($objAssociatedArray as $objAssociated)
  200. $strItems[] = $objAssociated->__toString();
  201. $this->lblContentItems->Text = implode($strGlue, $strItems);
  202. return $this->lblContentItems;
  203. }
  204. /**
  205. * Create and setup QListBox lstPages
  206. * @param string $strControlId optional ControlId to use
  207. * @return QListBox
  208. */
  209. public function lstPages_Create($strControlId = null) {
  210. $this->lstPages = new QListBox($this->objParentObject, $strControlId);
  211. $this->lstPages->Name = QApplication::Translate('Pages');
  212. $this->lstPages->SelectionMode = QSelectionMode::Multiple;
  213. $objAssociatedArray = $this->objUsergroup->GetPageArray();
  214. $objPageArray = Page::LoadAll();
  215. if ($objPageArray) foreach ($objPageArray as $objPage) {
  216. $objListItem = new QListItem($objPage->__toString(), $objPage->Id);
  217. foreach ($objAssociatedArray as $objAssociated) {
  218. if ($objAssociated->Id == $objPage->Id)
  219. $objListItem->Selected = true;
  220. }
  221. $this->lstPages->AddItem($objListItem);
  222. }
  223. return $this->lstPages;
  224. }
  225. /**
  226. * Create and setup QLabel lblPages
  227. * @param string $strControlId optional ControlId to use
  228. * @param string $strGlue glue to display in between each associated object
  229. * @return QLabel
  230. */
  231. public function lblPages_Create($strControlId = null, $strGlue = ', ') {
  232. $this->lblPages = new QLabel($this->objParentObject, $strControlId);
  233. $this->lblPages->Name = QApplication::Translate('Pages');
  234. $objAssociatedArray = $this->objUsergroup->GetPageArray();
  235. $strItems = array();
  236. foreach ($objAssociatedArray as $objAssociated)
  237. $strItems[] = $objAssociated->__toString();
  238. $this->lblPages->Text = implode($strGlue, $strItems);
  239. return $this->lblPages;
  240. }
  241. /**
  242. * Create and setup QListBox lstPeople
  243. * @param string $strControlId optional ControlId to use
  244. * @return QListBox
  245. */
  246. public function lstPeople_Create($strControlId = null) {
  247. $this->lstPeople = new QListBox($this->objParentObject, $strControlId);
  248. $this->lstPeople->Name = QApplication::Translate('People');
  249. $this->lstPeople->SelectionMode = QSelectionMode::Multiple;
  250. $objAssociatedArray = $this->objUsergroup->GetPersonArray();
  251. $objPersonArray = Person::LoadAll();
  252. if ($objPersonArray) foreach ($objPersonArray as $objPerson) {
  253. $objListItem = new QListItem($objPerson->__toString(), $objPerson->Id);
  254. foreach ($objAssociatedArray as $objAssociated) {
  255. if ($objAssociated->Id == $objPerson->Id)
  256. $objListItem->Selected = true;
  257. }
  258. $this->lstPeople->AddItem($objListItem);
  259. }
  260. return $this->lstPeople;
  261. }
  262. /**
  263. * Create and setup QLabel lblPeople
  264. * @param string $strControlId optional ControlId to use
  265. * @param string $strGlue glue to display in between each associated object
  266. * @return QLabel
  267. */
  268. public function lblPeople_Create($strControlId = null, $strGlue = ', ') {
  269. $this->lblPeople = new QLabel($this->objParentObject, $strControlId);
  270. $this->lblPeople->Name = QApplication::Translate('People');
  271. $objAssociatedArray = $this->objUsergroup->GetPersonArray();
  272. $strItems = array();
  273. foreach ($objAssociatedArray as $objAssociated)
  274. $strItems[] = $objAssociated->__toString();
  275. $this->lblPeople->Text = implode($strGlue, $strItems);
  276. return $this->lblPeople;
  277. }
  278. /**
  279. * Refresh this MetaControl with Data from the local Usergroup object.
  280. * @param boolean $blnReload reload Usergroup from the database
  281. * @return void
  282. */
  283. public function Refresh($blnReload = false) {
  284. if ($blnReload)
  285. $this->objUsergroup->Reload();
  286. if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objUsergroup->Id;
  287. if ($this->txtName) $this->txtName->Text = $this->objUsergroup->Name;
  288. if ($this->lblName) $this->lblName->Text = $this->objUsergroup->Name;
  289. if ($this->lstContentItems) {
  290. $this->lstContentItems->RemoveAllItems();
  291. $objAssociatedArray = $this->objUsergroup->GetContentItemArray();
  292. $objContentItemArray = ContentItem::LoadAll();
  293. if ($objContentItemArray) foreach ($objContentItemArray as $objContentItem) {
  294. $objListItem = new QListItem($objContentItem->__toString(), $objContentItem->Id);
  295. foreach ($objAssociatedArray as $objAssociated) {
  296. if ($objAssociated->Id == $objContentItem->Id)
  297. $objListItem->Selected = true;
  298. }
  299. $this->lstContentItems->AddItem($objListItem);
  300. }
  301. }
  302. if ($this->lblContentItems) {
  303. $objAssociatedArray = $this->objUsergroup->GetContentItemArray();
  304. $strItems = array();
  305. foreach ($objAssociatedArray as $objAssociated)
  306. $strItems[] = $objAssociated->__toString();
  307. $this->lblContentItems->Text = implode($strGlue, $strItems);
  308. }
  309. if ($this->lstPages) {
  310. $this->lstPages->RemoveAllItems();
  311. $objAssociatedArray = $this->objUsergroup->GetPageArray();
  312. $objPageArray = Page::LoadAll();
  313. if ($objPageArray) foreach ($objPageArray as $objPage) {
  314. $objListItem = new QListItem($objPage->__toString(), $objPage->Id);
  315. foreach ($objAssociatedArray as $objAssociated) {
  316. if ($objAssociated->Id == $objPage->Id)
  317. $objListItem->Selected = true;
  318. }
  319. $this->lstPages->AddItem($objListItem);
  320. }
  321. }
  322. if ($this->lblPages) {
  323. $objAssociatedArray = $this->objUsergroup->GetPageArray();
  324. $strItems = array();
  325. foreach ($objAssociatedArray as $objAssociated)
  326. $strItems[] = $objAssociated->__toString();
  327. $this->lblPages->Text = implode($strGlue, $strItems);
  328. }
  329. if ($this->lstPeople) {
  330. $this->lstPeople->RemoveAllItems();
  331. $objAssociatedArray = $this->objUsergroup->GetPersonArray();
  332. $objPersonArray = Person::LoadAll();
  333. if ($objPersonArray) foreach ($objPersonArray as $objPerson) {
  334. $objListItem = new QListItem($objPerson->__toString(), $objPerson->Id);
  335. foreach ($objAssociatedArray as $objAssociated) {
  336. if ($objAssociated->Id == $objPerson->Id)
  337. $objListItem->Selected = true;
  338. }
  339. $this->lstPeople->AddItem($objListItem);
  340. }
  341. }
  342. if ($this->lblPeople) {
  343. $objAssociatedArray = $this->objUsergroup->GetPersonArray();
  344. $strItems = array();
  345. foreach ($objAssociatedArray as $objAssociated)
  346. $strItems[] = $objAssociated->__toString();
  347. $this->lblPeople->Text = implode($strGlue, $strItems);
  348. }
  349. }
  350. ///////////////////////////////////////////////
  351. // PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
  352. ///////////////////////////////////////////////
  353. protected function lstContentItems_Update() {
  354. if ($this->lstContentItems) {
  355. $this->objUsergroup->UnassociateAllContentItems();
  356. $objSelectedListItems = $this->lstContentItems->SelectedItems;
  357. if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
  358. $this->objUsergroup->AssociateContentItem(ContentItem::Load($objListItem->Value));
  359. }
  360. }
  361. }
  362. protected function lstPages_Update() {
  363. if ($this->lstPages) {
  364. $this->objUsergroup->UnassociateAllPages();
  365. $objSelectedListItems = $this->lstPages->SelectedItems;
  366. if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
  367. $this->objUsergroup->AssociatePage(Page::Load($objListItem->Value));
  368. }
  369. }
  370. }
  371. protected function lstPeople_Update() {
  372. if ($this->lstPeople) {
  373. $this->objUsergroup->UnassociateAllPeople();
  374. $objSelectedListItems = $this->lstPeople->SelectedItems;
  375. if ($objSelectedListItems) foreach ($objSelectedListItems as $objListItem) {
  376. $this->objUsergroup->AssociatePerson(Person::Load($objListItem->Value));
  377. }
  378. }
  379. }
  380. ///////////////////////////////////////////////
  381. // PUBLIC USERGROUP OBJECT MANIPULATORS
  382. ///////////////////////////////////////////////
  383. /**
  384. * This will save this object's Usergroup instance,
  385. * updating only the fields which have had a control created for it.
  386. */
  387. public function SaveUsergroup() {
  388. try {
  389. // Update any fields for controls that have been created
  390. if ($this->txtName) $this->objUsergroup->Name = $this->txtName->Text;
  391. // Update any UniqueReverseReferences (if any) for controls that have been created for it
  392. // Save the Usergroup object
  393. $this->objUsergroup->Save();
  394. // Finally, update any ManyToManyReferences (if any)
  395. $this->lstContentItems_Update();
  396. $this->lstPages_Update();
  397. $this->lstPeople_Update();
  398. } catch (QCallerException $objExc) {
  399. $objExc->IncrementOffset();
  400. throw $objExc;
  401. }
  402. }
  403. /**
  404. * This will DELETE this object's Usergroup instance from the database.
  405. * It will also unassociate itself from any ManyToManyReferences.
  406. */
  407. public function DeleteUsergroup() {
  408. $this->objUsergroup->UnassociateAllContentItems();
  409. $this->objUsergroup->UnassociateAllPages();
  410. $this->objUsergroup->UnassociateAllPeople();
  411. $this->objUsergroup->Delete();
  412. }
  413. ///////////////////////////////////////////////
  414. // PUBLIC GETTERS and SETTERS
  415. ///////////////////////////////////////////////
  416. /**
  417. * Override method to perform a property "Get"
  418. * This will get the value of $strName
  419. *
  420. * @param string $strName Name of the property to get
  421. * @return mixed
  422. */
  423. public function __get($strName) {
  424. switch ($strName) {
  425. // General MetaControlVariables
  426. case 'Usergroup': return $this->objUsergroup;
  427. case 'TitleVerb': return $this->strTitleVerb;
  428. case 'EditMode': return $this->blnEditMode;
  429. // Controls that point to Usergroup fields -- will be created dynamically if not yet created
  430. case 'IdControl':
  431. if (!$this->lblId) return $this->lblId_Create();
  432. return $this->lblId;
  433. case 'IdLabel':
  434. if (!$this->lblId) return $this->lblId_Create();
  435. return $this->lblId;
  436. case 'NameControl':
  437. if (!$this->txtName) return $this->txtName_Create();
  438. return $this->txtName;
  439. case 'NameLabel':
  440. if (!$this->lblName) return $this->lblName_Create();
  441. return $this->lblName;
  442. case 'ContentItemControl':
  443. if (!$this->lstContentItems) return $this->lstContentItems_Create();
  444. return $this->lstContentItems;
  445. case 'ContentItemLabel':
  446. if (!$this->lblContentItems) return $this->lblContentItems_Create();
  447. return $this->lblContentItems;
  448. case 'PageControl':
  449. if (!$this->lstPages) return $this->lstPages_Create();
  450. return $this->lstPages;
  451. case 'PageLabel':
  452. if (!$this->lblPages) return $this->lblPages_Create();
  453. return $this->lblPages;
  454. case 'PersonControl':
  455. if (!$this->lstPeople) return $this->lstPeople_Create();
  456. return $this->lstPeople;
  457. case 'PersonLabel':
  458. if (!$this->lblPeople) return $this->lblPeople_Create();
  459. return $this->lblPeople;
  460. default:
  461. try {
  462. return parent::__get($strName);
  463. } catch (QCallerException $objExc) {
  464. $objExc->IncrementOffset();
  465. throw $objExc;
  466. }
  467. }
  468. }
  469. /**
  470. * Override method to perform a property "Set"
  471. * This will set the property $strName to be $mixValue
  472. *
  473. * @param string $strName Name of the property to set
  474. * @param string $mixValue New value of the property
  475. * @return mixed
  476. */
  477. public function __set($strName, $mixValue) {
  478. try {
  479. switch ($strName) {
  480. // Controls that point to Usergroup fields
  481. case 'IdControl':
  482. return ($this->lblId = QType::Cast($mixValue, 'QControl'));
  483. case 'NameControl':
  484. return ($this->txtName = QType::Cast($mixValue, 'QControl'));
  485. case 'ContentItemControl':
  486. return ($this->lstContentItems = QType::Cast($mixValue, 'QControl'));
  487. case 'PageControl':
  488. return ($this->lstPages = QType::Cast($mixValue, 'QControl'));
  489. case 'PersonControl':
  490. return ($this->lstPeople = QType::Cast($mixValue, 'QControl'));
  491. default:
  492. return parent::__set($strName, $mixValue);
  493. }
  494. } catch (QCallerException $objExc) {
  495. $objExc->IncrementOffset();
  496. throw $objExc;
  497. }
  498. }
  499. }
  500. ?>