Skip to content

Commit

Permalink
Hooks: Add HookDocumentAction, HookDocumentItemAction classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 30, 2020
1 parent 5ac02cf commit e09e2c1
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 5 deletions.
9 changes: 8 additions & 1 deletion main/document/document.php
Expand Up @@ -217,7 +217,6 @@

switch ($action) {
case 'replace':

if (($isAllowedToEdit ||
$groupMemberWithUploadRights ||
DocumentManager::isBasicCourseFolder($curdirpath, $sessionId) ||
Expand Down Expand Up @@ -1840,6 +1839,14 @@ function convertModal (id, format) {
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) {
Expand Down
10 changes: 10 additions & 0 deletions main/inc/lib/document.lib.php
Expand Up @@ -5595,6 +5595,16 @@ public static function build_edit_icons($document_data, $id, $is_template, $is_r
// 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,
Expand Down
31 changes: 31 additions & 0 deletions main/inc/lib/hook/HookDocumentAction.php
@@ -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;
}
}
31 changes: 31 additions & 0 deletions main/inc/lib/hook/HookDocumentItemAction.php
@@ -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);
}
6 changes: 2 additions & 4 deletions main/inc/lib/hook/interfaces/base/HookEventInterface.php
@@ -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
Expand Down

0 comments on commit e09e2c1

Please sign in to comment.