public function actionCreate($company_id) { $Deal = new Deal(); $Company = Company::model()->findByPk($company_id); if (isset($_POST['Deal'])) { $Deal->setAttributes($_POST['Deal'], false); $Deal->from_company_id = Yii::app()->getUser()->getProfile()->company->id; $Deal->to_company_id = $company_id; if ($Deal->validate()) { $Deal->save(); $this->redirect('/cabinet/deal/'); } } $this->render('create', ['Deal' => $Deal, 'Company' => $Company]); }
/** * makes a full copy of an instruction * * @param string $type * @param string $status * @return bool|\Deal * @throws InvalidArgumentException */ public function copyAs($type = self::TYPE_SALES, $status = self::STATUS_PRODUCTION) { if (!in_array($type, [self::TYPE_LETTINGS, self::TYPE_SALES])) { throw new InvalidArgumentException('type must be one of the following [' . self::TYPE_LETTINGS . ', ' . self::TYPE_SALES . '] actual value is: ' . $type); } if (!in_array($status, self::getStatuses())) { throw new InvalidArgumentException('Status must be in the list [' . implode(', ', self::getStatuses()) . '] actual value is: ' . $status); } /** @var $property Property */ $property = Property::model()->findByPk($this->dea_prop); $instruction = new Deal('copy'); $instruction->setAttributes($this->attributes); $instruction->dea_type = $type; $instruction->dea_status = $status; $instruction->dea_marketprice = 0; $instruction->dea_launchdate = null; $instruction->importFromProperty($property); if ($instruction->save(false)) { InstructionVideo::copyRecords($this->dea_id, $instruction->dea_id); LinkInstructionToFeature::copyRecords($this->dea_id, $instruction->dea_id); LinkClientToInstruction::copyRecords($this->dea_id, $instruction->dea_id); Media::copyRecords($this->dea_id, $instruction->dea_id); return $instruction; } return false; }