Hooks: Add HookDocumentAction, HookDocumentItemAction classes.

pull/3683/head
Julio Montoya 5 years ago
parent 5ac02cf34b
commit e09e2c1d46
  1. 9
      main/document/document.php
  2. 10
      main/inc/lib/document.lib.php
  3. 31
      main/inc/lib/hook/HookDocumentAction.php
  4. 31
      main/inc/lib/hook/HookDocumentItemAction.php
  5. 8
      main/inc/lib/hook/interfaces/HookDocumentActionEventInterface.php
  6. 8
      main/inc/lib/hook/interfaces/HookDocumentItemActionEventInterface.php
  7. 6
      main/inc/lib/hook/interfaces/base/HookEventInterface.php

@ -217,7 +217,6 @@ $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpat
switch ($action) {
case 'replace':
if (($isAllowedToEdit ||
$groupMemberWithUploadRights ||
DocumentManager::isBasicCourseFolder($curdirpath, $sessionId) ||
@ -1840,6 +1839,14 @@ if ($isAllowedToEdit ||
api_get_path(WEB_CODE_PATH).'document/add_link.php?'.api_get_cidreq().'&id='.$documentIdFromGet
);
}
$hook = HookDocumentAction::create();
if (!empty($hook)) {
$data = $hook->notifyDocumentAction(HOOK_EVENT_TYPE_PRE);
if (isset($data['action'])) {
$actionsLeft .= $data['action'];
}
}
}
if (!isset($_GET['keyword']) && !$is_certificate_mode) {

@ -5595,6 +5595,16 @@ class DocumentManager
// is from a non-session context, hide the edition capabilities
$modify_icons = [];
$modify_icons[] = self::getButtonEdit($is_read_only, $document_data, $extension, $is_certificate_mode);
$hook = HookDocumentItemAction::create();
if (!empty($hook)) {
$hook->setEventData($document_data);
$data = $hook->notifyDocumentItemAction(HOOK_EVENT_TYPE_PRE);
if (isset($data['action'])) {
$modify_icons[] = $data['action'];
}
}
$modify_icons[] = self::getButtonMove($is_read_only, $document_data, $is_certificate_mode, $parent_id);
$modify_icons[] = self::getButtonVisibility(
$is_read_only,

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
class HookDocumentAction extends HookEvent implements HookDocumentActionEventInterface
{
protected function __construct()
{
parent::__construct('HookDocumentAction');
}
/**
* Update all the observers.
*
* @param int $type
*
* @return array
*/
public function notifyDocumentAction($type)
{
$this->eventData['type'] = $type;
/** @var HookDocumentActionEventInterface $observer */
foreach ($this->observers as $observer) {
$data = $observer->notifyDocumentAction($this);
$this->setEventData($data);
}
return $this->eventData;
}
}

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
class HookDocumentItemAction extends HookEvent implements HookDocumentItemActionEventInterface
{
protected function __construct()
{
parent::__construct('HookDocumentItemAction');
}
/**
* Update all the observers.
*
* @param int $type
*
* @return array
*/
public function notifyDocumentItemAction($type)
{
$this->eventData['type'] = $type;
/** @var HookDocumentItemActionEventInterface $observer */
foreach ($this->observers as $observer) {
$data = $observer->notifyDocumentItemAction($this);
$this->setEventData($data);
}
return $this->eventData;
}
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookDocumentActionEventInterface extends HookEventInterface
{
public function notifyDocumentAction($type);
}

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
interface HookDocumentItemActionEventInterface extends HookEventInterface
{
public function notifyDocumentItemAction($type);
}

@ -1,13 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains all Hook interfaces and their relation.
* They are used for Hook classes.
*
* @package chamilo.library.hook
*/
/**
* Interface HookEventInterface.
*/
interface HookEventInterface

Loading…
Cancel
Save