Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix - Calendario laboral - Operar con todos los registros al actualizar masivamente la hora de inicio y de finalización #537

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions modules/stic_Work_Calendar/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ public function action_workCalendarAssistantSummary() {
*/
public function action_showMassUpdateDatesForm()
{

// If select_entire_list is used, select all stic_Work_Calendar records undeleted and different that current record
if (isset($_REQUEST['select_entire_list']) && $_REQUEST['select_entire_list'] == '1') {

// If the popup selection was previously filtered, use custom function to generate custom where conditions
if (isset($_REQUEST['current_query_by_page'])) {
include 'Utils.php';
$where = $this->generateAllWhereClausesFromFilter($_REQUEST);
}
$entireListSQL = "SELECT distinct id FROM stic_work_calendar WHERE deleted=0";
if (!empty($where)) {
$entireListSQL = $entireListSQL . ' AND ' . $where;
}

$entireListSQLResults = $GLOBALS['db']->query($entireListSQL);
unset($relateIds);
while ($row = $GLOBALS['db']->fetchByAssoc($entireListSQLResults)) {
$relateIds[] = $row['id'];
}
$_REQUEST['uid'] = empty($relateIds) ? $_REQUEST['uid'] : implode(',', $relateIds);
}
$this->view = "massupdatedatesform"; //call for the view file in views dir
}

Expand Down Expand Up @@ -216,4 +237,57 @@ protected function calculateNewDate($dateInfo)
}
return $date->format($format);
}

/**
* Returns generated where SQL conditions from popup view. Fuction uses the $_REQUEST object generated by popup callback javascript function
* The function is based in include/generic/Save2.php file, which contains the controller code for saving popup selection records when usin Select button in a "normal" subpanel throw SubPanelTopSelectButton widget.
* @return String Generated where SQL conditions
*/
protected function generateAllWhereClausesFromFilter()
{
require_once 'include/formbase.php';

// If the user selected "All records" from the selection menu, we pull up the list
// based on the query they used on that popup to relate them to the parent record
$current_query_by_page = $_REQUEST['current_query_by_page'];
$current_query_by_page_array = json_decode(html_entity_decode($current_query_by_page), true);

$module = $current_query_by_page_array['module'];
$seed = BeanFactory::getBean($module);
if (empty($seed)) {
sugar_die($GLOBALS['app_strings']['ERROR_NO_BEAN']);
}
$where_clauses = '';
require_once 'include/SearchForm/SearchForm2.php';

if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) {
require 'custom/modules/' . $module . '/metadata/metafiles.php';
} elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) {
require 'modules/' . $module . '/metadata/metafiles.php';
}

if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) {
require_once 'custom/modules/' . $module . '/metadata/searchdefs.php';
} elseif (!empty($metafiles[$module]['searchdefs'])) {
require_once $metafiles[$module]['searchdefs'];
} elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) {
require_once 'modules/' . $module . '/metadata/searchdefs.php';
}

if (!empty($metafiles[$module]['searchfields'])) {
require_once $metafiles[$module]['searchfields'];
} elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) {
require_once 'modules/' . $module . '/metadata/SearchFields.php';
}
if (!empty($searchdefs) && !empty($searchFields)) {
$searchForm = new SearchForm($seed, $module);
$searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl');
$searchForm->populateFromArray($current_query_by_page_array, $searchForm->displayView);
$where_clauses_arr = $searchForm->generateSearchWhere(true, $module);
if (count($where_clauses_arr) > 0) {
$where_clauses = '(' . implode(' ) AND ( ', $where_clauses_arr) . ')';
}
}
return $where_clauses;
}
}
4 changes: 3 additions & 1 deletion modules/stic_Work_Calendar/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
'type' => 'bool'
),
'assigned_user_id' => array('query_type' => 'default'),

'type' => array('query_type' => 'default'),
'description'=> array('query_type'=>'default'),

//Range Search Support
'range_date_entered' => array('query_type' => 'default', 'enable_range_search' => true, 'is_date_field' => true),
'start_range_date_entered' => array(
Expand Down
2 changes: 1 addition & 1 deletion modules/stic_Work_Calendar/stic_Work_Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function save($check_notify = true)
$this->end_date = $timedate->asDb($endDate, $current_user);
}

if ($_REQUEST["action"] != "Save") // MassUpdate, API, Import..
if ($_REQUEST["action"] != "Save" && $_REQUEST["action"] != "runMassUpdateDates") // MassUpdate, API, Import..
{
// Reactivate disable date_format to work with the rest of the date type fields
$GLOBALS['disable_date_format'] = true;
Expand Down
Loading