Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // *****************************************************************************
- // Capital IT Inc.
- // Copyright (C) 2008. All Rights Reserved
- //
- // $Source: /cvsroot/smn/app/modules/Default/models/UsersModel.class.php,v $
- // $Revision: 1.7 $
- // $Date: 2008/11/01 18:21:02 $
- // $Author: btiernay $
- //
- // *****************************************************************************
- class Default_UsersModel extends SMNDefaultBaseModel {
- public function login($username, $password) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare('SELECT c.*, u.* FROM CubeCart_customer c INNER JOIN SMN_user u ON u.customer_id = c.customer_id WHERE c.email = ? AND c.password = ? AND c.type > 0 LIMIT 1');
- $stmt->execute(array ($username, md5($password)));
- $user = $stmt->fetch(PDO::FETCH_ASSOC);
- if ($user) {
- $this->updateLogin($user['customer_id']);
- $user['birth_date'] = $this->formatDate($user['birth_date']);
- $user['start_date'] = $this->formatDate($user['start_date']);
- }
- return $user;
- }
- public function getUser($id) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare('SELECT c.*, u.* FROM CubeCart_customer c INNER JOIN SMN_user u ON u.customer_id = c.customer_id WHERE u.id = ? LIMIT 1');
- $stmt->execute(array($id));
- $user = $stmt->fetch(PDO::FETCH_ASSOC);
- if ($user) {
- $this->updateLogin($user['customer_id']);
- $user['birth_date'] = $this->formatDate($user['birth_date']);
- $user['start_date'] = $this->formatDate($user['start_date']);
- }
- return $user;
- }
- private function updateLogin($customer_id) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare("UPDATE SMN_user SET last_login_date=:date WHERE customer_id=:customer_id");
- $stmt->bindValue(":date", time());
- $stmt->bindValue(":customer_id", $customer_id);
- return $stmt->execute();
- }
- public function updateProfile($customer_id, $birth_date, $weight, $goal_weight, $height, $gender, $start_date) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare("UPDATE SMN_user SET birth_date=:birth_date, weight=:weight, goal_weight=:goal_weight, height=:height, gender=:gender, start_date=:start_date WHERE customer_id=:customer_id");
- $stmt->bindValue(':customer_id', $customer_id);
- $stmt->bindValue(':birth_date', $this->parseDate($birth_date));
- $stmt->bindValue(':weight', $weight);
- $stmt->bindValue(':goal_weight', $goal_weight);
- $stmt->bindValue(':height', $height);
- $stmt->bindValue(':gender', $gender);
- $stmt->bindValue(':start_date', $this->parseDate($start_date));
- return $stmt->execute();
- }
- public function updateCustomer($customer_id, $firstName, $lastName, $add_1, $add_2, $town, $county, $postcode, $email, $password) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare("UPDATE CubeCart_customer SET firstName=:firstName, lastName=:lastName, add_1=:add_1, add_2=:add_2, town=:town, county=:county, postcode=:postcode, email=:email, password=:password WHERE customer_id=:customer_id");
- $stmt->bindValue(':customer_id', $customer_id);
- $stmt->bindValue(':firstName', $firstName);
- $stmt->bindValue(':lastName', $lastName);
- $stmt->bindValue(':add_1', $add_1);
- $stmt->bindValue(':add_2', $add_2);
- $stmt->bindValue(':town', $town);
- $stmt->bindValue(':county', $county);
- $stmt->bindValue(':postcode', $postcode);
- $stmt->bindValue(':email', $email);
- $stmt->bindValue(':password', md5($password));
- return $stmt->execute();
- }
- public function updateStatus($customer_id, $status) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare("UPDATE SMN_user SET status=:status WHERE customer_id=:customer_id");
- $stmt->bindValue(":status", $status);
- $stmt->bindValue(":customer_id", $customer_id);
- return $stmt->execute();
- }
- public function updateWeight($customer_id, $weightName, $weightValue) {
- $pdo = $this->getPdo();
- $stmt = $pdo->prepare('UPDATE SMN_user SET '.$weightName.'=:value WHERE customer_id=:customer_id');
- $stmt->bindValue(":value", $weightValue);
- $stmt->bindValue(":customer_id", $customer_id);
- return $stmt->execute();
- }
- private function formatDate($value) {
- if ($value === null) {
- return null;
- }
- return date('m/d/Y', strtotime($value));
- }
- private function parseDate($value) {
- if ($value === null) {
- return null;
- }
- return date('Y-m-d',strtotime($value));
- }
- }
- ?>
Add Comment
Please, Sign In to add comment