View source
<?php
namespace Drupal\cmis;
use Dkd\PhpCmis\DataObjects\AbstractFileableCmisObject;
use Drupal\cmis\Entity\CmisConnectionEntity;
class CmisElement {
private $element;
private $config;
private $popup;
private $parent;
private $query_string;
private $data = [];
private $type;
private $rootId;
public function __construct($config, $popup = FALSE, AbstractFileableCmisObject $parent = NULL, $query = '', $root_id = '') {
$this->config = $config;
$this->popup = $popup;
$this->parent = $parent;
$this->query_string = $query;
$this->rootId = $root_id;
}
public function setElement($type, AbstractFileableCmisObject $element) {
$this->type = $type;
$this->element = $element;
$this
->prepare();
}
protected function prepare() {
$type_id = $this->element
->getBaseTypeId()
->__toString();
$name = $this->element
->getName();
$id = $this->element
->getId();
$link_options = [];
switch ($type_id) {
case 'cmis:folder':
switch ($this->type) {
case 'browser':
$url = \Drupal\Core\Url::fromUserInput('/cmis/browser/nojs/' . $this->config . '/' . $id);
$link_options = [
'attributes' => [
'class' => [
'use-ajax',
],
],
];
break;
case 'query':
$url = \Drupal\Core\Url::fromUserInput('/cmis/browser/' . $this->config . '/' . $id);
break;
}
if ($this->popup) {
$link_options['query'] = [
'type' => 'popup',
];
}
if (!empty($link_options)) {
$url
->setOptions($link_options);
}
$link = \Drupal\Core\Link::fromTextAndUrl($name, $url)
->toRenderable();
$this
->prepareElement('cmis_browser_folder_item', $link);
break;
case 'cmis:document':
$this
->prepareElement('cmis_browser_document_item', $name, $id);
break;
default:
$element = [
'#theme' => 'cmis_browser_other_item',
'#element' => $name,
];
$this->data = [
render($element),
];
}
}
private function getParent() {
if (empty($this->parent)) {
}
}
public function getDAta() {
return $this->data;
}
protected function prepareElement($theme, $data, $id = '') {
$author = $this->element
->getCreatedBy();
$created = $this->element
->getCreationDate()
->format('Y-m-d H:i:s');
$description = $this->element
->getDescription();
$title = '';
if ($title_property = $this->element
->getProperty('cm:title')) {
$title = $title_property
->getFirstValue();
}
$size = 0;
if ($size_property = $this->element
->getProperty('cmis:contentStreamLength')) {
$size = $size_property
->getFirstValue();
}
$mime_type = '';
$operations = '';
if ($theme == 'cmis_browser_document_item') {
$this
->prepareDocumentElement($data, $operations, $id);
}
if (!$this->popup) {
$this
->preparePropertiesLink($operations);
}
$element = [
'#theme' => $theme,
'#element' => $data,
];
$details = [
'#theme' => 'cmis_browser_document_details',
'#title' => $title,
'#mime_type' => $mime_type,
'#size' => number_format($size, 0, '', ' '),
];
$this->data = [
render($element),
render($details),
$author,
$created,
$description,
$operations,
];
}
private function prepareDocumentElement(&$data, &$operations, $id) {
$mime_type = $this->element
->getContentStreamMimeType();
if ($this->popup) {
$url = \Drupal\Core\Url::fromUserInput('/');
$link_options = array(
'attributes' => array(
'class' => array(
'cmis-field-insert',
),
'id' => $this->element
->getProperty('cmis:objectId')
->getFirstValue(),
'name' => $data,
),
);
$url
->setOptions($link_options);
$path = \Drupal\Core\Link::fromTextAndUrl(t('Choose'), $url)
->toRenderable();
$operations = render($path);
}
$url = \Drupal\Core\Url::fromUserInput('/cmis/document/' . $this->config . '/' . $id);
$path = \Drupal\Core\Link::fromTextAndUrl($data, $url)
->toRenderable();
$data = [
'#markup' => render($path),
];
}
private function preparePropertiesLink(&$operations) {
$url = \Drupal\Core\Url::fromUserInput('/cmis/object-properties/' . $this->config . '/' . $this->element
->getId());
$link_options = array(
'attributes' => array(
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => \Drupal\Component\Serialization\Json::encode([
'height' => 400,
'width' => 700,
]),
),
);
$url
->setOptions($link_options);
$path = \Drupal\Core\Link::fromTextAndUrl(t('Properties'), $url)
->toRenderable();
$links[] = [
'#markup' => render($path),
'#wrapper_attributes' => [
'class' => [
'object-properties',
],
],
];
if ($this->rootId != $this->element
->getId() && \Drupal::currentUser()
->hasPermission('access cmis operations')) {
$url = \Drupal\Core\Url::fromUserInput('/cmis/object-delete-verify/' . $this->config . '/' . $this->element
->getId());
$link_options = array(
'attributes' => array(
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => \Drupal\Component\Serialization\Json::encode([
'height' => 120,
'width' => 600,
]),
),
'query' => [
'type' => $this->type,
],
);
switch ($this->type) {
case 'browser':
$link_options['query']['parent'] = $this->parent
->getId();
break;
case 'query':
$link_options['query']['query_string'] = $this->query_string;
break;
}
$url
->setOptions($link_options);
$path = \Drupal\Core\Link::fromTextAndUrl(t('Delete'), $url)
->toRenderable();
$links[] = [
'#markup' => render($path),
'#wrapper_attributes' => [
'class' => [
'object-delete',
],
],
];
}
$list = [
'#theme' => 'item_list',
'#items' => $links,
'#type' => 'ul',
];
$operations = render($list);
}
}