/** * 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; }
/** * @param $featureId * @param $instructionId * @param string $format * @return int */ public function actionDeleteCustomFeature($featureId, $instructionId, $format = '') { $linkForCustomFeature = LinkInstructionToFeature::model()->findByAttributes(['dealId' => $instructionId, 'featureId' => $featureId]); if ($linkForCustomFeature) { $linkForCustomFeature->delete(); } $result = Feature::model()->deleteByPk($featureId); if ($format == 'JSON') { echo json_encode($result); } else { return $result; } }