public function actionView($id)
    {
        $model = Companies::find()->with([
            'dealerCompanies' => function ($query) use ($id){
                $query->joinWith([
                    'dealerCompanyPreferences' => function ($query) {
                        $query->joinWith([
                            'brand0',
                            'category0'
                        ]);
                    }
                ])->where([
                    'dealer_company.company' => $id,
                    'dealer_company.dealer' => Auction::dealer()
                ]);
            }
        ])->where([
            'id' => $id
        ])->one();

        if($model === null){
            Auction::error('There is no Company with Company Id '.$id);
            throw new HttpException(404, 'No Company Found');
        }

        return $this->render('view', [
            'model' => $model,
        ]);
    }
    public function addPreference($post){
        $this->brand = ArrayHelper::getValue($post , 'brand');
        $this->category = ArrayHelper::getValue($post ,'category');
        $this->dealer = Auction::dealer();

        if($this->save()){
            return true;
        }else {
            throw new InvalidValueException('Already Exist');
        }
    }
Esempio n. 3
0
    /**
     * Company Added By Dealer
     * then status => 1
     *
     * is_active need to change by company/company User
     */
    public function addedByDealer($id){

        $_model = DealerCompany::find()->where([
            'company' => $id,
            'dealer' => Auction::dealer()
        ])->one();

        if($_model === null){

            $_model = new DealerCompany();
            $_model->company = $id;
            $_model->dealer = Auction::dealer();
            $_model->is_active = DatabaseHelper::IN_ACTIVE;
            $_model->status = DatabaseHelper::ACTIVE;
            $_model->mode = DatabaseHelper::DEALER_APPROVE_APPROVAL_REQUIRED;

            Auction::infoLog('Creating A new Dealer Company Since No Record of DealerCompany of',['company' => $id ,'dealer' => Auction::dealer()]);

        }else{
            switch ($_model->status){

                case DatabaseHelper::ACTIVE :
                    $_model->status = DatabaseHelper::IN_ACTIVE;
                    break;

                case DatabaseHelper::IN_ACTIVE :
                    $_model->status = DatabaseHelper::ACTIVE;
                    break;
            }
            Auction::infoLog('Updating Dealer Company Status',['company' => $id ,'dealer' => Auction::dealer()]);
        }

        return $_model->save();
    }