Example #1
0
 /**
  * Creates a {@link Property} from an object directly from a call to the API.
  * WARNING: If this is called with the wrong raw object, you may get warnings or even errors!
  * @param stdClass $rawProperty The raw object from the API-call.
  * @author Björn Hjortsten
  * @return Property
  */
 public static function createFromRawObject(stdClass $rawProperty)
 {
     if (@(!is_null($rawProperty->propertyType))) {
         $propertyValueType = Property::getPropertyValueTypeFromString($rawProperty->propertyType);
     } else {
         $propertyValueType = null;
     }
     switch ($propertyValueType) {
         case PropertyValueType::QB_Array:
             if ($rawProperty->multiplechoice == true) {
                 $value = explode('|', $rawProperty->value);
                 $value = array_filter($value);
             } else {
                 $value = strval($rawProperty->value);
             }
             $defaultValue = explode('|', $rawProperty->defaultValue);
             $defaultValue = array_filter($defaultValue);
             break;
         case PropertyValueType::QB_Bool:
             $value = (bool) $rawProperty->value;
             $defaultValue = (bool) $rawProperty->defaultValue;
             break;
         case PropertyValueType::QB_Date:
             $value = strtotime($rawProperty->value);
             $defaultValue = strtotime($rawProperty->defaultValue);
             break;
         case PropertyValueType::QB_Float:
             $value = floatval($rawProperty->value);
             $defaultValue = floatval($rawProperty->defaultValue);
             break;
         case PropertyValueType::QB_Int:
             $value = intval($rawProperty->value);
             $defaultValue = intval($rawProperty->defaultValue);
             break;
         case PropertyValueType::QB_String:
             if (isset($rawProperty->keywords) && (bool) $rawProperty->keywords === true) {
                 $value = explode('|', $rawProperty->value);
                 $defaultValue = explode('|', $rawProperty->defaultValue);
                 $value = array_filter($value);
                 $defaultValue = array_filter($defaultValue);
             } else {
                 $value = $rawProperty->value;
                 $defaultValue = $rawProperty->defaultValue;
             }
             break;
         default:
             return Property::createFromSecondaryRawObject($rawProperty);
             break;
     }
     $property = new Property(intval($rawProperty->propertyId), intval($rawProperty->id), $rawProperty->propertyName, $rawProperty->title, $value, $defaultValue, $propertyValueType, (bool) $rawProperty->multiplechoice, (bool) $rawProperty->editable);
     @($property->qbankValueType = $rawProperty->propertyType);
     if (isset($rawProperty->editable)) {
         $property->editable = (bool) $rawProperty->editable;
     } else {
         $property->editable = null;
     }
     if (isset($rawProperty->mandatory)) {
         $property->mandatory = (bool) $rawProperty->mandatory;
     } else {
         $property->mandatory = null;
     }
     if (isset($rawProperty->keywords)) {
         $property->keywords = (bool) $rawProperty->keywords;
     } else {
         $property->keywords = null;
     }
     if (isset($rawProperty->link)) {
         $property->link = (bool) $rawProperty->link;
     } else {
         $property->link = null;
     }
     if (isset($rawProperty->info)) {
         $property->info = $rawProperty->info;
         if (empty($property->info)) {
             $property->info = null;
         }
     } else {
         $property->info = null;
     }
     return $property;
 }