Skip to content

Commit

Permalink
Merge branch 'pu/pm/TbCalMakeEventAttendeeHandleDependentRecs' into '…
Browse files Browse the repository at this point in the history
…2024.11'

tweak(TB/Cal) make cal event attendees handle dependent records

See merge request tine20/tine20!5722
  • Loading branch information
paulmhh committed Aug 5, 2024
2 parents bdd9d68 + c95b70a commit a31d88e
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 25 deletions.
14 changes: 12 additions & 2 deletions tine20/Calendar/Backend/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,11 @@ public function createAttendee(Calendar_Model_Attender $_attendee)
if ($_attendee->displaycontainer_id instanceof Tinebase_Model_Container) {
$_attendee->displaycontainer_id = $_attendee->displaycontainer_id->getId();
}

return $this->_attendeeBackend->create($_attendee);

/** @var Calendar_Model_Attender $createdAttendee */
$createdAttendee = $this->_attendeeBackend->create($_attendee);
Calendar_Controller_Attender::getInstance()->handleSetDependentRecords($createdAttendee, $_attendee, null, true);
return $createdAttendee;
}

/**
Expand Down Expand Up @@ -844,6 +847,13 @@ public function updateAttendee(Calendar_Model_Attender $_attendee)
*/
public function deleteAttendee(array $_ids)
{
foreach ($_ids as $id) {
try {
Calendar_Controller_Attender::getInstance()->handleDeleteDependentRecords($this->_attendeeBackend->get($id));
} catch (Exception $e) {
Tinebase_Exception::log($e);
}
}
return $this->_attendeeBackend->delete($_ids);
}

Expand Down
35 changes: 35 additions & 0 deletions tine20/Calendar/Controller/Attender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* Tine 2.0
*
* @package Calendar
* @subpackage Controller
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <p.mehrer@metaways.de>
* @copyright Copyright (c) 2024 Metaways Infosystems GmbH (http://www.metaways.de)
*/

/**
* Calendar Attender FAKE Controller, used to set dependent records on attendees
*
* @package Calendar
* @subpackage Controller
*/
class Calendar_Controller_Attender extends Tinebase_Controller_Record_Abstract
{
use Tinebase_Controller_SingletonTrait;

protected function __construct()
{
$this->_applicationName = Calendar_Config::APP_NAME;
$this->_modelName = Calendar_Model_Attender::class;
$this->_backend = new Tinebase_Backend_Sql([
Tinebase_Backend_Sql::MODEL_NAME => $this->_modelName,
Tinebase_Backend_Sql::TABLE_NAME => Calendar_Model_Attender::TABLE_NAME,
Tinebase_Backend_Sql::MODLOG_ACTIVE => true,
]);
$this->_purgeRecords = false;
$this->_doContainerACLChecks = false;
$this->_doRightChecks = false;
}
}
7 changes: 6 additions & 1 deletion tine20/Calendar/Controller/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,8 @@ public function attenderStatusUpdate(Calendar_Model_Event $_event, Calendar_Mode
$attenderDisplayContainerId = $_attender->displaycontainer_id instanceof Tinebase_Model_Container ?
$_attender->displaycontainer_id->getId() :
$_attender->displaycontainer_id;

Calendar_Controller_Attender::getInstance()->handleSetDependentRecords($updatedAttender, $_attender, $currentAttender, false);

// check if something what can be set as user has changed
if ($currentAttender->status == $_attender->status &&
Expand Down Expand Up @@ -3150,8 +3152,11 @@ protected function _updateAttender($attender, $currentAttender, $event, $isResch


Tinebase_Timemachine_ModificationLog::getInstance()->setRecordMetaData($attender, 'update', $currentAttender);

$updatedAttender = $this->_backend->updateAttendee($attender);
Calendar_Controller_Attender::getInstance()->handleSetDependentRecords($updatedAttender, $attender, $currentAttender, false);

Tinebase_Timemachine_ModificationLog::getInstance()->writeModLog($attender, $currentAttender, get_class($attender), $this->_getBackendType(), $attender->getId());
$this->_backend->updateAttendee($attender);

if ($attender->displaycontainer_id !== $currentAttender->displaycontainer_id) {
$this->_increaseDisplayContainerContentSequence($currentAttender, $event, Tinebase_Model_ContainerContent::ACTION_DELETE);
Expand Down
6 changes: 6 additions & 0 deletions tine20/Calendar/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ class Calendar_Model_Event extends Tinebase_Record_Abstract
'attendee' => [
self::TYPE => self::TYPE_VIRTUAL, // RecordSet of Calendar_Model_Attender
self::OMIT_MOD_LOG => false,
self::CONFIG => [
self::TYPE => self::TYPE_PRE_EXPANDED,
self::CONFIG => [
self::RECORD_CLASS_NAME => Calendar_Model_Attender::class,
],
],
],
'alarms' => [
self::TYPE => self::TYPE_VIRTUAL, // RecordSet of Tinebase_Model_Alarm
Expand Down
54 changes: 33 additions & 21 deletions tine20/Tinebase/Controller/Record/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,33 @@ protected function _setRelatedData(Tinebase_Record_Interface $updatedRecord, Tin
Tinebase_Notes::getInstance()->setNotesOfRecord($updatedRecord);
}
}

$this->handleSetDependentRecords($updatedRecord, $record, $currentRecord, $isCreate);

if ($returnUpdatedRelatedData) {
$this->_getRelatedData($updatedRecord);
}

// rebuild paths
if ($this->_isRecordPathFeatureEnabled() && ($updatedRecord::generatesPaths() ||
($record->has('relations') &&
$this->_checkRelationsForPathGeneratingModels($record, $currentRecord)))) {
Tinebase_Record_Path::getInstance()->rebuildPaths($updatedRecord, $currentRecord);
}

if (null !== ($mc = $updatedRecord::getConfiguration())) {
foreach (array_keys($mc->getVirtualFields()) as $virtualField) {
if (!isset($updatedRecord[$virtualField])) {
$updatedRecord->{$virtualField} = $record->{$virtualField};
}
}
}

return $updatedRecord;
}

public function handleSetDependentRecords($updatedRecord, $record, $currentRecord, $isCreate): void
{
if ($this->_handleDependentRecords && ($config = $updatedRecord::getConfiguration())) {
if (is_array($config->recordsFields)) {
foreach ($config->recordsFields as $property => $fieldDef) {
Expand Down Expand Up @@ -1568,27 +1595,6 @@ protected function _setRelatedData(Tinebase_Record_Interface $updatedRecord, Tin
$ctrl->executeDelayedDependentRecords();
}
}

if ($returnUpdatedRelatedData) {
$this->_getRelatedData($updatedRecord);
}

// rebuild paths
if ($this->_isRecordPathFeatureEnabled() && ($updatedRecord::generatesPaths() ||
($record->has('relations') &&
$this->_checkRelationsForPathGeneratingModels($record, $currentRecord)))) {
Tinebase_Record_Path::getInstance()->rebuildPaths($updatedRecord, $currentRecord);
}

if (null !== ($mc = $updatedRecord::getConfiguration())) {
foreach (array_keys($mc->getVirtualFields()) as $virtualField) {
if (!isset($updatedRecord[$virtualField])) {
$updatedRecord->{$virtualField} = $record->{$virtualField};
}
}
}

return $updatedRecord;
}

/**
Expand Down Expand Up @@ -2383,6 +2389,12 @@ protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
if ($_record->has('alarms')) {
$this->_deleteAlarmsForIds(array($_record->getId()));
}

$this->handleDeleteDependentRecords($_record);
}

public function handleDeleteDependentRecords(Tinebase_Record_Interface $_record): void
{
if ($this->_handleDependentRecords && ($config = $_record::getConfiguration())) {
if (is_array($config->recordsFields)) {
foreach ($config->recordsFields as $property => $fieldDef) {
Expand Down
1 change: 1 addition & 0 deletions tine20/Tinebase/ModelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,7 @@ public function getFieldModel($field)
case self::TYPE_VIRTUAL:
if (isset($this->_fields[$field][self::CONFIG][self::TYPE]) && (self::TYPE_RELATION ===
$this->_fields[$field][self::CONFIG][self::TYPE] || self::TYPE_RELATIONS ===
$this->_fields[$field][self::CONFIG][self::TYPE] || self::TYPE_PRE_EXPANDED ===
$this->_fields[$field][self::CONFIG][self::TYPE])) {
return $this->_fields[$field][self::CONFIG][self::CONFIG][self::RECORD_CLASS_NAME];
}
Expand Down
4 changes: 3 additions & 1 deletion tine20/Tinebase/ModelConfiguration/Const.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Tinebase
* @subpackage ModelConfiguration
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @copyright Copyright (c) 2018-2023 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2018-2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Paul Mehrer <p.mehrer@metaways.de>
*/

Expand Down Expand Up @@ -269,6 +269,8 @@ class Tinebase_ModelConfiguration_Const {
public const TYPE_NUMBERABLE_INT = 'numberableInt';
public const TYPE_NUMBERABLE_STRING = 'numberableStr';
public const TYPE_PASSWORD = 'password';

public const TYPE_PRE_EXPANDED = 'preExpanded';
public const TYPE_RECORD = 'record';
public const TYPE_RECORDS = 'records';
public const TYPE_RELATION = 'relation';
Expand Down
2 changes: 2 additions & 0 deletions tine20/Tinebase/Record/Expander/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public static function create($_model, array $_definition, $_property, Tinebase_
case MCC::TYPE_RELATION:
return new Tinebase_Record_Expander_VirtualRelation($fieldDef[MCC::CONFIG][MCC::CONFIG],
$propModel, $_property, $_definition, $_rootExpander);
case MCC::TYPE_PRE_EXPANDED:
return new Tinebase_Record_Expander_VirtualPreExpanded($propModel, $_property, $_definition, $_rootExpander);
}
}

Expand Down
32 changes: 32 additions & 0 deletions tine20/Tinebase/Record/Expander/VirtualPreExpanded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);
/**
* expands records based on provided definition
*
* @package Tinebase
* @subpackage Record
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <p.mehrer@metaways.de>
* @copyright Copyright (c) 2024 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/

use Tinebase_ModelConfiguration_Const as MCC;

class Tinebase_Record_Expander_VirtualPreExpanded extends Tinebase_Record_Expander_Property
{
protected function _lookForDataToFetch(Tinebase_Record_RecordSet $_records)
{
foreach ($_records as $record) {
if ($record->{$this->_property} instanceof Tinebase_Record_RecordSet && $record->{$this->_property}->count() > 0) {
foreach ($this->_subExpanders as $expander) {
$expander->_lookForDataToFetch($record->{$this->_property});
}
}
}
}

protected function _setData(Tinebase_Record_RecordSet $_data)
{
throw new Tinebase_Exception_NotImplemented('do not call this method on ' . self::class);
}
}

0 comments on commit a31d88e

Please sign in to comment.