Skip to content

Commit

Permalink
Prevent same custom box creation
Browse files Browse the repository at this point in the history
If the box with title and filter id is already present (either in all projects or in the current project) the new box is not created.
  • Loading branch information
paulgoetze committed Sep 29, 2014
1 parent 3b97851 commit 6e01ea4
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions Dashboard/api/dashboard_db_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ static function dashoard_data_exists()
$t_column_project_id = 'project_id';

$t_dashboard_table = '';

if($t_default_boxes_view){
$t_dashboard_table = plugin_table(self::TABLE_BOXES);
} else if($t_custom_boxes_view){
$t_dashboard_table = plugin_table(self::TABLE_CUSTOM_BOXES_POSITIONS);
}

$t_query = "SELECT id FROM $t_dashboard_table
WHERE user_id=".db_param() . " AND $t_column_project_id = " . db_param();
WHERE user_id=".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));

Expand Down Expand Up @@ -82,18 +85,26 @@ static function custom_box_exists($p_title = "", $p_filter_id = 0)
}

$t_current_user_id = auth_get_current_user_id();

$t_current_project_id = helper_get_current_project();

$t_column_filter_id = 'filter_id';
$t_column_user_id = 'user_id';
$t_column_title = 'title';
$t_column_project_id = 'project_id';

$t_dashboard_table = plugin_table(self::TABLE_CUSTOM_BOXES);
$t_query = "SELECT id FROM $t_dashboard_table
WHERE $t_column_user_id=" . db_param() .
" AND $t_column_title=".db_param() .
" AND $t_column_filter_id=" . db_param();
" AND $t_column_filter_id=" . db_param() .
" AND ($t_column_project_id=" . db_param() .
" OR $t_column_project_id=0)";

$t_result = db_query_bound($t_query, array($t_current_user_id, $p_title, $p_filter_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$p_title,
$p_filter_id,
$t_current_project_id));

return (db_num_rows($t_result) > 0);
}
Expand Down Expand Up @@ -627,16 +638,22 @@ static function get_positioned_custom_boxes_data()
if (self::user_has_custom_boxes()) {
$t_query = "SELECT $t_column_positions
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id = " . db_param();
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$t_current_project_id));

if ($t_result != false) {
$t_result_array = db_fetch_array($t_result);

# If there is no project-specific position, we use the global one instead.
if (!$t_result_array) {
$t_query = "SELECT $t_column_positions
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id = " . db_param();
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, 0));
if ($t_result)
Expand All @@ -655,9 +672,12 @@ static function get_positioned_custom_boxes_data()

$t_query = "SELECT $t_column_title, $t_column_id
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id IN(" . db_param() . ", 0) ";
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id IN(" . db_param() . ", 0) ";

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$t_current_project_id));

if ($t_result != false) {
$t_count = 0;
Expand All @@ -671,7 +691,10 @@ static function get_positioned_custom_boxes_data()
$t_column = (($t_count % 3) == 0) ? 3 : ($t_count % 3);
$t_title = $t_box['title'];
$t_id = $t_box['id'];
array_push($t_boxes, array('id' => $t_id, 'title' => $t_title, 'column' => $t_column));
array_push($t_boxes, array(
'id' => $t_id,
'title' => $t_title,
'column' => $t_column));
}
}
}
Expand Down

0 comments on commit 6e01ea4

Please sign in to comment.