/** * Creates a new Sale model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($object_id = 0) { $model = new Sale(); if ($object_id) { $object = Object::findOne($object_id); if ($object) { $temp = ArrayHelper::toArray($object->sale); unset($temp['id']); foreach ($temp as $k => $v) { $model->{$k} = $v; } } $model->view_ids = ArrayHelper::toArray($object->sale->view_ids); $model->facility_ids = ArrayHelper::toArray($object->sale->facility_ids); } $model->status = 1; $model->sold = 1; $model->code = rand(100000000, 999999999); for ($i = 1; $i <= Lang::find()->count(); $i++) { $model_content[$i] = new SaleLang(); $model_content[$i]['lang_id'] = $i; $model_content[$i]['id'] = 0; } if ($model->load(Yii::$app->request->post()) && Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content) && $model->validate() && $model->district_id > 0) { $model->save(); foreach ($model_content as $key => $content) { $content->id = $model->id; $content->lang_id = $key; $content->save(false); } return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'model_content' => $model_content]); } }
public function actionDoc() { /* @var $model Object*/ if (($model = Object::findOne(\Yii::$app->request->post('id'))) !== null) { $files = []; foreach ($model->files as $file) { $files[] = $file->hash . '.' . $file->type; } return Json::encode(['success' => true, 'files' => $files]); } return Json::encode(['success' => false]); }
/** * Renders the index view for the module * @return string */ public function actionChangeGroup() { $count = 0; foreach (Object::find()->all() as $object) { /** @var $object Object */ $group = Group::find()->where(['name' => mb_substr($object->name, 0, 1)])->one(); if ($group) { \Yii::$app->db->createCommand()->update('object', ['group_id' => $group->id], ['id' => $object->id])->execute(); $count++; } } echo "done - {$count}\n"; }
public function actionList() { if (isset($_POST['depdrop_parents'])) { if ($parents = $_POST['depdrop_parents']) { $out[-1] = Yii::t('app', 'New object'); $out += Object::getList($parents[0]); foreach ($out as $key => $value) { $result[] = ['id' => $key, 'name' => $value]; } print Json::encode(['output' => @$result, 'selected' => '']); return; } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Object::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'group_id' => $this->group_id, 'region_id' => $this->region_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Object::find()->joinWith(['sale']); //->orderBy(['id' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['object.id' => $this->id, 'sale.region_id' => $this->region_id, 'sale.status' => $this->status, 'sale.district_id' => $this->district_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'address', $this->address]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\ObjectInfo */ /* @var $form yii\widgets\ActiveForm */ $object_list = \common\models\Object::find()->all(); ?> <div class="object-info-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'address_ksk')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'amount_house')->textInput(); ?> <?php echo $form->field($model, 'address_house')->textInput(); ?> <?php echo $form->field($model, 'fullname_chairman')->textInput(); ?>
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if (!$this->id) { if (!$this->user_id) { $this->user_id = Yii::$app->user->identity->id; } if ($this->object_id < 1) { $object = new Object(); $object->save(); $this->object_id = $object->id; } } return true; } return false; }
/** * Finds the Object model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Object the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Object::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getObject() { return $this->hasOne(Object::className(), ['id' => 'object_id']); }
/** * @return \yii\db\ActiveQuery */ public function getObjects() { return $this->hasMany(Object::className(), ['region_id' => 'id']); }