ciao a tutti, mi aiutate a capire cosa fa il fill di una griglia (flex grid) usando questa funzione di PHP + Zend
vedo che vengono create delle var e poi gestito tutto tramite JSON
mi date qualche dritta (massiva) ... senza entrare troppo ne dettaglio
Io mi ci perdo
Thanks
codice:
public function listAction()
{
$this->checkLogin();
if ($this->getRequest()->isPost())
{
$data = $this->getRequest()->getPost();
$page = $data['page'];
$rp = $data['rp'];
$sortname = $data['sortname'];
$sortorder = $data['sortorder'];
//get ownerId from session
$storage = new Zend_Auth_Storage_Session();
$session_data = $storage->read();
$ownerId = $session_data->userId;
//search data
$email = isset($data['mail'])?$data['mail']:'';
$state = isset($data['state'])?$data['state']:'';
$regDate = isset($data['regDate'])?$data['regDate']:'';
if (!empty($regDate)) { $regDate = date("Y-m-d",strtotime($regDate));}
if (!$sortname) $sortname = 'mail';
if (!$sortorder) $sortorder = 'desc';
$sort = " ORDER BY $sortname $sortorder ";
if (!$page) $page = 1;
if (!$rp) $rp = 10;
$start = (($page-1) * $rp);
$limit = "LIMIT $start, $rp";
//get query condition if there is set on
$query = $data['query'];
$qtype = $data['qtype'];
$where = "";
if (!empty($query)) $where = " $qtype LIKE '%$query%' ";
if (!empty($email)) $where .= ' mail LIKE "%'.$email.'%" ';
if (!empty($state)) $where .= (!empty($where))? ' AND users.stateId ='. $state :' users.stateId = ' . $state ;
if (!empty($regDate)) $where .= (!empty($where))? ' AND regDate > "'. $regDate .'"':' regDate >"'. $regDate . '"';
if (!empty($where)) {
$where = ' WHERE ' . $where . ' AND ownerId =' . $ownerId;
}
else {
$where = ' WHERE ownerId =' . $ownerId;
}
//get main adapter config
$configuration = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini','production');
$dbAdapter = Zend_Db::factory($configuration->resources->db->adapter,
$configuration->resources->db->params->toArray());
$stmt = $dbAdapter->query('SELECT COUNT(*) As count FROM users'. $where);
$countusers = $stmt->fetch();
$total = $countusers['count'];
$sql = "SELECT * FROM users INNER JOIN state ON state.stateId= users.stateId
INNER JOIN city ON city.cityId= users.cityId
INNER JOIN town ON town.townId= users.townId
$where $sort $limit";
//echo $sql;exit;
$stmt = $dbAdapter->query($sql);
$users = $stmt->fetchAll();
//output json file
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
foreach ($users as $user)
{
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$user['userId']."',";
$json .= "cell:['".addslashes($user['userId'])."'";
$json .= ",'".addslashes($user['firstName'])."'";
$json .= ",'".addslashes($user['lastName'])."'";
$json .= ",'".addslashes($user['mail'])."'";
$json .= ",'".addslashes($user['stateName'])."'";
$json .= ",'".addslashes($user['cityName'])."'";
//$json .= ",'".addslashes($user['townName)."'";
$json .= ",'".$user['regDate']."']";
$json .= "}";
$rc = true;
}
$json .= "]\n";
$json .= "}";
echo $json;
exit;
}
}