Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #18936: User count in group is not OK after deleting a us…
…er (#3306) Co-authored-by: encuestabizdevgit <devgit@encuesta.biz> Co-authored-by: lapiudevgit <devgit@lapiu.biz>
- Loading branch information
1 parent
c9cb838
commit 2fee7cc
Showing
4 changed files
with
248 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace LimeSurvey\Datavalueobjects; | ||
|
||
/** | ||
* Class OperationResult | ||
* | ||
* This class represents the result of an operation (ie. the result of a | ||
* service's method), with a status and an optional list of messages. | ||
* | ||
* @package LimeSurvey\Datavalueobjects | ||
*/ | ||
class OperationResult | ||
{ | ||
/** @var bool the basic result of the operation */ | ||
private $success; | ||
|
||
/** @var TypedMessage[] an array of messages providing extra details */ | ||
private $messages; | ||
|
||
/** | ||
* @param bool $success | ||
* @param TypedMessage[]|TypedMessage $messages | ||
*/ | ||
public function __construct($success = false, $messages = []) { | ||
$this->success = $success; | ||
if (!is_array($messages)) { | ||
$messages = [$messages]; | ||
} | ||
$this->messages = $messages; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isSuccess(): bool | ||
{ | ||
return $this->success; | ||
} | ||
|
||
/** | ||
* @param bool $success | ||
*/ | ||
public function setSuccess(bool $success): void | ||
{ | ||
$this->success = $success; | ||
} | ||
|
||
/** | ||
* Returns the messages of the given type, or all messages if | ||
* no type is specified. | ||
* @param string|null $type | ||
* @return TypedMessage[] | ||
*/ | ||
public function getMessages($type = null) | ||
{ | ||
if ($type === null) { | ||
return $this->messages; | ||
} | ||
$messages = []; | ||
foreach ($this->messages as $message) { | ||
if ($message->getType() === $type) { | ||
$messages[] = $message; | ||
} | ||
} | ||
return $messages; | ||
} | ||
|
||
/** | ||
* @param TypedMessage[] $messages | ||
*/ | ||
public function setMessages($messages) | ||
{ | ||
$this->messages = $messages; | ||
} | ||
|
||
/** | ||
* @param TypedMessage $message | ||
*/ | ||
public function appendMessage(TypedMessage $message) | ||
{ | ||
$this->messages[] = $message; | ||
} | ||
|
||
/** | ||
* @param string $message | ||
* @param string $type | ||
*/ | ||
public function addMessage($message, $type) | ||
{ | ||
$this->appendMessage(new TypedMessage($message, $type)); | ||
} | ||
|
||
/** | ||
* Sets messages from an array of strings | ||
* @param string[] $messages | ||
*/ | ||
public function setRawMessages($messages) | ||
{ | ||
$this->messages = []; | ||
foreach ($messages as $message) { | ||
$this->messages[] = new TypedMessage($message); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the raw messages of the given type, or all messages if | ||
* no type is specified. | ||
* @param string|null $type | ||
* @return string[] | ||
*/ | ||
public function getRawMessages($type = null) | ||
{ | ||
$messages = []; | ||
foreach ($this->getMessages($type) as $message) { | ||
$messages[] = $message->getMessage(); | ||
} | ||
return $messages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace LimeSurvey\Datavalueobjects; | ||
|
||
/** | ||
* Class TypedMessage | ||
* | ||
* This class represents a message with a type (ie. success, error, etc.). | ||
* | ||
* @package LimeSurvey\Datavalueobjects | ||
*/ | ||
class TypedMessage | ||
{ | ||
/** @var string the type of the message */ | ||
private $type; | ||
|
||
/** @var string the message */ | ||
private $message; | ||
|
||
/** | ||
* @param string $type | ||
* @param string $message | ||
*/ | ||
public function __construct($message, $type = '') | ||
{ | ||
$this->message = $message; | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
*/ | ||
public function setType(string $type): void | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMessage(): string | ||
{ | ||
return $this->message; | ||
} | ||
|
||
/** | ||
* @param string $message | ||
*/ | ||
public function setMessage(string $message): void | ||
{ | ||
$this->message = $message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters