1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: ljt
- * DateTime: 2016/10/20 11:49
- * Description:
- */
- namespace backend\components;
- use common\models\Circle;
- use common\models\CircleCat;
- use common\modules\user\models\User;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Html;
- class Formatter extends \yii\i18n\Formatter
- {
- /**
- * 格式化用户名
- * @param $value
- * @return mixed
- * @author nodelog
- */
- public function asUser($value)
- {
- return $this->asAdmin($value);
- }
- public function asAdmin($value)
- {
- return ArrayHelper::getValue(User::findOne($value), 'nickname', '');
- }
- public function asColor($value, $color = 'default')
- {
- if ($color instanceof \Closure) {
- $color = call_user_func($color, $value);
- }
- return Html::tag('span', $value, ['class' => 'text-' . $color]);
- }
- /**
- * 添加后缀
- * @param $value
- * @param string $suffix
- * @return string
- * @author nodelog
- */
- public function asSuffix($value, $suffix = '')
- {
- return Html::tag('span', $value . $suffix);
- }
- /**
- * 添加前缀
- * @param $value
- * @param string $prefix
- * @return string
- * @author nodelog
- */
- public function asPrefix($value, $prefix = '')
- {
- return Html::tag('span', $prefix . $value);
- }
- /**
- * 多张图片格式化
- * @param $values
- * @param array $options
- * @return string
- * @author nodelog
- */
- public function asImages($values, $options = [])
- {
- $html = '';
- foreach ($values as $value) {
- $html .= parent::asImage($value, $options);
- }
- return $html;
- }
- public function asCircleCat($value)
- {
- return ArrayHelper::getValue(CircleCat::findOne($value), 'title', '');
- }
- public function asCircleType($value)
- {
- return Circle::$typeList[$value];
- }
- }
|