public function update($params) { $source_id = $params['source_id']; unset($params['source_id']); // we don't save because admin ref issues $duplicate = $params['duplicate_rates']; unset($params['duplicate_rates']); $entity = parent::update($params); if ($duplicate) { $new_id = $entity['_id']->getMongoID(); self::duplicate_rates($source_id, $new_id); } return $entity; }
/** * method to convert plans names into their refs * triggered before save the rate entity for edit * * @param Mongodloid collection $collection * @param array $data * * @return void * @todo move to model */ public function update($data) { if (isset($data['rates'])) { $plansColl = Billrun_Factory::db()->plansCollection(); $currentDate = new MongoDate(); $rates = $data['rates']; //convert plans foreach ($rates as &$rate) { if (isset($rate['plans'])) { $sourcePlans = (array) $rate['plans']; // this is array of strings (retreive from client) $newRefPlans = array(); // this will be the new array of DBRefs unset($rate['plans']); foreach ($sourcePlans as &$plan) { $planEntity = $plansColl->query('name', $plan)->lessEq('from', $currentDate)->greaterEq('to', $currentDate)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref'))->current(); $newRefPlans[] = $planEntity->createRef($plansColl); } $rate['plans'] = $newRefPlans; } } $data['rates'] = $rates; } return parent::update($data); }