/**
     * Get Company Info
     *
     * todo need to learn relational stat query worst method ever
     */
    protected function loadModel(){

        /**
         * Load All Related Models Of Users
         * having userId is logged in dealer user Id
         */
        $query= Companies::find()->with([
            'user' =>function($query){
                $query->andWhere(['id' => Auction::$app->user->id]);
            },
            'auctions' => function($query){
                $query->asArray();
            },
            'companyUsers' => function($query){
                $query->asArray();
            }
        ])->where([
            'id' => Auction::$app->session->get('user.company')
        ]);

        $model=$query->one();

        if($model === null){
            throw new HttpException(400, 'Not a Valid Company');
        }

        return $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 Company Info
     */
    protected function loadModel(){

        /**
         * Load All Related Models Of Users
         * having userId is logged in dealer user Id
         */

        $query= Companies::find()->joinWith([
            'user' => function($query){
                 $query->where([
                    'users.id' => Auction::$app->user->id
                ]);
            }
        ]);

        $model=$query->one();

        if($model === null){
            throw new HttpException(400, 'Not a Valid Dealer');
        }
        return $model;
    }
    private function SaveUserCompany(){
        $company = new Companies();
        $company->setAttributes($this->getAttributes());
        $company->logo_image = $this->image;

        Auction::info('Company Info Saved');
        return $company->save(false) ? $company->id : false;
    }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompany0()
 {
     return $this->hasOne(Companies::className(), ['id' => 'company']);
 }
Exemple #6
0
 public function getCompany(){
     return $this->hasOne(Companies::className(),['id' => 'company'])->viaTable(CompanyUsers::tableName(),['user' => 'id']);
 }
    public function searchDealerCompany(){

        /**
         * DealerCompany::find()->joinWith([
        'company0',
        ])->where([
        'dealer_company.dealer' => Auction::$app->session->get('user.dealer'),
        //   'dealer_company.is_active' => DatabaseHelper::ACTIVE
        ]);
         */
        $query = Companies::find();

        return new ActiveDataProvider([
            'query' => $query,
        ]);
    }
    public function actionListCompanies($term){

        $array = Companies::find()->select('id,name,logo_image as image')
            ->where(['like' , 'name' , $term])
            ->asArray()->all();

        return Json::encode($array);
    }