Esempio n. 1
0
 /**
  * Récupère les cardinalités entre une classe et une propriété
  *
  * @param string uri_class 
  * @param string uri_property 
  * @return onto_restriction
  * @access public
  */
 public function get_restriction($uri_class, $uri_property)
 {
     $restriction = new onto_restriction();
     //recherche des exlusions !
     $query = "select ?distinct where {\n\t\t\t<" . $uri_property . "> pmb:distinctWith ?distinct\n\t\t}";
     if ($this->store->query($query)) {
         if ($this->store->num_rows()) {
             $results = $this->store->get_result();
             foreach ($results as $result) {
                 $restriction->set_new_distinct($this->get_property($uri_class, $result->distinct));
             }
         }
     } else {
         var_dump($this->store->get_errors());
     }
     $query = "select ?max ?min where {\n\t\t\t<" . $uri_class . "> rdf:type <http://www.w3.org/2002/07/owl#Class> .\n\t\t\t<" . $uri_class . "> rdfs:subClassOf ?restrict .\t\n\t\t\t?restrict rdf:type <http://www.w3.org/2002/07/owl#Restriction> .\n\t\t\t?restrict owl:onProperty <" . $uri_property . "> .\t\t\n\t\t\toptional {\n\t\t\t\t?restrict owl:maxCardinality ?max\n\t\t\t} .\n\t\t\toptional {\n\t\t\t\t?restrict owl:minCardinality ?min\n\t\t\t}\n\t\t}";
     if ($this->store->query($query)) {
         if ($this->store->num_rows()) {
             $results = $this->store->get_result();
             foreach ($results as $result) {
                 if ($result->min) {
                     $restriction->set_min($result->min);
                 }
                 if ($result->max) {
                     $restriction->set_max($result->max);
                 }
             }
         }
     } else {
         var_dump($this->store->get_errors());
     }
     return $restriction;
 }
    /**
     *
     *
     * @param property property la propriété concernée
     * @param onto_restriction $restrictions le tableau des restrictions associées à la propriété
     * @param array datas le tableau des datatypes
     * @param string instance_name nom de l'instance
     * @param string flag Flag
     * @return string
     * @static
     * @access public
     */
    public static function get_validation_js($item_uri, $property, $restrictions, $datas, $instance_name, $flag)
    {
        global $msg;
        return '{
			"message": "' . addslashes($property->label) . '",
			"valid" : true,
			"nb_values": 0,
			"error": "",
			"values": new Array(),
			"check": function(){
				this.values = new Array();
				this.nb_values = 0;
				this.valid = true;
				var order = document.getElementById("' . $instance_name . '_' . $property->pmb_name . '_new_order").value;
				for (var i=0; i<=order ; i++){
					var label = document.getElementById("' . $instance_name . '_' . $property->pmb_name . '_"+i+"_value");
					var lang = document.getElementById("' . $instance_name . '_' . $property->pmb_name . '_"+i+"_lang");
					if(label.value != ""){
						if(!this.values[lang.value]){
							this.values[lang.value] = 0;
						}
						this.values[lang.value]++;
						if(this.nb_values < this.values[lang.value]) {
							this.nb_values = this.values[lang.value];
						}
					}
				}
							
				if(this.nb_values < ' . $restrictions->get_min() . '){
					this.valid = false;
					this.error = "min";
				}
				if(this.nb_values > ' . $restrictions->get_max() . '){
					this.valid = false;
					this.error = "max";
				}
				return this.valid;
			},
			"get_error_message": function(){
 				switch(this.error){
 					case "min" :
						this.message = "' . addslashes($msg['onto_error_no_minima']) . '";
						break;
					case "max" : 
						this.message = "' . addslashes($msg['onto_error_too_much_values']) . '";
						break;
 				}
				this.message = this.message.replace("%s","' . addslashes($property->label) . '");			
				return this.message;	
			} 	
		}';
    }