/** * draws the form element * @param int repeat group counter * @return string returns element html */ function render($data, $repeatCounter = 0) { $element =& $this->getElement(); $name = $this->getHTMLName($repeatCounter); $id = $this->getHTMLId($repeatCounter); $params =& $this->getParams(); // $$$ rob - if embedding a form inside a details view then rowid is true (for the detailed view) but we are still showing a new form // instead take a look at the element form's _rowId; //$rowid = JRequest::getVar('rowid', false); $rowid = $this->getForm()->_rowId; //@TODO when editing a form with joined repeat group the rowid will be set but //the record is in fact new if ($params->get('update_on_edit') || !$rowid || $this->_inRepeatGroup && $this->_inJoin && $this->_repeatGroupTotal == $repeatCounter) { //set user to logged in user if ($this->_editable) { $user =& JFactory::getUser(); } else { $user =& JFactory::getUser((int) $this->getValue($data, $repeatCounter)); } } else { // $$$ hugh - this is blowing away the userid, as $element->default is empty at this point // so for now I changed it to the $data value //keep previous user //$user =& JFactory::getUser((int)$element->default); $userKey = $id; // $$$ hugh ... what a mess ... of course if it's a new form, $data doesn't exist ... if (empty($data)) { // if $data is empty, we must (?) be a new row, so just grab logged on user $user =& JFactory::getUser(); } else { //$$$ rob - changed from $name to $id as if your element is in a repeat group name as "[]" at the end //$user =& JFactory::getUser((int)$data[$name . '_raw']); if ($this->_inDetailedView) { //$id = FabrikString::rtrimWord($id, "_ro"); $userKey = preg_replace('#_ro$#', '_raw', $userKey); } else { if (!strstr($userKey, '_raw') && array_key_exists($userKey . '_raw', $data)) { $userKey .= '_raw'; } } $uid = JArrayHelper::getValue($data, $userKey, ''); if ($uid === '') { $uid = $this->getValue($data, $repeatCounter); } $user =& JFactory::getUser((int) $uid); } } // if the table database is not the same as the joomla database then // we should simply return a hidden field with the user id in it. if (!$this->inJDb()) { return $this->_getHiddenField($name, $user->get('id'), $id); } $str = ''; if ($this->_editable) { $value = $user->get('id'); if ($element->hidden) { $str = $this->_getHiddenField($name, $value, $id); } else { $str = parent::render($data, $repeatCounter); } } else { $displayParam = $params->get('my_table_data', 'username'); if (is_a($user, 'JUser')) { $str = $user->get($displayParam); $str = $this->_replaceWithIcons($str); } else { JError::raiseWarning(E_NOTICE, "didnt load for {$element->default}"); } } return $str; }