コード例 #1
0
 /**
  * @param null $id
  * @return string|\yii\web\Response
  * @throws NotFoundHttpException
  * @throws \yii\web\ServerErrorHttpException
  */
 public function actionEdit($id = null)
 {
     if (null === $id) {
         throw new NotFoundHttpException();
     }
     /** @var Contragent $model */
     if (null === ($model = Contragent::findOne(['id' => $id]))) {
         throw new NotFoundHttpException();
     }
     if (true === \Yii::$app->request->isPost && $model->load(\Yii::$app->request->post())) {
         if ($model->saveModelWithProperties(\Yii::$app->request->post())) {
             return $this->refresh();
         }
     }
     return $this->render('edit', ['model' => $model]);
 }
コード例 #2
0
 /**
  * @return array
  */
 public function actionAjaxContragent($template = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $result = ['more' => false, 'results' => [[0 => Yii::t('app', 'New contragent')]]];
     $search = \Yii::$app->request->get('search', []);
     $customer_id = isset($search['customer']) ? intval($search['customer']) : 0;
     $query = Contragent::find()->select('id, type')->where(['customer_id' => $customer_id])->asArray();
     $result['results'] = array_merge(array_values($query->all()), $result['results']);
     if (!empty($result['results']) && 'simple' === $template) {
         $result['cards'] = array_reduce($result['results'], function ($result, $item) {
             /** @var array $item */
             if (!empty($item['id'])) {
                 $result[$item['id']] = \app\modules\shop\widgets\Contragent::widget(['viewFile' => 'contragent/backend_list', 'model' => Contragent::findOne(['id' => $item['id']])]);
             }
             return $result;
         }, []);
     }
     return $result;
 }
コード例 #3
0
ファイル: Customer.php プロジェクト: tqsq2005/dotplant2
 /**
  * @param integer|null $id
  * @return Contragent|null
  */
 public function getContragentById($id = null)
 {
     if (empty($id)) {
         return null;
     }
     return Contragent::findOne(['customer_id' => $this->id, 'id' => $id]);
 }