/** * * 列举共享信息 */ public function handlerListDetails() { $this->_slaves = array(); $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'user_id' => $this->_userId, 'is_deleted' => 0)); if (is_null($this->_file)) { throw new ApiException('Not Found'); } if ($this->_file['file_type'] != 2) { throw new ApiException('Not Found'); } $meta = FileMeta::model()->findByAttributes(array('file_path' => $this->_file['file_path'], 'meta_key' => self::SHARED_META_FLAG)); if (!$meta) { throw new ApiException('Not Found'); } $meta_value = unserialize($meta['meta_value']); if ($meta_value['master'] != $this->_userId) { throw new ApiException('Not Found'); } $slaves = $meta_value['slaves']; $send = $meta_value['send_msg']; foreach ($slaves as $key => $value) { $user = User::model()->findByPk($key); if (!$user) { continue; } $mate = UserMeta::model()->findByAttributes(array("user_id" => $user->id, "meta_key" => "nick")); if ($mate) { $value = $mate->meta_value; if (!empty($value) && strlen(trim($value)) > 0) { $nick = $value; } } else { $nick = $user['user_name']; } $shared_file = UserFile::model()->findByAttributes(array('user_id' => $key, 'file_path' => $value, 'is_deleted' => 0)); $path = $this->_file['file_path']; $permission = Yii::app()->privilege->checkPrivilegeUser($key, $path); array_push($this->_slaves, array('user_id' => $key, 'user_name' => $user['user_name'], 'nick' => $nick, 'type' => $shared_file['file_type'], 'permission' => $permission, 'send' => $send)); } }
/** * * 执行搜索操作 */ private function handlerSeach() { $params = array(); $params[':user_name'] = "%" . $this->search_key . "%"; $params[':meta_value'] = "%" . $this->search_key . "%"; // // 联合查询 // $conditions = User::model()->tableName() . ' as u left outer join '; $conditions .= UserMeta::model()->tableName(); $conditions .= ' as m on m.user_id = u.id and m.meta_key="nick" '; $conditions .= ' WHERE user_name like :user_name or meta_value like :meta_value'; $count_sql = 'SELECT count(*) as count FROM ' . $conditions; $this->total = User::model()->countBySql($count_sql, $params); // 创建sql $query = 'SELECT u.*,m.meta_value as nick FROM ' . $conditions; $query .= ' limit :offset, :limit'; $command = Yii::app()->db->createCommand($query); $command->bindParam(':user_name', $params[':user_name']); $command->bindParam(':meta_value', $params[':meta_value']); $command->bindParam(':limit', $this->limit); $command->bindParam(':offset', $this->offset); $userList = $command->queryAll(); $users = array(); if ($this->callback) { $users = call_user_func($this->callback, $userList, $this->total); } else { foreach ($userList as $user) { $user_name = trim($user['nick']); $user_name = empty($user_name) ? $user['user_name'] : $user_name; $users[$user['id']] = array("id" => $user['id'], "user_name" => $user_name); } $users = CJSON::encode($this->_getHashByList($users)); } return $users; }
/** * 添加用户meta信息 * @param $metas 用户的一些扩展信息 * @param $user 用户名、用户状态及uuid * */ public function create($user, $metas) { //存储用户扩展信息 if (array_key_exists('extend', $metas) && !empty($metas['extend'])) { foreach ($metas['extend'] as $key => $value) { if ($value === null) { continue; } $userMeta = UserMeta::model()->find("user_id=:user_id and meta_key=:key", array(":user_id" => $user['id'], ':key' => $key)); if (!empty($userMeta)) { if ($userMeta['meta_value'] != $value) { $userMeta['meta_value'] = $value; $userMeta->save(); } } else { $userMeta = new UserMeta(); $userMeta["user_id"] = $user["id"]; $userMeta["meta_key"] = $key; $userMeta["meta_value"] = $value; $userMeta->save(); } } } }
/** * 把系统中的中文用户名转化为拼音 */ public function updateAllUserNamePinyin() { $criteria = new CDbCriteria(); $criteria->order = "-id"; $items = User::model()->findAll($criteria); foreach ($items as $item) { if (empty($item->user_name_pinyin)) { //把登陆名转化为拼音 $name = $item->user_name; //把昵称转化为拼音 $nick = ""; $criteria = new CDbCriteria(); $criteria->condition = "user_id=:user_id and meta_key='nick'"; $criteria->params = array(":user_id" => $item->id); $meta = UserMeta::model()->find($criteria); if (!empty($meta)) { $nick = $meta->meta_value; } $item->user_name_pinyin = $this->getPinYinByName($name, $nick); $item->save(); } } }
/** * * 获得属于管理员的总数 * @since 1.0.3 */ public function adminCount() { $count = UserMeta::model()->count("meta_key = 'is_admin' and meta_value = '1'"); return $count; }
/** * * 列举共享信息 * * @since 1.1.0 */ public function handlerListDetails() { $this->_slaves = array(); $this->_file = UserFile::model()->findByAttributes(array('id' => $this->_id, 'is_deleted' => 0)); if (is_null($this->_file)) { throw new ApiException('Not Found'); } //判断此用户是否有 分配 权限 $file_path = $this->_file["file_path"]; $hasPermissionAllot = Yii::app()->privilege->hasPermission($file_path, MPrivilege::PERMISSION_GRANT); if (!$hasPermissionAllot) { $this->result["msg"] = Yii::t('front_common', 'Can not grant permission'); throw new ApiException('Can not grant permission'); } //获取此文件的拥有者 $master = CUtils::getUserFromPath($file_path); $privileges = MUserPrivilege::model()->findAll('file_path=:file_path', array(':file_path' => $this->_file['file_path'])); foreach ($privileges as $pri) { //文件属于拥有者则不能进行权限分配 if ($pri["user_id"] == $master) { continue; } //文件属于自己是不进行权限分配 $currentUser = MUserManager::getInstance()->getCurrentUser(); if ($pri["user_id"] == $currentUser["id"]) { continue; } $user = User::model()->findByPk($pri["user_id"]); if (!$user) { continue; } $mate = UserMeta::model()->findByAttributes(array("user_id" => $user->id, "meta_key" => "nick")); if ($mate) { $nick = $mate->meta_value; } else { $nick = $user['user_name']; } //没有设置分配权限则默认为不分配 $permission = unserialize($pri["permission"]); if (!isset($permission[MPrivilege::PERMISSION_GRANT])) { $permission[MPrivilege::PERMISSION_GRANT] = 0; } array_push($this->_slaves, array('user_id' => $pri["user_id"], 'user_name' => $user['user_name'], 'nick' => $nick, 'permission' => $permission)); } }