/** * Trigger called when a row is stored. * If we are creating a new record, and the element was set to readonly * then insert the users data into the record to be stored * * @param array &$data Data to store * @param int $repeatCounter Repeat group index * * @return bool If false, data should not be added. */ public function onStoreRow(&$data, $repeatCounter = 0) { if (!parent::onStoreRow($data, $repeatCounter)) { return false; } // $$$ hugh - if importing a CSV, just use the data as is if ($this->getListModel()->importingCSV) { return true; } $input = $this->app->input; // $$$ hugh - special case, if we have just run the fabrikjuser plugin, we need to // use the 'newuserid' as set by the plugin. $newUserId = $input->getInt('newuserid', 0); if (!empty($newUserId)) { $newUserIdElement = $input->get('newuserid_element', ''); $thisFullName = $this->getFullName(true, false); if ($newUserIdElement == $thisFullName) { return true; } } $element = $this->getElement(); $params = $this->getParams(); /* * After a failed validation, if readonly for ACL's, it may be JSON, and urlencoded, like ["94"] */ $data[$element->name] = is_array($data[$element->name]) ? $data[$element->name][0] : $data[$element->name]; $data[$element->name] = html_entity_decode($data[$element->name]); if (FabrikWorker::isJSON($data[$element->name])) { $data[$element->name] = FabrikWorker::JSONtoData($data[$element->name], true); } $data[$element->name] = is_array($data[$element->name]) ? $data[$element->name][0] : $data[$element->name]; /** * $$$ hugh - special case for social plugins (like CB plugin). If plugin sets * fabrik.plugin.profile_id, and 'user_use_social_plugin_profile' param is set, * and we are creating a new row, then use the session data as the user ID. * This allows user B to view a table in a CB profile for user A, do an "Add", * and have the user element set to user A's ID. */ // TODO - make this table/form specific, but not so easy to do in CB plugin if ((int) $params->get('user_use_social_plugin_profile', 0)) { //if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport') if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) { $session = JFactory::getSession(); if ($session->has('fabrik.plugin.profile_id')) { $data[$element->name] = $session->get('fabrik.plugin.profile_id'); $data[$element->name . '_raw'] = $data[$element->name]; // $session->clear('fabrik.plugin.profile_id'); return true; } } } // $$$ rob also check we aren't importing from CSV - if we are ignore //if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport') if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) { // $$$ rob if we cant use the element or its hidden force the use of current logged in user if (!$this->canUse() || $this->getElement()->hidden == 1) { $data[$element->name] = $this->user->get('id'); $data[$element->name . '_raw'] = $data[$element->name]; } } else { if ($this->updateOnEdit()) { $data[$element->name] = $this->user->get('id'); $data[$element->name . '_raw'] = $data[$element->name]; // Set the formDataWithTableName so any plugins (like email) pick it up with getProcessData() $thisFullName = $this->getFullName(true, false); $formModel = $this->getFormModel(); $groupModel = $this->getGroupModel(); if ($groupModel->canRepeat()) { $formModel->formDataWithTableName[$thisFullName][$repeatCounter] = array($data[$element->name]); $formModel->formDataWithTableName[$thisFullName . '_raw'][$repeatCounter] = array($data[$element->name]); } else { $formModel->formDataWithTableName[$thisFullName] = array($data[$element->name]); $formModel->formDataWithTableName[$thisFullName . '_raw'] = array($data[$element->name]); } // $$$ hugh - need to add to updatedByPlugin() in order to override write access settings. // This allows us to still 'update on edit' when element is write access controlled. if (!$this->canUse()) { $this->getFormModel()->updatedByPlugin($thisFullName, $this->user->get('id')); } } else { if ($this->getListModel()->importingCSV) { $formData = $this->getFormModel()->formData; $userId = FArrayHelper::getValue($formData, $element->name, ''); if (!empty($userId) && !is_numeric($userId)) { $user = JFactory::getUser($userId); $newUserId = $user->get('id'); if (empty($newUserId) && FabrikWorker::isEmail($userId)) { $db = $this->_db; $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__users'))->where($db->qn('email') . ' = ' . $db-- > q($userId)); $db->setQuery($query, 0, 1); $newUserId = (int) $db->loadResult(); } $data[$element->name] = $newUserId; } } } } return true; }
/** * Trigger called when a row is stored. * If we are creating a new record, and the element was set to readonly * then insert the users data into the record to be stored * * @param array &$data Data to store * @param int $repeatCounter Repeat group index * * @return bool If false, data should not be added. */ public function onStoreRow(&$data, $repeatCounter = 0) { if (!parent::onStoreRow($data, $repeatCounter)) { return false; } $app = JFactory::getApplication(); $input = $app->input; // $$$ hugh - special case, if we have just run the fabrikjuser plugin, we need to // use the 'newuserid' as set by the plugin. $newuserid = $input->getInt('newuserid', 0); if (!empty($newuserid)) { $newuserid_element = $input->get('newuserid_element', ''); $this_fullname = $this->getFullName(true, false); if ($newuserid_element == $this_fullname) { return true; } } $element = $this->getElement(); $params = $this->getParams(); /** * $$$ hugh - special case for social plugins (like CB plugin). If plugin sets * fabrik.plugin.profile_id, and 'user_use_social_plugin_profile' param is set, * and we are creating a new row, then use the session data as the user ID. * This allows user B to view a table in a CB profile for user A, do an "Add", * and have the user element set to user A's ID. */ // TODO - make this table/form specific, but not so easy to do in CB plugin if ((int) $params->get('user_use_social_plugin_profile', 0)) { //if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport') if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) { $session = JFactory::getSession(); if ($session->has('fabrik.plugin.profile_id')) { $data[$element->name] = $session->get('fabrik.plugin.profile_id'); $data[$element->name . '_raw'] = $data[$element->name]; // $session->clear('fabrik.plugin.profile_id'); return true; } } } // $$$ rob also check we aren't importing from CSV - if we are ignore //if ($input->getString('rowid', '', 'string') == '' && $input->get('task') !== 'doimport') if ($input->getString('rowid', '', 'string') == '' && !$this->getListModel()->importingCSV) { // $$$ rob if we cant use the element or its hidden force the use of current logged in user if (!$this->canUse() || $this->getElement()->hidden == 1) { $user = JFactory::getUser(); $data[$element->name] = $user->get('id'); $data[$element->name . '_raw'] = $data[$element->name]; } } else { if ($this->updateOnEdit()) { $user = JFactory::getUser(); $data[$element->name] = $user->get('id'); $data[$element->name . '_raw'] = $data[$element->name]; // $$$ hugh - need to add to updatedByPlugin() in order to override write access settings. // This allows us to still 'update on edit' when element is write access controlled. if (!$this->canUse()) { $this_fullname = $this->getFullName(true, false); $this->getFormModel()->updatedByPlugin($this_fullname, $user->get('id')); } } else { if ($this->getListModel()->importingCSV) { $formData = $this->getFormModel()->formData; $userid = JArrayHelper::getValue($formData, $element->name, ''); if (!empty($userid) && !is_numeric($userid)) { $user = JFactory::getUser($userid); $new_userid = $user->get('id'); if (empty($new_userid) && FabrikWorker::isEmail($userid)) { $db = JFactory::getDbo(); $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('email') . ' = ' . $db->quote($userid)); $db->setQuery($query, 0, 1); $new_userid = (int) $db->loadResult(); } $data[$element->name] = $new_userid; } } } } return true; }