From 11947f96dd000eabeaf0294fcc4a625717b0d7f2 Mon Sep 17 00:00:00 2001 From: ranjit redekar Date: Fri, 30 Jun 2017 17:56:12 +0530 Subject: [PATCH] Bug #107010 --- administrator/controllers/hierarchys.php | 7 +++-- administrator/models/hierarchy.php | 35 ++++++++++++++++++++++++ administrator/models/hierarchys.php | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/administrator/controllers/hierarchys.php b/administrator/controllers/hierarchys.php index 0e35c6a..59eaafe 100755 --- a/administrator/controllers/hierarchys.php +++ b/administrator/controllers/hierarchys.php @@ -185,11 +185,14 @@ public function setUser() { $jinput = JFactory::getApplication()->input; $subuserId = $jinput->get->get('subuserId', '', 'int'); - $bossuserId = $jinput->post->get('user_id', '', 'int'); + $userId = $jinput->post->get('user_id', '', 'int'); // Get the model $model = $this->getModel(); - $return = $model->saveUserHier($bossuserId, $subuserId); + $data = array(); + $data['subuser_id'] = $subuserId; + $data['user_id'] = $userId; + $return = $model->save($data); jexit(); } diff --git a/administrator/models/hierarchy.php b/administrator/models/hierarchy.php index 6d6dca3..14a2a4e 100755 --- a/administrator/models/hierarchy.php +++ b/administrator/models/hierarchy.php @@ -285,4 +285,39 @@ public function saveCSVdata($userData) return $output; } + + /** + * Prepare and sanitise the data prior to saving. + * + * @param ARRAY $data it is array of managerId, empId, client, clientId and state. + * + * @return void + * + * @since 1.6 + */ + public function save($data) + { + $db = $this->getDbo(); + + try + { + JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_hierarchy/tables'); + $userHierarchyObj = JTable::getInstance('Hierarchy', 'HierarchyTable', array('dbo', $db)); + $userHierarchyObj->load(array('subuser_id' => (int) $data['subuser_id'])); + $data['id'] = isset($userHierarchyObj->id) ? $userHierarchyObj->id : '' ; + + if (parent::save($data)) + { + return $data; + } + } + catch (RuntimeException $e) + { + $this->setError($e->getMessage()); + + return false; + } + + return false; + } } diff --git a/administrator/models/hierarchys.php b/administrator/models/hierarchys.php index e1cc3f0..22addd8 100644 --- a/administrator/models/hierarchys.php +++ b/administrator/models/hierarchys.php @@ -317,7 +317,7 @@ public function getSubusers($userId) } $query->select($db->quoteName('hu.subuser_id')); - $query->from($db->quoteName('#__hierarchy_users'), 'hu'); + $query->from($db->quoteName('#__hierarchy_users', 'hu')); $query->join('inner', $db->quoteName('#__users') . 'as u ON u.id=hu.subuser_id'); $query->where($conditions); $db->setQuery($query);