@@ -3,73 +3,73 @@ |
||
| 3 | 3 | |
| 4 | 4 | class FactsFactory implements FactsFactoryInterface { |
| 5 | 5 | |
| 6 | - protected $profile; |
|
| 7 | - protected $tripleCount =0; |
|
| 8 | - protected $errors = array(); |
|
| 6 | + protected $profile; |
|
| 7 | + protected $tripleCount =0; |
|
| 8 | + protected $errors = array(); |
|
| 9 | 9 | |
| 10 | 10 | |
| 11 | - public function __construct( array $profile ) |
|
| 12 | - { |
|
| 13 | - assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
|
| 14 | - assert(isset($profile['datamapper']) && is_callable($profile['datamapper'])); |
|
| 15 | - assert(isset($profile['options']) && is_array($profile['options'])); |
|
| 16 | - $this->profile = $profile; |
|
| 17 | - } |
|
| 11 | + public function __construct( array $profile ) |
|
| 12 | + { |
|
| 13 | + assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
|
| 14 | + assert(isset($profile['datamapper']) && is_callable($profile['datamapper'])); |
|
| 15 | + assert(isset($profile['options']) && is_array($profile['options'])); |
|
| 16 | + $this->profile = $profile; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * two level filter array |
|
| 22 | - */ |
|
| 23 | - public function removeEmpty( array $data ) |
|
| 24 | - { |
|
| 25 | - $a = array(); |
|
| 26 | - foreach ($data as $key => $value) { |
|
| 27 | - $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 28 | - } |
|
| 29 | - return array_filter($a); |
|
| 30 | - } |
|
| 20 | + /** |
|
| 21 | + * two level filter array |
|
| 22 | + */ |
|
| 23 | + public function removeEmpty( array $data ) |
|
| 24 | + { |
|
| 25 | + $a = array(); |
|
| 26 | + foreach ($data as $key => $value) { |
|
| 27 | + $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 28 | + } |
|
| 29 | + return array_filter($a); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function factualize( array $rawData ) |
|
| 34 | - { |
|
| 35 | - $datamapper = $this->profile['datamapper']; |
|
| 36 | - $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 37 | - $data =$this->removeEmpty($datamapper($rawData)); |
|
| 38 | - return new $class($data,$this->profile['options']); |
|
| 39 | - } |
|
| 33 | + public function factualize( array $rawData ) |
|
| 34 | + { |
|
| 35 | + $datamapper = $this->profile['datamapper']; |
|
| 36 | + $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 37 | + $data =$this->removeEmpty($datamapper($rawData)); |
|
| 38 | + return new $class($data,$this->profile['options']); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - public function generateLinkedDataHeader() |
|
| 43 | - { |
|
| 44 | - $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 45 | - $model = new $class(); |
|
| 46 | - return $model->getTurtleHeader(); |
|
| 47 | - } |
|
| 42 | + public function generateLinkedDataHeader() |
|
| 43 | + { |
|
| 44 | + $class = '\BOTK\Model\\'.$this->profile['model']; |
|
| 45 | + $model = new $class(); |
|
| 46 | + return $model->getTurtleHeader(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function generateLinkedDataFooter() |
|
| 51 | - { |
|
| 52 | - $errorCount = count($this->errors); |
|
| 53 | - return "\n#\n# Generated {$this->tripleCount} triples and $errorCount errors\n#\n"; |
|
| 54 | - } |
|
| 50 | + public function generateLinkedDataFooter() |
|
| 51 | + { |
|
| 52 | + $errorCount = count($this->errors); |
|
| 53 | + return "\n#\n# Generated {$this->tripleCount} triples and $errorCount errors\n#\n"; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function addToTripleCounter( $triplesCount) |
|
| 57 | - { |
|
| 58 | - $this->tripleCount += intval($triplesCount); |
|
| 59 | - return $this; |
|
| 60 | - } |
|
| 56 | + public function addToTripleCounter( $triplesCount) |
|
| 57 | + { |
|
| 58 | + $this->tripleCount += intval($triplesCount); |
|
| 59 | + return $this; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - public function getTripleCount() |
|
| 64 | - { |
|
| 65 | - return $this->tripleCount; |
|
| 66 | - } |
|
| 63 | + public function getTripleCount() |
|
| 64 | + { |
|
| 65 | + return $this->tripleCount; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - public function addError($error) |
|
| 70 | - { |
|
| 71 | - $this->errors[]= (string) $error; |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 69 | + public function addError($error) |
|
| 70 | + { |
|
| 71 | + $this->errors[]= (string) $error; |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | \ No newline at end of file |
@@ -4,11 +4,11 @@ discard block |
||
| 4 | 4 | class FactsFactory implements FactsFactoryInterface { |
| 5 | 5 | |
| 6 | 6 | protected $profile; |
| 7 | - protected $tripleCount =0; |
|
| 7 | + protected $tripleCount = 0; |
|
| 8 | 8 | protected $errors = array(); |
| 9 | 9 | |
| 10 | 10 | |
| 11 | - public function __construct( array $profile ) |
|
| 11 | + public function __construct(array $profile) |
|
| 12 | 12 | { |
| 13 | 13 | assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model'])); |
| 14 | 14 | assert(isset($profile['datamapper']) && is_callable($profile['datamapper'])); |
@@ -20,22 +20,22 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * two level filter array |
| 22 | 22 | */ |
| 23 | - public function removeEmpty( array $data ) |
|
| 23 | + public function removeEmpty(array $data) |
|
| 24 | 24 | { |
| 25 | 25 | $a = array(); |
| 26 | 26 | foreach ($data as $key => $value) { |
| 27 | - $a[$key] = is_array($value)?array_filter($value):$value; |
|
| 27 | + $a[$key] = is_array($value) ? array_filter($value) : $value; |
|
| 28 | 28 | } |
| 29 | 29 | return array_filter($a); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function factualize( array $rawData ) |
|
| 33 | + public function factualize(array $rawData) |
|
| 34 | 34 | { |
| 35 | 35 | $datamapper = $this->profile['datamapper']; |
| 36 | 36 | $class = '\BOTK\Model\\'.$this->profile['model']; |
| 37 | - $data =$this->removeEmpty($datamapper($rawData)); |
|
| 38 | - return new $class($data,$this->profile['options']); |
|
| 37 | + $data = $this->removeEmpty($datamapper($rawData)); |
|
| 38 | + return new $class($data, $this->profile['options']); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | return "\n#\n# Generated {$this->tripleCount} triples and $errorCount errors\n#\n"; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function addToTripleCounter( $triplesCount) |
|
| 56 | + public function addToTripleCounter($triplesCount) |
|
| 57 | 57 | { |
| 58 | 58 | $this->tripleCount += intval($triplesCount); |
| 59 | 59 | return $this; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function addError($error) |
| 70 | 70 | { |
| 71 | - $this->errors[]= (string) $error; |
|
| 71 | + $this->errors[] = (string) $error; |
|
| 72 | 72 | return $this; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -3,14 +3,14 @@ |
||
| 3 | 3 | |
| 4 | 4 | Interface ModelInterface |
| 5 | 5 | { |
| 6 | - public function getUri(); |
|
| 7 | - public function getOptions(); |
|
| 8 | - public function getVocabulary(); |
|
| 9 | - public function setVocabulary($prefix,$ns); |
|
| 10 | - public function unsetVocabulary($prefix); |
|
| 11 | - public function asArray(); |
|
| 12 | - public function asTurtle(); |
|
| 13 | - public function getTurtleHeader($base=null); |
|
| 14 | - public function getTripleCount(); |
|
| 15 | - public function __toString(); |
|
| 6 | + public function getUri(); |
|
| 7 | + public function getOptions(); |
|
| 8 | + public function getVocabulary(); |
|
| 9 | + public function setVocabulary($prefix,$ns); |
|
| 10 | + public function unsetVocabulary($prefix); |
|
| 11 | + public function asArray(); |
|
| 12 | + public function asTurtle(); |
|
| 13 | + public function getTurtleHeader($base=null); |
|
| 14 | + public function getTripleCount(); |
|
| 15 | + public function __toString(); |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | public function getUri(); |
| 7 | 7 | public function getOptions(); |
| 8 | 8 | public function getVocabulary(); |
| 9 | - public function setVocabulary($prefix,$ns); |
|
| 9 | + public function setVocabulary($prefix, $ns); |
|
| 10 | 10 | public function unsetVocabulary($prefix); |
| 11 | 11 | public function asArray(); |
| 12 | 12 | public function asTurtle(); |
| 13 | - public function getTurtleHeader($base=null); |
|
| 13 | + public function getTurtleHeader($base = null); |
|
| 14 | 14 | public function getTripleCount(); |
| 15 | 15 | public function __toString(); |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -11,218 +11,218 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class LocalBusiness extends AbstractModel implements ModelInterface |
| 13 | 13 | { |
| 14 | - protected static $DEFAULT_OPTIONS = array ( |
|
| 15 | - 'businessType' => array( |
|
| 16 | - // additional types as extension of schema:LocalBusiness |
|
| 17 | - 'filter' => FILTER_DEFAULT, |
|
| 18 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 19 | - ), |
|
| 20 | - 'taxID' => array( |
|
| 21 | - 'filter' => FILTER_CALLBACK, |
|
| 22 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 23 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 24 | - ), |
|
| 25 | - 'vatID' => array( // italian rules |
|
| 26 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 27 | - 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 28 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 29 | - ), |
|
| 30 | - 'legalName' => array( |
|
| 31 | - 'filter' => FILTER_CALLBACK, |
|
| 32 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 33 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 34 | - ), |
|
| 35 | - 'businessName' => array( |
|
| 36 | - // a schema:alternateName for schema:PostalAddress |
|
| 37 | - 'filter' => FILTER_DEFAULT, |
|
| 38 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 39 | - ), |
|
| 40 | - 'addressCountry' => array( |
|
| 41 | - 'default' => 'IT', |
|
| 42 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 43 | - 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 44 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 45 | - ), |
|
| 46 | - 'addressLocality' => array( |
|
| 47 | - 'filter' => FILTER_CALLBACK, |
|
| 48 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 49 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 50 | - ), |
|
| 51 | - 'addressRegion' => array( |
|
| 52 | - 'filter' => FILTER_CALLBACK, |
|
| 53 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 54 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 55 | - ), |
|
| 56 | - 'streetAddress' => array( |
|
| 57 | - 'filter' => FILTER_CALLBACK, |
|
| 58 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 59 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 60 | - ), |
|
| 61 | - 'postalCode' => array( // italian rules |
|
| 62 | - 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 63 | - 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 64 | - 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 65 | - ), |
|
| 66 | - 'page' => array( |
|
| 67 | - 'filter' => FILTER_SANITIZE_URL, |
|
| 68 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 69 | - ), |
|
| 70 | - 'telephone' => array( |
|
| 71 | - 'filter' => FILTER_CALLBACK, |
|
| 72 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 73 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 74 | - ), |
|
| 75 | - 'faxNumber' => array( |
|
| 76 | - 'filter' => FILTER_CALLBACK, |
|
| 77 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 78 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 79 | - ), |
|
| 80 | - 'email' => array( |
|
| 81 | - 'filter' => FILTER_CALLBACK, |
|
| 82 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 83 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 84 | - ), |
|
| 85 | - 'geoDescription' => array( |
|
| 86 | - // a schema:alternateName for schema:GeoCoordinates |
|
| 87 | - 'filter' => FILTER_CALLBACK, |
|
| 88 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 89 | - 'flags' => FILTER_FORCE_ARRAY, |
|
| 90 | - ), |
|
| 91 | - 'lat' => array( |
|
| 92 | - 'filter' => FILTER_CALLBACK, |
|
| 93 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 94 | - ), |
|
| 95 | - 'long' => array( |
|
| 96 | - 'filter' => FILTER_CALLBACK, |
|
| 97 | - 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 98 | - ), |
|
| 99 | - ); |
|
| 14 | + protected static $DEFAULT_OPTIONS = array ( |
|
| 15 | + 'businessType' => array( |
|
| 16 | + // additional types as extension of schema:LocalBusiness |
|
| 17 | + 'filter' => FILTER_DEFAULT, |
|
| 18 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 19 | + ), |
|
| 20 | + 'taxID' => array( |
|
| 21 | + 'filter' => FILTER_CALLBACK, |
|
| 22 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
| 23 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 24 | + ), |
|
| 25 | + 'vatID' => array( // italian rules |
|
| 26 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 27 | + 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
| 28 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 29 | + ), |
|
| 30 | + 'legalName' => array( |
|
| 31 | + 'filter' => FILTER_CALLBACK, |
|
| 32 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 33 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 34 | + ), |
|
| 35 | + 'businessName' => array( |
|
| 36 | + // a schema:alternateName for schema:PostalAddress |
|
| 37 | + 'filter' => FILTER_DEFAULT, |
|
| 38 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 39 | + ), |
|
| 40 | + 'addressCountry' => array( |
|
| 41 | + 'default' => 'IT', |
|
| 42 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 43 | + 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
| 44 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 45 | + ), |
|
| 46 | + 'addressLocality' => array( |
|
| 47 | + 'filter' => FILTER_CALLBACK, |
|
| 48 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 49 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 50 | + ), |
|
| 51 | + 'addressRegion' => array( |
|
| 52 | + 'filter' => FILTER_CALLBACK, |
|
| 53 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 54 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 55 | + ), |
|
| 56 | + 'streetAddress' => array( |
|
| 57 | + 'filter' => FILTER_CALLBACK, |
|
| 58 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 59 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 60 | + ), |
|
| 61 | + 'postalCode' => array( // italian rules |
|
| 62 | + 'filter' => FILTER_VALIDATE_REGEXP, |
|
| 63 | + 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
| 64 | + 'flags' => FILTER_REQUIRE_SCALAR, |
|
| 65 | + ), |
|
| 66 | + 'page' => array( |
|
| 67 | + 'filter' => FILTER_SANITIZE_URL, |
|
| 68 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 69 | + ), |
|
| 70 | + 'telephone' => array( |
|
| 71 | + 'filter' => FILTER_CALLBACK, |
|
| 72 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 73 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 74 | + ), |
|
| 75 | + 'faxNumber' => array( |
|
| 76 | + 'filter' => FILTER_CALLBACK, |
|
| 77 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
| 78 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 79 | + ), |
|
| 80 | + 'email' => array( |
|
| 81 | + 'filter' => FILTER_CALLBACK, |
|
| 82 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
| 83 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 84 | + ), |
|
| 85 | + 'geoDescription' => array( |
|
| 86 | + // a schema:alternateName for schema:GeoCoordinates |
|
| 87 | + 'filter' => FILTER_CALLBACK, |
|
| 88 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
| 89 | + 'flags' => FILTER_FORCE_ARRAY, |
|
| 90 | + ), |
|
| 91 | + 'lat' => array( |
|
| 92 | + 'filter' => FILTER_CALLBACK, |
|
| 93 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 94 | + ), |
|
| 95 | + 'long' => array( |
|
| 96 | + 'filter' => FILTER_CALLBACK, |
|
| 97 | + 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
| 98 | + ), |
|
| 99 | + ); |
|
| 100 | 100 | |
| 101 | - public function __construct(array $data = array(), array $customOptions = array()) |
|
| 101 | + public function __construct(array $data = array(), array $customOptions = array()) |
|
| 102 | 102 | { |
| 103 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 104 | - parent::__construct($data, $options); |
|
| 105 | - } |
|
| 103 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 104 | + parent::__construct($data, $options); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Create a normalized address from wollowing datam properties |
|
| 109 | - * 'addressCountry', |
|
| 110 | - * 'addressLocality', |
|
| 111 | - * 'addressRegion', |
|
| 112 | - * 'streetAddress', |
|
| 113 | - * 'postalCode', |
|
| 114 | - * If data is not sufficient to create a good addess, false is returned. |
|
| 115 | - */ |
|
| 116 | - public function buildNormalizedAddress() |
|
| 117 | - { |
|
| 118 | - extract($this->data); |
|
| 107 | + /** |
|
| 108 | + * Create a normalized address from wollowing datam properties |
|
| 109 | + * 'addressCountry', |
|
| 110 | + * 'addressLocality', |
|
| 111 | + * 'addressRegion', |
|
| 112 | + * 'streetAddress', |
|
| 113 | + * 'postalCode', |
|
| 114 | + * If data is not sufficient to create a good addess, false is returned. |
|
| 115 | + */ |
|
| 116 | + public function buildNormalizedAddress() |
|
| 117 | + { |
|
| 118 | + extract($this->data); |
|
| 119 | 119 | |
| 120 | - // veryfy that at least a minimum set of information are present |
|
| 121 | - if(empty($streetAddress) || empty($addressCountry) || (empty($addressLocality) && empty($postalCode))){ |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 120 | + // veryfy that at least a minimum set of information are present |
|
| 121 | + if(empty($streetAddress) || empty($addressCountry) || (empty($addressLocality) && empty($postalCode))){ |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $geolabel = "$streetAddress ,"; |
|
| 126 | - if(!empty($postalCode)) { $geolabel.= " $postalCode";} |
|
| 127 | - if(!empty($addressLocality)) { $geolabel.= " $addressLocality"; } |
|
| 128 | - if(!empty($addressRegion)) { $geolabel.= " ($addressRegion)"; } |
|
| 129 | - $geolabel.= " - $addressCountry"; |
|
| 125 | + $geolabel = "$streetAddress ,"; |
|
| 126 | + if(!empty($postalCode)) { $geolabel.= " $postalCode";} |
|
| 127 | + if(!empty($addressLocality)) { $geolabel.= " $addressLocality"; } |
|
| 128 | + if(!empty($addressRegion)) { $geolabel.= " ($addressRegion)"; } |
|
| 129 | + $geolabel.= " - $addressCountry"; |
|
| 130 | 130 | |
| 131 | - return \BOTK\Filters::FILTER_SANITIZE_ADDRESS($geolabel); |
|
| 132 | - } |
|
| 131 | + return \BOTK\Filters::FILTER_SANITIZE_ADDRESS($geolabel); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | - public function asTurtle() |
|
| 136 | - { |
|
| 137 | - if(is_null($this->rdf)) { |
|
| 138 | - extract($this->data); |
|
| 135 | + public function asTurtle() |
|
| 136 | + { |
|
| 137 | + if(is_null($this->rdf)) { |
|
| 138 | + extract($this->data); |
|
| 139 | 139 | |
| 140 | - // create uris |
|
| 141 | - $organizationUri = $this->getUri(); |
|
| 142 | - $addressUri = $organizationUri.'_address'; |
|
| 143 | - $placeUri = $organizationUri.'_place'; |
|
| 144 | - $geoUri = ( !empty($lat) && !empty($long) )?"geo:$lat,$long":($organizationUri.'_geo'); |
|
| 140 | + // create uris |
|
| 141 | + $organizationUri = $this->getUri(); |
|
| 142 | + $addressUri = $organizationUri.'_address'; |
|
| 143 | + $placeUri = $organizationUri.'_place'; |
|
| 144 | + $geoUri = ( !empty($lat) && !empty($long) )?"geo:$lat,$long":($organizationUri.'_geo'); |
|
| 145 | 145 | |
| 146 | - // define the minimum condition to skipp the rdf generation |
|
| 147 | - $skippAddress = empty($alternateName) && |
|
| 148 | - empty($addressLocality) && |
|
| 149 | - empty($streetAddress) && |
|
| 150 | - empty($postalCode) && |
|
| 151 | - empty($page) && |
|
| 152 | - empty($telephone) && |
|
| 153 | - empty($faxNumber) && |
|
| 154 | - empty($email) |
|
| 155 | - ; |
|
| 156 | - $skippGeo = empty($geoDescription) && |
|
| 157 | - empty($addressLocality) && |
|
| 158 | - empty($streetAddress) && |
|
| 159 | - empty($lat) && |
|
| 160 | - empty($long) ; |
|
| 161 | - $skippPlace = $skippGeo && $skippAddress; |
|
| 146 | + // define the minimum condition to skipp the rdf generation |
|
| 147 | + $skippAddress = empty($alternateName) && |
|
| 148 | + empty($addressLocality) && |
|
| 149 | + empty($streetAddress) && |
|
| 150 | + empty($postalCode) && |
|
| 151 | + empty($page) && |
|
| 152 | + empty($telephone) && |
|
| 153 | + empty($faxNumber) && |
|
| 154 | + empty($email) |
|
| 155 | + ; |
|
| 156 | + $skippGeo = empty($geoDescription) && |
|
| 157 | + empty($addressLocality) && |
|
| 158 | + empty($streetAddress) && |
|
| 159 | + empty($lat) && |
|
| 160 | + empty($long) ; |
|
| 161 | + $skippPlace = $skippGeo && $skippAddress; |
|
| 162 | 162 | |
| 163 | - $skippOrganization = $skippPlace && empty($id)&& empty($vatID) && empty($taxID) && empty($legalName) ; |
|
| 163 | + $skippOrganization = $skippPlace && empty($id)&& empty($vatID) && empty($taxID) && empty($legalName) ; |
|
| 164 | 164 | |
| 165 | - // define $_ as a macro to write simple rdf |
|
| 166 | - $tc =0; |
|
| 167 | - $rdf=''; |
|
| 168 | - $_= function($format, $var) use(&$lang, &$rdf, &$tc){ |
|
| 169 | - if(!is_array($var)) { $var = (array) $var;} |
|
| 170 | - foreach((array)$var as $v){$rdf.= sprintf($format,$v,$lang);$tc++;} |
|
| 171 | - }; |
|
| 165 | + // define $_ as a macro to write simple rdf |
|
| 166 | + $tc =0; |
|
| 167 | + $rdf=''; |
|
| 168 | + $_= function($format, $var) use(&$lang, &$rdf, &$tc){ |
|
| 169 | + if(!is_array($var)) { $var = (array) $var;} |
|
| 170 | + foreach((array)$var as $v){$rdf.= sprintf($format,$v,$lang);$tc++;} |
|
| 171 | + }; |
|
| 172 | 172 | |
| 173 | - // serialize schema:Organization |
|
| 174 | - if( !$skippOrganization){ |
|
| 175 | - $_('<%s> a schema:Organization;', $organizationUri); |
|
| 176 | - !empty($id) && $_('dct:identifier "%s";', $id); |
|
| 177 | - !empty($vatID) && $_('schema:vatID "%s"@%s;', $vatID); |
|
| 178 | - !empty($taxtID) && $_('schema:taxtID "%s"@%s;', $taxID); |
|
| 179 | - !empty($legalName) && $_('schema:legalName """%s"""@%s;', $legalName); |
|
| 180 | - !$skippPlace && $_('schema:location <%s>;', $placeUri); |
|
| 181 | - $rdf.=' . '; |
|
| 182 | - } |
|
| 173 | + // serialize schema:Organization |
|
| 174 | + if( !$skippOrganization){ |
|
| 175 | + $_('<%s> a schema:Organization;', $organizationUri); |
|
| 176 | + !empty($id) && $_('dct:identifier "%s";', $id); |
|
| 177 | + !empty($vatID) && $_('schema:vatID "%s"@%s;', $vatID); |
|
| 178 | + !empty($taxtID) && $_('schema:taxtID "%s"@%s;', $taxID); |
|
| 179 | + !empty($legalName) && $_('schema:legalName """%s"""@%s;', $legalName); |
|
| 180 | + !$skippPlace && $_('schema:location <%s>;', $placeUri); |
|
| 181 | + $rdf.=' . '; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - // serialize schema:PostalAddress |
|
| 185 | - if( !$skippAddress){ |
|
| 186 | - $_('<%s> a schema:PostalAddress;', $addressUri); |
|
| 187 | - !empty($businessName) && $_('schema:alternateName """%s"""@%s;', $businessName); |
|
| 188 | - !empty($streetAddress) && $_('schema:streetAddress """%s"""@%s;', $streetAddress); |
|
| 189 | - !empty($postalCode) && $_('schema:postalCode "%s"@%s;', $postalCode); |
|
| 190 | - !empty($addressLocality) && $_('schema:addressLocality """%s"""@%s;', $addressLocality); |
|
| 191 | - !empty($addressRegion) && $_('schema:addressRegion "%s"@%s;', $addressRegion); |
|
| 192 | - !empty($addressCountry) && $_('schema:addressCountry "%s";', $addressCountry); |
|
| 193 | - !empty($telephone) && $_('schema:telephone "%s"@%s;', $telephone); |
|
| 194 | - !empty($faxNumber) && $_('schema:faxNumber "%s"@%s;', $faxNumber); |
|
| 195 | - !empty($page) && $_('schema:page <%s>;', $page); |
|
| 196 | - !empty($email) && $_('schema:email "%s";', $email); |
|
| 197 | - $rdf.=' . '; |
|
| 198 | - } |
|
| 184 | + // serialize schema:PostalAddress |
|
| 185 | + if( !$skippAddress){ |
|
| 186 | + $_('<%s> a schema:PostalAddress;', $addressUri); |
|
| 187 | + !empty($businessName) && $_('schema:alternateName """%s"""@%s;', $businessName); |
|
| 188 | + !empty($streetAddress) && $_('schema:streetAddress """%s"""@%s;', $streetAddress); |
|
| 189 | + !empty($postalCode) && $_('schema:postalCode "%s"@%s;', $postalCode); |
|
| 190 | + !empty($addressLocality) && $_('schema:addressLocality """%s"""@%s;', $addressLocality); |
|
| 191 | + !empty($addressRegion) && $_('schema:addressRegion "%s"@%s;', $addressRegion); |
|
| 192 | + !empty($addressCountry) && $_('schema:addressCountry "%s";', $addressCountry); |
|
| 193 | + !empty($telephone) && $_('schema:telephone "%s"@%s;', $telephone); |
|
| 194 | + !empty($faxNumber) && $_('schema:faxNumber "%s"@%s;', $faxNumber); |
|
| 195 | + !empty($page) && $_('schema:page <%s>;', $page); |
|
| 196 | + !empty($email) && $_('schema:email "%s";', $email); |
|
| 197 | + $rdf.=' . '; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // serialize schema:GeoCoordinates |
|
| 201 | - if( !$skippGeo){ |
|
| 200 | + // serialize schema:GeoCoordinates |
|
| 201 | + if( !$skippGeo){ |
|
| 202 | 202 | |
| 203 | - $geoDescription = $this->buildNormalizedAddress(); |
|
| 203 | + $geoDescription = $this->buildNormalizedAddress(); |
|
| 204 | 204 | |
| 205 | - $_('<%s> a schema:GeoCoordinates;', $geoUri); |
|
| 206 | - !empty($geoDescription) && $_('schema:alternateLabel """%s"""@%s;', $geoDescription); |
|
| 207 | - !empty($lat) && $_('wgs:lat %s ;', $lat); |
|
| 208 | - !empty($long) && $_('wgs:long %s ;', $long); |
|
| 209 | - $rdf.=' . '; |
|
| 210 | - } |
|
| 205 | + $_('<%s> a schema:GeoCoordinates;', $geoUri); |
|
| 206 | + !empty($geoDescription) && $_('schema:alternateLabel """%s"""@%s;', $geoDescription); |
|
| 207 | + !empty($lat) && $_('wgs:lat %s ;', $lat); |
|
| 208 | + !empty($long) && $_('wgs:long %s ;', $long); |
|
| 209 | + $rdf.=' . '; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - // serialize schema:Place |
|
| 213 | - if( !$skippPlace){ |
|
| 214 | - $_('<%s> a schema:LocalBusiness;', $placeUri); |
|
| 215 | - !empty($businessType) && $_('a %s;', $businessType); |
|
| 216 | - !$skippAddress && $_('schema:address <%s>;', $addressUri); |
|
| 217 | - !$skippGeo && $_('schema:geo <%s>;', $geoUri); |
|
| 218 | - $rdf.=' . '; |
|
| 219 | - } |
|
| 212 | + // serialize schema:Place |
|
| 213 | + if( !$skippPlace){ |
|
| 214 | + $_('<%s> a schema:LocalBusiness;', $placeUri); |
|
| 215 | + !empty($businessType) && $_('a %s;', $businessType); |
|
| 216 | + !$skippAddress && $_('schema:address <%s>;', $addressUri); |
|
| 217 | + !$skippGeo && $_('schema:geo <%s>;', $geoUri); |
|
| 218 | + $rdf.=' . '; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - $this->rdf = $rdf; |
|
| 222 | - $this->tripleCount = $tc; |
|
| 223 | - } |
|
| 221 | + $this->rdf = $rdf; |
|
| 222 | + $this->tripleCount = $tc; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return $this->rdf; |
|
| 226 | - } |
|
| 225 | + return $this->rdf; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | } |
| 229 | 229 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class LocalBusiness extends AbstractModel implements ModelInterface |
| 13 | 13 | { |
| 14 | - protected static $DEFAULT_OPTIONS = array ( |
|
| 14 | + protected static $DEFAULT_OPTIONS = array( |
|
| 15 | 15 | 'businessType' => array( |
| 16 | 16 | // additional types as extension of schema:LocalBusiness |
| 17 | 17 | 'filter' => FILTER_DEFAULT, |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | public function __construct(array $data = array(), array $customOptions = array()) |
| 102 | 102 | { |
| 103 | - $options = $this->mergeOptions(self::$DEFAULT_OPTIONS,$customOptions); |
|
| 103 | + $options = $this->mergeOptions(self::$DEFAULT_OPTIONS, $customOptions); |
|
| 104 | 104 | parent::__construct($data, $options); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | extract($this->data); |
| 119 | 119 | |
| 120 | 120 | // veryfy that at least a minimum set of information are present |
| 121 | - if(empty($streetAddress) || empty($addressCountry) || (empty($addressLocality) && empty($postalCode))){ |
|
| 121 | + if (empty($streetAddress) || empty($addressCountry) || (empty($addressLocality) && empty($postalCode))) { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $geolabel = "$streetAddress ,"; |
| 126 | - if(!empty($postalCode)) { $geolabel.= " $postalCode";} |
|
| 127 | - if(!empty($addressLocality)) { $geolabel.= " $addressLocality"; } |
|
| 128 | - if(!empty($addressRegion)) { $geolabel.= " ($addressRegion)"; } |
|
| 129 | - $geolabel.= " - $addressCountry"; |
|
| 126 | + if (!empty($postalCode)) { $geolabel .= " $postalCode"; } |
|
| 127 | + if (!empty($addressLocality)) { $geolabel .= " $addressLocality"; } |
|
| 128 | + if (!empty($addressRegion)) { $geolabel .= " ($addressRegion)"; } |
|
| 129 | + $geolabel .= " - $addressCountry"; |
|
| 130 | 130 | |
| 131 | 131 | return \BOTK\Filters::FILTER_SANITIZE_ADDRESS($geolabel); |
| 132 | 132 | } |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | public function asTurtle() |
| 136 | 136 | { |
| 137 | - if(is_null($this->rdf)) { |
|
| 137 | + if (is_null($this->rdf)) { |
|
| 138 | 138 | extract($this->data); |
| 139 | 139 | |
| 140 | 140 | // create uris |
| 141 | 141 | $organizationUri = $this->getUri(); |
| 142 | 142 | $addressUri = $organizationUri.'_address'; |
| 143 | 143 | $placeUri = $organizationUri.'_place'; |
| 144 | - $geoUri = ( !empty($lat) && !empty($long) )?"geo:$lat,$long":($organizationUri.'_geo'); |
|
| 144 | + $geoUri = (!empty($lat) && !empty($long)) ? "geo:$lat,$long" : ($organizationUri.'_geo'); |
|
| 145 | 145 | |
| 146 | 146 | // define the minimum condition to skipp the rdf generation |
| 147 | - $skippAddress = empty($alternateName) && |
|
| 147 | + $skippAddress = empty($alternateName) && |
|
| 148 | 148 | empty($addressLocality) && |
| 149 | 149 | empty($streetAddress) && |
| 150 | 150 | empty($postalCode) && |
@@ -157,69 +157,69 @@ discard block |
||
| 157 | 157 | empty($addressLocality) && |
| 158 | 158 | empty($streetAddress) && |
| 159 | 159 | empty($lat) && |
| 160 | - empty($long) ; |
|
| 160 | + empty($long); |
|
| 161 | 161 | $skippPlace = $skippGeo && $skippAddress; |
| 162 | 162 | |
| 163 | - $skippOrganization = $skippPlace && empty($id)&& empty($vatID) && empty($taxID) && empty($legalName) ; |
|
| 163 | + $skippOrganization = $skippPlace && empty($id) && empty($vatID) && empty($taxID) && empty($legalName); |
|
| 164 | 164 | |
| 165 | 165 | // define $_ as a macro to write simple rdf |
| 166 | - $tc =0; |
|
| 167 | - $rdf=''; |
|
| 168 | - $_= function($format, $var) use(&$lang, &$rdf, &$tc){ |
|
| 169 | - if(!is_array($var)) { $var = (array) $var;} |
|
| 170 | - foreach((array)$var as $v){$rdf.= sprintf($format,$v,$lang);$tc++;} |
|
| 166 | + $tc = 0; |
|
| 167 | + $rdf = ''; |
|
| 168 | + $_ = function($format, $var) use(&$lang, &$rdf, &$tc){ |
|
| 169 | + if (!is_array($var)) { $var = (array) $var; } |
|
| 170 | + foreach ((array) $var as $v) {$rdf .= sprintf($format, $v, $lang); $tc++; } |
|
| 171 | 171 | }; |
| 172 | 172 | |
| 173 | 173 | // serialize schema:Organization |
| 174 | - if( !$skippOrganization){ |
|
| 174 | + if (!$skippOrganization) { |
|
| 175 | 175 | $_('<%s> a schema:Organization;', $organizationUri); |
| 176 | - !empty($id) && $_('dct:identifier "%s";', $id); |
|
| 177 | - !empty($vatID) && $_('schema:vatID "%s"@%s;', $vatID); |
|
| 178 | - !empty($taxtID) && $_('schema:taxtID "%s"@%s;', $taxID); |
|
| 179 | - !empty($legalName) && $_('schema:legalName """%s"""@%s;', $legalName); |
|
| 180 | - !$skippPlace && $_('schema:location <%s>;', $placeUri); |
|
| 181 | - $rdf.=' . '; |
|
| 176 | + !empty($id) && $_('dct:identifier "%s";', $id); |
|
| 177 | + !empty($vatID) && $_('schema:vatID "%s"@%s;', $vatID); |
|
| 178 | + !empty($taxtID) && $_('schema:taxtID "%s"@%s;', $taxID); |
|
| 179 | + !empty($legalName) && $_('schema:legalName """%s"""@%s;', $legalName); |
|
| 180 | + !$skippPlace && $_('schema:location <%s>;', $placeUri); |
|
| 181 | + $rdf .= ' . '; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // serialize schema:PostalAddress |
| 185 | - if( !$skippAddress){ |
|
| 185 | + if (!$skippAddress) { |
|
| 186 | 186 | $_('<%s> a schema:PostalAddress;', $addressUri); |
| 187 | - !empty($businessName) && $_('schema:alternateName """%s"""@%s;', $businessName); |
|
| 188 | - !empty($streetAddress) && $_('schema:streetAddress """%s"""@%s;', $streetAddress); |
|
| 189 | - !empty($postalCode) && $_('schema:postalCode "%s"@%s;', $postalCode); |
|
| 190 | - !empty($addressLocality) && $_('schema:addressLocality """%s"""@%s;', $addressLocality); |
|
| 191 | - !empty($addressRegion) && $_('schema:addressRegion "%s"@%s;', $addressRegion); |
|
| 192 | - !empty($addressCountry) && $_('schema:addressCountry "%s";', $addressCountry); |
|
| 193 | - !empty($telephone) && $_('schema:telephone "%s"@%s;', $telephone); |
|
| 194 | - !empty($faxNumber) && $_('schema:faxNumber "%s"@%s;', $faxNumber); |
|
| 195 | - !empty($page) && $_('schema:page <%s>;', $page); |
|
| 196 | - !empty($email) && $_('schema:email "%s";', $email); |
|
| 197 | - $rdf.=' . '; |
|
| 187 | + !empty($businessName) && $_('schema:alternateName """%s"""@%s;', $businessName); |
|
| 188 | + !empty($streetAddress) && $_('schema:streetAddress """%s"""@%s;', $streetAddress); |
|
| 189 | + !empty($postalCode) && $_('schema:postalCode "%s"@%s;', $postalCode); |
|
| 190 | + !empty($addressLocality) && $_('schema:addressLocality """%s"""@%s;', $addressLocality); |
|
| 191 | + !empty($addressRegion) && $_('schema:addressRegion "%s"@%s;', $addressRegion); |
|
| 192 | + !empty($addressCountry) && $_('schema:addressCountry "%s";', $addressCountry); |
|
| 193 | + !empty($telephone) && $_('schema:telephone "%s"@%s;', $telephone); |
|
| 194 | + !empty($faxNumber) && $_('schema:faxNumber "%s"@%s;', $faxNumber); |
|
| 195 | + !empty($page) && $_('schema:page <%s>;', $page); |
|
| 196 | + !empty($email) && $_('schema:email "%s";', $email); |
|
| 197 | + $rdf .= ' . '; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // serialize schema:GeoCoordinates |
| 201 | - if( !$skippGeo){ |
|
| 201 | + if (!$skippGeo) { |
|
| 202 | 202 | |
| 203 | 203 | $geoDescription = $this->buildNormalizedAddress(); |
| 204 | 204 | |
| 205 | 205 | $_('<%s> a schema:GeoCoordinates;', $geoUri); |
| 206 | - !empty($geoDescription) && $_('schema:alternateLabel """%s"""@%s;', $geoDescription); |
|
| 207 | - !empty($lat) && $_('wgs:lat %s ;', $lat); |
|
| 208 | - !empty($long) && $_('wgs:long %s ;', $long); |
|
| 209 | - $rdf.=' . '; |
|
| 206 | + !empty($geoDescription) && $_('schema:alternateLabel """%s"""@%s;', $geoDescription); |
|
| 207 | + !empty($lat) && $_('wgs:lat %s ;', $lat); |
|
| 208 | + !empty($long) && $_('wgs:long %s ;', $long); |
|
| 209 | + $rdf .= ' . '; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // serialize schema:Place |
| 213 | - if( !$skippPlace){ |
|
| 213 | + if (!$skippPlace) { |
|
| 214 | 214 | $_('<%s> a schema:LocalBusiness;', $placeUri); |
| 215 | - !empty($businessType) && $_('a %s;', $businessType); |
|
| 216 | - !$skippAddress && $_('schema:address <%s>;', $addressUri); |
|
| 217 | - !$skippGeo && $_('schema:geo <%s>;', $geoUri); |
|
| 218 | - $rdf.=' . '; |
|
| 215 | + !empty($businessType) && $_('a %s;', $businessType); |
|
| 216 | + !$skippAddress && $_('schema:address <%s>;', $addressUri); |
|
| 217 | + !$skippGeo && $_('schema:geo <%s>;', $geoUri); |
|
| 218 | + $rdf .= ' . '; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $this->rdf = $rdf; |
| 222 | - $this->tripleCount = $tc; |
|
| 222 | + $this->tripleCount = $tc; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | return $this->rdf; |