本文整理汇总了PHP中Prefs::getDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP Prefs::getDefaults方法的具体用法?PHP Prefs::getDefaults怎么用?PHP Prefs::getDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Prefs
的用法示例。
在下文中一共展示了Prefs::getDefaults方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Method used to get the preferences set by a specific user.
*
* @param integer $usr_id The user ID
* @param bool $force Set to true to force database refresh
* @return array The preferences
*/
public static function get($usr_id, $force = false)
{
static $returns;
if (!$force && !empty($returns[$usr_id])) {
return $returns[$usr_id];
}
$sql = 'SELECT
upr_timezone as timezone,
upr_week_firstday as week_firstday,
upr_list_refresh_rate as list_refresh_rate,
upr_email_refresh_rate as email_refresh_rate,
upr_email_signature as email_signature,
upr_auto_append_email_sig as auto_append_email_sig,
upr_auto_append_note_sig as auto_append_note_sig,
upr_auto_close_popup_window as close_popup_windows
FROM
{{%user_preference}}
WHERE
upr_usr_id=?';
try {
$res = DB_Helper::getInstance()->getRow($sql, array($usr_id));
} catch (DbException $e) {
return Prefs::getDefaults(array_keys(Project::getAssocList($usr_id, false, true)));
}
if ($res === null) {
return Prefs::getDefaults(array_keys(Project::getAssocList($usr_id, false, true)));
}
$returns[$usr_id] = $res;
$returns[$usr_id]['receive_assigned_email'] = array();
$returns[$usr_id]['receive_new_issue_email'] = array();
$returns[$usr_id]['receive_copy_of_own_action'] = array();
// check for the refresh rate variables, and use the default values if appropriate
if (empty($returns[$usr_id]['list_refresh_rate'])) {
$returns[$usr_id]['list_refresh_rate'] = APP_DEFAULT_REFRESH_RATE;
}
if (empty($returns[$usr_id]['email_refresh_rate'])) {
$returns[$usr_id]['email_refresh_rate'] = APP_DEFAULT_REFRESH_RATE;
}
// get per project preferences
$sql = "SELECT\n upp_prj_id as prj_id,\n upp_receive_assigned_email as receive_assigned_email,\n upp_receive_new_issue_email as receive_new_issue_email,\n upp_receive_copy_of_own_action as receive_copy_of_own_action\n FROM\n {{%user_project_preference}}\n WHERE\n upp_usr_id = {$usr_id}";
try {
$res = DB_Helper::getInstance()->fetchAssoc($sql, array(), DB_FETCHMODE_ASSOC);
} catch (DbException $e) {
return $returns[$usr_id];
}
foreach ($res as $prj_id => $project_prefs) {
$returns[$usr_id]['receive_assigned_email'][$prj_id] = $project_prefs['receive_assigned_email'];
$returns[$usr_id]['receive_new_issue_email'][$prj_id] = $project_prefs['receive_new_issue_email'];
$returns[$usr_id]['receive_copy_of_own_action'][$prj_id] = $project_prefs['receive_copy_of_own_action'];
}
return $returns[$usr_id];
}
示例2: insert
/**
* Method used to add a new user to the system.
*
* @param array $user The array of user information
* @return integer 1 if the update worked, -1 otherwise
*/
public static function insert($user)
{
$projects = array();
foreach ($user['role'] as $prj_id => $role) {
if ($role < 1) {
continue;
}
$projects[] = $prj_id;
}
$params = array(isset($user['customer_id']) ? $user['customer_id'] : null, isset($user['contact_id']) ? $user['contact_id'] : null, Date_Helper::getCurrentDateGMT(), Auth::hashPassword($user['password']), $user['full_name'], $user['email'], !empty($user['grp_id']) ? $user['grp_id'] : null, $user['external_id'], isset($user['par_code']) ? $user['par_code'] : null);
$stmt = 'INSERT INTO
{{%user}}
(
usr_customer_id,
usr_customer_contact_id,
usr_created_date,
usr_password,
usr_full_name,
usr_email,
usr_grp_id,
usr_external_id,
usr_par_code
) VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?
)';
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
$new_usr_id = DB_Helper::get_last_insert_id();
// add the project associations!
$projects = array();
foreach ($user['role'] as $prj_id => $role) {
if ($role < 1) {
continue;
}
Project::associateUser($prj_id, $new_usr_id, $role);
$projects[] = $prj_id;
}
Prefs::set($new_usr_id, Prefs::getDefaults($projects));
// send email to user
Notification::notifyNewUser($new_usr_id, $user['password']);
return $new_usr_id;
}
示例3: foreach
// | Authors: Bryan Alsdorf <bryan@mysql.com> |
// +----------------------------------------------------------------------+
//
//
include_once "../../config.inc.php";
include_once APP_INC_PATH . "db_access.php";
include_once APP_INC_PATH . "class.customer.php";
include_once APP_INC_PATH . "class.user.php";
// creates user accounts for all the customers
$prj_id = 1;
$customers = Customer::getAssocList($prj_id);
foreach ($customers as $customer_id => $customer_name) {
echo "Customer: {$customer_name}<br />\n";
$details = Customer::getDetails($prj_id, $customer_id);
foreach ($details['contacts'] as $contact) {
echo "Contact: " . $contact['first_name'] . " " . $contact['last_name'] . " (" . $contact['email'] . ")<br />\n";
$contact_id = User::getUserIDByContactID($contact['contact_id']);
if (empty($contact_id)) {
$sql = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user\n SET\n usr_created_date = '" . Date_API::getCurrentDateGMT() . "',\n usr_full_name = '" . Misc::escapeString($contact['first_name'] . " " . $contact['last_name']) . "',\n usr_email = '" . $contact['email'] . "',\n usr_customer_id = " . $customer_id . ",\n usr_customer_contact_id = " . $contact['contact_id'] . ",\n usr_preferences = '" . Misc::escapeString(Prefs::getDefaults(array($prj_id))) . "'";
$res = $GLOBALS["db_api"]->dbh->query($sql);
if (PEAR::isError($res)) {
echo "Error inserting user<br /><pre>";
print_r($res);
echo "</pre>";
}
$new_usr_id = $GLOBALS['db_api']->get_last_insert_id();
Project::associateUser($prj_id, $new_usr_id, User::getRoleID("Customer"));
}
}
echo "<hr />";
}
示例4: foreach
$prj_id = 1;
// FIXME: Customer::getAssocList does not exist
$customers = Customer::getAssocList($prj_id);
foreach ($customers as $customer_id => $customer_name) {
echo "Customer: {$customer_name}<br />\n";
$details = Customer::getDetails($prj_id, $customer_id);
foreach ($details['contacts'] as $contact) {
echo 'Contact: ' . $contact['first_name'] . ' ' . $contact['last_name'] . ' (' . $contact['email'] . ")<br />\n";
$contact_id = User::getUserIDByContactID($contact['contact_id']);
if (empty($contact_id)) {
$sql = 'INSERT INTO
{{%user}}
SET
usr_created_date = ?,
usr_full_name = ?,
usr_email = ?,
usr_customer_id = ?,
usr_customer_contact_id = ?,
usr_preferences = ?';
$params = array(Date_Helper::getCurrentDateGMT(), $contact['first_name'] . ' ' . $contact['last_name'], $contact['email'], $customer_id, $contact['contact_id'], Prefs::getDefaults(array($prj_id)));
try {
DB_Helper::getInstance()->query($sql, $params);
} catch (DbException $e) {
echo 'Error inserting user<br />';
}
$new_usr_id = DB_Helper::get_last_insert_id();
Project::associateUser($prj_id, $new_usr_id, User::ROLE_CUSTOMER);
}
}
echo '<hr />';
}
示例5: insert
/**
* Method used to add a new user to the system.
*
* @access public
* @return integer 1 if the update worked, -1 otherwise
*/
function insert()
{
global $HTTP_POST_VARS;
$projects = array();
foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) {
if ($role < 1) {
continue;
}
$projects[] = $prj_id;
}
$fn = preg_split('/\\s+/', $HTTP_POST_VARS["full_name"], 2);
$username = preg_split('/@/', $HTTP_POST_VARS["email"], 2);
$prefs = Prefs::getDefaults($projects);
$stmt = "INSERT INTO\n " . ETEL_USER_TABLE_NOSUB . "\n\t\t\t\tSET\n en_ev_customer_id = NULL,\n en_ev_contact_id = NULL,\n en_signup = '" . Date_API::getCurrentDateGMT() . "',\n en_username = '" . Misc::escapeString($username[0]) . "',\n en_password = '" . Auth::hashPassword(Misc::escapeString($username[0] . $HTTP_POST_VARS["password"])) . "',\n en_firstname = '" . Misc::escapeString($fn[0]) . "',\n en_lastname = '" . Misc::escapeString($fn[1]) . "',\n en_email = '" . Misc::escapeString($HTTP_POST_VARS["email"]) . "',\n en_ev_pref = '" . Misc::escapeString($prefs) . "'\n ";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
return -1;
} else {
$new_usr_id = $GLOBALS["db_api"]->get_last_insert_id();
// add the project associations!
foreach ($HTTP_POST_VARS["role"] as $prj_id => $role) {
if ($role < 1) {
continue;
}
Project::associateUser($prj_id, $new_usr_id, $role);
}
// send email to user
Notification::notifyNewUser($new_usr_id, $HTTP_POST_VARS["password"]);
return 1;
}
}