/** * 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); // $$$ 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"); $id = preg_replace('#_ro$#', '_raw', $id); } else { // $$$ rob 31/07/2011 not sure this is right - causes js error when field is hidden in form if (!strstr($id, '_raw') && array_key_exists($id . '_raw', $data)) { //$id .= '_raw'; } } $uid = JArrayHelper::getValue($data, $id, ''); 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); } else { JError::raiseWarning(E_NOTICE, "didnt load for {$element->default}"); } } return $str; }
/** * Draws the html form element * * @param array $data to preopulate element with * @param int $repeatCounter repeat group counter * * @return string elements html */ public function render($data, $repeatCounter = 0) { $element = $this->getElement(); $name = $this->getHTMLName($repeatCounter); $html_id = $this->getHTMLId($repeatCounter); $id = $html_id; $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->isEditable()) { $user = JFactory::getUser(); } else { $userid = (int) $this->getValue($data, $repeatCounter); $user = $userid === 0 ? JFactory::getUser() : JFactory::getUser($userid); } } 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); */ // $$$ 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 { if ($this->_inDetailedView) { $id = preg_replace('#_ro$#', '_raw', $id); } else { /** * $$$ rob 31/07/2011 not sure this is right - causes js error when field is hidden in form * $$$ hugh 10/31/2011 - but if we don't do it, $id is the label not the value (like 'username') * so wrong uid is written to form, and wipes out real ID when form is submitted. * OK, problem was we were using $id firther on as the html ID, so if we added _raw, element * on form had wrong ID. Added $html_id above, to use as (duh) html ID instead of $id. */ if (!strstr($id, '_raw') && array_key_exists($id . '_raw', $data)) { $id .= '_raw'; } } $id = JArrayHelper::getValue($data, $id, ''); if ($id === '') { $id = $this->getValue($data, $repeatCounter); } $id = is_array($id) ? $id[0] : $id; $user = $id === '' ? JFactory::getUser() : JFactory::getUser((int) $id); } } /** * 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'), $html_id); } $str = ''; if ($this->isEditable()) { $value = is_object($user) ? $user->get('id') : ''; if ($element->hidden) { $str = $this->_getHiddenField($name, $value, $html_id); } else { $str = parent::render($data, $repeatCounter); } } else { $displayParam = $this->getValColumn(); if (is_a($user, 'JUser')) { $str = $user->get($displayParam); } else { JError::raiseWarning(E_NOTICE, "didnt load for {$element->default}"); } } return $str; }