public function actionBatch()
 {
     $path = Yii::$app->request->get('path');
     $action = $this->module->findBatchAction($path);
     if ($action == null) {
         throw new InvalidConfigException('Cannot find action with path ' . $path);
     }
     list($class, $method) = $action['method'];
     if (!method_exists($class, $method)) {
         throw new InvalidConfigException('Cannot find method: ' . implode('::', $action['method']));
     }
     $result = call_user_func($action['method'], StringHelper::explode(Yii::$app->request->get('guids'), ','));
     if ($result instanceof BatchResultBase) {
         if (count($result->oks) > 0) {
             $ok = Yii::t('vps-uploader', 'Following files were processed.');
             $ok .= Html::ul($result->getListItems('ok'), ['encode' => false]);
             Yii::$app->notification->messageToSession($ok);
         }
         if (count($result->errors) > 0) {
             $error = Yii::t('vps-uploader', 'Following files were NOT processed.');
             $error .= Html::ul($result->getListItems('error'), ['encode' => false]);
             Yii::$app->notification->errorToSession($error);
         }
     }
     $this->redirect(Yii::$app->request->referrer);
 }
Beispiel #2
0
 public function testTable()
 {
     $this->assertEquals('<table><tbody></tbody></table>', Html::table([], []));
     $this->assertEquals('<table class="table"><tbody></tbody></table>', Html::table([], [], ['class' => 'table']));
     $this->assertEquals('<table class="table"><thead><tr><th>1</th><th>2</th><th>3</th></tr></thead><tbody></tbody></table>', Html::table([1, 2, 3], [], ['class' => 'table']));
     $this->assertEquals('<table class="table"><thead><tr><th>1</th><th>2</th><th>3</th></tr></thead><tbody><tr><td>2</td><td>3</td><td>4</td></tr><tr><td>3</td><td>4</td><td>5</td></tr></tbody></table>', Html::table([1, 2, 3], [[2, 3, 4], [3, 4, 5]], ['class' => 'table']));
 }
 /**
  * Creates list items (li tag) for display in (un)ordered list.
  * @param string $type Messages type to use as base for creating list.
  * @return mixed
  */
 public function getListItems($type = 'ok')
 {
     $array = $type == 'ok' ? $this->oks : $this->errors;
     $list = [];
     foreach ($array as $key => $value) {
         $list[] = Html::a($key, $value);
     }
     return $list;
 }
Beispiel #4
0
 /**
  * Adds some default configuration. I.e. form name and layout class.
  * @inheritdoc
  */
 public function init()
 {
     if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) {
         throw new InvalidConfigException('Invalid layout type: ' . $this->layout);
     }
     if ($this->layout !== 'default') {
         Html::addCssClass($this->options, 'form-' . $this->layout);
     }
     if ($this->name) {
         $this->options['name'] = $this->name;
     }
     parent::init();
 }
Beispiel #5
0
 /**
  * Renders [tagsinput](https://github.com/bootstrap-tagsinput/bootstrap-tagsinput).
  * @param array $options
  * @return $this
  */
 public function tags($options = [])
 {
     $options['data-role'] = 'tagsinput';
     $this->adjustLabelFor($options);
     if (!isset($options['id'])) {
         $options['id'] = $this->getInputId();
     }
     $model = $this->model;
     $attribute = $this->attribute;
     $data = $model->{$attribute};
     $value = '';
     if (is_array($data)) {
         if (count($data) > 0) {
             if (is_object($data[0])) {
                 $value = implode(',', ArrayHelper::objectsAttribute($data, 'title'));
             } else {
                 $value = implode(',', $data);
             }
         }
     } else {
         $value = $data;
     }
     $this->parts['{input}'] = Html::textInput(Html::getInputName($model, $attribute), $value, $options);
     return $this;
 }