Ejemplo n.º 1
0
 public function run()
 {
     $mapper = new UserMapper($this->adapter);
     $user = new \Cactus\Entity(array('name' => 'Mr. Test', 'password' => "testingpassword", 'create_date' => date("Y-m-d H:i:s")));
     list($id, $num) = $mapper->save($user);
     // Dont do this for real, but I need to clean up for testing
     $mapper->delete($user);
     return $num === 1;
 }
Ejemplo n.º 2
0
 public function testDeleteUser()
 {
     $user = getUserInstance('deleteUser');
     $umapper = new UserMapper(self::$pdo);
     $umapper->insert($user);
     $umapper->delete($user);
     $allUsers = $umapper->findAll()->fetchAll();
     $this->assertEmpty($allUsers);
 }
Ejemplo n.º 3
0
 public function deleteAction($I_id)
 {
     // On vérifie si l'utilisateur connecté est bien un admin
     $this->isAdmin();
     // On appelle le modele UserMapper et on lui demande de supprimer le user qui a l'$I_id
     $O_userMapper = new UserMapper();
     $O_userMapper->delete($I_id);
     die(header('Location:/'));
 }
Ejemplo n.º 4
0
 public function eliminar()
 {
     $currentuser = $this->view->getVariable("currentusername");
     $user = $this->userMapper->findById($currentuser);
     // Does the post exist?
     if ($user == NULL) {
         throw new Exception(i18n("Username does not exist"));
     }
     // Delete the Jurado Popular object from the database
     $this->userMapper->delete($user);
     $this->view->setFlash(i18n("Deleted user"));
     session_unset();
     session_destroy();
     $this->view->redirect("preguntas", "index");
 }
Ejemplo n.º 5
0
//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 />";
        }
    } else {