Ejemplo n.º 1
0
// by running searchgen, passing in the table name.
if (isset($command) && $command == 'loadAppuser') {
    header('Content-Type: application/json');
    $db = ConnectionFactory::getConnection();
    $appuserDAO = new AppuserDAO($db);
    $approleDAO = new ApproleDAO($db);
    $id = isset($params['id']) ? (int) trim($params['id']) : 0;
    if ($id <= 0) {
        $rows = array(Appuser::createDefault());
    } else {
        $sql = <<<EOF
select * from appuser pri where pri.id = ?
EOF;
        $ps = new PreparedStatement($sql, 0, 1);
        $ps->setInt($id);
        $rows = $appuserDAO->findWithPreparedStatement($ps);
    }
    $ps1 = new PreparedStatement(<<<EOF
select distinct r.* from appuserrole u_r inner join approle r on r.role_name = u_r.role_name where u_r.user_id = ? order by r.sort_order, r.role_name
EOF
, 0, 0);
    foreach ($rows as &$row) {
        $ps1->clearParams();
        $ps1->setInt($row->id);
        $row->roles = $id <= 0 ? array() : $approleDAO->findWithPreparedStatement($ps1);
    }
    unset($row);
    echo json_encode($rows);
    $db->close();
    exit;
}
Ejemplo n.º 2
0
// by running searchgen, passing in the table name.
if (isset($command) && $command == 'loadApprole') {
    header('Content-Type: application/json');
    $db = ConnectionFactory::getConnection();
    $approleDAO = new ApproleDAO($db);
    $apppermDAO = new ApppermDAO($db);
    $id = isset($params['id']) ? (int) trim($params['id']) : 0;
    if ($id <= 0) {
        $rows = array(Approle::createDefault());
    } else {
        $sql = <<<EOF
select * from approle pri where pri.id = ?
EOF;
        $ps = new PreparedStatement($sql, 0, 1);
        $ps->setInt($id);
        $rows = $approleDAO->findWithPreparedStatement($ps);
    }
    $ps1 = new PreparedStatement(<<<EOF
select distinct p.* from approleperm r_p inner join appperm p on p.perm_name = r_p.perm_name where r_p.role_name = ? order by p.perm_name
EOF
, 0, 0);
    foreach ($rows as &$row) {
        $ps1->clearParams();
        $ps1->setString($row->role_name);
        $row->perms = $id <= 0 ? array() : $apppermDAO->findWithPreparedStatement($ps1);
    }
    unset($row);
    echo json_encode($rows);
    $db->close();
    exit;
}