0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProfileTable.php
Go to the documentation of this file.
1 <?
24 require_once 'HypertableConnection.php';
25 require_once 'Profile.php';
26 
28 {
29  // load a user; will return null if this user does not exist
30  public function load($id) {
31  $result=HypertableConnection::query("SELECT * FROM profile ".
32  "WHERE ROW='$id'");
33  if (!$result or !count($result->cells))
34  return null;
35  $profile=new Profile();
36  $profile->setId($id);
37  $profile->setDisplayName($result->cells[1]->value);
38  $profile->setPasswordMd5($result->cells[2]->value);
39  $profile->setEmail($result->cells[3]->value);
40  $profile->setAvatar($result->cells[4]->value);
41  $profile->setLocation($result->cells[5]->value);
42  $profile->setWebpage($result->cells[6]->value);
43  $profile->setBio($result->cells[7]->value);
44  return $profile;
45  }
46 
47  // store a profile
48  public function store($profile) {
49  HypertableConnection::insert('profile', $profile->getId(), 'display_name',
50  $profile->getDisplayName());
51  HypertableConnection::insert('profile', $profile->getId(), 'password',
52  $profile->getPassword());
53  HypertableConnection::insert('profile', $profile->getId(), 'email',
54  $profile->getEmail());
55  HypertableConnection::insert('profile', $profile->getId(), 'avatar',
56  $profile->getAvatar());
57  HypertableConnection::insert('profile', $profile->getId(), 'location',
58  $profile->getLocation());
59  HypertableConnection::insert('profile', $profile->getId(), 'bio',
60  $profile->getBio());
61  HypertableConnection::insert('profile', $profile->getId(), 'webpage',
62  $profile->getWebpage());
63  }
64 
65  // create a new profile
66  //
67  // this function uses create_cell_unique() to insert a new cell. If that
68  // cell already exists the Thrift layer will throw an exception. In that
69  // case just return NULL, otherwise return the newly created object
70  public function create($username) {
71  try {
72  $guid=HypertableConnection::create_cell_unique('profile', $username,
73  'guid');
74  $profile = new Profile();
75  $profile->setGuid($guid);
76  $profile->setId($username);
77  return $profile;
78  }
79  catch (Exception $e) {
80  if($e->getCode()==48) // a cell with this username already exists
81  return null;
82  else
83  throw $e;
84  }
85  }
86 }
87 
88 ?>
static insert($table, $row, $column, $value, $timestamp=0)
create($username)
Copyright (C) 2007-2015 Hypertable, Inc.
Definition: Profile.php:24
Copyright (C) 2007-2015 Hypertable, Inc.
store($profile)
static create_cell_unique($table, $row, $cf)