Beispiel #1
0
 /**
  * get the value
  *
  * @param array $data
  * @param int $repeatCounter
  * @param array options
  * @return unknown
  */
 function getValue($data, $repeatCounter = 0, $opts = array())
 {
     //cludge for 2 scenarios
     if (is_array($data) && array_key_exists('rowid', $data)) {
         //when validating the data on form submission
         $key = 'rowid';
     } else {
         //when rendering the element to the form
         $key = '__pk_val';
     }
     //empty(data) when you are saving a new record and this element is in a joined group
     // $$$ hugh - added !array_key_exists(), as ... well, rowid doesn't always exist in the query string
     // $$$ rob replaced ALL references to rowid with __pk_val as rowid doesnt exists in the data :O
     //$$$ rob
     //($this->_inRepeatGroup && $this->_inJoin &&  $this->_repeatGroupTotal == $repeatCounter)
     //is for saying that the last record in a repeated join group should be treated as if it was in a new form
     // $$$ rob - erm why on earth would i want to do that! ?? (see above!) - test case:
     // form with joined data - make record with on repeated group (containing this element)
     // edit record and the commented out if statement below meant the user dd reverted
     // to the current logged in user and not the previously selected one
     if (empty($data) || !array_key_exists($key, $data) || array_key_exists($key, $data) && empty($data[$key])) {
         //if (empty($data) || !array_key_exists($key, $data) || (array_key_exists($key, $data) && empty($data[$key])) || ($this->_inRepeatGroup && $this->_inJoin &&  $this->_repeatGroupTotal == $repeatCounter)) {
         //new record
         //$$$ rob huh - whats with this else statement - the code is the same for both???
         // $$$ hugh - I was chasing a bug with user elements in joined data, but this bit was a blind alley
         // just forgot to get rid of it.
         /*if($this->_inRepeatGroup && $this->_inJoin &&  $this->_repeatGroupTotal == $repeatCounter && $this->_editable) {
         
         			$user =& JFactory::getUser();
         			// $$$ hugh - need to actually set $this->default
         			$element =& $this->getElement();
         			$element->default = $user->get('id');
         			return $element->default;
         			}else{
         			$user =& JFactory::getUser();
         			// $$$ hugh - need to actually set $this->default
         			$element =& $this->getElement();
         			$element->default = $user->get('id');
         			return $element->default;
         			}*/
         // 	$$$rob - if no search form data submitted for the search element then the default
         // selection was being applied instead
         // $$$ rob - added check on task to ensure that we are searching and not submitting a form
         // as otherwise not empty valdiation failed on user element
         if (JArrayHelper::getValue($opts, 'use_default', true) == false && !in_array(JRequest::getCmd('task'), array('processForm', 'view'))) {
             return '';
         } else {
             return $this->getDefaultValue($data);
         }
     }
     $res = parent::getValue($data, $repeatCounter, $opts);
     return $res;
 }