diff --git a/src/com_tjnotifications/admin/models/notifications.php b/src/com_tjnotifications/admin/models/notifications.php index 0ae26bf4..0200923a 100644 --- a/src/com_tjnotifications/admin/models/notifications.php +++ b/src/com_tjnotifications/admin/models/notifications.php @@ -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)); @@ -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]; } /** diff --git a/src/com_tjnotifications/admin/tjnotifications.xml b/src/com_tjnotifications/admin/tjnotifications.xml deleted file mode 100644 index 606b66eb..00000000 --- a/src/com_tjnotifications/admin/tjnotifications.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - TJNotifications - Dec 2016 - Tekdi Technology - 1.0.0 - - - sql/install.mysql.utf8.sql - - - - - sql/uninstall.mysql.utf8.sql - - - - index.html - tjnotifications.php - controller.php - views - images - models - controllers - - - en-GB.com_tjnotification.ini - - - Notifictions - - index.html - tjnotifications.php - controller.php - tables - views - sql - models - helpers - controllers - images - - - en-GB.com_tjnotifications.ini - en-GB.com_tjnotifications.sys.ini - - - install.tjnotification.php - diff --git a/src/com_tjnotifications/install.tjnotification.php b/src/com_tjnotifications/install.tjnotification.php index 0bc77591..bc6cc99f 100644 --- a/src/com_tjnotifications/install.tjnotification.php +++ b/src/com_tjnotifications/install.tjnotification.php @@ -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 * @@ -194,6 +203,8 @@ public function postflight($type, $parent) // Install SQL FIles $this->installSqlFiles($parent); + + $this->removeObsoleteFilesAndFolders($this->removeFilesAndFolders); } /** @@ -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); @@ -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); + } + } + } }