1: <?php
2: /*
3: * Copyright (c) 2016 Geraldo B. Landre
4: *
5: * See the file LICENSE for copying permission.
6: */
7: namespace pgn\tags;
8:
9: use utils\Parser;
10:
11: /**
12: * Description of Round:
13: * The Round tag value gives the playing round for the game. In a match
14: * competition, this value is the number of the game played. If the use of a
15: * round number is inappropriate, then the field should be a single hyphen
16: * character. If the round is unknown, a single question mark should appear as
17: * the tag value.
18: *
19: * Some organizers employ unusual round designations and have multipart playing
20: * rounds and sometimes even have conditional rounds. In these cases, a multipart
21: * round identifier can be made from a sequence of integer round numbers separated
22: * by periods. The leftmost integer represents the most significant round and
23: * succeeding integers represent round numbers in descending hierarchical order.
24: *
25: * Examples:
26: *
27: * [Round "1"]
28: *
29: * [Round "3.1"]
30: *
31: * [Round "4.1.2"]
32: * @see pgn_standard.txt
33: * @author Geraldo
34: */
35: class Round extends Tag {
36:
37: public function getName() {
38: $parsed = Parser::parseClassName(get_class());
39: return $parsed['className'];
40: }
41:
42: /**
43: * @assert("1") === true
44: * @assert(1) === true
45: * @assert("3.1") === true
46: * @assert(3.1) === true
47: * @assert("4.1.2") === true
48: * @assert("-") === true
49: * @assert("?") === true
50: * @assert(NULL) === false
51: * @assert("A") === false
52: * @assert("asdf") === false
53: * @assert("*") === false
54: * @assert("????.??.??") === false
55: * @param string $data
56: * @return boolean
57: */
58: public function validate($data) {
59:
60: if(!parent::validate($data)) {
61: return false;
62: }
63:
64: if($data === '?') {
65: return true;
66: }
67:
68: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
69: }
70:
71: /**
72: *
73: * @return string Valid Regular Expression Pattern for PGN Rounds
74: */
75: static public function validPattern() {
76: return "[\-]{1}|\d(\.\d)*";
77: }
78: }
79: