Source for file GUIManager.class.php

Documentation is available at GUIManager.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/GUIManager.abstract.php");
  4. require_once(HARMONI."GUIManager/Theme.class.php");
  5. require_once(HARMONI."GUIManager/StyleComponent.class.php");
  6. require_once(HARMONI."GUIManager/StyleProperty.class.php");
  7. require_once(HARMONI."GUIManager/Component.class.php");
  8.  
  9.  
  10.  
  11. /**
  12. * An implmentation of the GUIManagerInterface. This implementation
  13. * is pretty straightforward and does not maintain any sort of caching
  14. * data structures. Theme states are dealt with on the fly whenever one of
  15. * the load/replace/save/delete methods is called.<br /><br />
  16. * This class provides methods for theme management: saving/loading of theme state,
  17. * obtaining information about supported GUI components, etc.
  18. *
  19. * @package harmoni.gui
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: GUIManager.class.php,v 1.29 2007/09/04 20:25:21 adamfranco Exp $
  25. */
  26. class GUIManager
  27. extends GUIManagerAbstract
  28. {
  29.  
  30. /*******************************************************
  31. * GUIManager Setup Stuff
  32. *********************************************************/
  33.  
  34.  
  35. /**
  36. * The database connection as returned by the DBHandler.
  37. * @var integer _dbIndex
  38. * @access protected
  39. */
  40. var $_dbIndex;
  41.  
  42. /**
  43. * The database connection as returned by the DBHandler.
  44. * @var integer _dbIndex
  45. * @access protected
  46. */
  47. var $_dbName;
  48. /**
  49. * A list of default themes anyone can access. The array should
  50. * contain several arrays with two parameters. The first is a display name.
  51. * The second is the name of the Theme's class
  52. *
  53. * @var array _themeList
  54. * @access protected
  55. */
  56. var $_themeList;
  57.  
  58. /**
  59. * Constructor
  60. * @access public
  61. */
  62. function GUIManager() {
  63. }
  64.  
  65. /**
  66. * Assign the configuration of this Manager. Valid configuration options are as
  67. * follows:
  68. * database_index integer
  69. * database_name string
  70. * default_theme object Theme
  71. *
  72. * @param object Properties $configuration (original type: java.util.Properties)
  73. *
  74. * @throws object OsidException An exception with one of the following
  75. * messages defined in org.osid.OsidException: {@link }
  76. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  77. * {@link org.osid.OsidException#PERMISSION_DENIED}
  78. * PERMISSION_DENIED}, {@link }
  79. * org.osid.OsidException#CONFIGURATION_ERROR
  80. * CONFIGURATION_ERROR}, {@link }
  81. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  82. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  83. *
  84. * @access public
  85. */
  86. function assignConfiguration ( $configuration ) {
  87. $this->_configuration =$configuration;
  88.  
  89. $dbIndex =$configuration->getProperty('database_index');
  90. $dbName =$configuration->getProperty('database_name');
  91. $theme =$configuration->getProperty('default_theme');
  92. $id =$configuration->getProperty('default_state_id');
  93. $arrayOfDefaultThemes =$configuration->getProperty('array_of_default_themes');
  94.  
  95.  
  96. // ** parameter validation
  97. ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
  98. ArgumentValidator::validate($theme, ExtendsValidatorRule::getRule("ThemeInterface"), true);
  99. ArgumentValidator::validate($arrayOfDefaultThemes, ArrayValidatorRule::getRule(), true);
  100. // ** end of parameter validation
  101.  
  102. $this->_dbName = $dbName;
  103. $this->_dbIndex = $dbIndex;
  104. $this->_themeList = $arrayOfDefaultThemes;
  105. $this->setTheme($theme);
  106. }
  107.  
  108. /**
  109. * Return context of this OsidManager.
  110. *
  111. * @return object OsidContext
  112. *
  113. * @throws object OsidException
  114. *
  115. * @access public
  116. */
  117. function getOsidContext () {
  118. return $this->_osidContext;
  119. }
  120.  
  121. /**
  122. * Assign the context of this OsidManager.
  123. *
  124. * @param object OsidContext $context
  125. *
  126. * @throws object OsidException An exception with one of the following
  127. * messages defined in org.osid.OsidException: {@link }
  128. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  129. *
  130. * @access public
  131. */
  132. function assignOsidContext ( $context ) {
  133. ArgumentValidator::validate($context->getContext('harmoni'),
  134. ExtendsValidatorRule::getRule('Harmoni'));
  135.  
  136. $this->_osidContext =$context;
  137.  
  138. $this->attachToHarmoni();
  139. }
  140.  
  141. /*******************************************************
  142. * Helper Functions
  143. *********************************************************/
  144.  
  145.  
  146. /**
  147. * Returns a list of styleCollections supported by the GUIManager.
  148. * @access public
  149. * @return array An array of strings; each element is the class name of a theme.
  150. ***/
  151. function getSupportedStyleCollections() {
  152. $themesDir = dirname(__FILE__).$this->getStyleCollectionPath();
  153.  
  154. //the array of supported themes
  155. $themes = array();
  156.  
  157. //make sure the specified name is indeed a directory
  158. if(is_dir($themesDir)){
  159.  
  160. $dh = opendir($themesDir);
  161. while (($file = readdir($dh)) !== false) {
  162. //ignore other files or directories
  163. if (ereg(".class.php", $file)){
  164.  
  165. //strip the ".class.php" from the end of the file
  166. $file = rtrim($file,".class.php");
  167. $themes[] = $file;
  168. }
  169. }
  170. unset($file,$dh);
  171. }
  172. return $themes;
  173. }
  174.  
  175. /**
  176. * Returns the path that contains all the supported themes.
  177. * @access public
  178. * @return string The relative path to the Theme directory.
  179. ***/
  180. function getStyleCollectionPath() {
  181. return "/StyleCollections/";
  182. }
  183.  
  184. /**
  185. * Returns a list of style properties supported by the GUIManager.
  186. * @access public
  187. * @return array An array of strings; each element is the class name of a style property.
  188. ***/
  189. function getSupportedSPs() {
  190. $SPDir = dirname(__FILE__).$this->getSPPath();
  191.  
  192. //the array of supported SPs
  193. $SPs = array();
  194.  
  195. //make sure the specified name is indeed a directory
  196. if(is_dir($SPDir)){
  197.  
  198. $dh = opendir($SPDir);
  199. while (($file = readdir($dh)) !== false) {
  200. //ignore other files or directories
  201. if (ereg(".class.php", $file) && !ereg('^._', $file)){
  202.  
  203. //strip the ".class.php" from the end of the file
  204. $file = rtrim($file,".class.php");
  205. $SPs[] = $file;
  206. }
  207. }
  208. unset($file,$dh);
  209. }
  210. return $SPs;
  211.  
  212. }
  213.  
  214. /**
  215. * Returns the path that contains all the supported style properties.
  216. * @access public
  217. * @return string The relative path to the style property directory.
  218. ***/
  219. function getSPPath() {
  220. return "/StyleProperties/";
  221. }
  222.  
  223. /**
  224. * Returns a list of style components supported by the GUIManager.
  225. * @access public
  226. * @return array An array of strings; each element is the class name of a style components.
  227. ***/
  228. function getSupportedSCs() {
  229. $SCDir = dirname(__FILE__).$this->getSCPath();
  230.  
  231. //the array of supported SCs
  232. $SCs = array();
  233.  
  234. //make sure the specified name is indeed a directory
  235. if(is_dir($SCDir)){
  236.  
  237. $dh = opendir($SCDir);
  238. while (($file = readdir($dh)) !== false) {
  239. //ignore other files or directories
  240. if (ereg(".class.php", $file)){
  241.  
  242. //strip the ".class.php" from the end of the file
  243. $file = rtrim($file,".class.php");
  244. $SCs[] = $file;
  245. }
  246. }
  247. unset($file,$dh);
  248. }
  249. return $SCs;
  250. }
  251.  
  252. /**
  253. * Returns the path that contains all the supported style component.
  254. * @access public
  255. * @return string The relative path to the style component directory.
  256. ***/
  257. function getSCPath() {
  258. return "/StyleComponents/";
  259. }
  260.  
  261. /**
  262. * Returns a list of components supported by the GUIManager.
  263. * @access public
  264. * @return array An array of strings; each element is the class name of a component.
  265. ***/
  266. function getSupportedComponents() {
  267. $ComponentDir = dirname(__FILE__).$this->getComponentPath();
  268.  
  269. //the array of supported Components
  270. $Components = array();
  271.  
  272. //make sure the specified name is indeed a directory
  273. if(is_dir($ComponentDir)){
  274.  
  275. $dh = opendir($ComponentDir);
  276. while (($file = readdir($dh)) !== false) {
  277. //ignore other files or directories
  278. if (ereg(".class.php", $file)){
  279.  
  280. //strip the ".class.php" from the end of the file
  281. $file = rtrim($file,".class.php");
  282. $Components[] = $file;
  283. }
  284. }
  285. unset($file,$dh);
  286. }
  287. return $Components;
  288. }
  289.  
  290. /**
  291. * Returns the path that contains all the supported components.
  292. * @access public
  293. * @return string The relative path to the Component directory.
  294. ***/
  295. function getComponentPath() {
  296. return "/Components/";
  297. }
  298.  
  299. /**
  300. * Returns a list of layouts supported by the GUIManager.
  301. * @access public
  302. * @return array An array of strings; each element is the class name of a layout.
  303. ***/
  304. function getSupportedLayouts() {
  305. $LayoutDir = dirname(__FILE__).$this->getLayoutPath();
  306.  
  307. //the array of supported Layouts
  308. $Layouts = array();
  309.  
  310. //make sure the specified name is indeed a directory
  311. if(is_dir($LayoutDir)){
  312.  
  313. $dh = opendir($LayoutDir);
  314. while (($file = readdir($dh)) !== false) {
  315. //ignore other files or directories
  316. if (ereg(".class.php", $file)){
  317.  
  318. //strip the ".class.php" from the end of the file
  319. $file = rtrim($file,".class.php");
  320. $Layouts[] = $file;
  321. }
  322. }
  323. unset($file,$dh);
  324. }
  325. return $Layouts;
  326. }
  327.  
  328. /**
  329. * Returns the path that contains all the supported layouts.
  330. * @access public
  331. * @return string The relative path to the Layout directory.
  332. ***/
  333. function getLayoutPath() {
  334. return "/Layouts/";
  335. }
  336.  
  337. /*******************************************************
  338. * Customization of A Theme Instance (Create, Save, Load, Delete)
  339. *********************************************************/
  340.  
  341.  
  342. /*******************************************************
  343. * Theme Retrieving from the database
  344. *********************************************************/
  345.  
  346.  
  347. /**
  348. * Loads the theme stored earlier with <code>saveTheme()</code>. This
  349. * method reverses the steps of <code>saveTheme()</code>. It first obtains
  350. * the database-stored theme, then instantiates a Theme object with the data.
  351. *
  352. * @access public
  353. * @param ref object HarmoniId $themeId The id of the theme that will be loaded.
  354. * @return ref object Theme
  355. ***/
  356. function getThemeById($themeId) {
  357. // ** parameter validation
  358. ArgumentValidator::validate($themeId, ExtendsValidatorRule::getRule("HarmoniId"), true);
  359. // ** end of parameter validation
  360.  
  361. // get the theme state from the database
  362. $dbHandler = Services::getService("DatabaseManager");
  363. $idValue = $themeId->getIdString();
  364. $query = new SelectQuery();
  365. $query->addTable($this->_dbName.".tm_theme");
  366. $query->addWhere("theme_id = $idValue");
  367. $query->addColumn("*");
  368. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  369.  
  370. // build a new theme object for the results returned and set it as the theme
  371. if ($queryResult->getNumberOfRows() == 1) {
  372. $row =$queryResult->next();
  373. $theme = new Theme( $row['theme_display_name'],
  374. $row['theme_description']);
  375. $theme->setTemplate($row['theme_template']);
  376. $theme->setCustom($row['theme_custom_lev']);
  377. $theme->setId($themeId);
  378. $queryResult->free();
  379. // passes execution to collection loading from DB
  380. $this->loadStyleCollectionsForTheme($theme);
  381. } else {
  382. throwError( new Error( "GUIManager", "NO or MULTIPLE THEMES FOR ID"));
  383. }
  384. return $theme;
  385. }
  386.  
  387. /**
  388. * Load theme
  389. *
  390. * @param object HarmoniId $themeId
  391. * @return void
  392. * @access public
  393. * @since 4/26/06
  394. */
  395. function loadTheme ($themeId) {
  396. $this->setTheme($this->getTheme($themeId));
  397. }
  398.  
  399. /**
  400. * Creates a new theme object with an Id
  401. * @access static
  402. * @param string $displayName
  403. * @param string $description
  404. * @return ref object Theme
  405. ***/
  406. function createTheme($displayName, $description) {
  407. $idManager = Services::getService("Id");
  408. $theme = new Theme($displayName, $description);
  409.  
  410. $theme->_id =$idManager->createId();
  411.  
  412. return $theme;
  413. }
  414.  
  415. /**
  416. * Loads the Style Collections for the given theme_id from the database
  417. * and adds them to the current theme
  418. *
  419. * @param object Theme $theme The theme for which we are loading Collections
  420. * @return void
  421. * @access public
  422. * @since 4/25/06
  423. */
  424. function loadStyleCollectionsForTheme ($theme) {
  425. $dbHandler = Services::getService("DBHandler");
  426. $themeId =$theme->getId();
  427. $idValue =$themeId->getIdString();
  428. $idManager = Services::getService("Id");
  429.  
  430. $query = new SelectQuery();
  431. $query->addTable($this->_dbName.".tm_style_collection");
  432. $query->addWhere("FK_theme_id = $idValue");
  433. $query->addColumn("*");
  434. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  435.  
  436. // build a new theme object for the results returned and set it as the theme
  437. while ($queryResult->hasMoreRows()) {
  438. $row =$queryResult->next();
  439.  
  440. // this is where we decide on style collection class for image borders
  441. if ($row['collection_class'] == '') {
  442. $styleCollection = new StyleCollection(
  443. $row['collection_selector'],
  444. $row['collection_class_selector'],
  445. $row['collection_display_name'],
  446. $row['collection_description']);
  447. } else if (in_array(
  448. $row['collection_class']."StyleCollection",
  449. $this->getSupportedStyleCollections())) {
  450. $class = $row['collection_class']."StyleCollection";
  451. $styleCollection = new $class(
  452. $row['collection_selector'],
  453. $row['collection_class_selector'],
  454. $row['collection_display_name'],
  455. $row['collection_description']);
  456.  
  457. // deal with border urls here
  458. }
  459. $styleCollection->setId($idManager->getId($row['collection_id']));
  460. $styleCollection->setComponent($row['collection_component']);
  461. $styleCollection->setIndex($row['collection_index']);
  462. // passes execution to property loading from DB
  463. $this->loadStylePropertiesForCollection($styleCollection);
  464. if (is_null($row['collection_selector']))
  465. $theme->addGlobalStyle($styleCollection);
  466. else
  467. $theme->addStyleForComponentType($styleCollection,
  468. $styleCollection->getComponent(),
  469. $styleCollection->getIndex());
  470. }
  471. if ($queryResult->getNumberOfRows == 0) {
  472. // throwError( new Error( "GUIManager", "NO STYLE COLLECTIONS FOR THEME ID"));
  473. }
  474. $queryResult->free();
  475. }
  476.  
  477. /**
  478. * Loads the Style Properties for the given collection_id from the database
  479. * and adds them to the style collection.
  480. *
  481. * @param object StyleCollection $collection The style collection object
  482. * @return void
  483. * @access public
  484. * @since 4/25/06
  485. */
  486. function loadStylePropertiesForCollection($collection) {
  487. $dbHandler = Services::getService("DBHandler");
  488. $collectionId =$collection->getId();
  489. $idValue =$collectionId->getIdString();
  490.  
  491. $query = new SelectQuery();
  492. $query->addTable($this->_dbName.".tm_style_property");
  493. $query->addWhere("FK_collection_id = $idValue");
  494. $query->addColumn("*");
  495. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  496.  
  497. // build a new theme object for the results returned and set it as the theme
  498. while ($queryResult->hasMoreRows()) {
  499. $row =$queryResult->next();
  500.  
  501. $class = $row['property_name']."SP";
  502.  
  503. $styleProperty = new $class();
  504.  
  505. // passes execution to component loading from DB
  506. $this->loadStyleComponentsForProperty($row['property_id'], $styleProperty);
  507.  
  508. $collection->addSP($styleProperty);
  509. }
  510. if ($queryResult->getNumberOfRows == 0) {
  511. // throwError( new Error( "GUIManager", "NO STYLE PROPERTIES FOR THEME ID"));
  512. }
  513. $queryResult->free();
  514. }
  515.  
  516. /**
  517. * Loads the Style Components for the given property_id from the database
  518. * and adds them to the style property
  519. *
  520. * @param object StyleProperty the style property object
  521. * @return void
  522. * @access public
  523. * @since 4/25/06
  524. */
  525. function loadStyleComponentsForProperty ($property) {
  526. $dbHandler = Services::getService("DBHandler");
  527. $propertyId =$property->getId();
  528. $idValue =$propertyId->getIdString();
  529.  
  530. $query = new SelectQuery();
  531. $query->addTable($this->_dbName.".tm_style_component");
  532. $query->addWhere("FK_property_id = $idValue");
  533. $query->addColumn("*");
  534. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  535.  
  536. // build a new theme object for the results returned and set it as the theme
  537. while ($queryResult->hasMoreRows()) {
  538. $row =$queryResult->next();
  539.  
  540. $class = $row['component_class_name']."SC";
  541.  
  542. $styleComponent = new $class($row['component_value']);
  543.  
  544. $property->addSC($styleComponent);
  545. }
  546. if ($queryResult->getNumberOfRows == 0) {
  547. // throwError( new Error( "GUIManager", "NO STYLE PROPERTIES FOR THEME ID"));
  548. }
  549. $queryResult->free();
  550. }
  551.  
  552. /**
  553. * Answers the set of templates stored in the Database
  554. * Display name is 'Template'
  555. *
  556. * @return ref array The array of theme objects that are templates
  557. * @access public
  558. * @since 5/3/06
  559. */
  560. function getThemeTemplates () {
  561. $guiManager = Services::getService("GUI");
  562. $dbHandler = Services::getService("DBHandler");
  563. $idManager = Services::getService("Id");
  564. $templates = array();
  565.  
  566. $query = new SelectQuery();
  567. $query->addTable($this->_dbName.".tm_theme");
  568. $query->addWhere("theme_template = 1");
  569. $query->addColumn("theme_id");
  570. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  571.  
  572. while ($queryResult->hasMoreRows()) {
  573. $row = $queryResult->next();
  574.  
  575. $templates[] =$this->getTheme($idManager->getId($row['theme_id']));
  576. }
  577.  
  578. return $templates;
  579. }
  580.  
  581. /*******************************************************
  582. * Theme Saving to the database
  583. *********************************************************/
  584.  
  585.  
  586. /**
  587. * Saves the current theme by updating the theme settings in the database
  588. *
  589. * @return void
  590. * @access public
  591. * @since 4/26/06
  592. */
  593. function saveTheme () {
  594. // get the theme from the database (if it exists)
  595. $dbHandler = Services::getService("DatabaseManager");
  596. $id =$this->_theme->getId();
  597. if(is_null($id)){
  598. $im = Services::getService("Id");
  599. $id =$im->createId();
  600. $idValue = $id->getIdString();
  601. $this->_theme->setId($id);
  602. $query = new InsertQuery();
  603. }else{
  604. $idValue = $id->getIdString();
  605. $query = new SelectQuery();
  606. $query->addTable($this->_dbName.".tm_theme");
  607. $query->addWhere("theme_id = $idValue");
  608. $query->addColumn("theme_id");
  609. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  610. if ($queryResult->getNumberOfRows() > 1) {
  611. throwError( new Error("GUIManager", "Theme id multiplicity"));
  612. } else if ($queryResult->getNumberOfRows() == 1) {
  613. $queryResult->free();
  614. $query = new UpdateQuery();
  615. $query->setWhere("theme_id = $idValue");
  616. } else {
  617. $queryResult->free();
  618. $query = new InsertQuery();
  619. }
  620. }
  621. $authN = Services::getService("AuthN");
  622. $authNTypesIterator =$authN->getAuthenticationTypes();
  623. if($authNTypesIterator->hasNext()){
  624. $authNType1 =$authNTypesIterator->next();
  625. //hopefully the first one is the right one to choose.
  626. $creatorId =$authN->getUserId($authNType1);
  627. $creatorIdString = $creatorId->getIdString();
  628. }else{
  629. $creatorIdString = "";
  630. }
  631. $query->setTable($this->_dbName.".tm_theme");
  632. $query->setColumns(array('theme_id', 'theme_display_name',
  633. 'theme_description', 'theme_template', 'theme_custom_lev','theme_owner_id'));
  634. $query->setValues(array("'".addslashes($idValue)."'",
  635. "'".addslashes($this->_theme->getDisplayName())."'",
  636. "'".addslashes($this->_theme->getDescription())."'",
  637. "'".addslashes($this->_theme->getTemplate())."'",
  638. "'".addslashes($this->_theme->getCustom())."'",
  639. "'".addslashes($creatorIdString)."'"));
  640. $dbHandler->query($query, $this->_dbIndex);
  641.  
  642. $this->saveStyleCollections();
  643. }
  644.  
  645. /**
  646. * Saves the Style Collections associated with the current theme
  647. *
  648. * @return void
  649. * @access public
  650. * @since 4/26/06
  651. */
  652. function saveStyleCollections () {
  653. // get the style collections for the theme and make sure they're in the DB
  654. $dbHandler = Services::getService("DatabaseManager");
  655.  
  656. $styleCollections =$this->_theme->getStyleCollections();
  657. if(is_null($styleCollections)){
  658. throwError(new Error("its null","poo",true));
  659. }
  660. foreach ($styleCollections as $styleCollection) {
  661. $id =$styleCollection->getId();
  662. $idValue = $id->getIdString();
  663. $query = new SelectQuery();
  664. $query->addTable($this->_dbName.".tm_style_collection");
  665. $query->addWhere('collection_id = '.$idValue);
  666. $query->addColumn("collection_id");
  667. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  668. if ($queryResult->getNumberOfRows() > 1)
  669. throwError( new Error("GUIManager", "collection id multiplicity"));
  670. else if ($queryResult->getNumberOfRows() == 1) {
  671. $queryResult->free();
  672. $query = new UpdateQuery();
  673. $query->setWhere("collection_id = $idValue");
  674. } else {
  675. $queryResult->free();
  676. $query = new InsertQuery();
  677. }
  678. $query->setTable($this->_dbName.".tm_style_collection");
  679. $query->setColumns(array('collection_id', 'collection_display_name',
  680. 'collection_description', 'collection_class_selector',
  681. 'collection_selector', 'collection_component', 'collection_index',
  682. 'collection_class'));
  683. $query->setValues(array("'".addslashes($idValue)."'",
  684. "'".addslashes($styleCollection->getDisplayName())."'",
  685. "'".addslashes($styleCollection->getDescription())."'",
  686. "'".addslashes($styleCollection->getClassSelector())."'",
  687. "'".addslashes($styleCollection->getSelector())."'",
  688. "'".addslashes($styleCollection->getComponent())."'",
  689. "'".addslashes($styleCollection->getIndex())."'",
  690. "'".addslashes(trim(get_class($styleCollection), "StyleCollection"))."'"));
  691. $dbHandler->query($query, $this->_dbIndex);
  692. // save the style properties for this theme
  693. $this->saveStylePropertiesForCollection($styleCollection);
  694. }
  695. }
  696.  
  697. /**
  698. * Saves the style properties of a style collection with id $id
  699. *
  700. * @param object StyleCollection $collection
  701. * @return void
  702. * @access public
  703. * @since 4/26/06
  704. */
  705. function saveStylePropertiesForCollection ($collection) {
  706. // get the style properties for the collection
  707. $dbHandler = Services::getService("DatabaseManager");
  708.  
  709. $styleProperties =$collection->getSPs();
  710. foreach ($styleProperties as $styleProperty) {
  711. $id =$styleProperty->getId();
  712. $idValue = $id->getIdString();
  713. $query = new SelectQuery();
  714. $query->addTable($this->_dbName.".tm_style_property");
  715. $query->addWhere('property_id = '.$idValue);
  716. $query->addColumn("property_id");
  717. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  718. if ($queryResult->getNumberOfRows() > 1)
  719. throwError( new Error("GUIManager", "property id multiplicity"));
  720. else if ($queryResult->getNumberOfRows() == 1) {
  721. $queryResult->free();
  722. $query = new UpdateQuery();
  723. $query->setWhere("property_id = $idValue");
  724. } else {
  725. $queryResult->free();
  726. $query = new InsertQuery();
  727. }
  728. $query->setTable($this->_dbName.".tm_style_property");
  729. $query->setColumns(array('property_id', 'property_display_name',
  730. 'property_description', 'property_name'));
  731. $query->setValues(array("'".addslashes($idValue)."'",
  732. "'".addslashes($styleProperty->getDisplayName())."'",
  733. "'".addslashes($styleProperty->getDescription())."'",
  734. "'".addslashes($styleProperty->getName())."'"));
  735. $dbHandler->query($query, $this->_dbIndex);
  736. // save the style properties for this theme
  737. $this->saveStyleComponentsForProperty($styleProperty);
  738. }
  739. }
  740.  
  741. /**
  742. * Saves the style components of a style property
  743. *
  744. * @param object StyleCollection $property
  745. * @return void
  746. * @access public
  747. * @since 4/26/06
  748. */
  749. function saveStyleComponentsForProperty ($property) {
  750. // get the style components for the property
  751. $dbHandler = Services::getService("DatabaseManager");
  752.  
  753. $styleComponents =$property->getSCs();
  754. foreach ($styleComponents as $styleComponent) {
  755. $id =$styleComponent->getId();
  756. $idValue = $id->getIdString();
  757. $query = new SelectQuery();
  758. $query->addTable($this->_dbName.".tm_style_component");
  759. $query->addWhere('component_id = '.$idValue);
  760. $query->addColumn("component_id");
  761. $queryResult =$dbHandler->query($query, $this->_dbIndex);
  762. if ($queryResult->getNumberOfRows() > 1)
  763. throwError( new Error("GUIManager", "component id multiplicity"));
  764. else if ($queryResult->getNumberOfRows() == 1) {
  765. $queryResult->free();
  766. $query = new UpdateQuery();
  767. $query->setWhere("component_id = $idValue");
  768. } else {
  769. $queryResult->free();
  770. $query = new InsertQuery();
  771. }
  772. $query->setTable($this->_dbName.".tm_style_component");
  773. $query->setColumns(array('component_id', 'component_class_name',
  774. 'component_value'));
  775. $query->setValues(array("'".addslashes($idValue)."'",
  776. "'".addslashes(get_class($styleComponent))."'",
  777. "'".addslashes($styleComponent->getValue())."'"));
  778. $dbHandler->query($query, $this->_dbIndex);
  779. // save the style properties for this theme
  780. }
  781. }
  782.  
  783. /*******************************************************
  784. * Theme Removal from the database
  785. *********************************************************/
  786.  
  787.  
  788. /**
  789. * Deletes the theme from the database
  790. *
  791. * @param object HarmoniId $id
  792. * @return void
  793. * @access public
  794. * @since 4/26/06
  795. */
  796. function deleteTheme ($id) {
  797. $dbHandler = Services::getService("DatabaseManager");
  798.  
  799. $this->deleteCollectionsForTheme($this->getTheme($id));
  800.  
  801. $idValue = $id->getIdString();
  802. $query = new DeleteQuery();
  803. $query->setTable($this->_dbName.".tm_theme");
  804. $query->addWhere("theme_id = $idValue");
  805. $result =$dbHandler->query($query, $this->_dbIndex);
  806.  
  807. if ($result->getNumberOfRows() != 1){
  808. throwError( new Error("Theme Deletion Error--instead of one row being deleted, ".$result->getNumberOfRows()." rows were deleted.","GUIManager",true));
  809. }
  810.  
  811. }
  812.  
  813. /**
  814. * Deletes the style collections from the database
  815. *
  816. * @param object Theme $theme the theme
  817. * @return void
  818. * @access public
  819. * @since 4/26/06
  820. */
  821. function deleteCollectionsForTheme ($theme) {
  822. $dbHandler = Services::getService("DatabaseManager");
  823.  
  824. $styleCollections =$theme->getStyleCollections();
  825. foreach ($styleCollections as $styleCollection) {
  826. $this->deletePropertiesForCollection($styleCollection);
  827. }
  828.  
  829. $themeId =$theme->getId();
  830. $idValue = $themeId->getIdString();
  831. $query = new DeleteQuery();
  832. $query->setTable($this->_dbName.".tm_style_collection");
  833. $query->addWhere("FK_theme_id = $idValue");
  834. $result =$dbHandler->query($query, $this->_dbIndex);
  835.  
  836.  
  837. }
  838.  
  839. /**
  840. * Deletes the style properties from the database
  841. *
  842. * @param object StyleCollection $styleCollection the id of the theme
  843. * @return void
  844. * @access public
  845. * @since 4/26/06
  846. */
  847. function deletePropertiesForCollection ($styleCollection) {
  848. $dbHandler = Services::getService("DatabaseManager");
  849.  
  850. $sps =$styleCollection->getSPs();
  851. foreach ($sps as $sp) {
  852. $this->deleteComponentsForProperty($sp);
  853. }
  854. $id =$styleCollection->getId();
  855. $idValue = $id->getIdString();
  856. $query = new DeleteQuery();
  857. $query->setTable($this->_dbName.".tm_style_property");
  858. $query->addWhere("FK_collection_id = $idValue");
  859. $result =$dbHandler->query($query, $this->_dbIndex);
  860.  
  861.  
  862. }
  863.  
  864. /**
  865. * Deletes the components for the property from the db
  866. *
  867. * @param object StyleProperty $sp
  868. * @return void
  869. * @access public
  870. * @since 4/26/06
  871. */
  872. function deleteComponentsForProperty ($sp) {
  873. $dbHandler = Services::getService("DatabaseManager");
  874.  
  875. $id =$sp->getId();
  876. $idValue = $id->getIdString();
  877. $query = new DeleteQuery();
  878. $query->setTable($this->_dbName.".tm_style_component");
  879. $query->addWhere("FK_property_id = $idValue");
  880. $result =$dbHandler->query($query, $this->_dbIndex);
  881.  
  882.  
  883. }
  884.  
  885. /*******************************************************
  886. * Functionality for Theme Management
  887. *********************************************************/
  888.  
  889.  
  890. /**
  891. * Answers a list of themes that the User has access to edit
  892. *
  893. * @return array keyed on id's and valued to DisplayName
  894. * @access public
  895. * @since 5/30/06
  896. */
  897. function getThemeListForUser () {
  898. $returnArray = array();
  899. foreach ($this->_themeList as $theme){
  900. $returnArray[$theme[1]] = $theme[0];
  901. }
  902. $authN = Services::getService("AuthN");
  903. $authTypes =$authN->getAuthenticationTypes();
  904. $users = array();
  905. while ($authTypes->hasNext()) {
  906. $authType =$authTypes->next();
  907. $id =$authN->getUserId($authType);
  908. $users[] = $id->getIdString();
  909. }
  910.  
  911. $db = Services::getService('DatabaseManager');
  912.  
  913. $query = new SelectQuery();
  914. $query->addTable($this->_dbName.".tm_theme");
  915. $query->addColumn("theme_id");
  916. $query->addColumn("theme_display_name");
  917. $query->addWhere("theme_owner_id = '".addslashes($users[0])."'");
  918. for ($i = 1; $i < count($users); $i++) {
  919. $query->addWhere("theme_owner_id = '".addslashes($users[$i])."'", _OR);
  920. }
  921. $query->addWhere("theme_template = '1'", _OR);
  922.  
  923. $result =$db->query($query, $this->_dbIndex);
  924.  
  925. while ($result->hasMoreRows()) {
  926. $row = $result->next();
  927.  
  928. $returnArray[$result['theme_id']] = $result['theme_display_name'];
  929. }
  930.  
  931. return $returnArray;
  932. }
  933.  
  934. /**
  935. * Answers the style property containing the Global Background Color for the theme
  936. *
  937. * @return ref object StyleProperty
  938. * @access public
  939. * @since 5/30/06
  940. */
  941. function getGlobalBGColor () {
  942. $globalStyles =$this->_theme->getGlobalStyles();
  943.  
  944. // empty SP for returning if SP is 'background'
  945. $return = new BackgroundColorSP();
  946.  
  947. if (isset($globalStyles['body'])) {
  948. $body =$globalStyles['body'];
  949. $SPs =$body->getSPs();
  950. if (isset($SPs['background-color']))
  951. return $SPs['background-color'];
  952. else if (isset($SPs['background'])) {
  953. $SCs =$SPs['background']->getSCs();
  954. if (isset($SCs['colorsc']))
  955. $return->addSC($SCs['colorsc']);
  956. }
  957. }
  958. return $return;
  959. }
  960.  
  961. /**
  962. * Answers the style property containing the Global Font for the theme
  963. *
  964. * @return ref object StyleProperty
  965. * @access public
  966. * @since 5/30/06
  967. */
  968. function getGlobalFont () {
  969. $globalStyles =$this->_theme->getGlobalStyles();
  970.  
  971. // empty SP for returning if SP is not set
  972. $return = new FontSP();
  973.  
  974. if (isset($globalStyles['body'])) {
  975. $body =$globalStyles['body'];
  976. $SPs =$body->getSPs();
  977. if (isset($SPs['font']))
  978. return $SPs['font'];
  979. }
  980. return $return;
  981. }
  982.  
  983. /**
  984. * Answers the class of the style collections being used by this theme
  985. *
  986. * @return string the class for the collections
  987. * @access public
  988. * @since 5/30/06
  989. */
  990. function getCollectionClass () {
  991. return $this->_theme->getCollectionClass();
  992. }
  993. }
  994.  
  995. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:32 -0400 by phpDocumentor 1.3.0RC3