compiler.class.inc.php 36 KB

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