|
1 | 1 | <?php namespace Notion; |
2 | 2 |
|
3 | | -class RichText extends PropertyBase |
| 3 | +class RichText |
4 | 4 | { |
| 5 | + public $plain_text; |
| 6 | + |
| 7 | + public $href; |
| 8 | + |
| 9 | + public $annotations = [ |
| 10 | + 'color' => 'default', |
| 11 | + ]; |
| 12 | + |
| 13 | + public $type; |
| 14 | + |
| 15 | + public $typeConfiguration = []; |
| 16 | + |
| 17 | + public static $colorOptions = [ |
| 18 | + 'default', |
| 19 | + 'gray', |
| 20 | + 'brown', |
| 21 | + 'orange', |
| 22 | + 'yellow', |
| 23 | + 'green', |
| 24 | + 'blue', |
| 25 | + 'purple', |
| 26 | + 'pink', |
| 27 | + 'red', |
| 28 | + 'gray_background', |
| 29 | + 'brown_background', |
| 30 | + 'orange_background', |
| 31 | + 'yellow_background', |
| 32 | + 'green_background', |
| 33 | + 'blue_background', |
| 34 | + 'purple_background', |
| 35 | + 'pink_background', |
| 36 | + 'red_background', |
| 37 | + ]; |
| 38 | + |
| 39 | + public function __construct($config = null) |
| 40 | + { |
| 41 | + $this->init($config); |
| 42 | + } |
| 43 | + |
| 44 | + public function init($config) |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + public function get() |
| 49 | + { |
| 50 | + return [ |
| 51 | + 'annotations' => $this->annotations, |
| 52 | + $this->type => $this->typeConfiguration, |
| 53 | + ]; |
| 54 | + } |
| 55 | + |
| 56 | + public function text($content, $link = null): self |
| 57 | + { |
| 58 | + $this->type = 'text'; |
| 59 | + $this->typeConfiguration['content'] = $content; |
| 60 | + $this->typeConfiguration['type'] = 'text'; |
| 61 | + |
| 62 | + if ($link) { |
| 63 | + $this->typeConfiguration['link'] = [ |
| 64 | + 'type' => 'url', |
| 65 | + 'url' => $link, |
| 66 | + ]; |
| 67 | + } |
| 68 | + |
| 69 | + return $this; |
| 70 | + } |
| 71 | + |
| 72 | + public function mention($type, $config = null): self |
| 73 | + { |
| 74 | + $this->type = 'mention'; |
| 75 | + $this->typeConfiguration['type'] = $type; |
| 76 | + |
| 77 | + if ($type === 'user') { |
| 78 | + $this->typeConfiguration['user'] = [ |
| 79 | + 'object' => 'user', |
| 80 | + 'id' => $config, |
| 81 | + ]; |
| 82 | + } |
| 83 | + |
| 84 | + if ($type === 'page') { |
| 85 | + $this->typeConfiguration['page'] = [ |
| 86 | + 'id' => $config, |
| 87 | + ]; |
| 88 | + } |
| 89 | + |
| 90 | + if ($type === 'database') { |
| 91 | + $this->typeConfiguration['database'] = [ |
| 92 | + 'id' => $config, |
| 93 | + ]; |
| 94 | + } |
| 95 | + |
| 96 | + if ($type === 'date') { |
| 97 | + // Todo: Handle date |
| 98 | + } |
| 99 | + |
| 100 | + return $this; |
| 101 | + } |
| 102 | + |
| 103 | + public function equation($expression): self |
| 104 | + { |
| 105 | + $this->type = 'equation'; |
| 106 | + $this->typeConfiguration['expression'] = $expression; |
| 107 | + return $this; |
| 108 | + } |
| 109 | + |
| 110 | + public function bold($setting = true): self |
| 111 | + { |
| 112 | + $this->annotations['bold'] = $setting; |
| 113 | + return $this; |
| 114 | + } |
| 115 | + |
| 116 | + public function italic($setting = true): self |
| 117 | + { |
| 118 | + $this->annotations['italic'] = $setting; |
| 119 | + return $this; |
| 120 | + } |
| 121 | + |
| 122 | + public function strikethrough($setting = true): self |
| 123 | + { |
| 124 | + $this->annotations['strikethrough'] = $setting; |
| 125 | + return $this; |
| 126 | + } |
| 127 | + |
| 128 | + public function underline($setting = true): self |
| 129 | + { |
| 130 | + $this->annotations['underline'] = $setting; |
| 131 | + return $this; |
| 132 | + } |
| 133 | + |
| 134 | + public function code($setting = true): self |
| 135 | + { |
| 136 | + $this->annotations['code'] = $setting; |
| 137 | + return $this; |
| 138 | + } |
| 139 | + |
| 140 | + public function color($setting = 'default'): self |
| 141 | + { |
| 142 | + $this->annotations['color'] = $setting; |
| 143 | + return $this; |
| 144 | + } |
5 | 145 | } |
0 commit comments