Skip to content

Commit e60e48b

Browse files
pranotiTechjoomlamanojLondhe
authored andcommitted
Feature: Allow multiple templates for single notification key/type (#39)
* 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
1 parent b242b58 commit e60e48b

File tree

3 files changed

+73
-68
lines changed

3 files changed

+73
-68
lines changed

src/com_tjnotifications/admin/models/notifications.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function getListQuery()
8989
}
9090
}
9191

92-
// Fot getting templates
92+
// For getting templates
9393
if (!empty($client) && !empty($key))
9494
{
9595
$query->where($db->quoteName('client') . ' = ' . $db->quote($client) . ' AND ' . $db->quoteName('key') . ' = ' . $db->quote($key));
@@ -110,37 +110,36 @@ protected function getListQuery()
110110
/**
111111
* Method to get the record form.
112112
*
113-
* @param array $client An optional array of data for the form to interogate.
114-
* @param array $key True if the form is to load its own data (default case), false if not.
113+
* @param String $client An optional array of data for the form to interogate.
114+
* @param String $key True if the form is to load its own data (default case), false if not.
115115
*
116116
* @return JForm A JForm object on success, false on failure
117117
*
118118
* @since 1.6
119119
*/
120-
public function getTemplate($client,$key)
120+
public function getTemplate($client, $key)
121121
{
122-
$this->setState('filter.client', $client);
122+
$object = clone $this;
123+
123124
$this->setState('filter.key', $key);
125+
$this->setState('filter.client', $client);
124126

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

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

136-
return $template;
137-
}
138-
else
139-
{
140-
// If template is not overrided then return original template e.g: donate
136+
$key = preg_replace('/#[^#]*$/', '', $key);
141137

142-
return $templates[0];
138+
// Call function recursively with modified key
139+
return $object->getTemplate($client, $key);
143140
}
141+
142+
return $templates[0];
144143
}
145144

146145
/**

src/com_tjnotifications/admin/tjnotifications.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/com_tjnotifications/install.tjnotification.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ class Com_TjnotificationsInstallerScript
2828
),
2929
);
3030

31+
/** @var array Obsolete files and folders to remove*/
32+
private $removeFilesAndFolders = array(
33+
'files' => array(
34+
'administrator/components/com_tjnotifications/tjnotifications.xml'
35+
),
36+
'folders' => array(
37+
)
38+
);
39+
3140
/**
3241
* method to install the component
3342
*
@@ -194,6 +203,8 @@ public function postflight($type, $parent)
194203

195204
// Install SQL FIles
196205
$this->installSqlFiles($parent);
206+
207+
$this->removeObsoleteFilesAndFolders($this->removeFilesAndFolders);
197208
}
198209

199210
/**
@@ -355,7 +366,7 @@ public function fixMenuLinks()
355366
$db = JFactory::getDbo();
356367
$link = 'index.php?option=com_tjnotifications&view=notifications&extension=com_jticketing';
357368
$link1 = 'index.php?option=com_tjnotifications&extension=com_tjvendors';
358-
$allLinks = '"' . $link . '","'. $link1 . '"';
369+
$allLinks = '"' . $link . '","' . $link1 . '"';
359370

360371
// Delete the mainmenu from menu table
361372
$deleteMenu = $db->getQuery(true);
@@ -365,4 +376,48 @@ public function fixMenuLinks()
365376
$db->setQuery($deleteMenu);
366377
$db->execute();
367378
}
379+
380+
/**
381+
* Removes obsolete files and folders
382+
*
383+
* @param array $removeFilesAndFolders Array of the files and folders to be removed
384+
*
385+
* @return void
386+
*
387+
* @since __DEPLOY_VERSION__
388+
*/
389+
private function removeObsoleteFilesAndFolders($removeFilesAndFolders)
390+
{
391+
// Remove files
392+
if (!empty($removeFilesAndFolders['files']))
393+
{
394+
foreach ($removeFilesAndFolders['files'] as $file)
395+
{
396+
$f = JPATH_ROOT . '/' . $file;
397+
398+
if (!JFile::exists($f))
399+
{
400+
continue;
401+
}
402+
403+
JFile::delete($f);
404+
}
405+
}
406+
407+
// Remove folders
408+
if (!empty($removeFilesAndFolders['folders']))
409+
{
410+
foreach ($removeFilesAndFolders['folders'] as $folder)
411+
{
412+
$f = JPATH_ROOT . '/' . $folder;
413+
414+
if (!JFolder::exists($f))
415+
{
416+
continue;
417+
}
418+
419+
JFolder::delete($f);
420+
}
421+
}
422+
}
368423
}

0 commit comments

Comments
 (0)