public function getCompanyDetails(){ return (new Query())->select( '('.(new Query())->select('count(*)')->from(Auctions::tableName())->where(['company' => $this->id])->createCommand()->rawSql.') as companyAuctions,'. '('.(new Query())->select('count(*)')->from(CompanyUsers::tableName())->where('company=:c and user!=:u',[':c' => $this->id , ':u' => Auction::$app->user->id])->createCommand()->rawSql.') as companyUsers,'. '('.(new Query())->select('count(*)')->from(DealerCompany::tableName())->where(['company' => $this->id])->createCommand()->rawSql.') as companyDealers' )->one(); }
/** * Save Company INfO * 3 Models Inserted in Dealer Save * User,Company,UserCompany Table Inserted * @note User is inserted with company role */ public function SaveCompany(){ if($this->validate()) { $transaction = Auction::$app->db->beginTransaction(); try { $user=$this->SaveUser(); $company=$this->SaveUserCompany(); if(!$user || !$company) { return null; } $companyUser=new CompanyUsers(); $companyUser->company=$company; $companyUser->user=$user; if (!$companyUser->save(false)) { return null; } $transaction->commit(); //$this->trigger(self::AFTER_SAVE); Auction::info('Company Registration Success'); return true; } catch (Exception $ex) { $transaction->rollBack(); $_message = Auction::loggerMessageFormat('Company Registration Failed with Following Errors',$this->getErrors()); Auction::error($_message); } } return null; }
public function SaveCompanyUser(){ $this->user_role = DatabaseHelper::COMPANY_USER; if($this->save()){ $model = new CompanyUsers(); $model->user = $this->id; $model->company = Auction::$app->session->get('user.company'); $model->save(); return true; } return false; }