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.

1485 lines
61 KiB

  1. <?php
  2. /**
  3. * The abstract UsergroupGen class defined here is
  4. * code-generated and contains all the basic CRUD-type functionality as well as
  5. * basic methods to handle relationships and index-based loading.
  6. *
  7. * To use, you should use the Usergroup subclass which
  8. * extends this UsergroupGen class.
  9. *
  10. * Because subsequent re-code generations will overwrite any changes to this
  11. * file, you should leave this file unaltered to prevent yourself from losing
  12. * any information or code changes. All customizations should be done by
  13. * overriding existing or implementing new methods, properties and variables
  14. * in the Usergroup class.
  15. *
  16. * @package Quinta CMS
  17. * @subpackage GeneratedDataObjects
  18. * @property-read integer $Id the value for intId (Read-Only PK)
  19. * @property string $Name the value for strName (Unique)
  20. * @property-read ContentItem $_ContentItem the value for the private _objContentItem (Read-Only) if set due to an expansion on the content_item_usergroup_assn association table
  21. * @property-read ContentItem[] $_ContentItemArray the value for the private _objContentItemArray (Read-Only) if set due to an ExpandAsArray on the content_item_usergroup_assn association table
  22. * @property-read Page $_Page the value for the private _objPage (Read-Only) if set due to an expansion on the page_usergroup_assn association table
  23. * @property-read Page[] $_PageArray the value for the private _objPageArray (Read-Only) if set due to an ExpandAsArray on the page_usergroup_assn association table
  24. * @property-read Person $_Person the value for the private _objPerson (Read-Only) if set due to an expansion on the person_usergroup_assn association table
  25. * @property-read Person[] $_PersonArray the value for the private _objPersonArray (Read-Only) if set due to an ExpandAsArray on the person_usergroup_assn association table
  26. * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
  27. */
  28. class UsergroupGen extends QBaseClass
  29. {
  30. ///////////////////////////////////////////////////////////////////////
  31. // PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
  32. ///////////////////////////////////////////////////////////////////////
  33. /////////// Object properties ////////////
  34. /**
  35. * Protected member variable that maps to the database PK Identity column usergroup.id
  36. * @var integer intId
  37. *
  38. */
  39. protected $intId = null;
  40. /**
  41. * Protected member variable that maps to the database column usergroup.name
  42. * @var string strName
  43. *
  44. */
  45. protected $strName = null;
  46. const NameMaxLength = 128;
  47. /**
  48. * Private member variable that stores a reference to a single ContentItem object
  49. * (of type ContentItem), if this Usergroup object was restored with
  50. * an expansion on the content_item_usergroup_assn association table.
  51. * @var ContentItem _objContentItem;
  52. */
  53. private $_objContentItem;
  54. /**
  55. * Private member variable that stores a reference to an array of ContentItem objects
  56. * (of type ContentItem[]), if this Usergroup object was restored with
  57. * an ExpandAsArray on the content_item_usergroup_assn association table.
  58. * @var ContentItem[] _objContentItemArray;
  59. */
  60. private $_objContentItemArray = array();
  61. /**
  62. * Private member variable that stores a reference to a single Page object
  63. * (of type Page), if this Usergroup object was restored with
  64. * an expansion on the page_usergroup_assn association table.
  65. * @var Page _objPage;
  66. */
  67. private $_objPage;
  68. /**
  69. * Private member variable that stores a reference to an array of Page objects
  70. * (of type Page[]), if this Usergroup object was restored with
  71. * an ExpandAsArray on the page_usergroup_assn association table.
  72. * @var Page[] _objPageArray;
  73. */
  74. private $_objPageArray = array();
  75. /**
  76. * Private member variable that stores a reference to a single Person object
  77. * (of type Person), if this Usergroup object was restored with
  78. * an expansion on the person_usergroup_assn association table.
  79. * @var Person _objPerson;
  80. */
  81. private $_objPerson;
  82. /**
  83. * Private member variable that stores a reference to an array of Person objects
  84. * (of type Person[]), if this Usergroup object was restored with
  85. * an ExpandAsArray on the person_usergroup_assn association table.
  86. * @var Person[] _objPersonArray;
  87. */
  88. private $_objPersonArray = array();
  89. /**
  90. * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
  91. * columns from the run-time database query result for this object). Used by InstantiateDbRow and
  92. * GetVirtualAttribute.
  93. * @var string[] $__strVirtualAttributeArray
  94. */
  95. protected $__strVirtualAttributeArray = array();
  96. /**
  97. * Protected internal member variable that specifies whether or not this object is Restored from the database.
  98. * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
  99. * @var bool __blnRestored;
  100. */
  101. protected $__blnRestored;
  102. ///////////////////////////////
  103. // PROTECTED MEMBER OBJECTS
  104. ///////////////////////////////
  105. ///////////////////////////////
  106. // CLASS-WIDE LOAD AND COUNT METHODS
  107. ///////////////////////////////
  108. /**
  109. * Static method to retrieve the Database object that owns this class.
  110. * @return QDatabaseBase reference to the Database object that can query this class
  111. */
  112. public static function GetDatabase() {
  113. return QApplication::$Database[1];
  114. }
  115. /**
  116. * Load a Usergroup from PK Info
  117. * @param integer $intId
  118. * @return Usergroup
  119. */
  120. public static function Load($intId) {
  121. // Use QuerySingle to Perform the Query
  122. return Usergroup::QuerySingle(
  123. QQ::Equal(QQN::Usergroup()->Id, $intId)
  124. );
  125. }
  126. /**
  127. * Load all Usergroups
  128. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  129. * @return Usergroup[]
  130. */
  131. public static function LoadAll($objOptionalClauses = null) {
  132. // Call Usergroup::QueryArray to perform the LoadAll query
  133. try {
  134. return Usergroup::QueryArray(QQ::All(), $objOptionalClauses);
  135. } catch (QCallerException $objExc) {
  136. $objExc->IncrementOffset();
  137. throw $objExc;
  138. }
  139. }
  140. /**
  141. * Count all Usergroups
  142. * @return int
  143. */
  144. public static function CountAll() {
  145. // Call Usergroup::QueryCount to perform the CountAll query
  146. return Usergroup::QueryCount(QQ::All());
  147. }
  148. ///////////////////////////////
  149. // QCODO QUERY-RELATED METHODS
  150. ///////////////////////////////
  151. /**
  152. * Internally called method to assist with calling Qcodo Query for this class
  153. * on load methods.
  154. * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  155. * @param QQCondition $objConditions any conditions on the query, itself
  156. * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  157. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  158. * @param boolean $blnCountOnly only select a rowcount
  159. * @return string the query statement
  160. */
  161. protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
  162. // Get the Database Object for this Class
  163. $objDatabase = Usergroup::GetDatabase();
  164. // Create/Build out the QueryBuilder object with Usergroup-specific SELET and FROM fields
  165. $objQueryBuilder = new QQueryBuilder($objDatabase, 'usergroup');
  166. Usergroup::GetSelectFields($objQueryBuilder);
  167. $objQueryBuilder->AddFromItem('usergroup');
  168. // Set "CountOnly" option (if applicable)
  169. if ($blnCountOnly)
  170. $objQueryBuilder->SetCountOnlyFlag();
  171. // Apply Any Conditions
  172. if ($objConditions)
  173. try {
  174. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  175. } catch (QCallerException $objExc) {
  176. $objExc->IncrementOffset();
  177. throw $objExc;
  178. }
  179. // Iterate through all the Optional Clauses (if any) and perform accordingly
  180. if ($objOptionalClauses) {
  181. if ($objOptionalClauses instanceof QQClause)
  182. $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
  183. else if (is_array($objOptionalClauses))
  184. foreach ($objOptionalClauses as $objClause)
  185. $objClause->UpdateQueryBuilder($objQueryBuilder);
  186. else
  187. throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
  188. }
  189. // Get the SQL Statement
  190. $strQuery = $objQueryBuilder->GetStatement();
  191. // Prepare the Statement with the Query Parameters (if applicable)
  192. if ($mixParameterArray) {
  193. if (is_array($mixParameterArray)) {
  194. if (count($mixParameterArray))
  195. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  196. // Ensure that there are no other Unresolved Named Parameters
  197. if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
  198. throw new QCallerException('Unresolved named parameters in the query');
  199. } else
  200. throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
  201. }
  202. // Return the Objects
  203. return $strQuery;
  204. }
  205. /**
  206. * Static Qcodo Query method to query for a single Usergroup object.
  207. * Uses BuildQueryStatment to perform most of the work.
  208. * @param QQCondition $objConditions any conditions on the query, itself
  209. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  210. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  211. * @return Usergroup the queried object
  212. */
  213. public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  214. // Get the Query Statement
  215. try {
  216. $strQuery = Usergroup::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  217. } catch (QCallerException $objExc) {
  218. $objExc->IncrementOffset();
  219. throw $objExc;
  220. }
  221. // Perform the Query, Get the First Row, and Instantiate a new Usergroup object
  222. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  223. return Usergroup::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);
  224. }
  225. /**
  226. * Static Qcodo Query method to query for an array of Usergroup objects.
  227. * Uses BuildQueryStatment to perform most of the work.
  228. * @param QQCondition $objConditions any conditions on the query, itself
  229. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  230. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  231. * @return Usergroup[] the queried objects as an array
  232. */
  233. public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  234. // Get the Query Statement
  235. try {
  236. $strQuery = Usergroup::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
  237. } catch (QCallerException $objExc) {
  238. $objExc->IncrementOffset();
  239. throw $objExc;
  240. }
  241. // Perform the Query and Instantiate the Array Result
  242. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  243. return Usergroup::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
  244. }
  245. /**
  246. * Static Qcodo Query method to query for a count of Usergroup objects.
  247. * Uses BuildQueryStatment to perform most of the work.
  248. * @param QQCondition $objConditions any conditions on the query, itself
  249. * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
  250. * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
  251. * @return integer the count of queried objects as an integer
  252. */
  253. public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
  254. // Get the Query Statement
  255. try {
  256. $strQuery = Usergroup::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
  257. } catch (QCallerException $objExc) {
  258. $objExc->IncrementOffset();
  259. throw $objExc;
  260. }
  261. // Perform the Query and return the row_count
  262. $objDbResult = $objQueryBuilder->Database->Query($strQuery);
  263. // Figure out if the query is using GroupBy
  264. $blnGrouped = false;
  265. if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
  266. if ($objClause instanceof QQGroupBy) {
  267. $blnGrouped = true;
  268. break;
  269. }
  270. }
  271. if ($blnGrouped)
  272. // Groups in this query - return the count of Groups (which is the count of all rows)
  273. return $objDbResult->CountRows();
  274. else {
  275. // No Groups - return the sql-calculated count(*) value
  276. $strDbRow = $objDbResult->FetchRow();
  277. return QType::Cast($strDbRow[0], QType::Integer);
  278. }
  279. }
  280. /* public static function QueryArrayCached($strConditions, $mixParameterArray = null) {
  281. // Get the Database Object for this Class
  282. $objDatabase = Usergroup::GetDatabase();
  283. // Lookup the QCache for This Query Statement
  284. $objCache = new QCache('query', 'usergroup_' . serialize($strConditions));
  285. if (!($strQuery = $objCache->GetData())) {
  286. // Not Found -- Go ahead and Create/Build out a new QueryBuilder object with Usergroup-specific fields
  287. $objQueryBuilder = new QQueryBuilder($objDatabase);
  288. Usergroup::GetSelectFields($objQueryBuilder);
  289. Usergroup::GetFromFields($objQueryBuilder);
  290. // Ensure the Passed-in Conditions is a string
  291. try {
  292. $strConditions = QType::Cast($strConditions, QType::String);
  293. } catch (QCallerException $objExc) {
  294. $objExc->IncrementOffset();
  295. throw $objExc;
  296. }
  297. // Create the Conditions object, and apply it
  298. $objConditions = eval('return ' . $strConditions . ';');
  299. // Apply Any Conditions
  300. if ($objConditions)
  301. $objConditions->UpdateQueryBuilder($objQueryBuilder);
  302. // Get the SQL Statement
  303. $strQuery = $objQueryBuilder->GetStatement();
  304. // Save the SQL Statement in the Cache
  305. $objCache->SaveData($strQuery);
  306. }
  307. // Prepare the Statement with the Parameters
  308. if ($mixParameterArray)
  309. $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
  310. // Perform the Query and Instantiate the Array Result
  311. $objDbResult = $objDatabase->Query($strQuery);
  312. return Usergroup::InstantiateDbResult($objDbResult);
  313. }*/
  314. /**
  315. * Updates a QQueryBuilder with the SELECT fields for this Usergroup
  316. * @param QQueryBuilder $objBuilder the Query Builder object to update
  317. * @param string $strPrefix optional prefix to add to the SELECT fields
  318. */
  319. public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
  320. if ($strPrefix) {
  321. $strTableName = $strPrefix;
  322. $strAliasPrefix = $strPrefix . '__';
  323. } else {
  324. $strTableName = 'usergroup';
  325. $strAliasPrefix = '';
  326. }
  327. $objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
  328. $objBuilder->AddSelectItem($strTableName, 'name', $strAliasPrefix . 'name');
  329. }
  330. ///////////////////////////////
  331. // INSTANTIATION-RELATED METHODS
  332. ///////////////////////////////
  333. /**
  334. * Instantiate a Usergroup from a Database Row.
  335. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  336. * is calling this Usergroup::InstantiateDbRow in order to perform
  337. * early binding on referenced objects.
  338. * @param DatabaseRowBase $objDbRow
  339. * @param string $strAliasPrefix
  340. * @param string $strExpandAsArrayNodes
  341. * @param QBaseClass $objPreviousItem
  342. * @param string[] $strColumnAliasArray
  343. * @return Usergroup
  344. */
  345. public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null, $strColumnAliasArray = array()) {
  346. // If blank row, return null
  347. if (!$objDbRow)
  348. return null;
  349. // See if we're doing an array expansion on the previous item
  350. $strAlias = $strAliasPrefix . 'id';
  351. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  352. if (($strExpandAsArrayNodes) && ($objPreviousItem) &&
  353. ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer'))) {
  354. // We are. Now, prepare to check for ExpandAsArray clauses
  355. $blnExpandedViaArray = false;
  356. if (!$strAliasPrefix)
  357. $strAliasPrefix = 'usergroup__';
  358. $strAlias = $strAliasPrefix . 'contentitem__content_item_id__id';
  359. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  360. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  361. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  362. if ($intPreviousChildItemCount = count($objPreviousItem->_objContentItemArray)) {
  363. $objPreviousChildItem = $objPreviousItem->_objContentItemArray[$intPreviousChildItemCount - 1];
  364. $objChildItem = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  365. if ($objChildItem)
  366. $objPreviousItem->_objContentItemArray[] = $objChildItem;
  367. } else
  368. $objPreviousItem->_objContentItemArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  369. $blnExpandedViaArray = true;
  370. }
  371. $strAlias = $strAliasPrefix . 'page__page_id__id';
  372. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  373. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  374. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  375. if ($intPreviousChildItemCount = count($objPreviousItem->_objPageArray)) {
  376. $objPreviousChildItem = $objPreviousItem->_objPageArray[$intPreviousChildItemCount - 1];
  377. $objChildItem = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  378. if ($objChildItem)
  379. $objPreviousItem->_objPageArray[] = $objChildItem;
  380. } else
  381. $objPreviousItem->_objPageArray[] = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  382. $blnExpandedViaArray = true;
  383. }
  384. $strAlias = $strAliasPrefix . 'person__person_id__id';
  385. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  386. if ((array_key_exists($strAlias, $strExpandAsArrayNodes)) &&
  387. (!is_null($objDbRow->GetColumn($strAliasName)))) {
  388. if ($intPreviousChildItemCount = count($objPreviousItem->_objPersonArray)) {
  389. $objPreviousChildItem = $objPreviousItem->_objPersonArray[$intPreviousChildItemCount - 1];
  390. $objChildItem = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person__person_id__', $strExpandAsArrayNodes, $objPreviousChildItem, $strColumnAliasArray);
  391. if ($objChildItem)
  392. $objPreviousItem->_objPersonArray[] = $objChildItem;
  393. } else
  394. $objPreviousItem->_objPersonArray[] = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person__person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  395. $blnExpandedViaArray = true;
  396. }
  397. // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on
  398. if ($blnExpandedViaArray)
  399. return false;
  400. else if ($strAliasPrefix == 'usergroup__')
  401. $strAliasPrefix = null;
  402. }
  403. // Create a new instance of the Usergroup object
  404. $objToReturn = new Usergroup();
  405. $objToReturn->__blnRestored = true;
  406. $strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
  407. $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
  408. $strAliasName = array_key_exists($strAliasPrefix . 'name', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'name'] : $strAliasPrefix . 'name';
  409. $objToReturn->strName = $objDbRow->GetColumn($strAliasName, 'VarChar');
  410. // Instantiate Virtual Attributes
  411. foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
  412. $strVirtualPrefix = $strAliasPrefix . '__';
  413. $strVirtualPrefixLength = strlen($strVirtualPrefix);
  414. if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
  415. $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
  416. }
  417. // Prepare to Check for Early/Virtual Binding
  418. if (!$strAliasPrefix)
  419. $strAliasPrefix = 'usergroup__';
  420. // Check for ContentItem Virtual Binding
  421. $strAlias = $strAliasPrefix . 'contentitem__content_item_id__id';
  422. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  423. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  424. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  425. $objToReturn->_objContentItemArray[] = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  426. else
  427. $objToReturn->_objContentItem = ContentItem::InstantiateDbRow($objDbRow, $strAliasPrefix . 'contentitem__content_item_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  428. }
  429. // Check for Page Virtual Binding
  430. $strAlias = $strAliasPrefix . 'page__page_id__id';
  431. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  432. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  433. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  434. $objToReturn->_objPageArray[] = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  435. else
  436. $objToReturn->_objPage = Page::InstantiateDbRow($objDbRow, $strAliasPrefix . 'page__page_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  437. }
  438. // Check for Person Virtual Binding
  439. $strAlias = $strAliasPrefix . 'person__person_id__id';
  440. $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
  441. if (!is_null($objDbRow->GetColumn($strAliasName))) {
  442. if (($strExpandAsArrayNodes) && (array_key_exists($strAlias, $strExpandAsArrayNodes)))
  443. $objToReturn->_objPersonArray[] = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person__person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  444. else
  445. $objToReturn->_objPerson = Person::InstantiateDbRow($objDbRow, $strAliasPrefix . 'person__person_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
  446. }
  447. return $objToReturn;
  448. }
  449. /**
  450. * Instantiate an array of Usergroups from a Database Result
  451. * @param DatabaseResultBase $objDbResult
  452. * @param string $strExpandAsArrayNodes
  453. * @param string[] $strColumnAliasArray
  454. * @return Usergroup[]
  455. */
  456. public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
  457. $objToReturn = array();
  458. if (!$strColumnAliasArray)
  459. $strColumnAliasArray = array();
  460. // If blank resultset, then return empty array
  461. if (!$objDbResult)
  462. return $objToReturn;
  463. // Load up the return array with each row
  464. if ($strExpandAsArrayNodes) {
  465. $objLastRowItem = null;
  466. while ($objDbRow = $objDbResult->GetNextRow()) {
  467. $objItem = Usergroup::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray);
  468. if ($objItem) {
  469. $objToReturn[] = $objItem;
  470. $objLastRowItem = $objItem;
  471. }
  472. }
  473. } else {
  474. while ($objDbRow = $objDbResult->GetNextRow())
  475. $objToReturn[] = Usergroup::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
  476. }
  477. return $objToReturn;
  478. }
  479. ///////////////////////////////////////////////////
  480. // INDEX-BASED LOAD METHODS (Single Load and Array)
  481. ///////////////////////////////////////////////////
  482. /**
  483. * Load a single Usergroup object,
  484. * by Id Index(es)
  485. * @param integer $intId
  486. * @return Usergroup
  487. */
  488. public static function LoadById($intId) {
  489. return Usergroup::QuerySingle(
  490. QQ::Equal(QQN::Usergroup()->Id, $intId)
  491. );
  492. }
  493. /**
  494. * Load a single Usergroup object,
  495. * by Name Index(es)
  496. * @param string $strName
  497. * @return Usergroup
  498. */
  499. public static function LoadByName($strName) {
  500. return Usergroup::QuerySingle(
  501. QQ::Equal(QQN::Usergroup()->Name, $strName)
  502. );
  503. }
  504. ////////////////////////////////////////////////////
  505. // INDEX-BASED LOAD METHODS (Array via Many to Many)
  506. ////////////////////////////////////////////////////
  507. /**
  508. * Load an array of ContentItem objects for a given ContentItem
  509. * via the content_item_usergroup_assn table
  510. * @param integer $intContentItemId
  511. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  512. * @return Usergroup[]
  513. */
  514. public static function LoadArrayByContentItem($intContentItemId, $objOptionalClauses = null) {
  515. // Call Usergroup::QueryArray to perform the LoadArrayByContentItem query
  516. try {
  517. return Usergroup::QueryArray(
  518. QQ::Equal(QQN::Usergroup()->ContentItem->ContentItemId, $intContentItemId),
  519. $objOptionalClauses
  520. );
  521. } catch (QCallerException $objExc) {
  522. $objExc->IncrementOffset();
  523. throw $objExc;
  524. }
  525. }
  526. /**
  527. * Count Usergroups for a given ContentItem
  528. * via the content_item_usergroup_assn table
  529. * @param integer $intContentItemId
  530. * @return int
  531. */
  532. public static function CountByContentItem($intContentItemId) {
  533. return Usergroup::QueryCount(
  534. QQ::Equal(QQN::Usergroup()->ContentItem->ContentItemId, $intContentItemId)
  535. );
  536. }
  537. /**
  538. * Load an array of Page objects for a given Page
  539. * via the page_usergroup_assn table
  540. * @param integer $intPageId
  541. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  542. * @return Usergroup[]
  543. */
  544. public static function LoadArrayByPage($intPageId, $objOptionalClauses = null) {
  545. // Call Usergroup::QueryArray to perform the LoadArrayByPage query
  546. try {
  547. return Usergroup::QueryArray(
  548. QQ::Equal(QQN::Usergroup()->Page->PageId, $intPageId),
  549. $objOptionalClauses
  550. );
  551. } catch (QCallerException $objExc) {
  552. $objExc->IncrementOffset();
  553. throw $objExc;
  554. }
  555. }
  556. /**
  557. * Count Usergroups for a given Page
  558. * via the page_usergroup_assn table
  559. * @param integer $intPageId
  560. * @return int
  561. */
  562. public static function CountByPage($intPageId) {
  563. return Usergroup::QueryCount(
  564. QQ::Equal(QQN::Usergroup()->Page->PageId, $intPageId)
  565. );
  566. }
  567. /**
  568. * Load an array of Person objects for a given Person
  569. * via the person_usergroup_assn table
  570. * @param integer $intPersonId
  571. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  572. * @return Usergroup[]
  573. */
  574. public static function LoadArrayByPerson($intPersonId, $objOptionalClauses = null) {
  575. // Call Usergroup::QueryArray to perform the LoadArrayByPerson query
  576. try {
  577. return Usergroup::QueryArray(
  578. QQ::Equal(QQN::Usergroup()->Person->PersonId, $intPersonId),
  579. $objOptionalClauses
  580. );
  581. } catch (QCallerException $objExc) {
  582. $objExc->IncrementOffset();
  583. throw $objExc;
  584. }
  585. }
  586. /**
  587. * Count Usergroups for a given Person
  588. * via the person_usergroup_assn table
  589. * @param integer $intPersonId
  590. * @return int
  591. */
  592. public static function CountByPerson($intPersonId) {
  593. return Usergroup::QueryCount(
  594. QQ::Equal(QQN::Usergroup()->Person->PersonId, $intPersonId)
  595. );
  596. }
  597. //////////////////////////
  598. // SAVE, DELETE AND RELOAD
  599. //////////////////////////
  600. /**
  601. * Save this Usergroup
  602. * @param bool $blnForceInsert
  603. * @param bool $blnForceUpdate
  604. * @return int
  605. */
  606. public function Save($blnForceInsert = false, $blnForceUpdate = false) {
  607. // Get the Database Object for this Class
  608. $objDatabase = Usergroup::GetDatabase();
  609. $mixToReturn = null;
  610. try {
  611. if ((!$this->__blnRestored) || ($blnForceInsert)) {
  612. // Perform an INSERT query
  613. $objDatabase->NonQuery('
  614. INSERT INTO `usergroup` (
  615. `name`
  616. ) VALUES (
  617. ' . $objDatabase->SqlVariable($this->strName) . '
  618. )
  619. ');
  620. // Update Identity column and return its value
  621. $mixToReturn = $this->intId = $objDatabase->InsertId('usergroup', 'id');
  622. } else {
  623. // Perform an UPDATE query
  624. // First checking for Optimistic Locking constraints (if applicable)
  625. // Perform the UPDATE query
  626. $objDatabase->NonQuery('
  627. UPDATE
  628. `usergroup`
  629. SET
  630. `name` = ' . $objDatabase->SqlVariable($this->strName) . '
  631. WHERE
  632. `id` = ' . $objDatabase->SqlVariable($this->intId) . '
  633. ');
  634. }
  635. } catch (QCallerException $objExc) {
  636. $objExc->IncrementOffset();
  637. throw $objExc;
  638. }
  639. // Update __blnRestored and any Non-Identity PK Columns (if applicable)
  640. $this->__blnRestored = true;
  641. // Return
  642. return $mixToReturn;
  643. }
  644. /**
  645. * Delete this Usergroup
  646. * @return void
  647. */
  648. public function Delete() {
  649. if ((is_null($this->intId)))
  650. throw new QUndefinedPrimaryKeyException('Cannot delete this Usergroup with an unset primary key.');
  651. // Get the Database Object for this Class
  652. $objDatabase = Usergroup::GetDatabase();
  653. // Perform the SQL Query
  654. $objDatabase->NonQuery('
  655. DELETE FROM
  656. `usergroup`
  657. WHERE
  658. `id` = ' . $objDatabase->SqlVariable($this->intId) . '');
  659. }
  660. /**
  661. * Delete all Usergroups
  662. * @return void
  663. */
  664. public static function DeleteAll() {
  665. // Get the Database Object for this Class
  666. $objDatabase = Usergroup::GetDatabase();
  667. // Perform the Query
  668. $objDatabase->NonQuery('
  669. DELETE FROM
  670. `usergroup`');
  671. }
  672. /**
  673. * Truncate usergroup table
  674. * @return void
  675. */
  676. public static function Truncate() {
  677. // Get the Database Object for this Class
  678. $objDatabase = Usergroup::GetDatabase();
  679. // Perform the Query
  680. $objDatabase->NonQuery('
  681. TRUNCATE `usergroup`');
  682. }
  683. /**
  684. * Reload this Usergroup from the database.
  685. * @return void
  686. */
  687. public function Reload() {
  688. // Make sure we are actually Restored from the database
  689. if (!$this->__blnRestored)
  690. throw new QCallerException('Cannot call Reload() on a new, unsaved Usergroup object.');
  691. // Reload the Object
  692. $objReloaded = Usergroup::Load($this->intId);
  693. // Update $this's local variables to match
  694. $this->strName = $objReloaded->strName;
  695. }
  696. ////////////////////
  697. // GETTORS AND SETTORS
  698. ////////////////////
  699. /**
  700. * Lookup a VirtualAttribute value (if applicable). Returns NULL if none found.
  701. * @param string $strName
  702. * @return string
  703. */
  704. public function GetVirtualAttribute($strName)
  705. {
  706. if (array_key_exists($strName, $this->__strVirtualAttributeArray))
  707. return $this->__strVirtualAttributeArray[$strName];
  708. return null;
  709. }
  710. /**
  711. * Override method to perform a property "Get"
  712. * This will get the value of $strName
  713. *
  714. * @param string $strName Name of the property to get
  715. * @return mixed
  716. */
  717. public function __get($strName)
  718. {
  719. switch ($strName)
  720. {
  721. ///////////////////
  722. // Member Variables
  723. ///////////////////
  724. case 'Id':
  725. /**
  726. * Gets the value for intId (Read-Only PK)
  727. * @return integer
  728. */
  729. return $this->intId;
  730. case 'Name':
  731. /**
  732. * Gets the value for strName (Unique)
  733. * @return string
  734. */
  735. return $this->strName;
  736. ///////////////////
  737. // Member Objects
  738. ///////////////////
  739. ////////////////////////////
  740. // Virtual Object References (Many to Many and Reverse References)
  741. // (If restored via a "Many-to" expansion)
  742. ////////////////////////////
  743. case '_ContentItem':
  744. /**
  745. * Gets the value for the private _objContentItem (Read-Only)
  746. * if set due to an expansion on the content_item_usergroup_assn association table
  747. * @return ContentItem
  748. */
  749. return $this->_objContentItem;
  750. case '_ContentItemArray':
  751. /**
  752. * Gets the value for the private _objContentItemArray (Read-Only)
  753. * if set due to an ExpandAsArray on the content_item_usergroup_assn association table
  754. * @return ContentItem[]
  755. */
  756. return (array) $this->_objContentItemArray;
  757. case '_Page':
  758. /**
  759. * Gets the value for the private _objPage (Read-Only)
  760. * if set due to an expansion on the page_usergroup_assn association table
  761. * @return Page
  762. */
  763. return $this->_objPage;
  764. case '_PageArray':
  765. /**
  766. * Gets the value for the private _objPageArray (Read-Only)
  767. * if set due to an ExpandAsArray on the page_usergroup_assn association table
  768. * @return Page[]
  769. */
  770. return (array) $this->_objPageArray;
  771. case '_Person':
  772. /**
  773. * Gets the value for the private _objPerson (Read-Only)
  774. * if set due to an expansion on the person_usergroup_assn association table
  775. * @return Person
  776. */
  777. return $this->_objPerson;
  778. case '_PersonArray':
  779. /**
  780. * Gets the value for the private _objPersonArray (Read-Only)
  781. * if set due to an ExpandAsArray on the person_usergroup_assn association table
  782. * @return Person[]
  783. */
  784. return (array) $this->_objPersonArray;
  785. case '__Restored':
  786. return $this->__blnRestored;
  787. default:
  788. try {
  789. return parent::__get($strName);
  790. } catch (QCallerException $objExc) {
  791. $objExc->IncrementOffset();
  792. throw $objExc;
  793. }
  794. }
  795. }
  796. /**
  797. * Override method to perform a property "Set"
  798. * This will set the property $strName to be $mixValue
  799. *
  800. * @param string $strName Name of the property to set
  801. * @param string $mixValue New value of the property
  802. * @return mixed
  803. */
  804. public function __set($strName, $mixValue) {
  805. switch ($strName) {
  806. ///////////////////
  807. // Member Variables
  808. ///////////////////
  809. case 'Name':
  810. /**
  811. * Sets the value for strName (Unique)
  812. * @param string $mixValue
  813. * @return string
  814. */
  815. try {
  816. return ($this->strName = QType::Cast($mixValue, QType::String));
  817. } catch (QCallerException $objExc) {
  818. $objExc->IncrementOffset();
  819. throw $objExc;
  820. }
  821. ///////////////////
  822. // Member Objects
  823. ///////////////////
  824. default:
  825. try {
  826. return parent::__set($strName, $mixValue);
  827. } catch (QCallerException $objExc) {
  828. $objExc->IncrementOffset();
  829. throw $objExc;
  830. }
  831. }
  832. }
  833. ///////////////////////////////
  834. // ASSOCIATED OBJECTS' METHODS
  835. ///////////////////////////////
  836. // Related Many-to-Many Objects' Methods for ContentItem
  837. //-------------------------------------------------------------------
  838. /**
  839. * Gets all many-to-many associated ContentItems as an array of ContentItem objects
  840. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  841. * @return ContentItem[]
  842. */
  843. public function GetContentItemArray($objOptionalClauses = null) {
  844. if ((is_null($this->intId)))
  845. return array();
  846. try {
  847. return ContentItem::LoadArrayByUsergroup($this->intId, $objOptionalClauses);
  848. } catch (QCallerException $objExc) {
  849. $objExc->IncrementOffset();
  850. throw $objExc;
  851. }
  852. }
  853. /**
  854. * Counts all many-to-many associated ContentItems
  855. * @return int
  856. */
  857. public function CountContentItems() {
  858. if ((is_null($this->intId)))
  859. return 0;
  860. return ContentItem::CountByUsergroup($this->intId);
  861. }
  862. /**
  863. * Checks to see if an association exists with a specific ContentItem
  864. * @param ContentItem $objContentItem
  865. * @return bool
  866. */
  867. public function IsContentItemAssociated(ContentItem $objContentItem) {
  868. if ((is_null($this->intId)))
  869. throw new QUndefinedPrimaryKeyException('Unable to call IsContentItemAssociated on this unsaved Usergroup.');
  870. if ((is_null($objContentItem->Id)))
  871. throw new QUndefinedPrimaryKeyException('Unable to call IsContentItemAssociated on this Usergroup with an unsaved ContentItem.');
  872. $intRowCount = Usergroup::QueryCount(
  873. QQ::AndCondition(
  874. QQ::Equal(QQN::Usergroup()->Id, $this->intId),
  875. QQ::Equal(QQN::Usergroup()->ContentItem->ContentItemId, $objContentItem->Id)
  876. )
  877. );
  878. return ($intRowCount > 0);
  879. }
  880. /**
  881. * Associates a ContentItem
  882. * @param ContentItem $objContentItem
  883. * @return void
  884. */
  885. public function AssociateContentItem(ContentItem $objContentItem) {
  886. if ((is_null($this->intId)))
  887. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItem on this unsaved Usergroup.');
  888. if ((is_null($objContentItem->Id)))
  889. throw new QUndefinedPrimaryKeyException('Unable to call AssociateContentItem on this Usergroup with an unsaved ContentItem.');
  890. // Get the Database Object for this Class
  891. $objDatabase = Usergroup::GetDatabase();
  892. // Perform the SQL Query
  893. $objDatabase->NonQuery('
  894. INSERT INTO `content_item_usergroup_assn` (
  895. `usergroup_id`,
  896. `content_item_id`
  897. ) VALUES (
  898. ' . $objDatabase->SqlVariable($this->intId) . ',
  899. ' . $objDatabase->SqlVariable($objContentItem->Id) . '
  900. )
  901. ');
  902. }
  903. /**
  904. * Unassociates a ContentItem
  905. * @param ContentItem $objContentItem
  906. * @return void
  907. */
  908. public function UnassociateContentItem(ContentItem $objContentItem) {
  909. if ((is_null($this->intId)))
  910. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItem on this unsaved Usergroup.');
  911. if ((is_null($objContentItem->Id)))
  912. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateContentItem on this Usergroup with an unsaved ContentItem.');
  913. // Get the Database Object for this Class
  914. $objDatabase = Usergroup::GetDatabase();
  915. // Perform the SQL Query
  916. $objDatabase->NonQuery('
  917. DELETE FROM
  918. `content_item_usergroup_assn`
  919. WHERE
  920. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  921. `content_item_id` = ' . $objDatabase->SqlVariable($objContentItem->Id) . '
  922. ');
  923. }
  924. /**
  925. * Unassociates all ContentItems
  926. * @return void
  927. */
  928. public function UnassociateAllContentItems() {
  929. if ((is_null($this->intId)))
  930. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllContentItemArray on this unsaved Usergroup.');
  931. // Get the Database Object for this Class
  932. $objDatabase = Usergroup::GetDatabase();
  933. // Perform the SQL Query
  934. $objDatabase->NonQuery('
  935. DELETE FROM
  936. `content_item_usergroup_assn`
  937. WHERE
  938. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  939. ');
  940. }
  941. // Related Many-to-Many Objects' Methods for Page
  942. //-------------------------------------------------------------------
  943. /**
  944. * Gets all many-to-many associated Pages as an array of Page objects
  945. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  946. * @return Page[]
  947. */
  948. public function GetPageArray($objOptionalClauses = null) {
  949. if ((is_null($this->intId)))
  950. return array();
  951. try {
  952. return Page::LoadArrayByUsergroup($this->intId, $objOptionalClauses);
  953. } catch (QCallerException $objExc) {
  954. $objExc->IncrementOffset();
  955. throw $objExc;
  956. }
  957. }
  958. /**
  959. * Counts all many-to-many associated Pages
  960. * @return int
  961. */
  962. public function CountPages() {
  963. if ((is_null($this->intId)))
  964. return 0;
  965. return Page::CountByUsergroup($this->intId);
  966. }
  967. /**
  968. * Checks to see if an association exists with a specific Page
  969. * @param Page $objPage
  970. * @return bool
  971. */
  972. public function IsPageAssociated(Page $objPage) {
  973. if ((is_null($this->intId)))
  974. throw new QUndefinedPrimaryKeyException('Unable to call IsPageAssociated on this unsaved Usergroup.');
  975. if ((is_null($objPage->Id)))
  976. throw new QUndefinedPrimaryKeyException('Unable to call IsPageAssociated on this Usergroup with an unsaved Page.');
  977. $intRowCount = Usergroup::QueryCount(
  978. QQ::AndCondition(
  979. QQ::Equal(QQN::Usergroup()->Id, $this->intId),
  980. QQ::Equal(QQN::Usergroup()->Page->PageId, $objPage->Id)
  981. )
  982. );
  983. return ($intRowCount > 0);
  984. }
  985. /**
  986. * Associates a Page
  987. * @param Page $objPage
  988. * @return void
  989. */
  990. public function AssociatePage(Page $objPage) {
  991. if ((is_null($this->intId)))
  992. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePage on this unsaved Usergroup.');
  993. if ((is_null($objPage->Id)))
  994. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePage on this Usergroup with an unsaved Page.');
  995. // Get the Database Object for this Class
  996. $objDatabase = Usergroup::GetDatabase();
  997. // Perform the SQL Query
  998. $objDatabase->NonQuery('
  999. INSERT INTO `page_usergroup_assn` (
  1000. `usergroup_id`,
  1001. `page_id`
  1002. ) VALUES (
  1003. ' . $objDatabase->SqlVariable($this->intId) . ',
  1004. ' . $objDatabase->SqlVariable($objPage->Id) . '
  1005. )
  1006. ');
  1007. }
  1008. /**
  1009. * Unassociates a Page
  1010. * @param Page $objPage
  1011. * @return void
  1012. */
  1013. public function UnassociatePage(Page $objPage) {
  1014. if ((is_null($this->intId)))
  1015. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePage on this unsaved Usergroup.');
  1016. if ((is_null($objPage->Id)))
  1017. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePage on this Usergroup with an unsaved Page.');
  1018. // Get the Database Object for this Class
  1019. $objDatabase = Usergroup::GetDatabase();
  1020. // Perform the SQL Query
  1021. $objDatabase->NonQuery('
  1022. DELETE FROM
  1023. `page_usergroup_assn`
  1024. WHERE
  1025. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1026. `page_id` = ' . $objDatabase->SqlVariable($objPage->Id) . '
  1027. ');
  1028. }
  1029. /**
  1030. * Unassociates all Pages
  1031. * @return void
  1032. */
  1033. public function UnassociateAllPages() {
  1034. if ((is_null($this->intId)))
  1035. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllPageArray on this unsaved Usergroup.');
  1036. // Get the Database Object for this Class
  1037. $objDatabase = Usergroup::GetDatabase();
  1038. // Perform the SQL Query
  1039. $objDatabase->NonQuery('
  1040. DELETE FROM
  1041. `page_usergroup_assn`
  1042. WHERE
  1043. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1044. ');
  1045. }
  1046. // Related Many-to-Many Objects' Methods for Person
  1047. //-------------------------------------------------------------------
  1048. /**
  1049. * Gets all many-to-many associated People as an array of Person objects
  1050. * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  1051. * @return Person[]
  1052. */
  1053. public function GetPersonArray($objOptionalClauses = null) {
  1054. if ((is_null($this->intId)))
  1055. return array();
  1056. try {
  1057. return Person::LoadArrayByUsergroup($this->intId, $objOptionalClauses);
  1058. } catch (QCallerException $objExc) {
  1059. $objExc->IncrementOffset();
  1060. throw $objExc;
  1061. }
  1062. }
  1063. /**
  1064. * Counts all many-to-many associated People
  1065. * @return int
  1066. */
  1067. public function CountPeople() {
  1068. if ((is_null($this->intId)))
  1069. return 0;
  1070. return Person::CountByUsergroup($this->intId);
  1071. }
  1072. /**
  1073. * Checks to see if an association exists with a specific Person
  1074. * @param Person $objPerson
  1075. * @return bool
  1076. */
  1077. public function IsPersonAssociated(Person $objPerson) {
  1078. if ((is_null($this->intId)))
  1079. throw new QUndefinedPrimaryKeyException('Unable to call IsPersonAssociated on this unsaved Usergroup.');
  1080. if ((is_null($objPerson->Id)))
  1081. throw new QUndefinedPrimaryKeyException('Unable to call IsPersonAssociated on this Usergroup with an unsaved Person.');
  1082. $intRowCount = Usergroup::QueryCount(
  1083. QQ::AndCondition(
  1084. QQ::Equal(QQN::Usergroup()->Id, $this->intId),
  1085. QQ::Equal(QQN::Usergroup()->Person->PersonId, $objPerson->Id)
  1086. )
  1087. );
  1088. return ($intRowCount > 0);
  1089. }
  1090. /**
  1091. * Associates a Person
  1092. * @param Person $objPerson
  1093. * @return void
  1094. */
  1095. public function AssociatePerson(Person $objPerson) {
  1096. if ((is_null($this->intId)))
  1097. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePerson on this unsaved Usergroup.');
  1098. if ((is_null($objPerson->Id)))
  1099. throw new QUndefinedPrimaryKeyException('Unable to call AssociatePerson on this Usergroup with an unsaved Person.');
  1100. // Get the Database Object for this Class
  1101. $objDatabase = Usergroup::GetDatabase();
  1102. // Perform the SQL Query
  1103. $objDatabase->NonQuery('
  1104. INSERT INTO `person_usergroup_assn` (
  1105. `usergroup_id`,
  1106. `person_id`
  1107. ) VALUES (
  1108. ' . $objDatabase->SqlVariable($this->intId) . ',
  1109. ' . $objDatabase->SqlVariable($objPerson->Id) . '
  1110. )
  1111. ');
  1112. }
  1113. /**
  1114. * Unassociates a Person
  1115. * @param Person $objPerson
  1116. * @return void
  1117. */
  1118. public function UnassociatePerson(Person $objPerson) {
  1119. if ((is_null($this->intId)))
  1120. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePerson on this unsaved Usergroup.');
  1121. if ((is_null($objPerson->Id)))
  1122. throw new QUndefinedPrimaryKeyException('Unable to call UnassociatePerson on this Usergroup with an unsaved Person.');
  1123. // Get the Database Object for this Class
  1124. $objDatabase = Usergroup::GetDatabase();
  1125. // Perform the SQL Query
  1126. $objDatabase->NonQuery('
  1127. DELETE FROM
  1128. `person_usergroup_assn`
  1129. WHERE
  1130. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . ' AND
  1131. `person_id` = ' . $objDatabase->SqlVariable($objPerson->Id) . '
  1132. ');
  1133. }
  1134. /**
  1135. * Unassociates all People
  1136. * @return void
  1137. */
  1138. public function UnassociateAllPeople() {
  1139. if ((is_null($this->intId)))
  1140. throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAllPersonArray on this unsaved Usergroup.');
  1141. // Get the Database Object for this Class
  1142. $objDatabase = Usergroup::GetDatabase();
  1143. // Perform the SQL Query
  1144. $objDatabase->NonQuery('
  1145. DELETE FROM
  1146. `person_usergroup_assn`
  1147. WHERE
  1148. `usergroup_id` = ' . $objDatabase->SqlVariable($this->intId) . '
  1149. ');
  1150. }
  1151. }
  1152. /////////////////////////////////////
  1153. // ADDITIONAL CLASSES for QCODO QUERY
  1154. /////////////////////////////////////
  1155. class QQNodeUsergroupContentItem extends QQAssociationNode {
  1156. protected $strType = 'association';
  1157. protected $strName = 'contentitem';
  1158. protected $strTableName = 'content_item_usergroup_assn';
  1159. protected $strPrimaryKey = 'usergroup_id';
  1160. protected $strClassName = 'ContentItem';
  1161. public function __get($strName) {
  1162. switch ($strName) {
  1163. case 'ContentItemId':
  1164. return new QQNode('content_item_id', 'ContentItemId', 'integer', $this);
  1165. case 'ContentItem':
  1166. return new QQNodeContentItem('content_item_id', 'ContentItemId', 'integer', $this);
  1167. case '_ChildTableNode':
  1168. return new QQNodeContentItem('content_item_id', 'ContentItemId', 'integer', $this);
  1169. default:
  1170. try {
  1171. return parent::__get($strName);
  1172. } catch (QCallerException $objExc) {
  1173. $objExc->IncrementOffset();
  1174. throw $objExc;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. class QQNodeUsergroupPage extends QQAssociationNode {
  1180. protected $strType = 'association';
  1181. protected $strName = 'page';
  1182. protected $strTableName = 'page_usergroup_assn';
  1183. protected $strPrimaryKey = 'usergroup_id';
  1184. protected $strClassName = 'Page';
  1185. public function __get($strName) {
  1186. switch ($strName) {
  1187. case 'PageId':
  1188. return new QQNode('page_id', 'PageId', 'integer', $this);
  1189. case 'Page':
  1190. return new QQNodePage('page_id', 'PageId', 'integer', $this);
  1191. case '_ChildTableNode':
  1192. return new QQNodePage('page_id', 'PageId', 'integer', $this);
  1193. default:
  1194. try {
  1195. return parent::__get($strName);
  1196. } catch (QCallerException $objExc) {
  1197. $objExc->IncrementOffset();
  1198. throw $objExc;
  1199. }
  1200. }
  1201. }
  1202. }
  1203. class QQNodeUsergroupPerson extends QQAssociationNode {
  1204. protected $strType = 'association';
  1205. protected $strName = 'person';
  1206. protected $strTableName = 'person_usergroup_assn';
  1207. protected $strPrimaryKey = 'usergroup_id';
  1208. protected $strClassName = 'Person';
  1209. public function __get($strName) {
  1210. switch ($strName) {
  1211. case 'PersonId':
  1212. return new QQNode('person_id', 'PersonId', 'integer', $this);
  1213. case 'Person':
  1214. return new QQNodePerson('person_id', 'PersonId', 'integer', $this);
  1215. case '_ChildTableNode':
  1216. return new QQNodePerson('person_id', 'PersonId', 'integer', $this);
  1217. default:
  1218. try {
  1219. return parent::__get($strName);
  1220. } catch (QCallerException $objExc) {
  1221. $objExc->IncrementOffset();
  1222. throw $objExc;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. class QQNodeUsergroup extends QQNode {
  1228. protected $strTableName = 'usergroup';
  1229. protected $strPrimaryKey = 'id';
  1230. protected $strClassName = 'Usergroup';
  1231. public function __get($strName) {
  1232. switch ($strName) {
  1233. case 'Id':
  1234. return new QQNode('id', 'Id', 'integer', $this);
  1235. case 'Name':
  1236. return new QQNode('name', 'Name', 'string', $this);
  1237. case 'ContentItem':
  1238. return new QQNodeUsergroupContentItem($this);
  1239. case 'Page':
  1240. return new QQNodeUsergroupPage($this);
  1241. case 'Person':
  1242. return new QQNodeUsergroupPerson($this);
  1243. case '_PrimaryKeyNode':
  1244. return new QQNode('id', 'Id', 'integer', $this);
  1245. default:
  1246. try {
  1247. return parent::__get($strName);
  1248. } catch (QCallerException $objExc) {
  1249. $objExc->IncrementOffset();
  1250. throw $objExc;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. class QQReverseReferenceNodeUsergroup extends QQReverseReferenceNode {
  1256. protected $strTableName = 'usergroup';
  1257. protected $strPrimaryKey = 'id';
  1258. protected $strClassName = 'Usergroup';
  1259. public function __get($strName) {
  1260. switch ($strName) {
  1261. case 'Id':
  1262. return new QQNode('id', 'Id', 'integer', $this);
  1263. case 'Name':
  1264. return new QQNode('name', 'Name', 'string', $this);
  1265. case 'ContentItem':
  1266. return new QQNodeUsergroupContentItem($this);
  1267. case 'Page':
  1268. return new QQNodeUsergroupPage($this);
  1269. case 'Person':
  1270. return new QQNodeUsergroupPerson($this);
  1271. case '_PrimaryKeyNode':
  1272. return new QQNode('id', 'Id', 'integer', $this);
  1273. default:
  1274. try {
  1275. return parent::__get($strName);
  1276. } catch (QCallerException $objExc) {
  1277. $objExc->IncrementOffset();
  1278. throw $objExc;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. ?>