compiler.class.inc.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. <?php
  2. // Copyright (C) 2011 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. require_once(APPROOT.'setup/setuputils.class.inc.php');
  17. class DOMFormatException extends Exception
  18. {
  19. }
  20. /**
  21. * Compiler class
  22. */
  23. class MFCompiler
  24. {
  25. protected $oFactory;
  26. protected $aRootClasses;
  27. protected $aLog;
  28. public function __construct($oModelFactory)
  29. {
  30. $this->oFactory = $oModelFactory;
  31. $this->aLog = array();
  32. }
  33. protected function Log($sText)
  34. {
  35. $this->aLog[] = $sText;
  36. }
  37. protected function DumpLog($oPage)
  38. {
  39. foreach ($this->aLog as $sText)
  40. {
  41. $oPage->p($sText);
  42. }
  43. }
  44. public function Compile($sTargetDir, $oP = null, $bUseSymbolicLinks = false)
  45. {
  46. $aAllClasses = array(); // flat list of classes
  47. // Determine the target modules for the MENUS
  48. //
  49. $aMenuNodes = array();
  50. $aMenusByModule = array();
  51. foreach ($this->oFactory->ListActiveChildNodes('menus', 'menu') as $oMenuNode)
  52. {
  53. $sMenuId = $oMenuNode->getAttribute('id');
  54. $aMenuNodes[$sMenuId] = $oMenuNode;
  55. $sModuleMenu = $oMenuNode->getAttribute('_created_in');
  56. $aMenusByModule[$sModuleMenu][] = $sMenuId;
  57. }
  58. // Determine the target module (exactly one!) for USER RIGHTS
  59. //
  60. $sUserRightsModule = '';
  61. $oUserRightsNode = $this->oFactory->GetNodes('user_rights')->item(0);
  62. if ($oUserRightsNode)
  63. {
  64. $sUserRightsModule = $oUserRightsNode->getAttribute('_created_in');
  65. }
  66. // List root classes
  67. //
  68. $this->aRootClasses = array();
  69. foreach ($this->oFactory->ListRootClasses() as $oClass)
  70. {
  71. $this->Log("Root class: ".$oClass->getAttribute('id'));
  72. $this->aRootClasses[$oClass->getAttribute('id')] = $oClass;
  73. }
  74. // Compile, module by module
  75. //
  76. $aModules = $this->oFactory->GetLoadedModules();
  77. foreach($aModules as $foo => $oModule)
  78. {
  79. $sModuleName = $oModule->GetName();
  80. $sModuleVersion = $oModule->GetVersion();
  81. $sModuleRootDir = realpath($oModule->GetRootDir());
  82. $sRelativeDir = basename($sModuleRootDir);
  83. // Push the other module files
  84. SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
  85. $sCompiledCode = '';
  86. $oClasses = $this->oFactory->ListClasses($sModuleName);
  87. $iClassCount = $oClasses->length;
  88. if ($iClassCount == 0)
  89. {
  90. $this->Log("Found module without classes declared: $sModuleName");
  91. }
  92. else
  93. {
  94. foreach($oClasses as $oClass)
  95. {
  96. $sClass = $oClass->getAttribute("id");
  97. $aAllClasses[] = $sClass;
  98. try
  99. {
  100. $sCompiledCode .= $this->CompileClass($oClass, $sRelativeDir, $oP);
  101. }
  102. catch (DOMFormatException $e)
  103. {
  104. throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
  105. }
  106. }
  107. }
  108. if (!array_key_exists($sModuleName, $aMenusByModule))
  109. {
  110. $this->Log("Found module without menus declared: $sModuleName");
  111. }
  112. else
  113. {
  114. $sCompiledCode .=
  115. <<<EOF
  116. //
  117. // Menus
  118. //
  119. EOF;
  120. // Preliminary: determine parent menus not defined within the current module
  121. $aMenusToLoad = array();
  122. $aParentMenus = array();
  123. foreach($aMenusByModule[$sModuleName] as $sMenuId)
  124. {
  125. $oMenuNode = $aMenuNodes[$sMenuId];
  126. if ($sParent = $oMenuNode->GetChildText('parent', null))
  127. {
  128. $aMenusToLoad[] = $sParent;
  129. $aParentMenus[] = $sParent;
  130. }
  131. // Note: the order matters: the parents must be defined BEFORE
  132. $aMenusToLoad[] = $sMenuId;
  133. }
  134. $aMenusToLoad = array_unique($aMenusToLoad);
  135. foreach($aMenusToLoad as $sMenuId)
  136. {
  137. $oMenuNode = $aMenuNodes[$sMenuId];
  138. if ($oMenuNode->getAttribute("xsi:type") == 'MenuGroup')
  139. {
  140. // Note: this algorithm is wrong
  141. // 1 - the module may appear empty in the current module, while children are defined in other modules
  142. // 2 - check recursively that child nodes are not empty themselves
  143. // Future algorithm:
  144. // a- browse the modules and build the menu tree
  145. // b- browse the tree and blacklist empty menus
  146. // c- before compiling, discard if blacklisted
  147. if (!in_array($oMenuNode->getAttribute("id"), $aParentMenus))
  148. {
  149. // Discard empty menu groups
  150. continue;
  151. }
  152. }
  153. try
  154. {
  155. $sCompiledCode .= $this->CompileMenu($oMenuNode, $sRelativeDir, $oP);
  156. }
  157. catch (ssDOMFormatException $e)
  158. {
  159. throw new Exception("Failed to process menu '$sMenuId', from '$sModuleRootDir': ".$e->getMessage());
  160. }
  161. }
  162. }
  163. // User rights
  164. //
  165. if ($sModuleName == $sUserRightsModule)
  166. {
  167. $sCompiledCode .= $this->CompileUserRights($oUserRightsNode);
  168. }
  169. // Create (overwrite if existing) the compiled file
  170. //
  171. if (strlen($sCompiledCode) > 0)
  172. {
  173. // We have compiled something: write the result file
  174. //
  175. $sResultFile = $sTargetDir.'/'.$sRelativeDir.'/model.'.$sModuleName.'.php';
  176. if (is_file($sResultFile))
  177. {
  178. $this->Log("Updating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  179. }
  180. else
  181. {
  182. $sResultDir = dirname($sResultFile);
  183. if (!is_dir($sResultDir))
  184. {
  185. $this->Log("Creating directory $sResultDir");
  186. mkdir($sResultDir, 0777, true);
  187. }
  188. $this->Log("Creating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  189. }
  190. // Compile the module into a single file
  191. //
  192. $sId = $sModuleName;
  193. $sCurrDate = date(DATE_ISO8601);
  194. $sAuthor = 'Combodo compiler';
  195. $sLicence = 'http://www.opensource.org/licenses/gpl-3.0.html LGPL';
  196. $sFileHeader =
  197. <<<EOF
  198. <?php
  199. //
  200. // File generated by ... on the $sCurrDate
  201. // Please do not edit manually
  202. //
  203. //
  204. // Copyright (C) 2010 Combodo SARL
  205. //
  206. // ben on met quoi ici ?
  207. // Signé: Romain
  208. //
  209. // This program is free software; you can redistribute it and/or modify
  210. // it under the terms of the GNU General Public License as published by
  211. // the Free Software Foundation; version 3 of the License.
  212. //
  213. // This program is distributed in the hope that it will be useful,
  214. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  215. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  216. // GNU General Public License for more details.
  217. //
  218. // You should have received a copy of the GNU General Public License
  219. // along with this program; if not, write to the Free Software
  220. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  221. /**
  222. * Classes and menus for $sModuleName (version $sModuleVersion)
  223. *
  224. * @author $sAuthor
  225. * @license $sLicence
  226. */
  227. EOF;
  228. file_put_contents($sResultFile, $sFileHeader.$sCompiledCode);
  229. }
  230. }
  231. }
  232. /**
  233. * Helper to format the flags for an attribute, in a given state
  234. * @param object $oAttNode DOM node containing the information to build the flags
  235. * Returns string PHP flags, based on the OPT_ATT_ constants, or empty (meaning 0, can be omitted)
  236. */
  237. protected function FlagsToPHP($oAttNode)
  238. {
  239. static $aNodeAttributeToFlag = array(
  240. 'mandatory' => 'OPT_ATT_MANDATORY',
  241. 'read_only' => 'OPT_ATT_READONLY',
  242. 'must_prompt' => 'OPT_ATT_MUSTPROMPT',
  243. 'must_change' => 'OPT_ATT_MUSTCHANGE',
  244. 'hidden' => 'OPT_ATT_HIDDEN',
  245. );
  246. $aFlags = array();
  247. foreach ($aNodeAttributeToFlag as $sNodeAttribute => $sFlag)
  248. {
  249. $bFlag = ($oAttNode->GetOptionalElement($sNodeAttribute) != null);
  250. if ($bFlag)
  251. {
  252. $aFlags[] = $sFlag;
  253. }
  254. }
  255. $sRes = implode(' | ', $aFlags);
  256. return $sRes;
  257. }
  258. /**
  259. * Helper to format the tracking level for linkset (direct or indirect attributes)
  260. * @param string $sTrackingLevel Value set from within the XML
  261. * Returns string PHP flag
  262. */
  263. protected function TrackingLevelToPHP($sTrackingLevel)
  264. {
  265. static $aXmlToPHP = array(
  266. 'none' => 'LINKSET_TRACKING_NONE',
  267. 'list' => 'LINKSET_TRACKING_LIST',
  268. 'details' => 'LINKSET_TRACKING_DETAILS',
  269. 'all' => 'LINKSET_TRACKING_ALL',
  270. );
  271. if (!array_key_exists($sTrackingLevel, $aXmlToPHP))
  272. {
  273. throw new exception("Tracking level: unknown value '$sTrackingLevel'");
  274. }
  275. return $aXmlToPHP[$sTrackingLevel];
  276. }
  277. /**
  278. * Format a path (file or url) as an absolute path or relative to the module or the app
  279. */
  280. protected function PathToPHP($sPath, $sModuleRelativeDir, $bIsUrl = false)
  281. {
  282. if ($sPath == '')
  283. {
  284. $sPHP = "''";
  285. }
  286. elseif (substr($sPath, 0, 2) == '$$')
  287. {
  288. // Absolute
  289. $sPHP = self::QuoteForPHP(substr($sPath, 2));
  290. }
  291. elseif (substr($sPath, 0, 1) == '$')
  292. {
  293. // Relative to the application
  294. if ($bIsUrl)
  295. {
  296. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP(substr($sPath, 1));
  297. }
  298. else
  299. {
  300. $sPHP = "APPROOT.".self::QuoteForPHP(substr($sPath, 1));
  301. }
  302. }
  303. else
  304. {
  305. // Relative to the module
  306. if ($bIsUrl)
  307. {
  308. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP($sModuleRelativeDir.''.$sPath);
  309. }
  310. else
  311. {
  312. $sPHP = "dirname(__FILE__).'/$sPath'";
  313. }
  314. }
  315. return $sPHP;
  316. }
  317. protected function GetPropString($oNode, $sTag, $sDefault = null)
  318. {
  319. $val = $oNode->GetChildText($sTag);
  320. if (is_null($val))
  321. {
  322. if (is_null($sDefault))
  323. {
  324. return null;
  325. }
  326. else
  327. {
  328. $val = $sDefault;
  329. }
  330. }
  331. return "'".$val."'";
  332. }
  333. protected function GetPropBoolean($oNode, $sTag, $bDefault = null)
  334. {
  335. $val = $oNode->GetChildText($sTag);
  336. if (is_null($val))
  337. {
  338. if (is_null($bDefault))
  339. {
  340. return null;
  341. }
  342. else
  343. {
  344. return $bDefault ? 'true' : 'false';
  345. }
  346. }
  347. return $val == 'true' ? 'true' : 'false';
  348. }
  349. protected function GetPropNumber($oNode, $sTag, $nDefault = null)
  350. {
  351. $val = $oNode->GetChildText($sTag);
  352. if (is_null($val))
  353. {
  354. if (is_null($nDefault))
  355. {
  356. return null;
  357. }
  358. else
  359. {
  360. $val = $nDefault;
  361. }
  362. }
  363. return (string)$val;
  364. }
  365. /**
  366. * Adds quotes and escape characters
  367. */
  368. protected function QuoteForPHP($sStr)
  369. {
  370. $sEscaped = str_replace(array('\\', '"', "\n"), array('\\\\', '\\"', '\\n'), $sStr);
  371. $sRet = '"'.$sEscaped.'"';
  372. return $sRet;
  373. }
  374. protected function CompileClass($oClass, $sModuleRelativeDir, $oP)
  375. {
  376. $sClass = $oClass->getAttribute('id');
  377. $oProperties = $oClass->GetUniqueElement('properties');
  378. // Class caracteristics
  379. //
  380. $aClassParams = array();
  381. $aClassParams['category'] = $this->GetPropString($oProperties, 'category', '');
  382. $aClassParams['key_type'] = "'autoincrement'";
  383. if ($oNaming = $oProperties->GetOptionalElement('naming'))
  384. {
  385. $oNameAttributes = $oNaming->GetUniqueElement('attributes');
  386. $oAttributes = $oNameAttributes->getElementsByTagName('attribute');
  387. $aNameAttCodes = array();
  388. foreach($oAttributes as $oAttribute)
  389. {
  390. $aNameAttCodes[] = $oAttribute->getAttribute('id');
  391. }
  392. if (count($aNameAttCodes) > 1)
  393. {
  394. // New style...
  395. $sNameAttCode = "array('".implode("', '", $aNameAttCodes)."')";
  396. }
  397. elseif (count($aNameAttCodes) == 1)
  398. {
  399. // New style...
  400. $sNameAttCode = "'$aNameAttCodes[0]'";
  401. }
  402. else
  403. {
  404. $sNameAttCode = "''";
  405. }
  406. }
  407. else
  408. {
  409. $sNameAttCode = "''";
  410. }
  411. $aClassParams['name_attcode'] = $sNameAttCode;
  412. $oLifecycle = $oClass->GetOptionalElement('lifecycle');
  413. if ($oLifecycle)
  414. {
  415. $sStateAttCode = $oLifecycle->GetChildText('attribute');
  416. }
  417. else
  418. {
  419. $sStateAttCode = "";
  420. }
  421. $aClassParams['state_attcode'] = "'$sStateAttCode'";
  422. if ($oReconciliation = $oProperties->GetOptionalElement('reconciliation'))
  423. {
  424. $oReconcAttributes = $oReconciliation->getElementsByTagName('attribute');
  425. $aReconcAttCodes = array();
  426. foreach($oReconcAttributes as $oAttribute)
  427. {
  428. $aReconcAttCodes[] = $oAttribute->getAttribute('id');
  429. }
  430. $sReconcKeys = "array('".implode("', '", $aReconcAttCodes)."')";
  431. }
  432. else
  433. {
  434. $sReconcKeys = "array()";
  435. }
  436. $aClassParams['reconc_keys'] = $sReconcKeys;
  437. $aClassParams['db_table'] = $this->GetPropString($oProperties, 'db_table', '');
  438. $aClassParams['db_key_field'] = $this->GetPropString($oProperties, 'db_key_field', 'id');
  439. if (array_key_exists($sClass, $this->aRootClasses))
  440. {
  441. $sDefaultFinalClass = 'finalclass';
  442. }
  443. else
  444. {
  445. $sDefaultFinalClass = '';
  446. }
  447. $aClassParams['db_finalclass_field'] = $this->GetPropString($oProperties, 'db_final_class_field', $sDefaultFinalClass);
  448. if (($sDisplayTemplate = $oProperties->GetChildText('display_template')) && (strlen($sDisplayTemplate) > 0))
  449. {
  450. $sDisplayTemplate = $sModuleRelativeDir.'/'.$sDisplayTemplate;
  451. $aClassParams['display_template'] = "utils::GetAbsoluteUrlModulesRoot().'$sDisplayTemplate'";
  452. }
  453. if (($sIcon = $oProperties->GetChildText('icon')) && (strlen($sIcon) > 0))
  454. {
  455. $sIcon = $sModuleRelativeDir.'/'.$sIcon;
  456. $aClassParams['icon'] = "utils::GetAbsoluteUrlModulesRoot().'$sIcon'";
  457. }
  458. $oOrder = $oProperties->GetOptionalElement('order');
  459. if ($oOrder)
  460. {
  461. $oColumnsNode = $oOrder->GetUniqueElement('columns');
  462. $oColumns = $oColumnsNode->getElementsByTagName('column');
  463. $aSortColumns = array();
  464. foreach($oColumns as $oColumn)
  465. {
  466. $aSortColumns[] = "'".$oColumn->getAttribute('id')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
  467. }
  468. if (count($aSortColumns) > 0)
  469. {
  470. $aClassParams['order_by_default'] = "array(".implode(", ", $aSortColumns).")";
  471. }
  472. }
  473. // Finalize class params declaration
  474. //
  475. $aClassParamsPHP = array();
  476. foreach($aClassParams as $sKey => $sPHPValue)
  477. {
  478. $aClassParamsPHP[] = " '$sKey' => $sPHPValue,";
  479. }
  480. $sClassParams = implode("\n", $aClassParamsPHP);
  481. // Comment on top of the class declaration
  482. //
  483. $sCodeComment = $oProperties->GetChildText('comment');
  484. // Fields
  485. //
  486. $sAttributes = '';
  487. foreach($this->oFactory->ListFields($oClass) as $oField)
  488. {
  489. // $oField
  490. $sAttCode = $oField->getAttribute('id');
  491. $sAttType = $oField->getAttribute('xsi:type');
  492. $aDependencies = array();
  493. $oDependencies = $oField->GetOptionalElement('dependencies');
  494. if (!is_null($oDependencies))
  495. {
  496. $oDepNodes = $oDependencies->getElementsByTagName('attribute');
  497. foreach($oDepNodes as $oDepAttribute)
  498. {
  499. $aDependencies[] = "'".$oDepAttribute->getAttribute('id')."'";
  500. }
  501. }
  502. $sDependencies = 'array('.implode(', ', $aDependencies).')';
  503. $aParameters = array();
  504. if ($sAttType == 'AttributeLinkedSetIndirect')
  505. {
  506. $aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', '');
  507. $aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', '');
  508. $aParameters['ext_key_to_remote'] = $this->GetPropString($oField, 'ext_key_to_remote', '');
  509. $aParameters['allowed_values'] = 'null';
  510. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  511. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  512. $aParameters['duplicates'] = $this->GetPropBoolean($oField, 'duplicates', false);
  513. $sTrackingLevel = $oField->GetChildText('tracking_level');
  514. if (!is_null($sTrackingLevel))
  515. {
  516. $aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
  517. }
  518. $aParameters['depends_on'] = $sDependencies;
  519. }
  520. elseif ($sAttType == 'AttributeLinkedSet')
  521. {
  522. $aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', '');
  523. $aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', '');
  524. $aParameters['allowed_values'] = 'null';
  525. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  526. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  527. $sTrackingLevel = $oField->GetChildText('tracking_level');
  528. if (!is_null($sTrackingLevel))
  529. {
  530. $aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
  531. }
  532. $aParameters['depends_on'] = $sDependencies;
  533. }
  534. elseif ($sAttType == 'AttributeExternalKey')
  535. {
  536. $aParameters['targetclass'] = $this->GetPropString($oField, 'target_class', '');
  537. // deprecated: $aParameters['jointype'] = 'null';
  538. if ($sOql = $oField->GetChildText('filter'))
  539. {
  540. $sEscapedOql = self::QuoteForPHP($sOql);
  541. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  542. }
  543. else
  544. {
  545. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  546. }
  547. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  548. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  549. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  550. $aParameters['depends_on'] = $sDependencies;
  551. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  552. $aParameters['min_auto_complete_chars'] = $this->GetPropNumber($oField, 'min_auto_complete_chars');
  553. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  554. }
  555. elseif ($sAttType == 'AttributeHierarchicalKey')
  556. {
  557. if ($sOql = $oField->GetChildText('filter'))
  558. {
  559. $sEscapedOql = self::QuoteForPHP($sOql);
  560. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  561. }
  562. else
  563. {
  564. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  565. }
  566. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  567. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  568. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  569. $aParameters['depends_on'] = $sDependencies;
  570. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  571. $aParameters['min_auto_complete_chars'] = $this->GetPropNumber($oField, 'min_auto_complete_chars');
  572. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  573. }
  574. elseif ($sAttType == 'AttributeExternalField')
  575. {
  576. $aParameters['allowed_values'] = 'null';
  577. $aParameters['extkey_attcode'] = $this->GetPropString($oField, 'extkey_attcode', '');
  578. $aParameters['target_attcode'] = $this->GetPropString($oField, 'target_attcode', '');
  579. }
  580. elseif ($sAttType == 'AttributeURL')
  581. {
  582. $aParameters['target'] = $this->GetPropString($oField, 'target', '');
  583. $aParameters['allowed_values'] = 'null';
  584. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  585. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  586. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  587. $aParameters['depends_on'] = $sDependencies;
  588. }
  589. elseif ($sAttType == 'AttributeEnum')
  590. {
  591. $oValues = $oField->GetUniqueElement('values');
  592. $oValueNodes = $oValues->getElementsByTagName('value');
  593. $aValues = array();
  594. foreach($oValueNodes as $oValue)
  595. {
  596. // new style... $aValues[] = self::QuoteForPHP($oValue->textContent);
  597. $aValues[] = $oValue->textContent;
  598. }
  599. // new style... $sValues = 'array('.implode(', ', $aValues).')';
  600. $sValues = '"'.implode(',', $aValues).'"';
  601. $aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
  602. $aParameters['display_style'] = $this->GetPropString($oField, 'display_style', 'list');
  603. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  604. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  605. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  606. $aParameters['depends_on'] = $sDependencies;
  607. }
  608. elseif ($sAttType == 'AttributeBlob')
  609. {
  610. $aParameters['depends_on'] = $sDependencies;
  611. }
  612. elseif ($sAttType == 'AttributeStopWatch')
  613. {
  614. $oStates = $oField->GetUniqueElement('states');
  615. $oStateNodes = $oStates->getElementsByTagName('state');
  616. $aStates = array();
  617. foreach($oStateNodes as $oState)
  618. {
  619. $aStates[] = '"'.$oState->GetAttribute('id').'"';
  620. }
  621. $aParameters['states'] = 'array('.implode(', ', $aStates).')';
  622. $aParameters['goal_computing'] = $this->GetPropString($oField, 'goal', 'DefaultMetricComputer'); // Optional, no deadline by default
  623. $aParameters['working_time_computing'] = $this->GetPropString($oField, 'working_time', 'DefaultWorkingTimeComputer'); // Optional, defaults to 24x7
  624. $oThresholds = $oField->GetUniqueElement('thresholds');
  625. $oThresholdNodes = $oThresholds->getElementsByTagName('threshold');
  626. $aThresholds = array();
  627. foreach($oThresholdNodes as $oThreshold)
  628. {
  629. $iPercent = $this->GetPropNumber($oThreshold, 'percent');
  630. $oActions = $oThreshold->GetUniqueElement('actions');
  631. $oActionNodes = $oActions->getElementsByTagName('action');
  632. $aActions = array();
  633. foreach($oActionNodes as $oAction)
  634. {
  635. $oParams = $oAction->GetOptionalElement('params');
  636. $aActionParams = array();
  637. if ($oParams)
  638. {
  639. $oParamNodes = $oParams->getElementsByTagName('param');
  640. foreach($oParamNodes as $oParam)
  641. {
  642. $aActionParams[] = self::QuoteForPHP($oParam->textContent);
  643. }
  644. }
  645. $sActionParams = 'array('.implode(', ', $aActionParams).')';
  646. $sVerb = $this->GetPropString($oAction, 'verb');
  647. $aActions[] = "array('verb' => $sVerb, 'params' => $sActionParams)";
  648. }
  649. $sActions = 'array('.implode(', ', $aActions).')';
  650. $aThresholds[] = $iPercent." => array('percent' => $iPercent, 'actions' => $sActions)";
  651. }
  652. $aParameters['thresholds'] = 'array('.implode(', ', $aThresholds).')';
  653. }
  654. elseif ($sAttType == 'AttributeSubItem')
  655. {
  656. $aParameters['target_attcode'] = $this->GetPropString($oField, 'target_attcode');
  657. $aParameters['item_code'] = $this->GetPropString($oField, 'item_code');
  658. }
  659. else
  660. {
  661. $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')"
  662. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  663. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  664. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  665. $aParameters['depends_on'] = $sDependencies;
  666. }
  667. // Optional parameters (more for historical reasons)
  668. // Added if present...
  669. //
  670. $aParameters['validation_pattern'] = $this->GetPropString($oField, 'validation_pattern');
  671. $aParameters['width'] = $this->GetPropNumber($oField, 'width');
  672. $aParameters['height'] = $this->GetPropNumber($oField, 'height');
  673. $aParameters['digits'] = $this->GetPropNumber($oField, 'digits');
  674. $aParameters['decimals'] = $this->GetPropNumber($oField, 'decimals');
  675. $aParams = array();
  676. foreach($aParameters as $sKey => $sValue)
  677. {
  678. if (!is_null($sValue))
  679. {
  680. $aParams[] = '"'.$sKey.'"=>'.$sValue;
  681. }
  682. }
  683. $sParams = implode(', ', $aParams);
  684. $sAttributes .= " MetaModel::Init_AddAttribute(new $sAttType(\"$sAttCode\", array($sParams)));\n";
  685. }
  686. // Lifecycle
  687. //
  688. $sLifecycle = '';
  689. if ($oLifecycle)
  690. {
  691. $sLifecycle .= "\t\t// Lifecycle (status attribute: $sStateAttCode)\n";
  692. $sLifecycle .= "\t\t//\n";
  693. $oStimuli = $oLifecycle->GetUniqueElement('stimuli');
  694. foreach ($oStimuli->getElementsByTagName('stimulus') as $oStimulus)
  695. {
  696. $sStimulus = $oStimulus->getAttribute('id');
  697. $sStimulusClass = $oStimulus->getAttribute('xsi:type');
  698. $sLifecycle .= " MetaModel::Init_DefineStimulus(new ".$sStimulusClass."(\"".$sStimulus."\", array()));\n";
  699. }
  700. $oStates = $oLifecycle->GetUniqueElement('states');
  701. foreach ($oStates->getElementsByTagName('state') as $oState)
  702. {
  703. $sState = $oState->getAttribute('id');
  704. $oInitialStatePath = $oState->GetOptionalElement('initial_state_path');
  705. if ($oInitialStatePath)
  706. {
  707. $aInitialStatePath = array();
  708. foreach ($oInitialStatePath->getElementsByTagName('state_ref') as $oIntermediateState)
  709. {
  710. $aInitialStatePath[] = "'".$oIntermediateState->GetText()."'";
  711. }
  712. $sInitialStatePath = 'Array('.implode(', ', $aInitialStatePath).')';
  713. }
  714. $sLifecycle .= " MetaModel::Init_DefineState(\n";
  715. $sLifecycle .= " \"".$sState."\",\n";
  716. $sLifecycle .= " array(\n";
  717. $sLifecycle .= " \"attribute_inherit\" => '',\n";
  718. $sLifecycle .= " \"attribute_list\" => array(\n";
  719. $oFlags = $oState->GetUniqueElement('flags');
  720. foreach ($oFlags->getElementsByTagName('attribute') as $oAttributeNode)
  721. {
  722. $sFlags = $this->FlagsToPHP($oAttributeNode);
  723. if (strlen($sFlags) > 0)
  724. {
  725. $sAttCode = $oAttributeNode->GetAttribute('id');
  726. $sLifecycle .= " '$sAttCode' => $sFlags,\n";
  727. }
  728. }
  729. $sLifecycle .= " ),\n";
  730. if (!is_null($oInitialStatePath))
  731. {
  732. $sLifecycle .= " \"initial_state_path\" => $sInitialStatePath,\n";
  733. }
  734. $sLifecycle .= " )\n";
  735. $sLifecycle .= " );\n";
  736. $oTransitions = $oState->GetUniqueElement('transitions');
  737. foreach ($oTransitions->getElementsByTagName('transition') as $oTransition)
  738. {
  739. $sStimulus = $oTransition->GetChildText('stimulus');
  740. $sTargetState = $oTransition->GetChildText('target');
  741. $oActions = $oTransition->GetUniqueElement('actions');
  742. $aVerbs = array();
  743. foreach ($oActions->getElementsByTagName('action') as $oAction)
  744. {
  745. $sVerb = $oAction->GetChildText('verb');
  746. $aVerbs[] = "'$sVerb'";
  747. }
  748. $sActions = implode(', ', $aVerbs);
  749. $sLifecycle .= " MetaModel::Init_DefineTransition(\"$sState\", \"$sStimulus\", array(\"target_state\"=>\"$sTargetState\", \"actions\"=>array($sActions), \"user_restriction\"=>null));\n";
  750. }
  751. }
  752. }
  753. // ZLists
  754. //
  755. $aListRef = array(
  756. 'details' => 'details',
  757. 'standard_search' => 'search',
  758. 'list' => 'list'
  759. );
  760. $oPresentation = $oClass->GetUniqueElement('presentation');
  761. $sZlists = '';
  762. foreach ($aListRef as $sListCode => $sListTag)
  763. {
  764. $oListNode = $oPresentation->GetOptionalElement($sListTag);
  765. if ($oListNode)
  766. {
  767. $aAttributes = $oListNode->GetNodeAsArrayOfItems();
  768. $sZAttributes = var_export($aAttributes, true);
  769. $sZlists .= " MetaModel::Init_SetZListItems('$sListCode', $sZAttributes);\n";
  770. }
  771. }
  772. // Methods
  773. $sMethods = "";
  774. $oMethods = $oClass->GetUniqueElement('methods');
  775. foreach($oMethods->getElementsByTagName('method') as $oMethod)
  776. {
  777. $sMethodCode = $oMethod->GetChildText('code');
  778. if ($sMethodComment = $oMethod->GetChildText('comment', null))
  779. {
  780. $sMethods .= "\n\t$sMethodComment\n".$sMethodCode."\n";
  781. }
  782. else
  783. {
  784. $sMethods .= "\n\n".$sMethodCode."\n";
  785. }
  786. }
  787. // Let's make the whole class declaration
  788. //
  789. $sPHP = "\n\n$sCodeComment\n";
  790. $sParentClass = $oClass->GetChildText('php_parent');
  791. $oPhpParent = $oClass->GetUniqueElement('php_parent', false);
  792. if ($oPhpParent)
  793. {
  794. $sParentClass = $oPhpParent->GetChildText('name', '');
  795. if ($sParentClass == '')
  796. {
  797. throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sRelativeDir': missing required tag 'name' under 'php_parent'.");
  798. }
  799. $sIncludeFile = $oPhpParent->GetChildText('file', '');
  800. if ($sIncludeFile != '')
  801. {
  802. $sPHP .= "\nrequire_once('$sIncludeFile'); // Implementation of the class $sParentClass\n";
  803. }
  804. //TODO fix this !!!
  805. // $sFullPath = $this->sSourceDir.'/'.$sModuleRelativeDir.'/'.$sIncludeFile;
  806. // if (!file_exists($sFullPath))
  807. // {
  808. // throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sModuleRelativeDir'. The required include file: '$sFullPath' does not exist.");
  809. // }
  810. }
  811. else
  812. {
  813. $sParentClass = $oClass->GetChildText('parent', 'DBObject');
  814. }
  815. if ($oProperties->GetChildText('abstract') == 'true')
  816. {
  817. $sPHP .= 'abstract class '.$oClass->getAttribute('id');
  818. }
  819. else
  820. {
  821. $sPHP .= 'class '.$oClass->getAttribute('id');
  822. }
  823. $sPHP .= " extends $sParentClass\n";
  824. $sPHP .=
  825. <<<EOF
  826. {
  827. public static function Init()
  828. {
  829. \$aParams = array
  830. (
  831. $sClassParams
  832. );
  833. MetaModel::Init_Params(\$aParams);
  834. MetaModel::Init_InheritAttributes();
  835. $sAttributes
  836. $sLifecycle
  837. $sZlists
  838. }
  839. $sMethods
  840. }
  841. EOF;
  842. return $sPHP;
  843. }// function CompileClass()
  844. protected function CompileMenu($oMenu, $sModuleRelativeDir, $oP)
  845. {
  846. $sMenuId = $oMenu->getAttribute("id");
  847. $sMenuClass = $oMenu->getAttribute("xsi:type");
  848. $sParent = $oMenu->GetChildText('parent', null);
  849. if ($sParent)
  850. {
  851. $sParentSpec = "\$__comp_menus__['$sParent']->GetIndex()";
  852. }
  853. else
  854. {
  855. $sParentSpec = '-1';
  856. }
  857. $fRank = $oMenu->GetChildText('rank');
  858. switch($sMenuClass)
  859. {
  860. case 'WebPageMenuNode':
  861. $sUrl = $oMenu->GetChildText('url');
  862. $sUrlSpec = $this->PathToPHP($sUrl, $sModuleRelativeDir, true /* Url */);
  863. $sNewMenu = "new WebPageMenuNode('$sMenuId', $sUrlSpec, $sParentSpec, $fRank);";
  864. break;
  865. case 'DashboardMenuNode':
  866. $sTemplateFile = $oMenu->GetChildText('definition_file');
  867. $sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
  868. $sNewMenu = "new DashboardMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
  869. break;
  870. case 'TemplateMenuNode':
  871. $sTemplateFile = $oMenu->GetChildText('template_file');
  872. $sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
  873. $sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
  874. break;
  875. case 'OQLMenuNode':
  876. $sOQL = self::QuoteForPHP($oMenu->GetChildText('oql'));
  877. $bSearch = ($oMenu->GetChildText('do_search') == '1') ? 'true' : 'false';
  878. $sNewMenu = "new OQLMenuNode('$sMenuId', $sOQL, $sParentSpec, $fRank, $bSearch);";
  879. break;
  880. case 'NewObjectMenuNode':
  881. $sClass = $oMenu->GetChildText('class');
  882. $sNewMenu = "new NewObjectMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
  883. break;
  884. case 'SearchMenuNode':
  885. $sClass = $oMenu->GetChildText('class');
  886. $sNewMenu = "new SearchMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
  887. break;
  888. case 'MenuGroup':
  889. default:
  890. if ($sEnableClass = $oMenu->GetChildText('enable_class'))
  891. {
  892. $sEnableAction = $oMenu->GetChildText('enable_action');
  893. $sEnablePermission = $oMenu->GetChildText('enable_permission');
  894. $sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
  895. if (strlen($sEnableStimulus) > 0)
  896. {
  897. $sNewMenu = "new MenuGroup('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
  898. }
  899. else
  900. {
  901. $sNewMenu = "new MenuGroup('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission);";
  902. }
  903. //$sNewMenu = "new MenuGroup('$sMenuId', $fRank, '$sEnableClass', UR_ACTION_MODIFY, UR_ALLOWED_YES|UR_ALLOWED_DEPENDS);";
  904. }
  905. else
  906. {
  907. $sNewMenu = "new MenuGroup('$sMenuId', $fRank);";
  908. }
  909. }
  910. $sIndent = '';
  911. $aPHPMenu = array("\$__comp_menus__['$sMenuId'] = $sNewMenu");
  912. if ($sAutoReload = $oMenu->GetChildText('auto_reload'))
  913. {
  914. $sAutoReload = self::QuoteForPHP($sAutoReload);
  915. $aPHPMenu[] = "\$__comp_menus__['$sMenuId']->SetParameters(array('auto_reload' => $sAutoReload));";
  916. }
  917. $sAdminOnly = $oMenu->GetChildText('enable_admin_only');
  918. if ($sAdminOnly && ($sAdminOnly == '1'))
  919. {
  920. $sPHP = $sIndent."if (UserRights::IsAdministrator())\n";
  921. $sPHP .= $sIndent."{\n";
  922. foreach($aPHPMenu as $sPHPLine)
  923. {
  924. $sPHP .= $sIndent." $sPHPLine\n";
  925. }
  926. $sPHP .= $sIndent."}\n";
  927. }
  928. else
  929. {
  930. $sPHP = '';
  931. foreach($aPHPMenu as $sPHPLine)
  932. {
  933. $sPHP .= $sIndent.$sPHPLine."\n";
  934. }
  935. }
  936. return $sPHP;
  937. } // function CompileMenu
  938. protected function CompileUserRights($oUserRightsNode)
  939. {
  940. static $aActionsInShort = array(
  941. 'read' => 'r',
  942. 'bulk read' => 'br',
  943. 'write' => 'w',
  944. 'bulk write' => 'bw',
  945. 'delete' => 'd',
  946. 'bulk delete' => 'bd',
  947. );
  948. // Groups
  949. //
  950. $aGroupClasses = array();
  951. $oGroups = $oUserRightsNode->GetUniqueElement('groups');
  952. foreach($oGroups->getElementsByTagName('group') as $oGroup)
  953. {
  954. $sGroupId = $oGroup->getAttribute("id");
  955. $aClasses = array();
  956. $oClasses = $oGroup->GetUniqueElement('classes');
  957. foreach($oClasses->getElementsByTagName('class') as $oClass)
  958. {
  959. $sClass = $oClass->getAttribute("id");
  960. $aClasses[] = $sClass;
  961. //$bSubclasses = $this->GetPropBoolean($oClass, 'subclasses', true);
  962. //if ($bSubclasses)...
  963. }
  964. $aGroupClasses[$sGroupId] = $aClasses;
  965. }
  966. // Profiles and grants
  967. //
  968. $aProfiles = array();
  969. // Hardcode the administrator profile
  970. $aProfiles[1] = array(
  971. 'name' => 'Administrator',
  972. 'description' => 'Has the rights on everything (bypassing any control)'
  973. );
  974. $aGrants = array();
  975. $oProfiles = $oUserRightsNode->GetUniqueElement('profiles');
  976. foreach($oProfiles->getElementsByTagName('profile') as $oProfile)
  977. {
  978. $iProfile = $oProfile->getAttribute("id");
  979. $sName = $oProfile->GetChildText('name');
  980. $sDescription = $oProfile->GetChildText('description');
  981. $oGroups = $oProfile->GetUniqueElement('groups');
  982. foreach($oGroups->getElementsByTagName('group') as $oGroup)
  983. {
  984. $sGroupId = $oGroup->getAttribute("id");
  985. $aActions = array();
  986. $oActions = $oGroup->GetUniqueElement('actions');
  987. foreach($oActions->getElementsByTagName('action') as $oAction)
  988. {
  989. $sAction = $oAction->getAttribute("id");
  990. $sType = $oAction->getAttribute("xsi:type");
  991. $sGrant = $oAction->GetText();
  992. $bGrant = ($sGrant == 'allow');
  993. if ($sGroupId == '*')
  994. {
  995. $aGrantClasses = array('*');
  996. }
  997. else
  998. {
  999. $aGrantClasses = $aGroupClasses[$sGroupId];
  1000. }
  1001. foreach ($aGrantClasses as $sClass)
  1002. {
  1003. if ($sType == 'stimulus')
  1004. {
  1005. $sGrantKey = $iProfile.'_'.$sClass.'_s_'.$sAction;
  1006. $sGrantKeyPlus = $iProfile.'_'.$sClass.'+_s_'.$sAction; // subclasses inherit this grant
  1007. }
  1008. else
  1009. {
  1010. $sAction = $aActionsInShort[$sType];
  1011. $sGrantKey = $iProfile.'_'.$sClass.'_'.$sAction;
  1012. $sGrantKeyPlus = $iProfile.'_'.$sClass.'+_'.$sAction; // subclasses inherit this grant
  1013. }
  1014. // The class itself
  1015. if (isset($aGrants[$sGrantKey]))
  1016. {
  1017. if (!$bGrant)
  1018. {
  1019. $aGrants[$sGrantKey] = false;
  1020. }
  1021. }
  1022. else
  1023. {
  1024. $aGrants[$sGrantKey] = $bGrant;
  1025. }
  1026. // The subclasses
  1027. if (isset($aGrants[$sGrantKeyPlus]))
  1028. {
  1029. if (!$bGrant)
  1030. {
  1031. $aGrants[$sGrantKeyPlus] = false;
  1032. }
  1033. }
  1034. else
  1035. {
  1036. $aGrants[$sGrantKeyPlus] = $bGrant;
  1037. }
  1038. }
  1039. }
  1040. }
  1041. $aProfiles[$iProfile] = array(
  1042. 'name' => $sName,
  1043. 'description' => $sDescription
  1044. );
  1045. }
  1046. $sProfiles = var_export($aProfiles, true);
  1047. $sGrants = var_export($aGrants, true);
  1048. $sPHP =
  1049. <<<EOF
  1050. //
  1051. // List of constant profiles
  1052. // - used by the class URP_Profiles at setup (create/update/delete records)
  1053. // - used by the addon UserRightsProfile to determine user rights
  1054. //
  1055. class ProfilesConfig
  1056. {
  1057. protected static \$aPROFILES = $sProfiles;
  1058. protected static \$aGRANTS = $sGrants;
  1059. public static function GetProfileActionGrant(\$iProfileId, \$sClass, \$sAction)
  1060. {
  1061. \$sGrantKey = \$iProfileId.'_'.\$sClass.'_'.\$sAction;
  1062. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1063. {
  1064. return self::\$aGRANTS[\$sGrantKey];
  1065. }
  1066. foreach (MetaModel::EnumParentClasses(\$sClass) as \$sParent)
  1067. {
  1068. \$sGrantKey = \$iProfileId.'_'.\$sParent.'+_'.\$sAction;
  1069. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1070. {
  1071. return self::\$aGRANTS[\$sGrantKey];
  1072. }
  1073. }
  1074. \$sGrantKey = \$iProfileId.'_*_'.\$sAction;
  1075. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1076. {
  1077. return self::\$aGRANTS[\$sGrantKey];
  1078. }
  1079. return null;
  1080. }
  1081. public static function GetProfileStimulusGrant(\$iProfileId, \$sClass, \$sStimulus)
  1082. {
  1083. \$sGrantKey = \$iProfileId.'_'.\$sClass.'_s_'.\$sStimulus;
  1084. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1085. {
  1086. return self::\$aGRANTS[\$sGrantKey];
  1087. }
  1088. \$sGrantKey = \$iProfileId.'_*_s_'.\$sStimulus;
  1089. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1090. {
  1091. return self::\$aGRANTS[\$sGrantKey];
  1092. }
  1093. return null;
  1094. }
  1095. // returns an array of id => array of column => php value(so-called "real value")
  1096. public static function GetProfilesValues()
  1097. {
  1098. return self::\$aPROFILES;
  1099. }
  1100. }
  1101. EOF;
  1102. return $sPHP;
  1103. } // function CompileUserRights
  1104. }
  1105. ?>