コード例 #1
0
 /**
  * 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 {
             if ($this->criteria === false) {
                 $parentobjects = CActiveRecord::model(get_class($this->_relatedModel))->findAll(array('order' => GHelper::guessNameColumn($this->_relatedModel->tableSchema->columns)));
             } else {
                 $parentobjects = CActiveRecord::model(get_class($this->_relatedModel));
                 $parentobjects->setDbCriteria($this->criteria);
                 $parentobjects = $parentobjects->findAll(array('order' => GHelper::guessNameColumn($this->_relatedModel->tableSchema->columns)));
             }
         }
     }
     if ($this->allowEmpty) {
         if (is_string($this->allowEmpty)) {
             $dataArray[''] = $this->allowEmpty;
         } else {
             $dataArray[''] = Yii::t('app', 'None');
         }
     }
     foreach ($parentobjects as $obj) {
         if (!is_array($this->fields)) {
             $this->fields = array($this->fields);
         }
         $fields = '';
         $i = 0;
         foreach ($this->fields as $field) {
             $rule = sprintf('{%s}', $field);
             $rules[$rule] = $obj->{$field};
             if ($i++ > 0) {
                 $fields .= $this->delimiter;
             }
             $fields .= $this->getModelData($obj, $field);
         }
         $defaultrules = array('{fields}' => $fields, '{id}' => $obj->{$obj->tableSchema->primaryKey});
         // Look for user-contributed functions and evaluate them
         if ($this->functions != array()) {
             foreach ($this->functions as $key => $function) {
                 // If the key is of type string, it's assumed to be a named function,
                 //  used like {myFuncName}.
                 // If the key is an integer, it's assumed to be an unnamed function used
                 //  the old way, {funcX} where X is its index in the functions array.
                 // We keep the integer support mostly for backwards compatibility, the
                 //  new way is encouraged.
                 if (is_string($key)) {
                     $funcrules[sprintf('{%s}', $key)] = $this->controller->evaluateExpression(strtr($function, $defaultrules));
                 } else {
                     $funcrules[sprintf('{func%d}', $key)] = $this->controller->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);
         // Apply the user contributed functions to $htmlOptions's template, if requested.
         if (isset($this->htmlOptions['template']) && $this->functionsInHtmlOptionsTemplate !== false && isset($funcrules) && is_array($funcrules)) {
             if (is_array($this->functionsInHtmlOptionsTemplate)) {
                 $funcrulesToUse = array();
                 foreach ($this->functionsInHtmlOptionsTemplate as $functionName) {
                     $functionName = sprintf('{%s}', $functionName);
                     if (isset($funcrules[$functionName])) {
                         $funcrulesToUse[$functionName] = $funcrules[$functionName];
                     }
                 }
                 $this->htmlOptions['template'] = strtr($this->htmlOptions['template'], $funcrulesToUse);
             } else {
                 $this->htmlOptions['template'] = strtr($this->htmlOptions['template'], $funcrules);
             }
         }
         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;
 }
コード例 #2
0
ファイル: update.php プロジェクト: rusli-nasir/smsempresayii
<?php

echo "<?php\n";
$nameColumn = GHelper::guessNameColumn($this->tableSchema->columns);
$label = $this->pluralize($this->class2name($this->modelClass));
echo "if(!isset(\$this->breadcrumbs))\n\r\n\$this->breadcrumbs=array(\r\n\t'{$label}'=>array('index'),\r\n\t\$model->{$nameColumn}=>array('view','id'=>\$model->{$this->tableSchema->primaryKey}),\r\n\tYii::t('app', 'Update'),\r\n);\n";
?>

if(!isset($this->menu))
$this->menu=array(
	array('label'=>Yii::t('app', 'List') . ' <?php 
echo $this->modelClass;
?>
', 'url'=>array('index')),
	array('label'=>Yii::t('app', 'Create') . ' <?php 
echo $this->modelClass;
?>
', 'url'=>array('create')),
	array('label'=>Yii::t('app', 'View') . ' <?php 
echo $this->modelClass;
?>
', 'url'=>array('view', 'id'=>$model-><?php 
echo $this->tableSchema->primaryKey;
?>
)),
	array('label'=>Yii::t('app', 'Manage') . ' <?php 
echo $this->modelClass;
?>
', 'url'=>array('admin')),
);
?>
コード例 #3
0
 public function getRecordTitle()
 {
     $nameColumn = GHelper::guessNameColumn($this->tableSchema->columns);
     return $this->{$nameColumn};
 }