/** * Get the meta data of a user. * @param long $uid - the unique ID of the user * @return an array contains all meta data of the user */ public function getUserMetaUsingUid($uid) { $userMeta = array(); $resultSet = UserMeta::find(array('conditions' => 'uid = ?1', 'bind' => array(1 => $uid))); foreach ($resultSet as $rowSet) { $key = $rowSet->getMetaKey(); $value = $rowSet->getMetaValue(); if ($key == 'socialLinks') { $value = (array) json_decode($value); } $userMeta = array_merge($userMeta, array($key => $value)); } return $userMeta; }
public function postVerify() { $this->beforeFilter('admin'); $request = Input::get('request'); $status = Input::get('status'); $accepted = array('pending', 'verified', 'denied'); if (!in_array($status, $accepted)) { throw new Exception('Invalid value for verify request: ' . $status); } $meta = UserMeta::find($request['id']); $meta->meta_value = $status; $ret = $meta->save(); return Response::json($ret); }
/** * * 赋予用户角色 */ public function changeRole($userIds, $isAdmin) { if ($userIds != '' && strlen($userIds) > 0) { $idsArray = explode(",", $userIds); //查出admin 用户信息 $userInfo = $this->find('user_name=:user_name', array(':user_name' => 'admin')); foreach ($idsArray as $index => $userId) { //如果是amdin账号id则不修改角色信息 if ($userInfo['id'] == $userId) { continue; } $userMeta = new UserMeta(); $item = $userMeta->find("meta_key='is_admin' and user_id=" . $userId); if (isset($item)) { $userMeta = $item; } else { $userMeta["meta_key"] = "is_admin"; $userMeta["user_id"] = $userId; $userMeta["created_at"] = date("Y-m-d H:i:s"); $userMeta["updated_at"] = date("Y-m-d H:i:s"); } $userMeta["meta_value"] = $isAdmin ? "1" : "0"; $userMeta->save(); } } }