Skip to content

Commit

Permalink
Feature: Allow multiple templates for single notification key/type (#39)
Browse files Browse the repository at this point in the history
* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Feature #136941 feat: Shika - TJNotification integration

* Feature #136941 feat: Shika - TJNotification integration

* Task #137713 feat: Multiple template for single notification

* Task #137713 feat: Multiple template for single notification

* Update notifications.php
  • Loading branch information
pranotiTechjoomla authored and manojLondhe committed Jan 14, 2019
1 parent b242b58 commit e60e48b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 68 deletions.
35 changes: 17 additions & 18 deletions src/com_tjnotifications/admin/models/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getListQuery()
}
}

// Fot getting templates
// For getting templates
if (!empty($client) && !empty($key))
{
$query->where($db->quoteName('client') . ' = ' . $db->quote($client) . ' AND ' . $db->quoteName('key') . ' = ' . $db->quote($key));
Expand All @@ -110,37 +110,36 @@ protected function getListQuery()
/**
* Method to get the record form.
*
* @param array $client An optional array of data for the form to interogate.
* @param array $key True if the form is to load its own data (default case), false if not.
* @param String $client An optional array of data for the form to interogate.
* @param String $key True if the form is to load its own data (default case), false if not.
*
* @return JForm A JForm object on success, false on failure
*
* @since 1.6
*/
public function getTemplate($client,$key)
public function getTemplate($client, $key)
{
$this->setState('filter.client', $client);
$object = clone $this;

$this->setState('filter.key', $key);
$this->setState('filter.client', $client);

// Explode the key at #. e.g : donate#vendor1#store1
$key_parts = explode('#', $key);
// Return exact template according key and client
$templates = $this->getItems();

// If $key_parts[1] i.e vendor1 is set means overrided then it will return latest template. i.e donate#vendor1#store1
if (isset($key_parts[1]))
// If templates object is empty and key contain # then check for default (fallback) template.
if (empty($templates) && strpos($key, '#'))
{
// Get index of latest template.
$latest = sizeof($templates) - 1;
$template = $templates[$latest];
// Regex for removing last part of the string
// Eg if input string is global#vendor#course then the output is global#vendor

return $template;
}
else
{
// If template is not overrided then return original template e.g: donate
$key = preg_replace('/#[^#]*$/', '', $key);

return $templates[0];
// Call function recursively with modified key
return $object->getTemplate($client, $key);
}

return $templates[0];
}

/**
Expand Down
49 changes: 0 additions & 49 deletions src/com_tjnotifications/admin/tjnotifications.xml

This file was deleted.

57 changes: 56 additions & 1 deletion src/com_tjnotifications/install.tjnotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ class Com_TjnotificationsInstallerScript
),
);

/** @var array Obsolete files and folders to remove*/
private $removeFilesAndFolders = array(
'files' => array(
'administrator/components/com_tjnotifications/tjnotifications.xml'
),
'folders' => array(
)
);

/**
* method to install the component
*
Expand Down Expand Up @@ -194,6 +203,8 @@ public function postflight($type, $parent)

// Install SQL FIles
$this->installSqlFiles($parent);

$this->removeObsoleteFilesAndFolders($this->removeFilesAndFolders);
}

/**
Expand Down Expand Up @@ -355,7 +366,7 @@ public function fixMenuLinks()
$db = JFactory::getDbo();
$link = 'index.php?option=com_tjnotifications&view=notifications&extension=com_jticketing';
$link1 = 'index.php?option=com_tjnotifications&extension=com_tjvendors';
$allLinks = '"' . $link . '","'. $link1 . '"';
$allLinks = '"' . $link . '","' . $link1 . '"';

// Delete the mainmenu from menu table
$deleteMenu = $db->getQuery(true);
Expand All @@ -365,4 +376,48 @@ public function fixMenuLinks()
$db->setQuery($deleteMenu);
$db->execute();
}

/**
* Removes obsolete files and folders
*
* @param array $removeFilesAndFolders Array of the files and folders to be removed
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
private function removeObsoleteFilesAndFolders($removeFilesAndFolders)
{
// Remove files
if (!empty($removeFilesAndFolders['files']))
{
foreach ($removeFilesAndFolders['files'] as $file)
{
$f = JPATH_ROOT . '/' . $file;

if (!JFile::exists($f))
{
continue;
}

JFile::delete($f);
}
}

// Remove folders
if (!empty($removeFilesAndFolders['folders']))
{
foreach ($removeFilesAndFolders['folders'] as $folder)
{
$f = JPATH_ROOT . '/' . $folder;

if (!JFolder::exists($f))
{
continue;
}

JFolder::delete($f);
}
}
}
}

0 comments on commit e60e48b

Please sign in to comment.