diff --git a/src/com_tjnotifications/admin/models/forms/notification.xml b/src/com_tjnotifications/admin/models/forms/notification.xml index 535a17e3..8aa70ebd 100644 --- a/src/com_tjnotifications/admin/models/forms/notification.xml +++ b/src/com_tjnotifications/admin/models/forms/notification.xml @@ -18,7 +18,7 @@ label="COM_TJNOTIFICATIONS_FIELD_CLIENT_LABEL" description="COM_TJNOTIFICATIONS_FIELD_CLIENT_DESC" type="sql" - query="select name from `#__extensions` where type='component' " + query="select LOWER(name) as name from `#__extensions` where type='component' " key_field="name" value_field="name" required="true" diff --git a/src/com_tjnotifications/admin/models/notification.php b/src/com_tjnotifications/admin/models/notification.php index 6c8c4e21..ca188d5f 100644 --- a/src/com_tjnotifications/admin/models/notification.php +++ b/src/com_tjnotifications/admin/models/notification.php @@ -17,6 +17,19 @@ */ class TjnotificationsModelNotification extends JModelAdmin { + /** + * Constructor. + * + * @param array $config An optional associative array of configuration settings. + * + * @since 3.2 + */ + public function __construct($config = array()) + { + $config['event_after_save'] = 'tjnOnAfterSaveNotificationTemplate'; + parent::__construct($config); + } + /** * Returns a reference to the a Table object, always creating it. * @@ -182,6 +195,9 @@ public function delete(&$cid) { $value[] = 1; parent::delete($data->id); + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('tjnotification'); + $dispatcher->trigger('tjnOnAfterDeleteNotificationTemplate', array($data)); } } else diff --git a/src/com_tjnotifications/install.tjnotification.php b/src/com_tjnotifications/install.tjnotification.php index 1cf0fd1b..0bc77591 100644 --- a/src/com_tjnotifications/install.tjnotification.php +++ b/src/com_tjnotifications/install.tjnotification.php @@ -15,6 +15,19 @@ **/ class Com_TjnotificationsInstallerScript { + /** @var array The list of extra modules and plugins to install */ + private $queue = array( + // Plugins => { (folder) => { (element) => (published) }* }* + 'plugins' => array( + 'actionlog' => array( + 'tjnotification' => 1 + ), + 'privacy' => array( + 'tjnotification' => 1, + ), + ), + ); + /** * method to install the component * @@ -26,6 +39,57 @@ public function install($parent) { } + /** + * This method is called after a component is uninstalled. + * + * @param \stdClass $parent Parent object calling this method. + * + * @return void + */ + public function uninstall($parent) + { + jimport('joomla.installer.installer'); + $db = JFactory::getDBO(); + $status = new JObject; + $status->plugins = array(); + $src = $parent->getParent()->getPath('source'); + + // Plugins uninstallation + if (count($this->queue['plugins'])) + { + foreach ($this->queue['plugins'] as $folder => $plugins) + { + if (count($plugins)) + { + foreach ($plugins as $plugin => $published) + { + $sql = $db->getQuery(true)->select($db->qn('extension_id')) + ->from($db->qn('#__extensions')) + ->where($db->qn('type') . ' = ' . $db->q('plugin')) + ->where($db->qn('element') . ' = ' . $db->q($plugin)) + ->where($db->qn('folder') . ' = ' . $db->q($folder)); + $db->setQuery($sql); + + $id = $db->loadResult(); + + if ($id) + { + $installer = new JInstaller; + $result = $installer->uninstall('plugin', $id); + $status->plugins[] = array( + 'name' => 'plg_' . $plugin, + 'group' => $folder, + 'result' => $result + ); + } + } + } + } + } + + return $status; + } + /** * method to update the component * @@ -38,6 +102,7 @@ public function update($parent) // Install SQL FIles $this->installSqlFiles($parent); $this->fix_db_on_update(); + $this->fixMenuLinks(); } /** @@ -62,6 +127,71 @@ public function preflight($type, $parent) */ public function postflight($type, $parent) { + $src = $parent->getParent()->getPath('source'); + $db = JFactory::getDbo(); + $status = new JObject; + $status->plugins = array(); + + // Plugins installation + if (count($this->queue['plugins'])) + { + foreach ($this->queue['plugins'] as $folder => $plugins) + { + if (count($plugins)) + { + foreach ($plugins as $plugin => $published) + { + $path = "$src/plugins/$folder/$plugin"; + + if (!is_dir($path)) + { + $path = "$src/plugins/$folder/plg_$plugin"; + } + + if (!is_dir($path)) + { + $path = "$src/plugins/$plugin"; + } + + if (!is_dir($path)) + { + $path = "$src/plugins/plg_$plugin"; + } + + if (!is_dir($path)) + { + continue; + } + + // Was the plugin already installed? + $query = $db->getQuery(true) + ->select('COUNT(*)') + ->from($db->qn('#__extensions')) + ->where($db->qn('element') . ' = ' . $db->q($plugin)) + ->where($db->qn('folder') . ' = ' . $db->q($folder)); + $db->setQuery($query); + $count = $db->loadResult(); + + $installer = new JInstaller; + $result = $installer->install($path); + + $status->plugins[] = array('name' => 'plg_' . $plugin, 'group' => $folder, 'result' => $result); + + if ($published && !$count) + { + $query = $db->getQuery(true) + ->update($db->qn('#__extensions')) + ->set($db->qn('enabled') . ' = ' . $db->q('1')) + ->where($db->qn('element') . ' = ' . $db->q($plugin)) + ->where($db->qn('folder') . ' = ' . $db->q($folder)); + $db->setQuery($query); + $db->execute(); + } + } + } + } + } + // Install SQL FIles $this->installSqlFiles($parent); } @@ -212,4 +342,27 @@ public function fix_db_on_update() $this->fixTemplateTable($db, $dbprefix, $config); } + + /** + * Fix Duplicate menu created for Notification + * + * @return void + * + * @Since 1.1 + */ + 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 . '"'; + + // Delete the mainmenu from menu table + $deleteMenu = $db->getQuery(true); + $deleteMenu->delete($db->quoteName('#__menu')); + $deleteMenu->where($db->quoteName('link') . 'IN (' . $allLinks . ')'); + $deleteMenu->where($db->quoteName('level') . " = 1"); + $db->setQuery($deleteMenu); + $db->execute(); + } } diff --git a/src/com_tjnotifications/site/controllers/preferences.php b/src/com_tjnotifications/site/controllers/preferences.php index e3fb1e56..65718327 100644 --- a/src/com_tjnotifications/site/controllers/preferences.php +++ b/src/com_tjnotifications/site/controllers/preferences.php @@ -24,7 +24,7 @@ class TJNotificationsControllerPreferences extends JControllerForm * @since 1.6 */ - public function save() + public function save($key = null, $urlVar = '') { $jinput = JFactory::getApplication()->input; $clientName = $jinput->get('client_name', ''); diff --git a/src/com_tjnotifications/site/models/preferences.php b/src/com_tjnotifications/site/models/preferences.php index 19f0c089..e976a0fd 100644 --- a/src/com_tjnotifications/site/models/preferences.php +++ b/src/com_tjnotifications/site/models/preferences.php @@ -111,6 +111,9 @@ public function save($data) if ($data) { parent::save($data); + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('tjnotification'); + $dispatcher->trigger('tjnOnAfterUnsubscribeNotification', array($data)); return true; } @@ -133,6 +136,9 @@ public function deletePreference(&$data) { if ($data) { + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('tjnotification'); + $dispatcher->trigger('tjnOnAfterResubscribeNotification', array($data)); $db = JFactory::getDbo(); $query = $db->getQuery(true); $conditions = array( @@ -281,7 +287,7 @@ public function getUnsubscribedUsers($client,$key) ); $db->setQuery($query); $userIds = $db->loadObjectList(); - $unsubscribed_users = ''; + $unsubscribed_users = array(); foreach ($userIds as $userId) { diff --git a/src/com_tjnotifications/site/views/preferences/tmpl/default.php b/src/com_tjnotifications/site/views/preferences/tmpl/default.php index 14efac69..d8965857 100644 --- a/src/com_tjnotifications/site/views/preferences/tmpl/default.php +++ b/src/com_tjnotifications/site/views/preferences/tmpl/default.php @@ -12,6 +12,7 @@