Skip to content

Commit

Permalink
Feature #147693 feat: Update replcaement tags (#53)
Browse files Browse the repository at this point in the history
* Feature #147693 feat: Update replcaement tags

* Feature #147693 feat: Update replcaement tags

* Feature #147693 feat: Update replcaement tags
  • Loading branch information
snehal0904 authored and manojLondhe committed Jul 18, 2019
1 parent 3198cda commit 20686c7
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/com_tjnotifications/admin/models/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,68 @@ public function getKeys($client)

return $existingKeys;
}

/**
* Method to get tag replacement count
*
* @param string $key Template key.
* @param string $client client.
*
* @return integer replacement tags count
*
* @since __DEPLOY_VERSION__
*/
public function getReplacementTagsCount($key, $client)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('replacement_tags'));
$query->from($db->quoteName('#__tj_notification_templates'));
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
$query->where($db->quoteName('key') . ' = ' . $db->quote($key));
$db->setQuery($query);
$replacementTags = $db->loadResult();

return count(json_decode($replacementTags));
}

/**
* Method to replace tags if they are changed
*
* @param array $data template data
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function updateReplacementTags($data)
{
if (!empty($data['replacement_tags']))
{
$replacementTags = json_encode($data['replacement_tags']);
}
else
{
return;
}

$db = JFactory::getDbo();
$query = $db->getQuery(true);

// Fields to update.
$fields = array(
$db->quoteName('replacement_tags') . ' = ' . $db->quote($replacementTags)
);

// Conditions for which records should be updated.
$conditions = array(
$db->quoteName('client') . ' = ' . $db->quote($data['client']),
$db->quoteName('key') . ' = ' . $db->quote($data['key'])
);

$query->update($db->quoteName('#__tj_notification_templates'))->set($fields)->where($conditions);
$db->setQuery($query);

$result = $db->execute();
}
}

0 comments on commit 20686c7

Please sign in to comment.