private function createCommission($analyticsActivity) { if ($analyticsActivity) { $yiidActivity = MongoManager::getDM()->getRepository("Documents\\YiidActivity")->find($analyticsActivity->getYiidActivityId()); $commissionValue = $this->getBillingType() == DealTable::BILLING_TYPE_LIKE ? $this->commission_per_unit : $this->commission_per_unit * $analyticsActivity->getMediaPenetration(); if ($this->commission_pot < $commissionValue) { $commissionValue = $this->commission_pot; } if ($commissionValue > 0) { $commission = new Commission(); $commission->setPrice($commissionValue); $commission->setDomainProfileId($yiidActivity->getIId()); $commission->setDealId($this->getId()); $commission->setYaId($yiidActivity->getId()); $commission->save(); $this->commission_pot -= $commissionValue; } } }