@@ -71,6 +71,7 @@ class course {
7171 * @param bool $enabled whether the course is enabled
7272 */
7373 public function __construct (int $ id , int $ courseid , int $ userid , string $ shortname , string $ color , bool $ enabled ) {
74+ // TODO: private constructor, remove checks, separate public function with checks.
7475 $ this ->id = $ id ;
7576 $ this ->courseid = $ courseid ;
7677 $ this ->userid = $ userid ;
@@ -110,7 +111,7 @@ public function set_fresh(int $id) {
110111 */
111112 public function set_color (string $ color ) {
112113 if ($ color [0 ] !== '# ' ) {
113- throw new \coding_exception (" incorrect color format - must be either #RGB or #RRGGBB, got \"{ $ color}\" instead " );
114+ throw new \coding_exception (get_string ( ' err_color_wrongformat ' , ' local_lbplanner ' , $ color) );
114115 }
115116 $ len = strlen ($ color );
116117 if ($ len === 4 ) {
@@ -122,11 +123,11 @@ public function set_color(string $color) {
122123 // Format #RRGGBB.
123124 $ rrggbb = $ color ;
124125 } else {
125- throw new \coding_exception (" incorrect color format - got incorrect length of { $ len}" );
126+ throw new \coding_exception (get_string ( ' err_color_wronglength ' , ' local_lbplanner ' , $ len) );
126127 }
127128 $ rrggbb = strtoupper ($ rrggbb );
128129 if (preg_match ('/^#[1-9A-F]{6}$/ ' , $ rrggbb ) === false ) {
129- throw new \coding_exception (" incorrect color format - found non-hexadecimal character in color \"{ $ color}\"" );
130+ throw new \coding_exception (get_string ( ' err_color_nonhexadecimal ' , ' local_lbplanner ' , $ color) );
130131 }
131132 $ this ->color = $ rrggbb ;
132133 }
@@ -139,7 +140,7 @@ public function set_color(string $color) {
139140 public function set_shortname (string $ shortname ) {
140141 $ length = strlen ($ shortname );
141142 if ($ length > 5 || $ length < 0 ) {
142- throw new \moodle_exception (" shortname length must be <=5 and >0, but is { $ length} instead " );
143+ throw new \moodle_exception (get_string ( ' err_course_shortnamelength ' , ' local_lbplanner ' , $ length) );
143144 }
144145 $ this ->shortname = $ shortname ;
145146 }
@@ -173,7 +174,7 @@ public static function prepare_shortname(string $shortname): string {
173174 */
174175 public function set_mdlcourse (\stdClass $ mdlcourse ): void {
175176 if ($ this ->mdlcourse !== null ) {
176- throw new \coding_exception (' tried to set cached mdluser twice ' );
177+ throw new \coding_exception (get_string ( ' err_doublechacheset ' , ' local_lbplanner ' , ' mdlcourse ' ) );
177178 }
178179 $ this ->mdlcourse = $ mdlcourse ;
179180 }
0 commit comments