コード例 #1
0
ファイル: GxActiveRecord.php プロジェクト: dlds/yii2-giixer
 /**
  * @inheritdoc
  */
 public function getAttributeLabel($attribute)
 {
     $behavior = $this->getBehavior(self::BN_MUTATION);
     if ($behavior && in_array($attribute, $behavior->attrs)) {
         $relation = ArrayHelper::getValue($behavior->config, 3, false);
         if ($relation) {
             $attribute = sprintf('%s.%s', $relation, $attribute);
         }
     }
     return parent::getAttributeLabel($attribute);
 }
コード例 #2
0
ファイル: Misc.php プロジェクト: sjoorm/yii2-components
 /**
  * Formats associative array of attributes to string for email body insertion
  * @param ActiveRecord $model
  * @param boolean $html
  * @return string
  */
 public static function attributesToString(ActiveRecord $model, $html = true)
 {
     $result = '';
     $delimiter = $html ? "<br/>\n" : "\n";
     $attributes = $model instanceof PrintableRecordInterface ? $model->getAttributesToPrint($html) : $model->attributes;
     foreach ($attributes as $key => $value) {
         if (is_array($value)) {
             $value = json_encode($value);
         }
         $label = $model->getAttributeLabel($key);
         $result .= "<strong>{$label}:</strong> {$value} {$delimiter}";
     }
     return $result;
 }
コード例 #3
0
ファイル: Html.php プロジェクト: nisnaker/yii2-template
    public static function editor(ActiveRecord $model, $name, $options = [])
    {
        $label = $model->getAttributeLabel($name);
        $value = $model->{$name};
        $class = get_class($model);
        $class = basename(str_replace('\\', '/', $class));
        $low_class = strtolower($class);
        $filed_id = $low_class . '-' . $name;
        $str = <<<STR
<div class="form-group field-{$filed_id} editor" data-input-name="{$class}[{$name}]">
    <label class="control-label" for="{$filed_id}">{$label}</label>
    <div class="wrapper">
        <textarea id="{$filed_id}" style="width:600px" name="{$class}[{$name}]">{$value}</textarea>
    </div>
</div>
<script>KindEditor.create('#{$filed_id}', KEOptions)</script>
STR;
        return $str;
    }
コード例 #4
0
ファイル: ActiveRecord.php プロジェクト: nox-it/yii2-nox-mvc
 /**
  * Gets an attribute label
  *
  * @param string $attribute
  *
  * @return string
  */
 public function getAttributeLabel($attribute)
 {
     return parent::getAttributeLabel($attribute);
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public function getAttributeLabel($attribute)
 {
     if (isset($this->attributeLabels[$attribute])) {
         return Yii::t($this->messageCategory, $this->attributeLabels[$attribute]);
     }
     return parent::getAttributeLabel($attribute);
 }
コード例 #6
0
ファイル: Helper.php プロジェクト: tqsq2005/dotplant2
 /**
  * used with backend/widgets/DataRelationsWidget
  * @param ActiveRecord $model
  * @param $relationData
  * @return array
  */
 public static function getRelationDataByModel(ActiveRecord $model, $relationData)
 {
     $result = [];
     foreach ($relationData as $name => $data) {
         if ($data['type'] == 'field') {
             if (isset($model->attributes[$data['key']])) {
                 $result[$name] = ['value' => $model->{$data['key']}, 'label' => $model->getAttributeLabel($data['key'])];
             }
         } elseif ($data['type'] == 'property') {
             try {
                 $result[$name] = ['value' => $model->AbstractModel->{$data['key']}, 'label' => $model->AbstractModel->getAttributeLabel($data['key'])];
             } catch (Exception $e) {
                 Yii::warning('relation data not found: class: ' . $model::className() . '; relation Type' . $data['type'] . '; id ' . $model->id);
             }
         } elseif ($data['type'] == 'relation') {
             try {
                 $result[$name] = ['value' => $model->{$data['relationName']}->{$data['key']}, 'label' => $model->{$data['relationName']}->getAttributeLabel($data['key'])];
             } catch (Exception $e) {
                 Yii::warning('relation data not found: class: ' . $model::className() . '; relation Type' . $data['type'] . '; id ' . $model->id);
             }
         }
     }
     return $result;
 }