OpignoGroupContent.php in Opigno group manager 8
File
src/OpignoGroupContent.php
View source
<?php
namespace Drupal\opigno_group_manager;
use Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent;
class OpignoGroupContent {
private $groupContentTypeId;
private $entityType;
private $entityId;
private $title;
private $imageUrl;
private $imageAlt;
public function __construct($group_content_type_id, $entity_type, $entity_id, $title, $image_url, $image_alt) {
$this
->setGroupContentTypeId($group_content_type_id);
$this
->setEntityType($entity_type);
$this
->setEntityId($entity_id);
$this
->setTitle($title);
$this
->setImageUrl($image_url);
$this
->setImageAlt($image_alt);
}
public function __toString() {
return implode('.', [
self::class,
$this->entityType,
$this->entityId,
]);
}
public function toManagerArray(OpignoGroupManagedContent $content = NULL) {
if ($content === NULL) {
$cid = '';
$is_mandatory = FALSE;
$success_score_min = 0;
$parents_links = [];
$is_in_skills_system = FALSE;
}
else {
$cid = $content
->id();
$is_mandatory = $content
->isMandatory();
$success_score_min = $content
->getSuccessScoreMin();
$parents_links = $content
->getParentsLinks();
$is_in_skills_system = $content
->isInSkillSystem();
}
$entity = \Drupal::entityTypeManager()
->getStorage($this
->getEntityType())
->load($this
->getEntityId());
$this_array = [
'cid' => $cid,
'entityId' => $this
->getEntityId(),
'contentType' => $this
->getGroupContentTypeId(),
'title' => $this
->getTitle(),
'imageUrl' => $this
->getImageUrl(),
'imageAlt' => $this
->getImageAlt(),
'isMandatory' => $is_mandatory,
'successScoreMin' => $success_score_min,
'editable' => $entity
->access('update'),
'in_skills_system' => $is_in_skills_system,
];
$parents = [];
foreach ($parents_links as $link) {
if (get_class($link) != 'Drupal\\opigno_group_manager\\Entity\\OpignoGroupManagedLink') {
continue;
}
$parents[] = [
'cid' => $link
->getParentContentId(),
'minScore' => $link
->getRequiredScore(),
'activities' => $link
->getRequiredActivities(),
];
}
$this_array['parents'] = $parents;
return $this_array;
}
public function getEntityType() {
return $this->entityType;
}
public function setEntityType($entity_type) {
$this->entityType = $entity_type;
}
public function getEntityId() {
return $this->entityId;
}
public function setEntityId($entity_id) {
$this->entityId = $entity_id;
}
public function getTitle() {
return $this->title;
}
public function setTitle($entity_title) {
$this->title = $entity_title;
}
public function getGroupContentTypeId() {
return $this->groupContentTypeId;
}
public function setGroupContentTypeId($group_content_type_id) {
$this->groupContentTypeId = $group_content_type_id;
}
public function getImageUrl() {
return $this->imageUrl;
}
public function setImageUrl($image_url) {
$this->imageUrl = $image_url;
}
public function getImageAlt() {
return $this->imageAlt;
}
public function setImageAlt($image_alt) {
$this->imageAlt = $image_alt;
}
}