public static function getTank($name, $lname = null, $level = 0, $nation = null, $class = null, $imageUrl = null) { if (preg_match("/#(.*?):(.*)/", $lname, $mathes)) { $lname = $mathes[2]; } if (empty(self::$_models)) { self::$_models = self::model()->findAll(array('index' => 'tank_name')); } if (!isset(self::$_models[$name])) { $tankNation = WotTankNation::model()->findByPk($nation); if (empty($tankNation)) { $tankNation = new WotTankNation(); $tankNation->tank_nation_id = $tankNation->tank_nation_name = $nation; $tankNation->save(false); } $tankClass = WotTankClass::model()->findByPk($class); if (empty($tankClass)) { $tankClass = new WotTankClass(); $tankClass->tank_class_id = $tankClass->tank_class_name = $class; $tankClass->save(false); } $tank = new WotTank(); $tank->tank_class_id = $class; $tank->tank_nation_id = $nation; $tank->tank_name = $name; $tank->tank_localized_name = $lname; $tank->tank_level = $level; $tank->tank_image = $imageUrl; $tank->save(false); self::$_models = self::model()->findAll(array('index' => 'tank_name')); } else { $tank = self::$_models[$name]; if ($tank->tank_level != $level || $tank->tank_nation_id != $nation || $tank->tank_class_id != $class || $tank->tank_localized_name != $lname || $tank->tank_image != $imageUrl) { $tank->tank_nation_id = $nation; $tank->tank_name = $name; $tank->tank_localized_name = $lname; $tank->tank_level = $level; $tank->tank_image = $imageUrl; $tank->save(false); } } return self::$_models[$name]; }