compiler.class.inc.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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 $sSourceDir;
  27. protected $aRootClasses;
  28. protected $aLog;
  29. public function __construct($oModelFactory, $sSourceDir)
  30. {
  31. $this->oFactory = $oModelFactory;
  32. $this->sSourceDir = $sSourceDir;
  33. $this->aLog = array();
  34. }
  35. protected function Log($sText)
  36. {
  37. $this->aLog[] = $sText;
  38. }
  39. protected function DumpLog($oPage)
  40. {
  41. foreach ($this->aLog as $sText)
  42. {
  43. $oPage->p($sText);
  44. }
  45. }
  46. public function Compile($sTargetDir, $oP = null, $bUseSymbolicLinks = false)
  47. {
  48. $aAllClasses = array(); // flat list of classes
  49. // Determine the target modules for the MENUS
  50. //
  51. $aMenuNodes = array();
  52. $aMenusByModule = array();
  53. foreach ($this->oFactory->ListActiveChildNodes('menus', 'menu') as $oMenuNode)
  54. {
  55. $sMenuId = $oMenuNode->getAttribute('id');
  56. $aMenuNodes[$sMenuId] = $oMenuNode;
  57. $sModuleMenu = $oMenuNode->getAttribute('_created_in');
  58. $aMenusByModule[$sModuleMenu][] = $sMenuId;
  59. }
  60. // Determine the target module (exactly one!) for USER RIGHTS
  61. //
  62. $sUserRightsModule = '';
  63. $oUserRightsNode = $this->oFactory->GetNodes('user_rights')->item(0);
  64. if ($oUserRightsNode)
  65. {
  66. $sUserRightsModule = $oUserRightsNode->getAttribute('_created_in');
  67. }
  68. // List root classes
  69. //
  70. $this->aRootClasses = array();
  71. foreach ($this->oFactory->ListRootClasses() as $oClass)
  72. {
  73. $this->Log("Root class: ".$oClass->getAttribute('id'));
  74. $this->aRootClasses[$oClass->getAttribute('id')] = $oClass;
  75. }
  76. // Compile, module by module
  77. //
  78. $aModules = $this->oFactory->GetLoadedModules();
  79. foreach($aModules as $foo => $oModule)
  80. {
  81. $sModuleName = $oModule->GetName();
  82. $sModuleVersion = $oModule->GetVersion();
  83. $sModuleRootDir = realpath($oModule->GetRootDir());
  84. $sRelativeDir = substr($sModuleRootDir, strlen($this->sSourceDir) + 1);
  85. // Push the other module files
  86. SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
  87. $sCompiledCode = '';
  88. $oClasses = $this->oFactory->ListClasses($sModuleName);
  89. $iClassCount = $oClasses->length;
  90. if ($iClassCount == 0)
  91. {
  92. $this->Log("Found module without classes declared: $sModuleName");
  93. }
  94. else
  95. {
  96. foreach($oClasses as $oClass)
  97. {
  98. $sClass = $oClass->getAttribute("id");
  99. $aAllClasses[] = $sClass;
  100. try
  101. {
  102. $sCompiledCode .= $this->CompileClass($oClass, $sRelativeDir, $oP);
  103. }
  104. catch (DOMFormatException $e)
  105. {
  106. throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
  107. }
  108. }
  109. }
  110. if (!array_key_exists($sModuleName, $aMenusByModule))
  111. {
  112. $this->Log("Found module without menus declared: $sModuleName");
  113. }
  114. else
  115. {
  116. $sCompiledCode .=
  117. <<<EOF
  118. //
  119. // Menus
  120. //
  121. EOF;
  122. // Preliminary: determine parent menus not defined within the current module
  123. $aMenusToLoad = array();
  124. $aParentMenus = array();
  125. foreach($aMenusByModule[$sModuleName] as $sMenuId)
  126. {
  127. $oMenuNode = $aMenuNodes[$sMenuId];
  128. if ($sParent = $oMenuNode->GetChildText('parent', null))
  129. {
  130. $aMenusToLoad[] = $sParent;
  131. $aParentMenus[] = $sParent;
  132. }
  133. // Note: the order matters: the parents must be defined BEFORE
  134. $aMenusToLoad[] = $sMenuId;
  135. }
  136. $aMenusToLoad = array_unique($aMenusToLoad);
  137. foreach($aMenusToLoad as $sMenuId)
  138. {
  139. $oMenuNode = $aMenuNodes[$sMenuId];
  140. if ($oMenuNode->getAttribute("xsi:type") == 'MenuGroup')
  141. {
  142. // Note: this algorithm is wrong
  143. // 1 - the module may appear empty in the current module, while children are defined in other modules
  144. // 2 - check recursively that child nodes are not empty themselves
  145. // Future algorithm:
  146. // a- browse the modules and build the menu tree
  147. // b- browse the tree and blacklist empty menus
  148. // c- before compiling, discard if blacklisted
  149. if (!in_array($oMenuNode->getAttribute("id"), $aParentMenus))
  150. {
  151. // Discard empty menu groups
  152. continue;
  153. }
  154. }
  155. try
  156. {
  157. $sCompiledCode .= $this->CompileMenu($oMenuNode, $sRelativeDir, $oP);
  158. }
  159. catch (ssDOMFormatException $e)
  160. {
  161. throw new Exception("Failed to process menu '$sMenuId', from '$sModuleRootDir': ".$e->getMessage());
  162. }
  163. }
  164. }
  165. // User rights
  166. //
  167. if ($sModuleName == $sUserRightsModule)
  168. {
  169. $sCompiledCode .= $this->CompileUserRights($oUserRightsNode);
  170. }
  171. // Create (overwrite if existing) the compiled file
  172. //
  173. if (strlen($sCompiledCode) > 0)
  174. {
  175. // We have compiled something: write the result file
  176. //
  177. $sResultFile = $sTargetDir.'/'.$sRelativeDir.'/model.'.$sModuleName.'.php';
  178. if (is_file($sResultFile))
  179. {
  180. $this->Log("Updating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  181. }
  182. else
  183. {
  184. $sResultDir = dirname($sResultFile);
  185. if (!is_dir($sResultDir))
  186. {
  187. $this->Log("Creating directory $sResultDir");
  188. mkdir($sResultDir, 0777, true);
  189. }
  190. $this->Log("Creating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  191. }
  192. // Compile the module into a single file
  193. //
  194. $sId = $sModuleName;
  195. $sCurrDate = date(DATE_ISO8601);
  196. $sAuthor = 'Combodo compiler';
  197. $sLicence = 'http://www.opensource.org/licenses/gpl-3.0.html LGPL';
  198. $sFileHeader =
  199. <<<EOF
  200. <?php
  201. //
  202. // File generated by ... on the $sCurrDate
  203. // Please do not edit manually
  204. //
  205. //
  206. // Copyright (C) 2010 Combodo SARL
  207. //
  208. // ben on met quoi ici ?
  209. // Signé: Romain
  210. //
  211. // This program is free software; you can redistribute it and/or modify
  212. // it under the terms of the GNU General Public License as published by
  213. // the Free Software Foundation; version 3 of the License.
  214. //
  215. // This program is distributed in the hope that it will be useful,
  216. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  217. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  218. // GNU General Public License for more details.
  219. //
  220. // You should have received a copy of the GNU General Public License
  221. // along with this program; if not, write to the Free Software
  222. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  223. /**
  224. * Classes and menus for $sModuleName (version $sModuleVersion)
  225. *
  226. * @author $sAuthor
  227. * @license $sLicence
  228. */
  229. EOF;
  230. file_put_contents($sResultFile, $sFileHeader.$sCompiledCode);
  231. }
  232. }
  233. }
  234. /**
  235. * Helper to format the flags for an attribute, in a given state
  236. * @param object $oAttNode DOM node containing the information to build the flags
  237. * Returns string PHP flags, based on the OPT_ATT_ constants, or empty (meaning 0, can be omitted)
  238. */
  239. protected function FlagsToPHP($oAttNode)
  240. {
  241. static $aNodeAttributeToFlag = array(
  242. 'mandatory' => 'OPT_ATT_MANDATORY',
  243. 'read_only' => 'OPT_ATT_READONLY',
  244. 'must_prompt' => 'OPT_ATT_MUSTPROMPT',
  245. 'must_change' => 'OPT_ATT_MUSTCHANGE',
  246. 'hidden' => 'OPT_ATT_HIDDEN',
  247. );
  248. $aFlags = array();
  249. foreach ($aNodeAttributeToFlag as $sNodeAttribute => $sFlag)
  250. {
  251. $bFlag = ($oAttNode->GetOptionalElement($sNodeAttribute) != null);
  252. if ($bFlag)
  253. {
  254. $aFlags[] = $sFlag;
  255. }
  256. }
  257. $sRes = implode(' | ', $aFlags);
  258. return $sRes;
  259. }
  260. /**
  261. * Helper to format the tracking level for linkset (direct or indirect attributes)
  262. * @param string $sTrackingLevel Value set from within the XML
  263. * Returns string PHP flag
  264. */
  265. protected function TrackingLevelToPHP($sTrackingLevel)
  266. {
  267. static $aXmlToPHP = array(
  268. 'none' => 'LINKSET_TRACKING_NONE',
  269. 'list' => 'LINKSET_TRACKING_LIST',
  270. 'details' => 'LINKSET_TRACKING_DETAILS',
  271. 'all' => 'LINKSET_TRACKING_ALL',
  272. );
  273. if (!array_key_exists($sTrackingLevel, $aXmlToPHP))
  274. {
  275. throw new exception("Tracking level: unknown value '$sTrackingLevel'");
  276. }
  277. return $aXmlToPHP[$sTrackingLevel];
  278. }
  279. /**
  280. * Format a path (file or url) as an absolute path or relative to the module or the app
  281. */
  282. protected function PathToPHP($sPath, $sModuleRelativeDir, $bIsUrl = false)
  283. {
  284. if ($sPath == '')
  285. {
  286. $sPHP = "''";
  287. }
  288. elseif (substr($sPath, 0, 2) == '$$')
  289. {
  290. // Absolute
  291. $sPHP = self::QuoteForPHP(substr($sPath, 2));
  292. }
  293. elseif (substr($sPath, 0, 1) == '$')
  294. {
  295. // Relative to the application
  296. if ($bIsUrl)
  297. {
  298. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP(substr($sPath, 1));
  299. }
  300. else
  301. {
  302. $sPHP = "APPROOT.".self::QuoteForPHP(substr($sPath, 1));
  303. }
  304. }
  305. else
  306. {
  307. // Relative to the module
  308. if ($bIsUrl)
  309. {
  310. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP($sModuleRelativeDir.''.$sPath);
  311. }
  312. else
  313. {
  314. $sPHP = "dirname(__FILE__).'/$sPath'";
  315. }
  316. }
  317. return $sPHP;
  318. }
  319. protected function GetPropString($oNode, $sTag, $sDefault = null)
  320. {
  321. $val = $oNode->GetChildText($sTag);
  322. if (is_null($val))
  323. {
  324. if (is_null($sDefault))
  325. {
  326. return null;
  327. }
  328. else
  329. {
  330. $val = $sDefault;
  331. }
  332. }
  333. return "'".$val."'";
  334. }
  335. protected function GetPropBoolean($oNode, $sTag, $bDefault = null)
  336. {
  337. $val = $oNode->GetChildText($sTag);
  338. if (is_null($val))
  339. {
  340. if (is_null($bDefault))
  341. {
  342. return null;
  343. }
  344. else
  345. {
  346. return $bDefault ? 'true' : 'false';
  347. }
  348. }
  349. return $val == 'true' ? 'true' : 'false';
  350. }
  351. protected function GetPropNumber($oNode, $sTag, $nDefault = null)
  352. {
  353. $val = $oNode->GetChildText($sTag);
  354. if (is_null($val))
  355. {
  356. if (is_null($nDefault))
  357. {
  358. return null;
  359. }
  360. else
  361. {
  362. $val = $nDefault;
  363. }
  364. }
  365. return (string)$val;
  366. }
  367. /**
  368. * Adds quotes and escape characters
  369. */
  370. protected function QuoteForPHP($sStr)
  371. {
  372. $sEscaped = str_replace(array('\\', '"', "\n"), array('\\\\', '\\"', '\\n'), $sStr);
  373. $sRet = '"'.$sEscaped.'"';
  374. return $sRet;
  375. }
  376. protected function CompileClass($oClass, $sModuleRelativeDir, $oP)
  377. {
  378. $sClass = $oClass->getAttribute('id');
  379. $oProperties = $oClass->GetUniqueElement('properties');
  380. // Class caracteristics
  381. //
  382. $aClassParams = array();
  383. $aClassParams['category'] = $this->GetPropString($oProperties, 'category', '');
  384. $aClassParams['key_type'] = "'autoincrement'";
  385. if ($oNaming = $oProperties->GetOptionalElement('naming'))
  386. {
  387. $oNameAttributes = $oNaming->GetUniqueElement('attributes');
  388. $oAttributes = $oNameAttributes->getElementsByTagName('attribute');
  389. $aNameAttCodes = array();
  390. foreach($oAttributes as $oAttribute)
  391. {
  392. $aNameAttCodes[] = $oAttribute->getAttribute('id');
  393. }
  394. if (count($aNameAttCodes) > 1)
  395. {
  396. // New style...
  397. $sNameAttCode = "array('".implode("', '", $aNameAttCodes)."')";
  398. }
  399. elseif (count($aNameAttCodes) == 1)
  400. {
  401. // New style...
  402. $sNameAttCode = "'$aNameAttCodes[0]'";
  403. }
  404. else
  405. {
  406. $sNameAttCode = "''";
  407. }
  408. }
  409. else
  410. {
  411. $sNameAttCode = "''";
  412. }
  413. $aClassParams['name_attcode'] = $sNameAttCode;
  414. $oLifecycle = $oClass->GetOptionalElement('lifecycle');
  415. if ($oLifecycle)
  416. {
  417. $sStateAttCode = $oLifecycle->GetChildText('attribute');
  418. }
  419. else
  420. {
  421. $sStateAttCode = "";
  422. }
  423. $aClassParams['state_attcode'] = "'$sStateAttCode'";
  424. if ($oReconciliation = $oProperties->GetOptionalElement('reconciliation'))
  425. {
  426. $oReconcAttributes = $oReconciliation->getElementsByTagName('attribute');
  427. $aReconcAttCodes = array();
  428. foreach($oReconcAttributes as $oAttribute)
  429. {
  430. $aReconcAttCodes[] = $oAttribute->getAttribute('id');
  431. }
  432. $sReconcKeys = "array('".implode("', '", $aReconcAttCodes)."')";
  433. }
  434. else
  435. {
  436. $sReconcKeys = "array()";
  437. }
  438. $aClassParams['reconc_keys'] = $sReconcKeys;
  439. $aClassParams['db_table'] = $this->GetPropString($oProperties, 'db_table', '');
  440. $aClassParams['db_key_field'] = $this->GetPropString($oProperties, 'db_key_field', 'id');
  441. if (array_key_exists($sClass, $this->aRootClasses))
  442. {
  443. $sDefaultFinalClass = 'finalclass';
  444. }
  445. else
  446. {
  447. $sDefaultFinalClass = '';
  448. }
  449. $aClassParams['db_finalclass_field'] = $this->GetPropString($oProperties, 'db_final_class_field', $sDefaultFinalClass);
  450. if (($sDisplayTemplate = $oProperties->GetChildText('display_template')) && (strlen($sDisplayTemplate) > 0))
  451. {
  452. $sDisplayTemplate = $sModuleRelativeDir.'/'.$sDisplayTemplate;
  453. $aClassParams['display_template'] = "utils::GetAbsoluteUrlModulesRoot().'$sDisplayTemplate'";
  454. }
  455. if (($sIcon = $oProperties->GetChildText('icon')) && (strlen($sIcon) > 0))
  456. {
  457. $sIcon = $sModuleRelativeDir.'/'.$sIcon;
  458. $aClassParams['icon'] = "utils::GetAbsoluteUrlModulesRoot().'$sIcon'";
  459. }
  460. $oOrder = $oProperties->GetOptionalElement('order');
  461. if ($oOrder)
  462. {
  463. $oColumnsNode = $oOrder->GetUniqueElement('columns');
  464. $oColumns = $oColumnsNode->getElementsByTagName('column');
  465. $aSortColumns = array();
  466. foreach($oColumns as $oColumn)
  467. {
  468. $aSortColumns[] = "'".$oColumn->getAttribute('id')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
  469. }
  470. if (count($aSortColumns) > 0)
  471. {
  472. $aClassParams['order_by_default'] = "array(".implode(", ", $aSortColumns).")";
  473. }
  474. }
  475. // Finalize class params declaration
  476. //
  477. $aClassParamsPHP = array();
  478. foreach($aClassParams as $sKey => $sPHPValue)
  479. {
  480. $aClassParamsPHP[] = " '$sKey' => $sPHPValue,";
  481. }
  482. $sClassParams = implode("\n", $aClassParamsPHP);
  483. // Comment on top of the class declaration
  484. //
  485. $sCodeComment = $oProperties->GetChildText('comment');
  486. // Fields
  487. //
  488. $sAttributes = '';
  489. foreach($this->oFactory->ListFields($oClass) as $oField)
  490. {
  491. // $oField
  492. $sAttCode = $oField->getAttribute('id');
  493. $sAttType = $oField->getAttribute('xsi:type');
  494. $aDependencies = array();
  495. $oDependencies = $oField->GetOptionalElement('dependencies');
  496. if (!is_null($oDependencies))
  497. {
  498. $oDepNodes = $oDependencies->getElementsByTagName('attribute');
  499. foreach($oDepNodes as $oDepAttribute)
  500. {
  501. $aDependencies[] = "'".$oDepAttribute->getAttribute('id')."'";
  502. }
  503. }
  504. $sDependencies = 'array('.implode(', ', $aDependencies).')';
  505. $aParameters = array();
  506. if ($sAttType == 'AttributeLinkedSetIndirect')
  507. {
  508. $aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', '');
  509. $aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', '');
  510. $aParameters['ext_key_to_remote'] = $this->GetPropString($oField, 'ext_key_to_remote', '');
  511. $aParameters['allowed_values'] = 'null';
  512. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  513. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  514. $aParameters['duplicates'] = $this->GetPropBoolean($oField, 'duplicates', false);
  515. $sTrackingLevel = $oField->GetChildText('tracking_level');
  516. if (!is_null($sTrackingLevel))
  517. {
  518. $aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
  519. }
  520. $aParameters['depends_on'] = $sDependencies;
  521. }
  522. elseif ($sAttType == 'AttributeLinkedSet')
  523. {
  524. $aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', '');
  525. $aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', '');
  526. $aParameters['allowed_values'] = 'null';
  527. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  528. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  529. $sTrackingLevel = $oField->GetChildText('tracking_level');
  530. if (!is_null($sTrackingLevel))
  531. {
  532. $aParameters['tracking_level'] = $this->TrackingLevelToPHP($sTrackingLevel);
  533. }
  534. $aParameters['depends_on'] = $sDependencies;
  535. }
  536. elseif ($sAttType == 'AttributeExternalKey')
  537. {
  538. $aParameters['targetclass'] = $this->GetPropString($oField, 'target_class', '');
  539. // deprecated: $aParameters['jointype'] = 'null';
  540. if ($sOql = $oField->GetChildText('filter'))
  541. {
  542. $sEscapedOql = self::QuoteForPHP($sOql);
  543. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  544. }
  545. else
  546. {
  547. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  548. }
  549. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  550. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  551. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  552. $aParameters['depends_on'] = $sDependencies;
  553. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  554. $aParameters['min_auto_complete_chars'] = $this->GetPropNumber($oField, 'min_auto_complete_chars');
  555. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  556. }
  557. elseif ($sAttType == 'AttributeHierarchicalKey')
  558. {
  559. if ($sOql = $oField->GetChildText('filter'))
  560. {
  561. $sEscapedOql = self::QuoteForPHP($sOql);
  562. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  563. }
  564. else
  565. {
  566. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  567. }
  568. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  569. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  570. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  571. $aParameters['depends_on'] = $sDependencies;
  572. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  573. $aParameters['min_auto_complete_chars'] = $this->GetPropNumber($oField, 'min_auto_complete_chars');
  574. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  575. }
  576. elseif ($sAttType == 'AttributeExternalField')
  577. {
  578. $aParameters['allowed_values'] = 'null';
  579. $aParameters['extkey_attcode'] = $this->GetPropString($oField, 'extkey_attcode', '');
  580. $aParameters['target_attcode'] = $this->GetPropString($oField, 'target_attcode', '');
  581. }
  582. elseif ($sAttType == 'AttributeURL')
  583. {
  584. $aParameters['target'] = $this->GetPropString($oField, 'target', '');
  585. $aParameters['allowed_values'] = 'null';
  586. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  587. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  588. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  589. $aParameters['depends_on'] = $sDependencies;
  590. }
  591. elseif ($sAttType == 'AttributeEnum')
  592. {
  593. $oValues = $oField->GetUniqueElement('values');
  594. $oValueNodes = $oValues->getElementsByTagName('value');
  595. $aValues = array();
  596. foreach($oValueNodes as $oValue)
  597. {
  598. // new style... $aValues[] = self::QuoteForPHP($oValue->textContent);
  599. $aValues[] = $oValue->textContent;
  600. }
  601. // new style... $sValues = 'array('.implode(', ', $aValues).')';
  602. $sValues = '"'.implode(',', $aValues).'"';
  603. $aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
  604. $aParameters['display_style'] = $this->GetPropString($oField, 'display_style', 'list');
  605. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  606. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  607. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  608. $aParameters['depends_on'] = $sDependencies;
  609. }
  610. elseif ($sAttType == 'AttributeBlob')
  611. {
  612. $aParameters['depends_on'] = $sDependencies;
  613. }
  614. elseif ($sAttType == 'AttributeStopWatch')
  615. {
  616. $oStates = $oField->GetUniqueElement('states');
  617. $oStateNodes = $oStates->getElementsByTagName('state');
  618. $aStates = array();
  619. foreach($oStateNodes as $oState)
  620. {
  621. $aStates[] = '"'.$oState->GetAttribute('id').'"';
  622. }
  623. $aParameters['states'] = 'array('.implode(', ', $aStates).')';
  624. $aParameters['goal_computing'] = $this->GetPropString($oField, 'goal', 'DefaultMetricComputer'); // Optional, no deadline by default
  625. $aParameters['working_time_computing'] = $this->GetPropString($oField, 'working_time', 'DefaultWorkingTimeComputer'); // Optional, defaults to 24x7
  626. $oThresholds = $oField->GetUniqueElement('thresholds');
  627. $oThresholdNodes = $oThresholds->getElementsByTagName('threshold');
  628. $aThresholds = array();
  629. foreach($oThresholdNodes as $oThreshold)
  630. {
  631. $iPercent = $this->GetPropNumber($oThreshold, 'percent');
  632. $oActions = $oThreshold->GetUniqueElement('actions');
  633. $oActionNodes = $oActions->getElementsByTagName('action');
  634. $aActions = array();
  635. foreach($oActionNodes as $oAction)
  636. {
  637. $oParams = $oAction->GetOptionalElement('params');
  638. $aActionParams = array();
  639. if ($oParams)
  640. {
  641. $oParamNodes = $oParams->getElementsByTagName('param');
  642. foreach($oParamNodes as $oParam)
  643. {
  644. $aActionParams[] = self::QuoteForPHP($oParam->textContent);
  645. }
  646. }
  647. $sActionParams = 'array('.implode(', ', $aActionParams).')';
  648. $sVerb = $this->GetPropString($oAction, 'verb');
  649. $aActions[] = "array('verb' => $sVerb, 'params' => $sActionParams)";
  650. }
  651. $sActions = 'array('.implode(', ', $aActions).')';
  652. $aThresholds[] = $iPercent." => array('percent' => $iPercent, 'actions' => $sActions)";
  653. }
  654. $aParameters['thresholds'] = 'array('.implode(', ', $aThresholds).')';
  655. }
  656. elseif ($sAttType == 'AttributeSubItem')
  657. {
  658. $aParameters['target_attcode'] = $this->GetPropString($oField, 'target_attcode');
  659. $aParameters['item_code'] = $this->GetPropString($oField, 'item_code');
  660. }
  661. else
  662. {
  663. $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')"
  664. $aParameters['sql'] = $this->GetPropString($oField, 'sql', '');
  665. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  666. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  667. $aParameters['depends_on'] = $sDependencies;
  668. }
  669. // Optional parameters (more for historical reasons)
  670. // Added if present...
  671. //
  672. $aParameters['validation_pattern'] = $this->GetPropString($oField, 'validation_pattern');
  673. $aParameters['width'] = $this->GetPropNumber($oField, 'width');
  674. $aParameters['height'] = $this->GetPropNumber($oField, 'height');
  675. $aParameters['digits'] = $this->GetPropNumber($oField, 'digits');
  676. $aParameters['decimals'] = $this->GetPropNumber($oField, 'decimals');
  677. $aParams = array();
  678. foreach($aParameters as $sKey => $sValue)
  679. {
  680. if (!is_null($sValue))
  681. {
  682. $aParams[] = '"'.$sKey.'"=>'.$sValue;
  683. }
  684. }
  685. $sParams = implode(', ', $aParams);
  686. $sAttributes .= " MetaModel::Init_AddAttribute(new $sAttType(\"$sAttCode\", array($sParams)));\n";
  687. }
  688. // Lifecycle
  689. //
  690. $sLifecycle = '';
  691. if ($oLifecycle)
  692. {
  693. $sLifecycle .= "\t\t// Lifecycle (status attribute: $sStateAttCode)\n";
  694. $sLifecycle .= "\t\t//\n";
  695. $oStimuli = $oLifecycle->GetUniqueElement('stimuli');
  696. foreach ($oStimuli->getElementsByTagName('stimulus') as $oStimulus)
  697. {
  698. $sStimulus = $oStimulus->getAttribute('id');
  699. $sStimulusClass = $oStimulus->getAttribute('xsi:type');
  700. $sLifecycle .= " MetaModel::Init_DefineStimulus(new ".$sStimulusClass."(\"".$sStimulus."\", array()));\n";
  701. }
  702. $oStates = $oLifecycle->GetUniqueElement('states');
  703. foreach ($oStates->getElementsByTagName('state') as $oState)
  704. {
  705. $sState = $oState->getAttribute('id');
  706. $oInitialStatePath = $oState->GetOptionalElement('initial_state_path');
  707. if ($oInitialStatePath)
  708. {
  709. $aInitialStatePath = array();
  710. foreach ($oInitialStatePath->getElementsByTagName('state_ref') as $oIntermediateState)
  711. {
  712. $aInitialStatePath[] = "'".$oIntermediateState->GetText()."'";
  713. }
  714. $sInitialStatePath = 'Array('.implode(', ', $aInitialStatePath).')';
  715. }
  716. $sLifecycle .= " MetaModel::Init_DefineState(\n";
  717. $sLifecycle .= " \"".$sState."\",\n";
  718. $sLifecycle .= " array(\n";
  719. $sLifecycle .= " \"attribute_inherit\" => '',\n";
  720. $sLifecycle .= " \"attribute_list\" => array(\n";
  721. $oFlags = $oState->GetUniqueElement('flags');
  722. foreach ($oFlags->getElementsByTagName('attribute') as $oAttributeNode)
  723. {
  724. $sFlags = $this->FlagsToPHP($oAttributeNode);
  725. if (strlen($sFlags) > 0)
  726. {
  727. $sAttCode = $oAttributeNode->GetAttribute('id');
  728. $sLifecycle .= " '$sAttCode' => $sFlags,\n";
  729. }
  730. }
  731. $sLifecycle .= " ),\n";
  732. if (!is_null($oInitialStatePath))
  733. {
  734. $sLifecycle .= " \"initial_state_path\" => $sInitialStatePath,\n";
  735. }
  736. $sLifecycle .= " )\n";
  737. $sLifecycle .= " );\n";
  738. $oTransitions = $oState->GetUniqueElement('transitions');
  739. foreach ($oTransitions->getElementsByTagName('transition') as $oTransition)
  740. {
  741. $sStimulus = $oTransition->GetChildText('stimulus');
  742. $sTargetState = $oTransition->GetChildText('target');
  743. $oActions = $oTransition->GetUniqueElement('actions');
  744. $aVerbs = array();
  745. foreach ($oActions->getElementsByTagName('action') as $oAction)
  746. {
  747. $sVerb = $oAction->GetChildText('verb');
  748. $aVerbs[] = "'$sVerb'";
  749. }
  750. $sActions = implode(', ', $aVerbs);
  751. $sLifecycle .= " MetaModel::Init_DefineTransition(\"$sState\", \"$sStimulus\", array(\"target_state\"=>\"$sTargetState\", \"actions\"=>array($sActions), \"user_restriction\"=>null));\n";
  752. }
  753. }
  754. }
  755. // ZLists
  756. //
  757. $aListRef = array(
  758. 'details' => 'details',
  759. 'standard_search' => 'search',
  760. 'list' => 'list'
  761. );
  762. $oPresentation = $oClass->GetUniqueElement('presentation');
  763. $sZlists = '';
  764. foreach ($aListRef as $sListCode => $sListTag)
  765. {
  766. $oListNode = $oPresentation->GetOptionalElement($sListTag);
  767. if ($oListNode)
  768. {
  769. $aAttributes = $oListNode->GetNodeAsArrayOfItems();
  770. $sZAttributes = var_export($aAttributes, true);
  771. $sZlists .= " MetaModel::Init_SetZListItems('$sListCode', $sZAttributes);\n";
  772. }
  773. }
  774. // Methods
  775. $sMethods = "";
  776. $oMethods = $oClass->GetUniqueElement('methods');
  777. foreach($oMethods->getElementsByTagName('method') as $oMethod)
  778. {
  779. $sMethodCode = $oMethod->GetChildText('code');
  780. if ($sMethodComment = $oMethod->GetChildText('comment', null))
  781. {
  782. $sMethods .= "\n\t$sMethodComment\n".$sMethodCode."\n";
  783. }
  784. else
  785. {
  786. $sMethods .= "\n\n".$sMethodCode."\n";
  787. }
  788. }
  789. // Let's make the whole class declaration
  790. //
  791. $sPHP = "\n\n$sCodeComment\n";
  792. $sParentClass = $oClass->GetChildText('php_parent');
  793. $oPhpParent = $oClass->GetUniqueElement('php_parent', false);
  794. if ($oPhpParent)
  795. {
  796. $sParentClass = $oPhpParent->GetChildText('name', '');
  797. if ($sParentClass == '')
  798. {
  799. throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sRelativeDir': missing required tag 'name' under 'php_parent'.");
  800. }
  801. $sIncludeFile = $oPhpParent->GetChildText('file', '');
  802. if ($sIncludeFile != '')
  803. {
  804. $sPHP .= "\nrequire_once('$sIncludeFile'); // Implementation of the class $sParentClass\n";
  805. }
  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. ?>