/** * 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; }
public function actionSelectInstruction() { $builder = AppointmentBuilder::getCurrent(); if (isset($_POST['Deal']) && $_POST['Deal']) { // need to finish instruction info; $instruction = Deal::model()->findByPk($builder->getInstructionId()); $instruction->attributes = $_POST['Deal']; if ($instruction->save()) { $this->redirect(['InstructionSelected', 'instructionId' => $instruction->dea_id]); } else { echo "<pre style='color:blue' title='" . __FILE__ . "'>" . basename(__FILE__) . ":" . __LINE__ . "<br>"; print_r($instruction->getErrors()); echo "</pre>"; } $this->render('createInstruction', ['model' => $instruction]); return; } /** @var $property Property */ $property = Property::model()->findByPk($builder->getPropertyId()); if (!$property->instructions || isset($_GET['new'])) { // need to create one. $instruction = new Deal(); $instruction->dea_prop = $property->pro_id; $instruction->dea_status = Deal::STATUS_VALUATION; $instruction->importFromProperty($property); $instruction->save(false); $builder->setInstructionId($instruction->dea_id); $this->render('createInstruction', ['model' => $instruction]); return; } $this->render('selectInstruction', ['model' => $property]); }