Esempio n. 1
0
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Dealers::find();

        $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;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user' => $this->user,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'city', $this->city])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'address', $this->address]);

        return $dataProvider;
    }
    /**
     * Displays a single Dealers model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        $_model = Dealers::find()
                    ->with(['user0'])
                    ->where('id=:id',[':id' => $id])
                    ->one();

        if($_model === null){
            Auction::infoLog('No Dealer Found' , ['id' => $id]);
            throw new NotFoundHttpException('No Dealer Found');
        }
        return $this->render('view', [
            'model' => $_model
        ]);
    }
    protected function dataTables(){

        $allModels =  (new Query())->select(
            '('.(new Query())->select('count(*)')->from(Auctions::tableName())->createCommand()->rawSql.') as auctions,'.
            '('.(new Query())->select('count(*)')->from(Dealers::tableName())->createCommand()->rawSql.') as dealers,'.
            '('.(new Query())->select('count(*)')->from(Companies::tableName())->createCommand()->rawSql.') as companies,'.
            '('.(new Query())->select('count(*)')->from(Brands::tableName())->createCommand()->rawSql.') as brands,'.
            '('.(new Query())->select('count(*)')->from(Categories::tableName())->createCommand()->rawSql.') as categories'
        )->one();

        $_message = Auction::loggerMessageFormat('Admin Dashboard Created With :: ',$allModels);
        Auction::info($_message);

        return new ArrayDataProvider([
            'allModels' => $allModels,
            'pagination' => false
        ]);

    }
    /**
     * Get Dealer Info
     */
    protected function loadModel(){

        /**
         * Load All Related Models Of Users
         * having userId is logged in dealer user Id
         */
        $query= Dealers::find()->joinWith([
            'user0',
        ])->where([
            'user' => Auction::$app->user->id
        ]);

        $model=$query->one();

        if($model === null){
            throw new HttpException(400, 'Not a Valid Dealer');
        }
        return $model;
    }
    protected function loadProfile(){
        $model = Dealers::find()->joinWith([
            'user0',
            'dealerPreferences' => function($query){
                $query->with([
                    'category0',
                    'brand0'
                ]);
            }
        ])->where([
            'dealers.id' => Auction::$app->session->get('user.dealer', 0)
        ])->one();

        if($model === null){
            Auction::error('No Valid Dealer Found with userid '.Auction::$app->user->id);
            throw new HttpException(404, 'No user found');
        }

        return $model;
    }
Esempio n. 6
0
    public function getDealerDetails(){

        return (new Query())->select('Coalesce(ds.security, 0) as `dealerSecurity`,count(dc.id) as dealerCompanies,count(da.dealer) as dealerAuctions')
            ->from(Dealers::tableName(). 'd')
            ->leftJoin(DealerCompany::tableName().' dc', 'dc.dealer=d.id')
            ->leftJoin(DealerSecurity::tableName(). 'ds', 'ds.dealer=d.id')
            ->leftJoin(DealerAuctions::tableName().' da', 'da.dealer=d.id')
            ->where([
                'd.id' => $this->id
            ])->one();

    }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDealer0()
 {
     return $this->hasOne(Dealers::className(), ['id' => 'dealer']);
 }
Esempio n. 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDealers()
 {
     return $this->hasOne(Dealers::className(), ['user' => 'id']);
 }
    private function SaveDealer($user){

        $dealer = new Dealers();
        $dealer->setAttributes($this->getAttributes());
        $dealer->contact = $this->mobile;
        $dealer->user=$user;

        Auction::info('Dealer Info Saved');
        return $dealer->save(false) ? $dealer->id : false;
    }