Skip to content

Commit

Permalink
Merge pull request #185 from ankush-maherwal/release-1.2.1
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
ankush-maherwal authored Aug 28, 2019
2 parents ef35ffb + 7471853 commit 5250b5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg)
if (returnedData.data !== null)
{
jQuery('#item-form').removeClass('dirty');
jQuery("#recordId").val(returnedData.data.id);

if ('save' == status)
{
Expand All @@ -133,7 +134,6 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg)
}
else
{
jQuery("#recordId").val(returnedData.data.id);
promise = true;

if (showDraftSuccessMsg === "1")
Expand Down
33 changes: 23 additions & 10 deletions src/components/com_tjucm/site/models/itemform.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,19 @@ public function save($data, $extra_jform_data = '')

// If there is ownership field in form and the field is assigned some value then update created_by for the record
$client = explode(".", $itemDetails->client);
$createdByField = $client[0] . '_' . $client[1] . '_ownershipcreatedby';
$ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby';

if (isset($extra_jform_data[$createdByField]) && !empty($extra_jform_data[$createdByField]))
if (isset($extra_jform_data[$ownershipField]) && !empty($extra_jform_data[$ownershipField]))
{
$data['created_by'] = $extra_jform_data[$createdByField];
JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR);
$ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable');
$ownershipFieldData->load(array('name' => $ownershipField));
$ownershipFieldParams = json_decode($ownershipFieldData->params);

if ($ownershipFieldParams->ucmItemOwner == 1)
{
$data['created_by'] = $extra_jform_data[$ownershipField];
}
}
else
{
Expand Down Expand Up @@ -819,20 +827,25 @@ public function allowedToAddTypeData($userId, $client, $allowedCount)
*/
public function setClusterData(&$validData, $data)
{
$clusterField = $createdByField = '';
$clusterField = $ownershipField = '';

// To get type of UCM
if (!empty($this->client))
{
$client = explode(".", $this->client);
$clusterField = $client[0] . '_' . $client[1] . '_clusterclusterid';
$createdByField = $client[0] . '_' . $client[1] . '_ownershipcreatedby';
$ownershipField = $client[0] . '_' . $client[1] . '_ownershipcreatedby';
}

JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR);
$ownershipFieldData = Table::getInstance('Field', 'TjfieldsTable');
$ownershipFieldData->load(array('name' => $ownershipField));
$ownershipFieldParams = json_decode($ownershipFieldData->params);

// Save created_by field by ownership user field (To save form on behalf of someone)
if (!empty($data[$createdByField]) && empty($data[$clusterField]))
if (!empty($data[$ownershipField]) && empty($data[$clusterField]) && ($ownershipFieldParams->ucmItemOwner == 1))
{
$validData['created_by'] = $data[$createdByField];
$validData['created_by'] = $data[$ownershipField];
}

// Cluster Id store in UCM data
Expand Down Expand Up @@ -861,7 +874,7 @@ public function setClusterData(&$validData, $data)
{
$validData['cluster_id'] = $data[$clusterField];

if (!empty($data[$createdByField]))
if (!empty($data[$ownershipField]))
{
$clusterUsers = array();

Expand All @@ -870,9 +883,9 @@ public function setClusterData(&$validData, $data)
$clusterUsers[] = $cluster->user_id;
}

if (in_array($data[$createdByField], $clusterUsers))
if (in_array($data[$ownershipField], $clusterUsers) && ($ownershipFieldParams->ucmItemOwner == 1))
{
$validData['created_by'] = $data[$createdByField];
$validData['created_by'] = $data[$ownershipField];
}
}
}
Expand Down

0 comments on commit 5250b5d

Please sign in to comment.