Rebuilding everything on Yii ?

In my old project I have only that code:

JS


	get_polygon : function (x,y,z) {

		$.getJSON("get_polygon.php", {x:x,y:y,zoom:z}, function(p) {

			tab = mapp.mapa.addRegions(p[0]);

			mapp.renderRegions(tab,z);

		});

	},

And get_polygon.php file:


<?php 

$x = (isset($_GET['x']) && !empty($_GET['x'])) ? $_GET['x'] : 0; 

$y = (isset($_GET['y']) && !empty($_GET['y'])) ? $_GET['y'] : 0; 

$zoom = (isset($_GET['zoom']) && !empty($_GET['zoom'])) ? $_GET['zoom'] : 2; 


$link = mysql_pconnect ('127.0.0.1', 'root');

mysql_select_db("Gra_strategiczna");

		


$szerokosc_ekranu = 680/$zoom;

$wysokosc_ekranu = 400/$zoom;


$p = 150;

$lewoX = $x-($p);

$dolY = $y+$wysokosc_ekranu+($p);

$prawoX = $x+$szerokosc_ekranu+($p*$zoom);

$goraY = $y-($p);


$Pola = array();


$query = mysql_query("SELECT  x, y, data, tekst, id_p FROM tab2 WHERE (x BETWEEN $lewoX AND $prawoX) AND (y BETWEEN $goraY AND $dolY)");

if($query) {

	while ($wiersz = mysql_fetch_row($query)){

		$X = $wiersz[0];

		$Y = $wiersz[1];

		$data = $wiersz[2];

		$tekst = $wiersz[3];

		$id = $wiersz[4];

		$t = explode("-", $data);

		$_data = null;

		for ($i =0; $i<count($t); $i+=2){

		    if(isset($t[$i])){

			$_data[] = array('x' =>$t[$i], 'y' =>$t[$i+1]);

			}

		}

		$Pola[$id] = array($id,$X,$Y,$_data,$tekst);

		}

	}

echo json_encode(array($Pola));

?>

It is justify to rebuild EVERTHING on Yii (model,controler, action) or better to leave alone this code?

If it works for you… why rebuild it…

If that code is going to be within a Yii project (and that happened to me), I would just modify those parts that connect to and query from the DB, and I will use DAO instead of AR or MVC pattern -with just that piece of code of course.

Nevertheless, I am also on the opinion of mdomba.