Exemplo n.º 1
0
 public function run(array $ids)
 {
     $data = $this->model->find()->where(['id' => $ids, 'with_request' => true])->all();
     foreach ($data as $item) {
         $res[$item->id] = ['id' => $item->id, 'name' => $item->name, 'html' => RequestState::widget(['module' => 'server', 'model' => $item])];
     }
     return $this->controller->renderJson($res);
 }
Exemplo n.º 2
0
 public function init()
 {
     parent::init();
     if ($this->model->request_state_label) {
         $this->model->request_state_label = Yii::t('hipanel', $this->model->request_state_label);
     }
     if ($this->model->state_label) {
         $this->model->state_label = Yii::t('hipanel', $this->model->state_label);
     }
     if (empty($this->module)) {
         $this->module = $this->model->formName();
     }
 }
Exemplo n.º 3
0
 /**
  * Populates joined relations from [[join]] array.
  *
  * @param ActiveRecord $model
  * @param array $row
  */
 public function populateJoinedRelations($model, array $row)
 {
     foreach ($row as $key => $value) {
         if (empty($this->join) || !is_array($value) || $model->hasAttribute($key)) {
             continue;
         }
         foreach ($this->join as $name) {
             if ($model->isRelationPopulated($name)) {
                 continue 2;
             }
             $records = [];
             $relation = $model->getRelation($name);
             $relationClass = $relation->modelClass;
             if ($relation->multiple) {
                 foreach ($value as $item) {
                     $relationModel = $relationClass::instantiate($item);
                     $relationModelClass = get_class($relationModel);
                     $relationModelClass::populateRecord($relationModel, $item);
                     $relation->populateJoinedRelations($relationModel, $item);
                     $records[] = $relationModel;
                 }
             } else {
                 $relationModel = $relationClass::instantiate($value);
                 $relationModelClass = get_class($relationModel);
                 $relationModelClass::populateRecord($relationModel, $value);
                 $relation->populateJoinedRelations($relationModel, $value);
                 $records = $relationModel;
             }
             $model->populateRelation($name, $records);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Populates joined relations from [[join]] array.
  *
  * @param ActiveRecord $model
  * @param array $row
  */
 public function populateJoinedRelations($model, array $row)
 {
     foreach ($row as $key => $value) {
         if (empty($this->join) || !is_array($value) || $model->hasAttribute($key)) {
             continue;
         }
         foreach ($this->join as $join) {
             $name = array_shift(array_keys($join));
             $closure = array_shift($join);
             if (is_int($name)) {
                 $name = $closure;
                 $closure = null;
             }
             if ($name !== $key) {
                 continue;
             }
             if ($model->isRelationPopulated($name)) {
                 continue 2;
             }
             $records = [];
             $relation = $model->getRelation($name);
             $relationClass = $relation->modelClass;
             if ($closure !== null) {
                 call_user_func($closure, $relation);
             }
             $relation->prepare();
             if ($relation->multiple) {
                 foreach ($value as $item) {
                     $relatedModel = $relationClass::instantiate($item);
                     $relatedModelClass = get_class($relatedModel);
                     $relatedModelClass::populateRecord($relatedModel, $item);
                     $relation->populateJoinedRelations($relatedModel, $item);
                     $relation->addInverseRelation($relatedModel, $model);
                     if ($relation->indexBy !== null) {
                         $index = is_string($relation->indexBy) ? $relatedModel[$relation->indexBy] : call_user_func($relation->indexBy, $relatedModel);
                         $records[$index] = $relatedModel;
                     } else {
                         $records[] = $relatedModel;
                     }
                 }
             } else {
                 $relatedModel = $relationClass::instantiate($value);
                 $relatedModelClass = get_class($relatedModel);
                 $relatedModelClass::populateRecord($relatedModel, $value);
                 $relation->populateJoinedRelations($relatedModel, $value);
                 $relation->addInverseRelation($relatedModel, $model);
                 $records = $relatedModel;
             }
             $model->populateRelation($name, $records);
         }
     }
 }