Commit 9589b3f8 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #271 in ZP/z-push from...

Merge pull request #271 in ZP/z-push from bugfix/ZP-953-print-human-friendly-strings-for-integer to develop

* commit '5f19a688':
  ZP-953 Fixed wrong access.
  ZP-953 Changed getNameFromPropertyValue's access to public, so that it's possible to call this function from another SyncObject and not in local context only.
  ZP-953 Added getNameFromPropertyValue function to SyncObject.
  ZP-953 Print human friendly strings for integer values.
parents 606fc67b 5f19a688
......@@ -53,6 +53,7 @@ class Streamer implements Serializable {
const STREAMER_TYPE = 3;
const STREAMER_PROP = 4;
const STREAMER_RONOTIFY = 5;
const STREAMER_VALUEMAP = 20;
const STREAMER_TYPE_DATE = 1;
const STREAMER_TYPE_HEX = 2;
const STREAMER_TYPE_DATE_DASHES = 3;
......
......@@ -123,7 +123,11 @@ class SyncAppointment extends SyncObject {
// 3 = Confident
SYNC_POOMCAL_SENSITIVITY => array ( self::STREAMER_VAR => "sensitivity",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_ONEVALUEOF => array(0,1,2,3) ),
self::STREAMER_RONOTIFY => true),
self::STREAMER_RONOTIFY => true,
self::STREAMER_VALUEMAP => array( 0 => "Normal",
1 => "Personal",
2 => "Private",
3 => "Confident")),
// Busystatus values
// 0 = Free
......@@ -134,11 +138,18 @@ class SyncAppointment extends SyncObject {
SYNC_POOMCAL_BUSYSTATUS => array ( self::STREAMER_VAR => "busystatus",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_REQUIRED => self::STREAMER_CHECK_SETTWO,
self::STREAMER_CHECK_ONEVALUEOF => array(0,1,2,3,4) ),
self::STREAMER_RONOTIFY => true),
self::STREAMER_RONOTIFY => true,
self::STREAMER_VALUEMAP => array( 0 => "Free",
1 => "Tentative",
2 => "Busy",
3 => "Out of office",
4 => "Working Elsewhere")),
SYNC_POOMCAL_ALLDAYEVENT => array ( self::STREAMER_VAR => "alldayevent",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_ZEROORONE => self::STREAMER_CHECK_SETZERO),
self::STREAMER_RONOTIFY => true),
self::STREAMER_RONOTIFY => true,
self::STREAMER_VALUEMAP => array( 0 => "No",
1 => "Yes")),
SYNC_POOMCAL_REMINDER => array ( self::STREAMER_VAR => "reminder",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_CMPHIGHER => -1),
......@@ -158,7 +169,16 @@ class SyncAppointment extends SyncObject {
// 15 = as 7
SYNC_POOMCAL_MEETINGSTATUS => array ( self::STREAMER_VAR => "meetingstatus",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_ONEVALUEOF => array(0,1,3,5,7,9,11,13,15) ),
self::STREAMER_RONOTIFY => true),
self::STREAMER_RONOTIFY => true,
self::STREAMER_VALUEMAP => array( 0 => "Not a meeting",
1 => "Meeting",
3 => "Meeting received",
5 => "Meeting canceled",
7 => "Meeting canceled and received",
9 => "Meeting",
11 => "Meeting received",
13 => "Meeting canceled",
15 => "Meeting canceled and received",)),
SYNC_POOMCAL_ATTENDEES => array ( self::STREAMER_VAR => "attendees",
self::STREAMER_TYPE => "SyncAttendee",
......
......@@ -126,7 +126,9 @@ class SyncMail extends SyncObject {
SYNC_POOMMAIL_READ => array ( self::STREAMER_VAR => "read",
self::STREAMER_CHECKS => array( self::STREAMER_CHECK_ONEVALUEOF => array(0,1) ),
self::STREAMER_RONOTIFY => true),
self::STREAMER_RONOTIFY => true,
self::STREAMER_VALUEMAP => array( 0 => "No",
1 => "Yes")),
SYNC_POOMMAIL_ATTACHMENTS => array ( self::STREAMER_VAR => "attachments",
self::STREAMER_TYPE => "SyncAttachment",
......
......@@ -246,18 +246,20 @@ abstract class SyncObject extends Streamer {
$out[$keyprefix.$val] = Utils::GetFormattedTime($this->$val);
}
else {
$out[$keyprefix.$val] = (isset($this->$val) && strlen($this->$val) ?
$out[$keyprefix.$val] = (strlen($this->$val) ?
Utils::GetFormattedTime($this->$val):"undefined") ." - ". $odoName .": ".
(isset($odo->$val) && strlen($odo->$val) ? Utils::GetFormattedTime($odo->$val) : "undefined");
(strlen($odo->$val) ? Utils::GetFormattedTime($odo->$val) : "undefined");
}
}
// else just compare their values
// else just compare their values and print human friendly if necessary
else {
if($this->$val == $odo->$val) {
$out[$keyprefix.$val] = $this->$val;
$out[$keyprefix.$val] = $this->GetNameFromPropertyValue($v, $this->$val);
}
else {
$out[$keyprefix.$val] = (isset($this->$val) && $this->$val ? $this->$val:"undefined") ." - ". $odoName .": ". (isset($odo->$val) && $odo->$val ? $odo->$val:"undefined");
$out[$keyprefix.$val] = (strlen($this->$val) ? $this->GetNameFromPropertyValue($v, $this->$val) : "undefined") .
" - ". $odoName .": ".
(strlen($odo->$val) ? $odo->GetNameFromPropertyValue($v, $odo->$val) : "undefined");
}
}
}
......@@ -272,7 +274,7 @@ abstract class SyncObject extends Streamer {
else {
if($this->$val == $odo->$val) {
if (! ($this instanceof SyncRecurrence)) {
$out[$keyprefix.$val] = $this->$val;
$out[$keyprefix.$val] = ($this->GetNameFromPropertyValue($v, $this->$val));
}
}
else {
......@@ -280,7 +282,9 @@ abstract class SyncObject extends Streamer {
$out["Recurrence"] = "Recurrence changed";
}
else {
$out[$keyprefix.$val] = (strlen($this->$val) ? $this->$val:"undefined") ." - ". $odoName .": ". (strlen($odo->$val) ? $odo->$val:"undefined");
$out[$keyprefix.$val] = (strlen($this->$val) ? $this->GetNameFromPropertyValue($v, $this->$val) : "undefined") .
" - ". $odoName .": ".
(strlen($odo->$val) ? ($odo->GetNameFromPropertyValue($v, $odo->$val)) : "undefined");
}
}
}
......@@ -291,7 +295,8 @@ abstract class SyncObject extends Streamer {
// Otherwise it's a ghosted property and the device didn't send it, so we don't have to care about that case.
if (in_array($k, $supportedFields)) {
if ((is_scalar($this->$val) && strlen($this->$val)) || (!is_scalar($this->$val) && !empty($this->$val))) {
$out[$keyprefix.$val] = (is_array($this->$val) ? implode(",", $this->$val) : $this->$val) . " - " . $odoName .": value completely removed";
$out[$keyprefix.$val] = (is_array($this->$val) ? implode(",", $this->$val) : $this->GetNameFromPropertyValue($v, $this->$val)) .
" - " . $odoName .": value completely removed";
}
}
// there is no data sent for SyncMail, so just output its values
......@@ -300,7 +305,7 @@ abstract class SyncObject extends Streamer {
$out[$keyprefix.$val] = Utils::GetFormattedTime($this->$val);
}
else {
$out[$keyprefix.$val] = $this->$val;
$out[$keyprefix.$val] = $this->GetNameFromPropertyValue($v, $this->$val);
}
}
}
......@@ -314,7 +319,7 @@ abstract class SyncObject extends Streamer {
$out[$keyprefix.$val] = "Not set - " . $odoName . ": an exception was added";
}
else {
$out[$keyprefix.$val] = "Not set - " . $odoName . ": " . $odo->$val . " (value added)";
$out[$keyprefix.$val] = "Not set - " . $odoName . ": " . $odo->GetNameFromPropertyValue($v, $odo->$val) . " (value added)";
}
}
else if (isset($v[self::STREAMER_ARRAY])) {
......@@ -322,7 +327,7 @@ abstract class SyncObject extends Streamer {
$out[$keyprefix.$val] = "Not set - ". $odoName .": ". implode(", ", $odo->$val) . " (value added)";
}
else {
$out[$keyprefix.$val] = "Not set - " . $odoName . ": " . $odo->$val . " (value added)";
$out[$keyprefix.$val] = "Not set - " . $odoName . ": " . $odo->GetNameFromPropertyValue($v, $odo->$val) . " (value added)";
}
}
}
......@@ -587,4 +592,20 @@ abstract class SyncObject extends Streamer {
return true;
}
/**
* Returns human friendly property name from its value if a mapping is available.
*
* @param array $v
* @param mixed $val
*
* @access public
* @return mixed
*/
public function GetNameFromPropertyValue($v, $val) {
if (isset($v[self::STREAMER_VALUEMAP][$val])) {
return $v[self::STREAMER_VALUEMAP][$val];
}
return $val;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment