Skip to content

Commit

Permalink
Merge branch 'release-48.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 19, 2024
2 parents 448508d + 2271fac commit b580485
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 150 deletions.
101 changes: 45 additions & 56 deletions models/classes/TestCategoryPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA;
* Copyright (c) 2017-2024 (original work) Open Assessment Technologies SA;
*
*/

Expand All @@ -31,52 +31,45 @@
*/
class TestCategoryPreset implements JsonSerializable
{
private string $id;

/**
* @var string $id
* Short preset name
*/
private $id;
private string $label;

/**
* @var string $label - short preset name
* The actual qti category that will end up in the QTI markup
*/
private $label;
private string $qtiCategory;

/**
* @var string $qtiCategory - the actual qti category that will end up in the QTI markup
* The other possible qti categories that would activate the preset
*/
private $qtiCategory;
private array $altCategories = [];

/**
* @var string $description - what is the category purpose
* What is the category purpose
*/
private $description = '';
private string $description = '';

/**
* @var string $order - to sort the categories
* To sort the categories
*/
private $order = 0;
private int $order = 0;

/**
* @var string $pluginId - related plugin that the preset depends on
* Related plugin that the preset depends on
*/
private $pluginId = '';
private string $pluginId = '';

/**
* @var string $featureFlag - the name of a config flag,
* the preset will be deactivated based on this optional value.
* The name of a config flag, the preset will be deactivated based on this optional value.
*/
private $featureFlag;
private string $featureFlag = '';


/**
* Create a test category preset
* @param string $id
* @param string $label
* @param string $qtiCategory
* @param array $data - optional parameters
* @throws common_exception_InconsistentData
*/
public function __construct($id, $label, $qtiCategory, $data)
public function __construct(string $id, string $label, string $qtiCategory, array $data = [])
{
if (! is_string($id) || empty($id)) {
throw new common_exception_InconsistentData('The category preset needs an id');
Expand Down Expand Up @@ -104,75 +97,71 @@ public function __construct($id, $label, $qtiCategory, $data)
if (isset($data['featureFlag'])) {
$this->featureFlag = (string) $data['featureFlag'];
}
if (isset($data['altCategories'])) {
$this->altCategories = array_map('strval', $data['altCategories']);
}
}

public function getId()
public function getId(): string
{
return $this->id;
}

public function getLabel()
public function getLabel(): string
{
return $this->label;
}

public function getQtiCategory()
public function getQtiCategory(): string
{
return $this->qtiCategory;
}

public function getDescription()
public function getAltCategory(): array
{
return $this->altCategories;
}

public function getDescription(): string
{
return $this->description;
}

public function getOrder()
public function getOrder(): int
{
return $this->order;
}

public function getPluginId()
public function getPluginId(): string
{
return $this->pluginId;
}

public function getFeatureFlag()
public function getFeatureFlag(): string
{
return (string) $this->featureFlag;
return $this->featureFlag;
}

/**
* @see JsonSerializable::jsonSerialize
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->toArray();
}

/**
* Convenient method to convert the members to an assoc array
* @return array the data
*/
public function toArray()
public function toArray(): array
{
return [
'id' => $this->id,
'label' => $this->label,
'qtiCategory' => $this->qtiCategory,
'description' => $this->description,
'order' => $this->order,
'pluginId' => $this->pluginId,
'featureFlag' => $this->featureFlag
'id' => $this->id,
'label' => $this->label,
'qtiCategory' => $this->qtiCategory,
'altCategories' => $this->altCategories,
'description' => $this->description,
'order' => $this->order,
'pluginId' => $this->pluginId,
'featureFlag' => $this->featureFlag
];
}

/**
* Create a test category preset from an assoc array
* @param array $data
* @return TestCategoryPreset the new instance
* @throws common_exception_InconsistentData
*/
public static function fromArray(array $data)
public static function fromArray(array $data): TestCategoryPreset
{
if (!isset($data['id']) || !isset($data['label']) || !isset($data['qtiCategory'])) {
throw new common_exception_InconsistentData(
Expand Down
Loading

0 comments on commit b580485

Please sign in to comment.