3
1

CustomColorModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php namespace Kanboard\Plugin\OMIProjectBranding\Model;
  2. use Kanboard\Model\ColorModel;
  3. class CustomColorModel extends ColorModel {
  4. /**
  5. * CustomColorModel Model
  6. * Get all available colors.
  7. *
  8. * @access public
  9. * @param bool $prepend
  10. * @return array
  11. * @author Dwayne @ OMI NZ
  12. */
  13. public function getList($prepend = false) {
  14. $colors = parent::getList($prepend);
  15. $colorFile = DATA_DIR . DIRECTORY_SEPARATOR . "OMIProjectBrandingColours.txt";// Define the path to your color file
  16. if (! file_exists($colorFile)) {// Check if the file exists, if not create it
  17. $defaultContent = "Aqua=aqua\nBeige=beige\nBlack=black\nDark Blue=darkblue\nFuchsia=fuchsia\nGray=gray\nIndigo=indigo\nMaroon=maroon\nNavy=navy\nOlive=olive\nSlategrey=slategrey\nWhite=white\nWhitesmoke=whitesmoke";
  18. file_put_contents($colorFile, $defaultContent);
  19. }
  20. $handle = fopen($colorFile, "r");// read from $colorFile
  21. if ($handle) {
  22. while (($line = fgets($handle)) !== false) {
  23. $line = trim($line);
  24. if (!empty($line)) {
  25. list($name, $colorCode) = explode("=", $line, 2);// Split the line into name and color code
  26. $colors[trim($colorCode)] = t(trim($name));// Add the color to the list
  27. }
  28. }
  29. fclose($handle);
  30. }
  31. return $colors;
  32. }
  33. }
  34. #-
  35. #plugins/OMIProjectBranding/Model/CustomColorModel.php