CreateChartRels.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Create relationships used by images, charts...
  4. *
  5. * @category Phpdocx
  6. * @package elements
  7. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  8. * (http://www.2mdc.com)
  9. * @license LGPL
  10. * @version 1.0
  11. * @link http://www.phpdocx.com
  12. * @since File available since Release 1.0
  13. */
  14. include_once dirname(__FILE__) . '/CreateElement.inc';
  15. /**
  16. * Create relationships used by images, charts...
  17. *
  18. * @category Phpdocx
  19. * @package elements
  20. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  21. * (http://www.2mdc.com)
  22. * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  23. * @version 1.0
  24. * @link http://www.phpdocx.com
  25. * @since Class available since Release 1.0
  26. */
  27. class CreateChartRels extends CreateElement
  28. {
  29. /**
  30. *
  31. * @access protected
  32. */
  33. protected $_xml;
  34. /**
  35. *
  36. * @access private
  37. * @static
  38. */
  39. private static $_instance = NULL;
  40. /**
  41. * Construct
  42. *
  43. * @access public
  44. */
  45. public function __construct()
  46. {
  47. }
  48. /**
  49. * Destruct
  50. *
  51. * @access public
  52. */
  53. public function __destruct()
  54. {
  55. }
  56. /**
  57. * Magic method, returns current XML
  58. *
  59. * @access public
  60. * @return string Return current XML
  61. */
  62. public function __toString()
  63. {
  64. return $this->_xml;
  65. }
  66. /**
  67. * Singleton, return instance of class
  68. *
  69. * @access public
  70. * @return CreateChartRels
  71. */
  72. public static function getInstance()
  73. {
  74. if (self::$_instance == NULL) {
  75. self::$_instance = new CreateChartRels();
  76. }
  77. return self::$_instance;
  78. }
  79. /**
  80. * Create relationship document to use in DOCX file
  81. *
  82. * @access public
  83. * @param int $idChart
  84. */
  85. public function createRelationship($idChart)
  86. {
  87. $this->generateRELATIONSHIPS();
  88. $this->generateRELATIONSHIP($idChart);
  89. $this->cleanTemplate();
  90. }
  91. /**
  92. * New relationship, added to relationships XML
  93. *
  94. * @access protected
  95. * @param int $idChart
  96. * @param int $id. Optional, use 1 as default
  97. */
  98. protected function generateRELATIONSHIP($idChart, $id = 1)
  99. {
  100. $xml = '<Relationship Id="rId' . $id . '" Type="http://schemas.open'
  101. . 'xmlformats.org/officeDocument/2006/relationships/package" '
  102. . 'Target="../embeddings/datos' . $idChart
  103. . '.xlsx"></Relationship>__GENERATECHARTSPACE__';
  104. $tag = '__GENERATERELATIONSHIPS__';
  105. $this->_xml = str_replace($tag, $xml, $this->_xml);
  106. }
  107. /**
  108. * Main tags of relationships XML
  109. *
  110. * @access protected
  111. */
  112. protected function generateRELATIONSHIPS()
  113. {
  114. $this->_xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'
  115. . '<Relationships xmlns="http://schemas.openxmlformats.org/'
  116. . 'package/2006/relationships">__GENERATERELATIONSHIPS__'
  117. . '</Relationships>';
  118. }
  119. }