diff --git "a/class-wb\\DataValueGlobeCoordinate.php" "b/class-wb\\DataValueGlobeCoordinate.php" index 5c56d38..a76414e 100644 --- "a/class-wb\\DataValueGlobeCoordinate.php" +++ "b/class-wb\\DataValueGlobeCoordinate.php" @@ -1,46 +1,46 @@ . # Wikibase DataValue -namespace wb\DataValue; +namespace wb; /** * A DataValue for a globe coordinate. */ -class GlobeCoordinate extends DataValue { +class DataValueGlobeCoordinate extends DataValue { /** * @param $latitude float * @param $longitude float + * @param $precision float * @param $altitude float - * @param $precision string * @param $globe string */ - public function __construct( $latitude, $longitude, $altitude = null, $precision = null, $globe = null ) { + public function __construct( $latitude, $longitude, $precision, $altitude = null, $globe = null ) { if( null === $globe ) { $globe = 'Q2'; } - parent::__construct( wb\DataType:GLOBE_COORDINATE , [ + parent::__construct( DataType::GLOBE_COORDINATE, [ 'latitude' => $latitude, 'longitude' => $longitude, - 'altitude' => $altitude, 'precision' => $precision, + 'altitude' => $altitude, 'globe' => "http://www.wikidata.org/entity/$globe" ] ); } } diff --git "a/class-wb\\DataValueTime.php" "b/class-wb\\DataValueTime.php" new file mode 100644 index 0000000..84bda23 --- /dev/null +++ "b/class-wb\\DataValueTime.php" @@ -0,0 +1,65 @@ +. + +# Wikibase +namespace wb; + +/** + * A DataValue for a time. + */ +class DataValueTime extends DataValue { + + const PRECISION_YEARS = 9; + const PRECISION_MONTHS = 10; + const PRECISION_DAYS = 11; + + /** + * @param $time string example "+1539-00-00T00:00:00Z" + * @param $precision int + * 0: 1 Gigayear + * 1: 100 Megayears + * 2: 10 Megayears + * 3: Megayear + * 4: 100 Kiloyears + * 5: 10 Kiloyears + * 6: Kiloyear + * 7: 100 years + * 8: 10 years + * 9: years + * 10: months + * 11: days + * @param $args array example: + * timezone: 0, + * before: 0, + * after: 0, + * precision: 9, + * calendarmodel: "Q1985786" + * @see https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON + */ + public function __construct( $time, $precision, $args = [] ) { + + $args = array_replace( [ + 'time' => $time, + 'precision' => $precision, + 'calendarmodel' => 'Q1985786', + ], $args ); + + $args['calendarmodel'] = "http://www.wikidata.org/entity/{$args['calendarmodel']}"; + + parent::__construct( DataType::TIME, $args ); + } +} diff --git "a/class-wb\\SnakGlobeCoordinate.php" "b/class-wb\\SnakGlobeCoordinate.php" index 7a6c952..5752a31 100644 --- "a/class-wb\\SnakGlobeCoordinate.php" +++ "b/class-wb\\SnakGlobeCoordinate.php" @@ -1,41 +1,41 @@ . # Wikibase namespace wb; /** * A Snak for a Wikibase global coordinate. * * @see https://www.wikidata.org/wiki/Special:ListDatatypes */ class SnakGlobeCoordinate extends Snak { /** * @param $property Wikidata property as 'P123' * @param $latitude float * @param $longitude float + * @param $precision float * @param $altitude float - * @param $precision string * @param $globe string */ - public function __construct( $property, $latitude, $longitude, $altitude = null, $precision = null, $globe = null ) { - return parent::__construct( 'globecoordinate', $property, - new DataValueGlobeCoordinate( $latitude, $longitude, $altitude, $precision, $globe ) + public function __construct( $property, $latitude, $longitude, $precision, $altitude = null, $globe = null ) { + return parent::__construct( 'value', $property, 'globe-coordinate', + new DataValueGlobeCoordinate( $latitude, $longitude, $precision, $altitude, $globe ) ); } } diff --git "a/class-wb\\SnakGlobeCoordinate.php" "b/class-wb\\SnakTime.php" similarity index 50% copy from "class-wb\\SnakGlobeCoordinate.php" copy to "class-wb\\SnakTime.php" index 7a6c952..30f1236 100644 --- "a/class-wb\\SnakGlobeCoordinate.php" +++ "b/class-wb\\SnakTime.php" @@ -1,41 +1,55 @@ . # Wikibase namespace wb; /** - * A Snak for a Wikibase global coordinate. - * - * @see https://www.wikidata.org/wiki/Special:ListDatatypes + * A Snak for a string. */ -class SnakGlobeCoordinate extends Snak { +class SnakTime extends Snak { /** - * @param $property Wikidata property as 'P123' - * @param $latitude float - * @param $longitude float - * @param $altitude float - * @param $precision string - * @param $globe string + * @param $property string Property as 'P123' + * @param $time string example "+1539-00-00T00:00:00Z" + * @param $precision int + * 0: 1 Gigayear + * 1: 100 Megayears + * 2: 10 Megayears + * 3: Megayear + * 4: 100 Kiloyears + * 5: 10 Kiloyears + * 6: Kiloyear + * 7: 100 years + * 8: 10 years + * 9: years + * 10: months + * 11: days + * @param $args array example: + * timezone: 0, + * before: 0, + * after: 0, + * precision: 9, + * calendarmodel: "Q1985786" + * @see https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON */ - public function __construct( $property, $latitude, $longitude, $altitude = null, $precision = null, $globe = null ) { - return parent::__construct( 'globecoordinate', $property, - new DataValueGlobeCoordinate( $latitude, $longitude, $altitude, $precision, $globe ) + public function __construct( $property, $time, $precision, $args = [] ) { + return parent::__construct( 'time', $property, DataType::QUANTITY, + new DataValueTime( $time, $precision, $args ) ); } } diff --git "a/class-wb\\StatementGlobeCoordinate.php" "b/class-wb\\StatementGlobeCoordinate.php" index 494cb69..62117c2 100644 --- "a/class-wb\\StatementGlobeCoordinate.php" +++ "b/class-wb\\StatementGlobeCoordinate.php" @@ -1,41 +1,49 @@ . # Wikibase namespace wb; /** * A StatementItem is a Statement that contains a SnakItem. */ class StatementGlobeCoordinate extends Statement { /** * @param $property Wikidata property as 'P123' - * @param $item Wikidata item as 'Q1' + * @param $latitude float + * @param $longitude float + * @param $precision float + * @param $altitude float + * @param $globe string */ - public function __construct( $property, $latitude, $longitude, $altitude = null, $precision = null, $globe = null ) { - parent::__construct( new SnakGlobeCoordinate( $property, $latitude, $longitude, $altitude, $precision, $globe ) ); + public function __construct( $property, $latitude, $longitude, $precision, $altitude = null, $globe = null ) { + parent::__construct( new SnakGlobeCoordinate( $property, $latitude, $longitude, $precision, $altitude, $globe ) ); } /** * @param $property Wikidata property as 'P123' - * @param $item Wikidata item as 'Q1' + * @param $latitude float + * @param $longitude float + * @param $precision float + * @param $altitude float + * @param $globe string */ - public static function factory( $property, $item ) { - return new self( $property, $item ); + public static function factory( $property, $latitude, $longitude, $precision, $altitude = null, $globe = null ) { + return new self( $property, $latitude, $longitude, $precision, $altitude, $globe ); } } diff --git "a/class-wb\\StatementTime.php" "b/class-wb\\StatementTime.php" new file mode 100644 index 0000000..698997d --- /dev/null +++ "b/class-wb\\StatementTime.php" @@ -0,0 +1,81 @@ +. + +# Wikibase +namespace wb; + +/** + * A StatementString is a Statement that contains a SnakString. + */ +class StatementTime extends Statement { + + /** + * @param $property string Property as 'P123' + * @param $time string example "+1539-00-00T00:00:00Z" + * @param $precision int + * 0: 1 Gigayear + * 1: 100 Megayears + * 2: 10 Megayears + * 3: Megayear + * 4: 100 Kiloyears + * 5: 10 Kiloyears + * 6: Kiloyear + * 7: 100 years + * 8: 10 years + * 9: years + * 10: months + * 11: days + * @param $args array example: + * timezone: 0, + * before: 0, + * after: 0, + * precision: 9, + * calendarmodel: "Q1985786" + * @see https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON + */ + public function __construct( $property, $time, $precision, $args = [] ) { + parent::__construct( new SnakTime( $property, $time, $precision, $args ) ); + } + + /** + * @param $property string Property as 'P123' + * @param $time string example "+1539-00-00T00:00:00Z" + * @param $precision int + * 0: 1 Gigayear + * 1: 100 Megayears + * 2: 10 Megayears + * 3: Megayear + * 4: 100 Kiloyears + * 5: 10 Kiloyears + * 6: Kiloyear + * 7: 100 years + * 8: 10 years + * 9: years + * 10: months + * 11: days + * @param $args array example: + * timezone: 0, + * before: 0, + * after: 0, + * precision: 9, + * calendarmodel: "Q1985786" + * @see https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON + */ + public static function factory( $property, $time, $precision, $args = [] ) { + return new self( $property, $time, $precision, $args ); + } +}