예제 #1
0
파일: index.php 프로젝트: AaronDeb/cloudbox
        $userMapper = new UserMapper($db);
        $user = $userMapper->findById($_SESSION['userID']);
        $tpl_engine->__set_filetpl('main.html', array('user' => $user->getUserName()));
        $tpl_engine->render();
    } else {
        (new ReportingFramework())->report(['condition' => "failure", 'message' => "This is a restricted area! Please login"]);
    }
});
$rout_r->map('GET', '/api/user/register/', function () {
    global $GLOBALS;
    $query = $GLOBALS['query'];
    if (isset($query["username"]) || isset($query["name"]) || isset($query["password"]) || isset($query["email"]) || isset($query["key"])) {
        $user = new User(null, $query["username"], $query["name"], $query["password"], false, $query["email"], $query["key"]);
        $db = new MySqlDAO();
        $userMapper = new UserMapper($db);
        $userMapper->insert($user);
        die("User registration was successful!");
    } else {
        die("Input all params!");
    }
});
$rout_r->map('GET', '/api/user/login/', function () {
    session_start();
    global $GLOBALS;
    $query = $GLOBALS['query'];
    if (isset($query["username"]) || isset($query["password"])) {
        $db = new MySqlDAO();
        $userMapper = new UserMapper($db);
        $user = $userMapper->findByUserName($query["username"]);
        $userID = $user->getID();
        if (count($user) != 0 && isset($userID) && $userID != null) {
예제 #2
0
 public function testFindByName()
 {
     $userName = "******";
     $userName2 = "otherUser";
     $user = getUserInstance($userName);
     $user2 = getUserInstance($userName2);
     $umapper = new UserMapper(self::$pdo);
     $umapper->insert($user);
     $umapper->insert($user2);
     $newUser = $umapper->findByName($user->user_name);
     $this->assertEquals($newUser->user_name, $userName);
 }
예제 #3
0
파일: index.php 프로젝트: bartronix/orm
$userMapper = new UserMapper($db);
$articleMapper = new ArticleMapper($db);
//get user by username
$user = $userMapper->findOne(array("conditions" => array('username = ? ', "john doe")));
echo "Username: "******"<br />Articles of this user:<br />";
foreach ($user->articles as $article) {
    echo $article->title . '<br />';
}
//edit the user
$user->username = "******";
$userMapper->update($user);
//add a new user
$newUser = new User();
$newUser->username = "******";
$userMapper->insert($newUser);
//delete a user
$userMapper->delete(4);
//get users with their articles
//get all users limited by 2, sorted by username ascending and eager load the article relationship
//only 2 queries - one for fetching the users and one for coupling the related articles
$users = $userMapper->findMany(array("limit" => 3, "sort" => array("username", "asc"), "relations" => array("Article")));
//4 queries: one for retrieving the users and 1 per user lazy loading the articles.
$users = $userMapper->findMany(array("limit" => 3, "sort" => array("username", "asc")));
echo sizeof($users) . " users found<br />";
foreach ($users as $user) {
    echo "<br />Username:"******"<br />";
    if (sizeof($user->articles) > 0) {
        echo "Articles of this user:<br />";
        foreach ($user->articles as $article) {
            echo $article->title . "<br />";
예제 #4
0
 public function createAction()
 {
     $this->isAdmin();
     if (isset($_POST['operator'])) {
         $O_operator = new Operator();
         $O_operator->setName($_POST['name']);
         $O_operator->setFirstName($_POST['firstName']);
         $O_operator->setSizeHarness($_POST['sizeHarness']);
         $O_operator->setEmail($_POST['email']);
         $O_operator->initInceptionDate();
         $O_teamMapper = new TeamMapper();
         $O_team = $O_teamMapper->findByTwoIds($_POST['staff_id'], $_POST['subgroup_id']);
         $O_operator->setTeamId($O_team->getId());
         $O_operatorMapper = new OperatorMapper();
         $I_operatorId = $O_operatorMapper->insert($O_operator);
         //die(header('Location:/user/default/'));
     }
     if (isset($_POST['inspector'])) {
         $O_inspector = new Inspector();
         $O_inspector->setName($_POST['name']);
         $O_inspector->setFirstName($_POST['firstName']);
         $O_inspector->setEmail($_POST['email']);
         $O_inspector->setSubgroupId($_POST['subgroup_id']);
         $O_inspector->initInceptionDate();
         $O_inspectorMapper = new InspectorMapper();
         $I_inspectorId = $O_inspectorMapper->insert($O_inspector);
     }
     $O_user = new User();
     $O_user->setLogin($_POST['login']);
     $O_user->setPassword($_POST['password']);
     $O_user->setProfileId($_POST['profile_id']);
     if (isset($_POST['operator'])) {
         $O_user->setOperatorId($I_operatorId);
     }
     if (isset($_POST['inspector'])) {
         $O_user->setInspectorId($I_inspectorId);
     }
     $O_userMapper = new UserMapper();
     $I_userId = $O_userMapper->insert($O_user);
 }