Commit 75c454b1 authored by skummer's avatar skummer

ZP-270 #comment as foldertype email, contact, calendar and note should also be accepted #time 2h

git-svn-id: https://z-push.org/svn/z-push/trunk@1490 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent 3cf402fa
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
class SyncParameters extends StateObject { class SyncParameters extends StateObject {
const DEFAULTOPTIONS = "DEFAULT"; const DEFAULTOPTIONS = "DEFAULT";
const EMAILOPTIONS = "EMAILS";
const CALENDAROPTIONS = "CALENDAR";
const CONTACTOPTIONS = "CONTACTS";
const NOTEOPTIONS = "NOTE";
const SMSOPTIONS = "SMS"; const SMSOPTIONS = "SMS";
private $synckeyChanged = false; private $synckeyChanged = false;
...@@ -228,8 +232,8 @@ class SyncParameters extends StateObject { ...@@ -228,8 +232,8 @@ class SyncParameters extends StateObject {
* @return ContentParameters object * @return ContentParameters object
*/ */
public function GetCPO($options = self::DEFAULTOPTIONS) { public function GetCPO($options = self::DEFAULTOPTIONS) {
if ($options !== self::DEFAULTOPTIONS && $options !== self::SMSOPTIONS) $this->isValidType($options);
throw new FatalNotImplementedException(sprintf("SyncParameters->GetCPO('%s') ContentParameters is invalid. Such type is not available.", $options)); $options = $this->normalizeType($options);
$this->checkCPO($options); $this->checkCPO($options);
...@@ -250,8 +254,7 @@ class SyncParameters extends StateObject { ...@@ -250,8 +254,7 @@ class SyncParameters extends StateObject {
* @return * @return
*/ */
public function UseCPO($options = self::DEFAULTOPTIONS) { public function UseCPO($options = self::DEFAULTOPTIONS) {
if ($options !== self::DEFAULTOPTIONS && $options !== self::SMSOPTIONS) $this->isValidType($options);
throw new FatalNotImplementedException(sprintf("SyncParameters->UseCPO('%s') ContentParameters is invalid. Such type is not available.", $options));
ZLOG::Write(LOGLEVEL_DEBUG, sprintf("SyncParameters->UseCPO('%s')", $options)); ZLOG::Write(LOGLEVEL_DEBUG, sprintf("SyncParameters->UseCPO('%s')", $options));
$this->currentCPO = $options; $this->currentCPO = $options;
...@@ -268,6 +271,8 @@ class SyncParameters extends StateObject { ...@@ -268,6 +271,8 @@ class SyncParameters extends StateObject {
* @return boolean * @return boolean
*/ */
private function checkCPO($options = self::DEFAULTOPTIONS) { private function checkCPO($options = self::DEFAULTOPTIONS) {
$this->isValidType($options);
if (!isset($this->contentParameters[$options])) { if (!isset($this->contentParameters[$options])) {
$a = $this->contentParameters; $a = $this->contentParameters;
$a[$options] = new ContentParameters(); $a[$options] = new ContentParameters();
...@@ -277,6 +282,65 @@ class SyncParameters extends StateObject { ...@@ -277,6 +282,65 @@ class SyncParameters extends StateObject {
return true; return true;
} }
/**
* Checks if the requested option type is available
*
* @param string $options CPO type
*
* @access private
* @return boolean
* @throws FatalNotImplementedException
*/
private function isValidType($options) {
$options = strtoupper($options);
if ($options !== self::DEFAULTOPTIONS &&
$options !== self::EMAILOPTIONS &&
$options !== self::CALENDAROPTIONS &&
$options !== self::CONTACTOPTIONS &&
$options !== self::NOTEOPTIONS &&
$options !== self::SMSOPTIONS)
throw new FatalNotImplementedException(sprintf("SyncParameters->isAllowedType('%s') ContentParameters is invalid. Such type is not available.", $options));
return true;
}
/**
* Normalizes the requested option type and returns it as
* default option if no default is available
*
* @param string $options CPO type
*
* @access private
* @return string
* @throws FatalNotImplementedException
*/
private function normalizeType($options) {
// return the requested CPO as it is defined
if (isset($this->contentParameters[$options]))
return $options;
// return email, calendar, contact or note CPO as default CPO if there no explicit default CPO defined
if ($options == self::DEFAULTOPTIONS && !isset($this->contentParameters[self::DEFAULTOPTIONS])) {
if ($options == self::EMAILOPTIONS && isset($this->contentParameters[self::EMAILOPTIONS]))
return self::EMAILOPTIONS;
if ($options == self::CALENDAROPTIONS && isset($this->contentParameters[self::CALENDAROPTIONS]))
return self::CALENDAROPTIONS;
if ($options == self::CONTACTOPTIONS && isset($this->contentParameters[self::CONTACTOPTIONS]))
return self::CONTACTOPTIONS;
if ($options == self::NOTEOPTIONS && isset($this->contentParameters[self::NOTEOPTIONS]))
return self::NOTEOPTIONS;
}
// something unexpected happened, just return default, empty in the worst case
else {
$this->checkCPO(self::DEFAULTOPTIONS);
return self::DEFAULTOPTIONS;
}
}
/** /**
* PHP magic to implement any getter, setter, has and delete operations * PHP magic to implement any getter, setter, has and delete operations
* on an instance variable. * on an instance variable.
...@@ -333,5 +397,4 @@ class SyncParameters extends StateObject { ...@@ -333,5 +397,4 @@ class SyncParameters extends StateObject {
return true; return true;
} }
} }
?> ?>
\ No newline at end of file
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