PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/application/third_party/phpoffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Borders.php

https://gitlab.com/Japang-Jawara/jawara-penilaian
PHP | 411 lines | 178 code | 43 blank | 190 comment | 21 complexity | a9beff80aab4d5dc1a6b87fdde29f394 MD5 | raw file
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Style;
  3. use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
  4. class Borders extends Supervisor
  5. {
  6. // Diagonal directions
  7. const DIAGONAL_NONE = 0;
  8. const DIAGONAL_UP = 1;
  9. const DIAGONAL_DOWN = 2;
  10. const DIAGONAL_BOTH = 3;
  11. /**
  12. * Left.
  13. *
  14. * @var Border
  15. */
  16. protected $left;
  17. /**
  18. * Right.
  19. *
  20. * @var Border
  21. */
  22. protected $right;
  23. /**
  24. * Top.
  25. *
  26. * @var Border
  27. */
  28. protected $top;
  29. /**
  30. * Bottom.
  31. *
  32. * @var Border
  33. */
  34. protected $bottom;
  35. /**
  36. * Diagonal.
  37. *
  38. * @var Border
  39. */
  40. protected $diagonal;
  41. /**
  42. * DiagonalDirection.
  43. *
  44. * @var int
  45. */
  46. protected $diagonalDirection;
  47. /**
  48. * All borders pseudo-border. Only applies to supervisor.
  49. *
  50. * @var Border
  51. */
  52. protected $allBorders;
  53. /**
  54. * Outline pseudo-border. Only applies to supervisor.
  55. *
  56. * @var Border
  57. */
  58. protected $outline;
  59. /**
  60. * Inside pseudo-border. Only applies to supervisor.
  61. *
  62. * @var Border
  63. */
  64. protected $inside;
  65. /**
  66. * Vertical pseudo-border. Only applies to supervisor.
  67. *
  68. * @var Border
  69. */
  70. protected $vertical;
  71. /**
  72. * Horizontal pseudo-border. Only applies to supervisor.
  73. *
  74. * @var Border
  75. */
  76. protected $horizontal;
  77. /**
  78. * Create a new Borders.
  79. *
  80. * @param bool $isSupervisor Flag indicating if this is a supervisor or not
  81. * Leave this value at default unless you understand exactly what
  82. * its ramifications are
  83. * @param bool $isConditional Flag indicating if this is a conditional style or not
  84. * Leave this value at default unless you understand exactly what
  85. * its ramifications are
  86. */
  87. public function __construct($isSupervisor = false, $isConditional = false)
  88. {
  89. // Supervisor?
  90. parent::__construct($isSupervisor);
  91. // Initialise values
  92. $this->left = new Border($isSupervisor, $isConditional);
  93. $this->right = new Border($isSupervisor, $isConditional);
  94. $this->top = new Border($isSupervisor, $isConditional);
  95. $this->bottom = new Border($isSupervisor, $isConditional);
  96. $this->diagonal = new Border($isSupervisor, $isConditional);
  97. $this->diagonalDirection = self::DIAGONAL_NONE;
  98. // Specially for supervisor
  99. if ($isSupervisor) {
  100. // Initialize pseudo-borders
  101. $this->allBorders = new Border(true);
  102. $this->outline = new Border(true);
  103. $this->inside = new Border(true);
  104. $this->vertical = new Border(true);
  105. $this->horizontal = new Border(true);
  106. // bind parent if we are a supervisor
  107. $this->left->bindParent($this, 'left');
  108. $this->right->bindParent($this, 'right');
  109. $this->top->bindParent($this, 'top');
  110. $this->bottom->bindParent($this, 'bottom');
  111. $this->diagonal->bindParent($this, 'diagonal');
  112. $this->allBorders->bindParent($this, 'allBorders');
  113. $this->outline->bindParent($this, 'outline');
  114. $this->inside->bindParent($this, 'inside');
  115. $this->vertical->bindParent($this, 'vertical');
  116. $this->horizontal->bindParent($this, 'horizontal');
  117. }
  118. }
  119. /**
  120. * Get the shared style component for the currently active cell in currently active sheet.
  121. * Only used for style supervisor.
  122. *
  123. * @return Borders
  124. */
  125. public function getSharedComponent()
  126. {
  127. return $this->parent->getSharedComponent()->getBorders();
  128. }
  129. /**
  130. * Build style array from subcomponents.
  131. *
  132. * @param array $array
  133. *
  134. * @return array
  135. */
  136. public function getStyleArray($array)
  137. {
  138. return ['borders' => $array];
  139. }
  140. /**
  141. * Apply styles from array.
  142. *
  143. * <code>
  144. * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
  145. * [
  146. * 'bottom' => [
  147. * 'borderStyle' => Border::BORDER_DASHDOT,
  148. * 'color' => [
  149. * 'rgb' => '808080'
  150. * ]
  151. * ],
  152. * 'top' => [
  153. * 'borderStyle' => Border::BORDER_DASHDOT,
  154. * 'color' => [
  155. * 'rgb' => '808080'
  156. * ]
  157. * ]
  158. * ]
  159. * );
  160. * </code>
  161. *
  162. * <code>
  163. * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
  164. * [
  165. * 'allBorders' => [
  166. * 'borderStyle' => Border::BORDER_DASHDOT,
  167. * 'color' => [
  168. * 'rgb' => '808080'
  169. * ]
  170. * ]
  171. * ]
  172. * );
  173. * </code>
  174. *
  175. * @param array $pStyles Array containing style information
  176. *
  177. * @return $this
  178. */
  179. public function applyFromArray(array $pStyles)
  180. {
  181. if ($this->isSupervisor) {
  182. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
  183. } else {
  184. if (isset($pStyles['left'])) {
  185. $this->getLeft()->applyFromArray($pStyles['left']);
  186. }
  187. if (isset($pStyles['right'])) {
  188. $this->getRight()->applyFromArray($pStyles['right']);
  189. }
  190. if (isset($pStyles['top'])) {
  191. $this->getTop()->applyFromArray($pStyles['top']);
  192. }
  193. if (isset($pStyles['bottom'])) {
  194. $this->getBottom()->applyFromArray($pStyles['bottom']);
  195. }
  196. if (isset($pStyles['diagonal'])) {
  197. $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
  198. }
  199. if (isset($pStyles['diagonalDirection'])) {
  200. $this->setDiagonalDirection($pStyles['diagonalDirection']);
  201. }
  202. if (isset($pStyles['allBorders'])) {
  203. $this->getLeft()->applyFromArray($pStyles['allBorders']);
  204. $this->getRight()->applyFromArray($pStyles['allBorders']);
  205. $this->getTop()->applyFromArray($pStyles['allBorders']);
  206. $this->getBottom()->applyFromArray($pStyles['allBorders']);
  207. }
  208. }
  209. return $this;
  210. }
  211. /**
  212. * Get Left.
  213. *
  214. * @return Border
  215. */
  216. public function getLeft()
  217. {
  218. return $this->left;
  219. }
  220. /**
  221. * Get Right.
  222. *
  223. * @return Border
  224. */
  225. public function getRight()
  226. {
  227. return $this->right;
  228. }
  229. /**
  230. * Get Top.
  231. *
  232. * @return Border
  233. */
  234. public function getTop()
  235. {
  236. return $this->top;
  237. }
  238. /**
  239. * Get Bottom.
  240. *
  241. * @return Border
  242. */
  243. public function getBottom()
  244. {
  245. return $this->bottom;
  246. }
  247. /**
  248. * Get Diagonal.
  249. *
  250. * @return Border
  251. */
  252. public function getDiagonal()
  253. {
  254. return $this->diagonal;
  255. }
  256. /**
  257. * Get AllBorders (pseudo-border). Only applies to supervisor.
  258. *
  259. * @return Border
  260. */
  261. public function getAllBorders()
  262. {
  263. if (!$this->isSupervisor) {
  264. throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
  265. }
  266. return $this->allBorders;
  267. }
  268. /**
  269. * Get Outline (pseudo-border). Only applies to supervisor.
  270. *
  271. * @return Border
  272. */
  273. public function getOutline()
  274. {
  275. if (!$this->isSupervisor) {
  276. throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
  277. }
  278. return $this->outline;
  279. }
  280. /**
  281. * Get Inside (pseudo-border). Only applies to supervisor.
  282. *
  283. * @return Border
  284. */
  285. public function getInside()
  286. {
  287. if (!$this->isSupervisor) {
  288. throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
  289. }
  290. return $this->inside;
  291. }
  292. /**
  293. * Get Vertical (pseudo-border). Only applies to supervisor.
  294. *
  295. * @return Border
  296. */
  297. public function getVertical()
  298. {
  299. if (!$this->isSupervisor) {
  300. throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
  301. }
  302. return $this->vertical;
  303. }
  304. /**
  305. * Get Horizontal (pseudo-border). Only applies to supervisor.
  306. *
  307. * @return Border
  308. */
  309. public function getHorizontal()
  310. {
  311. if (!$this->isSupervisor) {
  312. throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
  313. }
  314. return $this->horizontal;
  315. }
  316. /**
  317. * Get DiagonalDirection.
  318. *
  319. * @return int
  320. */
  321. public function getDiagonalDirection()
  322. {
  323. if ($this->isSupervisor) {
  324. return $this->getSharedComponent()->getDiagonalDirection();
  325. }
  326. return $this->diagonalDirection;
  327. }
  328. /**
  329. * Set DiagonalDirection.
  330. *
  331. * @param int $pValue see self::DIAGONAL_*
  332. *
  333. * @return $this
  334. */
  335. public function setDiagonalDirection($pValue)
  336. {
  337. if ($pValue == '') {
  338. $pValue = self::DIAGONAL_NONE;
  339. }
  340. if ($this->isSupervisor) {
  341. $styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]);
  342. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  343. } else {
  344. $this->diagonalDirection = $pValue;
  345. }
  346. return $this;
  347. }
  348. /**
  349. * Get hash code.
  350. *
  351. * @return string Hash code
  352. */
  353. public function getHashCode()
  354. {
  355. if ($this->isSupervisor) {
  356. return $this->getSharedComponent()->getHashcode();
  357. }
  358. return md5(
  359. $this->getLeft()->getHashCode() .
  360. $this->getRight()->getHashCode() .
  361. $this->getTop()->getHashCode() .
  362. $this->getBottom()->getHashCode() .
  363. $this->getDiagonal()->getHashCode() .
  364. $this->getDiagonalDirection() .
  365. __CLASS__
  366. );
  367. }
  368. }