/**
* Gets the query string for the fields
*
* @param array $fields The fields list looks like (fild1, field2, .. or fieldN => uriParameterAlias)
* @return string Returns the query string
*/
protected function _getQueryStringForFields(array $fields = null)
{
$str = '';
$reflProperties = $this->_getReflectionProperties();
if ($fields === null) {
//Trying to determine fields from reflection class
$fields = array();
foreach ($reflProperties as $prop) {
$fields[$prop->getName()] = OpenStack::decamelize($prop->getName());
}
}
foreach ($fields as $index => $prop) {
if (!is_numeric($index)) {
$uriProp = $prop;
$prop = $index;
} else {
$uriProp = $prop;
}
if (!isset($reflProperties[$prop])) {
continue;
}
$refProp = $reflProperties[$prop];
$value = $refProp->getValue($this);
if ($value !== null) {
if (is_array($value) || $value instanceof \Traversable) {
foreach ($value as $v) {
if ($v instanceof \DateTime) {
$v = $v->format('c');
}
$str .= '&' . $uriProp . '=' . rawurlencode((string) $v);
}
} else {
if ($value instanceof \DateTime) {
$value = $value->format('c');
}
$str .= '&' . $uriProp . '=' . rawurlencode((string) $value);
}
}
unset($uriProp);
}
return $str;
}