public function hydrate(array $data = array())
 {
     foreach ($data as $value) {
         $assignment = new User();
         $assignment->hydrate($value);
         $this[] = $assignment;
     }
 }
 public function exportUsers()
 {
     $users = array();
     $results = $this->_db->select("SELECT * from users");
     foreach ($results as $result) {
         $user = new User();
         $user->hydrate($result);
         $users[] = $user;
     }
     return $users;
 }
 public function getAllUsers()
 {
     $db = new Db();
     $users = array();
     $results = $db->select("SELECT * from users");
     foreach ($results as $result) {
         $user = new User();
         $user->hydrate($result);
         $users[] = $user;
     }
     return $users;
 }
Example #4
0
 public function getAll()
 {
     $array = $this->get('*', $this->table);
     $result = array();
     $i = 0;
     foreach ($array as $value) {
         $user = new User();
         $user->hydrate($value);
         $result[$i] = $user;
     }
     return $result;
 }
Example #5
0
    /**
     * Ajout des utilisateurs à la base de données
     * @param $user User instance de la classe User
     **/
    public function add(User $user)
    {
        $q = $this->_db->prepare('INSERT INTO User 
			SET name = :name, 
				email = :email, 
				password = :password,
				gender = :gender,
				description = :description');
        $q->bindValue(':name', $user->name());
        $q->bindValue(':email', $user->email());
        $q->bindValue(':password', $user->password());
        $q->bindValue(':gender', $user->gender());
        $q->bindValue(':description', $user->description());
        $q->execute();
        $user->hydrate(['id' => $this->_db->lastInsertId()]);
        echo "Création du profil, avec succès";
    }
 public function editAction()
 {
     //Check if the attributes that passed are valid.
     //Do not forget about FIEO!!!!
     if ($this->getRequest()->isPost()) {
         $user = new User();
         $user->hydrate($_POST['user']);
         //Attention here!
         try {
             $user->save();
             $this->view->message = "Success";
         } catch (Exception $e) {
             $this->view->message = "Failure";
             $this->_logger->err("Update Failed on user");
         }
         $this->_forward("index");
     }
     $userTable = Doctrine::getTable("user");
     $this->view->user = $userTable->find($this->getRequest->getParam("id"));
 }
Example #7
0
function registerUser()
{
    $stat = '';
    try {
        $userManager = new UserManager();
        $userId = $userManager->getUserId($_GET["email"]);
        if (!$userId) {
            $user = new User();
            $user->hydrate(populateUserArrayFromGet());
            $userManager->save($user);
            if (session_status() == PHP_SESSION_NONE) {
                session_start();
            }
            $_SESSION['FFuser'] = serialize($user);
            $stat = 'Registration successful; ' . $user->getName() . " logged in";
        } else {
            $stat = 'Registration failed; duplicate user email';
        }
    } catch (Exception $e) {
        error_log('registerUser Exception: ' . $e->getMessage(), 0);
        $stat = $e->getMessage();
    }
    return $stat;
}
Example #8
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return                 User A model object, or null if the key is not found
  * @throws PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `id`, `account_id`, `domain_id`, `deleted`, `name`, `firstname`, `lastname`, `phone`, `manager_of`, `is_admin`, `email`, `password_hash`, `number` FROM `user` WHERE `id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new User();
         $obj->hydrate($row);
         UserPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
 /**
  *  Return all items Student.
  *
  * @return user All items in the array where user is a student.
  */
 public static function findAllStudents()
 {
     $users = array();
     $data = BaseSingleton::select('SELECT id_user, login, passwd, mail, inscription_date, first_name, ' . 'last_name, birth_date, address, phone_number, avatar, ROLE_id_role ' . 'FROM user, role WHERE `role`.`id_role`=`user`.`ROLE_id_role` AND `role`.`role_name`="Student"; ');
     foreach ($data as $row) {
         $user = new User();
         $user->hydrate($row);
         $users[] = $user;
     }
     return $users;
 }
Example #10
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return   User A model object, or null if the key is not found
  * @throws   PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `NOMBRE`, `PASS`, `TIPO`, `ID` FROM `hc_usuarios` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new User();
         $obj->hydrate($row);
         UserPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Example #11
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return                 User A model object, or null if the key is not found
  * @throws PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `id`, `email`, `pwd`, `activate_token`, `reset_password_token`, `role`, `deleted`, `language`, `created_at`, `name`, `website`, `sm_profile`, `oauth_signin` FROM `user` WHERE `id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new User();
         $obj->hydrate($row);
         UserPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Example #12
0
        include '../views/user_add_edit.php';
        break;
    case 'edit_user':
        $userManager = new UserManager();
        $user = $userManager->getUser($target);
        include '../views/user_add_edit.php';
        break;
    case 'save_user':
        $userManager = new UserManager();
        $arr = array();
        $arr["id"] = isset($_GET["id"]) ? $_GET["id"] : '';
        $arr["species"] = isset($_GET["species"]) ? $_GET["species"] : '';
        $arr["amount"] = isset($_GET["amount"]) ? $_GET["amount"] : '';
        $arr["ph"] = isset($_GET["ph"]) ? $_GET["ph"] : '';
        $arr["temp"] = isset($_GET["temp"]) ? $_GET["temp"] : '';
        $user = new User();
        $user->hydrate($arr);
        $userManager->save($user);
        header('Location: user.php');
        break;
    default:
        $userManager = new UserManager();
        $users = $userManager->getAllUsers();
        include '../views/user_view_list.php';
        break;
}
?>

</body>
</html>
Example #13
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    User A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `EMAIL`, `PWD`, `ACTIVATE_TOKEN`, `RESET_PASSWORD_TOKEN`, `ROLE`, `DELETED`, `LANGUAGE`, `CREATED_AT`, `NAME`, `WEBSITE`, `SM_PROFILE` FROM `user` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new User();
         $obj->hydrate($row);
         UserPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Example #14
0
 public static function connection($pseudo, $password)
 {
     $data = BaseSingleton::select('SELECT id, prenom, nom, mail, adresse, date_naissance, ' . 'date_creation, pseudo, password, affiche, fichier_id, type_user_id ' . 'FROM user ' . 'WHERE pseudo = ? ' . 'AND password = ? ', array('ss', &$pseudo, &$password));
     if (sizeof($data) === 0) {
         return false;
     } else {
         $user = new User();
         $user->hydrate($data[0]);
         return $user;
     }
 }
Example #15
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return                 User A model object, or null if the key is not found
  * @throws PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `id`, `username`, `password`, `digest_ha1`, `first_name`, `last_name`, `email`, `language_id`, `timezone`, `is_admin`, `is_backend_login_enabled`, `is_admin_login_enabled`, `is_inactive`, `password_recover_hint`, `backend_settings`, `created_at`, `updated_at`, `created_by`, `updated_by` FROM `users` WHERE `id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new User();
         $obj->hydrate($row);
         UserPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Example #16
0
    public static function get_from_token($token)
    {
        global $g_pdo;
        $request = <<<EOF
SELECT * FROM `user`
WHERE `token`= :token
EOF;
        debug($request);
        $pst = $g_pdo->prepare($request);
        $pst->execute(array(":token" => $token));
        $record = $pst->fetch();
        if ($record == NULL) {
            throw new Exception(_t("No user found with this token."));
        }
        $user = new User();
        $user->hydrate($record);
        $user->set_token(NULL);
        $exp_ts = explode("_", $token);
        if ($exp_ts[0] < time()) {
            throw new Exception(_t("This token is expired."));
        }
        return $user;
    }