本文整理汇总了PHP中Workflow::handleCustomFieldsUpdated方法的典型用法代码示例。如果您正苦于以下问题:PHP Workflow::handleCustomFieldsUpdated方法的具体用法?PHP Workflow::handleCustomFieldsUpdated怎么用?PHP Workflow::handleCustomFieldsUpdated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workflow
的用法示例。
在下文中一共展示了Workflow::handleCustomFieldsUpdated方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateValues
/**
* Method used to update the values stored in the database.
*
* @access public
* @return integer 1 if the update worked properly, any other value otherwise
*/
function updateValues()
{
global $HTTP_POST_VARS;
$prj_id = Auth::getCurrentProject();
$issue_id = Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
$old_values = Custom_Field::getValuesByIssue($prj_id, $issue_id);
// get the types for all of the custom fields being submitted
$stmt = "SELECT\n fld_id,\n fld_type\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n WHERE\n fld_id IN (" . implode(", ", Misc::escapeInteger(@array_keys($HTTP_POST_VARS['custom_fields']))) . ")";
$field_types = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
// get the titles for all of the custom fields being submitted
$stmt = "SELECT\n fld_id,\n fld_title\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n WHERE\n fld_id IN (" . implode(", ", Misc::escapeInteger(@array_keys($HTTP_POST_VARS['custom_fields']))) . ")";
$field_titles = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
$updated_fields = array();
foreach ($HTTP_POST_VARS["custom_fields"] as $fld_id => $value) {
$fld_id = Misc::escapeInteger($fld_id);
// security check
$sql = "SELECT\n fld_min_role\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field\n WHERE\n fld_id = {$fld_id}";
$min_role = $GLOBALS["db_api"]->dbh->getOne($sql);
if ($min_role > Auth::getCurrentRole()) {
continue;
}
$option_types = array('multiple', 'combo');
if (!in_array($field_types[$fld_id], $option_types)) {
// check if this is a date field
if ($field_types[$fld_id] == 'date') {
$value = $value['Year'] . "-" . $value['Month'] . "-" . $value['Day'];
if ($value == '--') {
$value = '';
}
}
// first check if there is actually a record for this field for the issue
$stmt = "SELECT\n icf_id,\n icf_value\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n WHERE\n icf_iss_id=" . $issue_id . " AND\n icf_fld_id={$fld_id}";
$res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC);
if (PEAR::isError($res)) {
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
return -1;
}
$icf_id = $res['icf_id'];
$icf_value = $res['icf_value'];
if ($icf_value == $value) {
continue;
}
if (empty($icf_id)) {
// record doesn't exist, insert new record
$stmt = "INSERT IGNORE INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n (\n icf_iss_id,\n icf_fld_id,\n icf_value\n ) VALUES (\n " . $issue_id . ",\n {$fld_id},\n '" . Misc::escapeString($value) . "'\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 {
// record exists, update it
$stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field\n SET\n icf_value='" . Misc::escapeString($value) . "'\n WHERE\n icf_id={$icf_id}";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
return -1;
}
}
if ($field_types[$fld_id] == 'textarea') {
$updated_fields[$field_titles[$fld_id]] = '';
} else {
$updated_fields[$field_titles[$fld_id]] = History::formatChanges($icf_value, $value);
}
} else {
$old_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id, true);
if (!is_array($old_value)) {
$old_value = array($old_value);
}
if (!is_array($value)) {
$value = array($value);
}
if (count(array_diff($old_value, $value)) > 0 || count(array_diff($value, $old_value)) > 0) {
$old_display_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id);
// need to remove all associated options from issue_custom_field and then
// add the selected options coming from the form
Custom_Field::removeIssueAssociation($fld_id, $HTTP_POST_VARS["issue_id"]);
if (@count($value) > 0) {
Custom_Field::associateIssue($HTTP_POST_VARS["issue_id"], $fld_id, $value);
}
$new_display_value = Custom_Field::getDisplayValue($HTTP_POST_VARS['issue_id'], $fld_id);
$updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_display_value, $new_display_value);
}
}
}
Workflow::handleCustomFieldsUpdated($prj_id, $issue_id, $old_values, Custom_Field::getValuesByIssue($prj_id, $issue_id));
Issue::markAsUpdated($HTTP_POST_VARS["issue_id"]);
// need to save a history entry for this
if (count($updated_fields) > 0) {
// log the changes
$changes = '';
$i = 0;
foreach ($updated_fields as $key => $value) {
if ($i > 0) {
//.........这里部分代码省略.........
示例2: updateValues
/**
* Method used to update the values stored in the database.
*
* @return integer 1 if the update worked properly, any other value otherwise
*/
public static function updateValues()
{
$prj_id = Auth::getCurrentProject();
$issue_id = $_POST['issue_id'];
$old_values = self::getValuesByIssue($prj_id, $issue_id);
if (isset($_POST['custom_fields']) && count($_POST['custom_fields']) > 0) {
$custom_fields = $_POST['custom_fields'];
// get the types for all of the custom fields being submitted
$cf = array_keys($custom_fields);
$cf_list = DB_Helper::buildList($cf);
$stmt = "SELECT\n fld_id,\n fld_type\n FROM\n {{%custom_field}}\n WHERE\n fld_id IN ({$cf_list})";
$field_types = DB_Helper::getInstance()->getPair($stmt, $cf);
// get the titles for all of the custom fields being submitted
$stmt = "SELECT\n fld_id,\n fld_title\n FROM\n {{%custom_field}}\n WHERE\n fld_id IN ({$cf_list})";
$field_titles = DB_Helper::getInstance()->getPair($stmt, $cf);
$updated_fields = array();
foreach ($custom_fields as $fld_id => $value) {
// security check
$sql = 'SELECT
fld_min_role
FROM
{{%custom_field}}
WHERE
fld_id = ?';
$min_role = DB_Helper::getInstance()->getOne($sql, array($fld_id));
if ($min_role > Auth::getCurrentRole()) {
continue;
}
$option_types = array('multiple', 'combo', 'checkbox');
if (!in_array($field_types[$fld_id], $option_types)) {
// check if this is a date field
$fld_db_name = self::getDBValueFieldNameByType($field_types[$fld_id]);
// first check if there is actually a record for this field for the issue
$stmt = "SELECT\n icf_id,\n {$fld_db_name} as value\n FROM\n {{%issue_custom_field}}\n WHERE\n icf_iss_id=? AND\n icf_fld_id=?";
try {
$res = DB_Helper::getInstance()->getRow($stmt, array($issue_id, $fld_id));
} catch (DbException $e) {
return -1;
}
$icf_id = $res['icf_id'];
$old_value = $res['value'];
if ($old_value == $value) {
continue;
}
if (empty($icf_id)) {
// record doesn't exist, insert new record
$stmt = "INSERT INTO\n {{%issue_custom_field}}\n (\n icf_iss_id,\n icf_fld_id,\n {$fld_db_name}\n ) VALUES (\n ?, ?, ?\n )";
$params = array($issue_id, $fld_id, $value);
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
} else {
// record exists, update it
$stmt = "UPDATE\n {{%issue_custom_field}}\n SET\n {$fld_db_name}=?\n WHERE\n icf_id=?";
$params = array($value, $icf_id);
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
}
if ($field_types[$fld_id] == 'textarea') {
$updated_fields[$field_titles[$fld_id]] = '';
} else {
$updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_value, $value);
}
} else {
$old_value = self::getDisplayValue($issue_id, $fld_id, true);
if (!is_array($old_value)) {
$old_value = array($old_value);
}
if (!is_array($value)) {
$value = array($value);
}
if (count(array_diff($old_value, $value)) > 0 || count(array_diff($value, $old_value)) > 0) {
$old_display_value = self::getDisplayValue($issue_id, $fld_id);
// need to remove all associated options from issue_custom_field and then
// add the selected options coming from the form
self::removeIssueAssociation($fld_id, $issue_id);
if (@count($value) > 0) {
self::associateIssue($issue_id, $fld_id, $value);
}
$new_display_value = self::getDisplayValue($issue_id, $fld_id);
$updated_fields[$field_titles[$fld_id]] = History::formatChanges($old_display_value, $new_display_value);
}
}
}
Workflow::handleCustomFieldsUpdated($prj_id, $issue_id, $old_values, self::getValuesByIssue($prj_id, $issue_id));
Issue::markAsUpdated($issue_id);
// need to save a history entry for this
if (count($updated_fields) > 0) {
// log the changes
$changes = '';
//.........这里部分代码省略.........
示例3: updateValues
//.........这里部分代码省略.........
}
$updated_fields[$fld_id] = array('title' => $field_titles[$fld_id], 'type' => $field_types[$fld_id], 'min_role' => $min_role, 'changes' => '', 'old_display' => '', 'new_display' => '');
if (!in_array($field_types[$fld_id], self::$option_types)) {
// check if this is a date field
$fld_db_name = self::getDBValueFieldNameByType($field_types[$fld_id]);
// first check if there is actually a record for this field for the issue
$stmt = "SELECT\n icf_id,\n {$fld_db_name} as value\n FROM\n {{%issue_custom_field}}\n WHERE\n icf_iss_id=? AND\n icf_fld_id=?";
try {
$res = DB_Helper::getInstance()->getRow($stmt, array($issue_id, $fld_id));
} catch (DbException $e) {
return -1;
}
$icf_id = $res['icf_id'];
$old_value = $res['value'];
if ($old_value == $value) {
unset($updated_fields[$fld_id]);
continue;
}
if (empty($icf_id)) {
// record doesn't exist, insert new record
$stmt = "INSERT INTO\n {{%issue_custom_field}}\n (\n icf_iss_id,\n icf_fld_id,\n {$fld_db_name}\n ) VALUES (\n ?, ?, ?\n )";
$params = array($issue_id, $fld_id, $value);
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
} else {
// record exists, update it
$stmt = "UPDATE\n {{%issue_custom_field}}\n SET\n {$fld_db_name}=?\n WHERE\n icf_id=?";
$params = array($value, $icf_id);
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
}
$updated_fields[$fld_id]['old_display'] = $old_value;
$updated_fields[$fld_id]['new_display'] = $value;
if ($field_types[$fld_id] == 'textarea') {
$updated_fields[$fld_id]['changes'] = '';
} else {
$updated_fields[$fld_id]['changes'] = History::formatChanges($old_value, $value);
}
} else {
$old_value = self::getDisplayValue($issue_id, $fld_id, true);
// remove dummy value from checkboxes. This dummy value is required so all real values can be unchecked.
if ($field_types[$fld_id] == 'checkbox') {
$value = array_filter($value);
}
if (!is_array($old_value)) {
$old_value = array($old_value);
}
if (!is_array($value)) {
$value = array($value);
}
if (count(array_diff($old_value, $value)) > 0 || count(array_diff($value, $old_value)) > 0) {
$old_display_value = self::getDisplayValue($issue_id, $fld_id);
// need to remove all associated options from issue_custom_field and then
// add the selected options coming from the form
self::removeIssueAssociation($fld_id, $issue_id);
if (@count($value) > 0) {
self::associateIssue($issue_id, $fld_id, $value);
}
$new_display_value = self::getDisplayValue($issue_id, $fld_id);
$updated_fields[$fld_id]['changes'] = History::formatChanges($old_display_value, $new_display_value);
$updated_fields[$fld_id]['old_display'] = $old_display_value;
$updated_fields[$fld_id]['new_display'] = $new_display_value;
} else {
unset($updated_fields[$fld_id]);
}
}
}
Workflow::handleCustomFieldsUpdated($prj_id, $issue_id, $old_values, self::getValuesByIssue($prj_id, $issue_id), $updated_fields);
Issue::markAsUpdated($issue_id);
if (count($updated_fields) > 0) {
// log the changes
$changes = array();
foreach ($updated_fields as $fld_id => $updated_field) {
if (!isset($changes[$updated_field['min_role']])) {
$changes[$updated_field['min_role']] = array();
}
$title = $updated_field['title'];
$value = $updated_field['changes'];
if (!empty($value)) {
$changes[$updated_field['min_role']][] = "{$title}: {$value}";
} else {
$changes[$updated_field['min_role']][] = $title;
}
}
$usr_id = Auth::getUserID();
$usr_full_name = User::getFullName($usr_id);
foreach ($changes as $min_role => $role_changes) {
History::add($issue_id, $usr_id, 'custom_field_updated', 'Custom field updated ({changes}) by {user}', array('changes' => implode('; ', $role_changes), 'user' => $usr_full_name), $min_role);
}
}
return $updated_fields;
}
return array();
}