public function up() { /** @var $propertyAreas PropertyArea[] */ $propertyAreas = PropertyArea::model()->findAll(); $mapIdToPostcode = []; foreach ($propertyAreas as $value) { $mapIdToPostcode[$value->are_id] = $value->are_postcode; } $sql = "SELECT * FROM client where cli_area !=''"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $sql = "UPDATE client SET cli_area = ? WHERE cli_id = ?"; $command = Yii::app()->db->createCommand($sql); foreach ($data as $value) { $areas = explode('|', $value['cli_area']); $newAreas = []; foreach ($areas as $area) { if (isset($mapIdToPostcode[$area])) { $newAreas[$mapIdToPostcode[$area]] = $mapIdToPostcode[$area]; } } $command->execute(array(implode('|', $newAreas), $value['cli_id'])); } }
/** * * @param Client $client * @return CActiveDataProvider */ public function findMathingPropertyByClient(Client $client) { $criteria = new CDbCriteria(); $areas = explode('|', $client->cli_area); // postcodes /** @var $propertyAreas PropertyArea */ $propertyAreas = PropertyArea::model()->findAllByAttributes(array('are_postcode' => $areas)); $areas = []; foreach ($propertyAreas as $value) { $areas[] = $value->are_id; } $criteria->together = true; $criteria->with = array('property', 'propertyType', 'propertySubtype'); $criteria->addInCondition('property.pro_area', $areas); $criteria->addBetweenCondition('dea_marketprice', $client->cli_salemin, $client->cli_salemax); $criteria->compare('dea_bedroom', '>=' . $client->cli_salebed); $criteria->compare('dea_type', 'sales'); $criteria->addInCondition('dea_ptype', explode("|", $client->cli_saleptype)); $criteria->addInCondition('dea_psubtype', explode("|", $client->cli_saleptype), 'OR'); $criteria->compare('dea_status', 'Available'); $CActiveDataProvider = new CActiveDataProvider($this, array('criteria' => $criteria, 'pagination' => false)); return $CActiveDataProvider; }