Replace q() call with Profile::get() method
This commit is contained in:
parent
6c2cf494b5
commit
2a87464c97
2 changed files with 52 additions and 38 deletions
|
@ -27,6 +27,7 @@ use Friendica\Model\Group;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Mail;
|
use Friendica\Model\Mail;
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\FKOAuth1;
|
use Friendica\Network\FKOAuth1;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
@ -6205,47 +6206,39 @@ function api_friendica_profile_show($type)
|
||||||
|
|
||||||
// get data of the specified profile id or all profiles of the user if not specified
|
// get data of the specified profile id or all profiles of the user if not specified
|
||||||
if ($profile_id != 0) {
|
if ($profile_id != 0) {
|
||||||
$r = q(
|
$r = Profile::get(api_user(), $profile_id);
|
||||||
"SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
|
|
||||||
intval(api_user()),
|
|
||||||
intval($profile_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
// error message if specified gid is not in database
|
// error message if specified gid is not in database
|
||||||
if (!DBA::isResult($r)) {
|
if (!DBA::isResult($r)) {
|
||||||
throw new BadRequestException("profile_id not available");
|
throw new BadRequestException("profile_id not available");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$r = q(
|
$r = Profile::get(api_user());
|
||||||
"SELECT * FROM `profile` WHERE `uid` = %d",
|
|
||||||
intval(api_user())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// loop through all returned profiles and retrieve data and users
|
// loop through all returned profiles and retrieve data and users
|
||||||
$k = 0;
|
$k = 0;
|
||||||
$profiles = [];
|
$profiles = [];
|
||||||
foreach ($r as $rr) {
|
if (DBA::isResult($r)) {
|
||||||
$profile = api_format_items_profiles($rr);
|
foreach ($r as $rr) {
|
||||||
|
$profile = api_format_items_profiles($rr);
|
||||||
|
|
||||||
// select all users from contact table, loop and prepare standard return for user data
|
// select all users from contact table, loop and prepare standard return for user data
|
||||||
$users = [];
|
$users = [];
|
||||||
$nurls = q(
|
$nurls = Contact::select(['id', 'nurl'], ['uid' => api_user(), 'profile-id' => $rr['id']]);
|
||||||
"SELECT `id`, `nurl` FROM `contact` WHERE `uid`= %d AND `profile-id` = %d",
|
|
||||||
intval(api_user()),
|
|
||||||
intval($rr['id'])
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($nurls as $nurl) {
|
if (DBA::isResult($nurls)) {
|
||||||
$user = api_get_user($a, $nurl['nurl']);
|
foreach ($nurls as $nurl) {
|
||||||
($type == "xml") ? $users[$k++ . ":user"] = $user : $users[] = $user;
|
$user = api_get_user($a, $nurl['nurl']);
|
||||||
}
|
($type == "xml") ? $users[$k++ . ":user"] = $user : $users[] = $user;
|
||||||
$profile['users'] = $users;
|
}
|
||||||
|
}
|
||||||
|
$profile['users'] = $users;
|
||||||
|
|
||||||
// add prepared profile data to array for final return
|
// add prepared profile data to array for final return
|
||||||
if ($type == "xml") {
|
if ($type == "xml") {
|
||||||
$profiles[$k++ . ":profile"] = $profile;
|
$profiles[$k++ . ":profile"] = $profile;
|
||||||
} else {
|
} else {
|
||||||
$profiles[] = $profile;
|
$profiles[] = $profile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6275,15 +6268,17 @@ function api_saved_searches_list($type)
|
||||||
$terms = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
|
$terms = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
while ($term = $terms->fetch()) {
|
if (DBA::isResult($terms)) {
|
||||||
$result[] = [
|
while ($term = $terms->fetch()) {
|
||||||
'created_at' => api_date(time()),
|
$result[] = [
|
||||||
'id' => intval($term['id']),
|
'created_at' => api_date(time()),
|
||||||
'id_str' => $term['id'],
|
'id' => intval($term['id']),
|
||||||
'name' => $term['term'],
|
'id_str' => $term['id'],
|
||||||
'position' => null,
|
'name' => $term['term'],
|
||||||
'query' => $term['term']
|
'position' => null,
|
||||||
];
|
'query' => $term['term']
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBA::close($terms);
|
DBA::close($terms);
|
||||||
|
|
|
@ -45,6 +45,25 @@ class Profile
|
||||||
return $profile;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the profile based on a ID
|
||||||
|
*
|
||||||
|
* @param int $uid The User ID
|
||||||
|
* @param int $id The id of the profile (optional)
|
||||||
|
* @param array $fields The fields to retrieve
|
||||||
|
*
|
||||||
|
* @return array Array of profile data
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function get(int $uid, int $id = null, array $fields = [])
|
||||||
|
{
|
||||||
|
if (empty($id)) {
|
||||||
|
return DBA::select('profile', $fields, ['uid' => $uid]);
|
||||||
|
} else {
|
||||||
|
return DBA::select('profile', $fields, ['uid' => $uid, 'id' => $id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a formatted location string from the given profile array
|
* @brief Returns a formatted location string from the given profile array
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue