/**
  * This function fetches all needed data of the related Object and returns them
  * in an array that is prepared for use in ListData.
  */
 public function getRelatedData()
 {
     /* At first we determine, if we want to display all parent Objects, or
      * if the User supplied an list of Objects */
     if (is_object($this->parentObjects)) {
         $parentobjects = array($this->parentObjects);
     } else {
         if (is_array($this->parentObjects)) {
             $parentobjects = $this->parentObjects;
         } else {
             $parentobjects = CActiveRecord::model(get_class($this->_relatedModel))->findAll();
         }
     }
     if ($this->allowEmpty) {
         if (is_string($this->allowEmpty)) {
             $dataArray[0] = $this->allowEmpty;
         } else {
             $dataArray[0] = Yii::t('app', 'None');
         }
     }
     foreach ($parentobjects as $obj) {
         if (!is_array($this->fields)) {
             $this->fields = array($this->fields);
         }
         $fields = '';
         foreach ($this->fields as $field) {
             $rule = sprintf('{%s}', $field);
             $rules[$rule] = $obj->{$field};
             $fields .= $this->getModelData($obj, $field);
             if (count($this->fields) > 1) {
                 $fields .= $this->delimiter;
             }
         }
         $defaultrules = array('{fields}' => $fields, '{id}' => $obj->id);
         // Look for user-contributed functions and evaluate them
         if ($this->functions != array()) {
             foreach ($this->functions as $key => $function) {
                 $funcrules[sprintf('{func%d}', $key)] = CComponent::evaluateExpression(strtr($function, $defaultrules));
             }
         }
         // Merge the evaluated rules, if exist
         if (isset($funcrules)) {
             $rules = array_merge($rules, $funcrules);
         }
         // Merge the default rules into our ruleset
         $rules = array_merge($rules, $defaultrules);
         // Apply the rules to the template
         $value = strtr($this->template, $rules);
         if ($this->groupParentsBy != '') {
             $dataArray[$obj->{$this->groupParentsBy}][$obj->{$this->relatedPk}] = $value;
         } else {
             $dataArray[$obj->{$this->relatedPk}] = $value;
         }
     }
     if (!isset($dataArray) || !is_array($dataArray)) {
         $dataArray = array();
     }
     return $dataArray;
 }