Skip to content

Commit

Permalink
Merge pull request #357 from compucorp/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
davialexandre authored Oct 6, 2017
2 parents ab3136e + 4a6b156 commit 32022e2
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 867 deletions.
4 changes: 2 additions & 2 deletions civicrm_resources/civicrm_resources.module
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function civicrm_resources_add_resources($extention_path, $req_files = []) {
drupal_add_css(ltrim(str_replace(DRUPAL_ROOT, '', $css_file), '/'));
}
foreach ($js_list as $key => $js_file) {
drupal_add_js(ltrim(str_replace(DRUPAL_ROOT, '', $js_file), '/'));
drupal_add_js(ltrim(str_replace(DRUPAL_ROOT, '', $js_file), '/'), array('scope' => 'footer'));
}
}

Expand Down Expand Up @@ -165,4 +165,4 @@ function civicrm_resources_load($extention_full_name, $files = []) {
*/
function civicrm_resources_flush_caches() {
return ['cache_civicrm_resources'];
}
}
40 changes: 25 additions & 15 deletions civihr_employee_portal/civihr_employee_portal.module
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ function _setup_modals() {
* @param string $resources the name of the script file (extension included)
* @param string $extension
* @param string $page
* @param string $scope
*/
function _add_script_to_page($resources, $extension = NULL, $page = NULL) {
function _add_script_to_page($resources, $extension = NULL, $page = NULL, $scope = 'footer') {
$options = ['type' => 'file', 'scope' => $scope];

if (!is_null($page) && arg(0) != $page) {
return;
Expand All @@ -148,11 +150,11 @@ function _add_script_to_page($resources, $extension = NULL, $page = NULL) {
else {
if (is_array($resources)) {
foreach ($resources as $value) {
drupal_add_js(drupal_get_path('module', 'civihr_employee_portal') . $value, 'file');
drupal_add_js(drupal_get_path('module', 'civihr_employee_portal') . $value, $options);
}
}
else {
drupal_add_js(drupal_get_path('module', 'civihr_employee_portal') . $resources, 'file');
drupal_add_js(drupal_get_path('module', 'civihr_employee_portal') . $resources, $options);
}
}
}
Expand Down Expand Up @@ -602,7 +604,9 @@ function civihr_employee_portal_init() {

_add_script_to_page(['reqangular.min.js'], 'org.civicrm.reqangular', 'dashboard');
_add_script_to_page(['reqangular.min.js'], 'org.civicrm.reqangular', 'tasks-and-documents');
_add_script_to_page(['/js/tasks.js', '/js/ta-documents-app.js'], NULL, 'tasks-and-documents');
_add_script_to_page(['/js/tasks.js'], NULL, 'tasks-and-documents', 'header');
_add_script_to_page(['/js/ta-documents-app.js'], NULL, 'tasks-and-documents');
_add_script_to_page(['tasks-assignments.min.js'], 'uk.co.compucorp.civicrm.tasksassignments', 'tasks-and-documents');

_rebuild_view('absence_list');
_rebuild_view('length_of_service');
Expand Down Expand Up @@ -5867,7 +5871,7 @@ function civihr_employee_portal_form_alter(&$form, &$form_state, $form_id) {
function civihr_employee_portal_form_user_profile_form_alter(&$form, &$form_state, $form_id) {

// Adding Yoti Login fieldset with button.
if (module_exists('yoti_connect')) {
if (module_exists('yoti')) {

// Fetching block id from block description.
$query = db_select('block_custom', 'b')
Expand Down Expand Up @@ -6980,21 +6984,27 @@ function civihr_employee_portal_module_implements_alter(&$implementations, $hook

/**
* Check if a passed date is weekend day or not
*
* @param \DateTime $date
*
* @return bool
*/
function _isWeekend($date_passed) {

$date = explode("-", $date_passed);

$time = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
$weekday = date('w', $time);
return ($weekday == 0 || $weekday == 6);
function _isWeekend(\DateTime $date) {
$saturday = 6;
$sunday = 0;
$weekday = $date->format('w');
return ($weekday == $saturday || $weekday == $sunday);
}

/**
* @param $public_holidays
* Check if the requested day is holiday or not working day
* Check if the requested day is holiday or not working day
* @param \DateTime $date
* The requested day
*
* @return array
*/
function _checkRequestedDay($public_holidays, $date) {
function _checkRequestedDay($public_holidays, \DateTime $date) {

$not_working_day = t('Weekend');

Expand All @@ -7003,7 +7013,7 @@ function _checkRequestedDay($public_holidays, $date) {
$public_holiday_date = explode(" ", $public_holiday['activity_date_time']);

// If the public holiday equals with the requested date and the public holiday is enabled
if ($public_holiday_date[0] == $date && $public_holiday['status_id'] == 1) {
if ($public_holiday_date[0] == $date->format('Y-m-d') && $public_holiday['status_id'] == 1) {
$exclude_type = " (" . $public_holiday['subject'] . ")";

return array(
Expand Down
43 changes: 14 additions & 29 deletions civihr_employee_portal/civihr_employee_portal.rules.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function civihr_employee_portal_rules_action_info() {
),
),
);

return $actions;
}

Expand All @@ -136,13 +136,13 @@ function _new_absence_request_action($roles, $absence_type, $absence_details, $f
// TODO --> status ID should be dynamic??
'status_id' => '1'
);

$result = civicrm_api3('Activity', 'create', $activityParam);

// Get the main "absence" activity ID
$activityTypes = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'name');
$activityTypeId = CRM_Utils_Array::key('Absence', $activityTypes);

// Create sub-activities
$activityLeavesParam = array(
'sequential' => 1,
Expand Down Expand Up @@ -172,41 +172,26 @@ function _new_absence_request_action($roles, $absence_type, $absence_details, $f

// Define Absence Date Durations
$absentDateDurations = array();
$date_counter = 0;


$fromDate = new \DateTime($form_values->absence_request_date_from);
foreach ($form_values as $object_property_key => $object_property_value) {

if (strpos($object_property_key, '_requested_day_') !== false) {

if ($date_counter > 0) {

$new_date = strtotime($form_values->absence_request_date_from);
$new_date = $new_date + (60 * 60 * 24 * $date_counter);
$new_date = date('Y-m-d', $new_date);

$absentDateDurations[$object_property_key] = array('date' => $new_date . " 00:00:00", 'duration' => $object_property_value, 'approval' => '1');

}
else {

$absentDateDurations[$object_property_key] = array('date' => $form_values->absence_request_date_from . " 00:00:00", 'duration' => $object_property_value, 'approval' => '1');

}

$date_counter++;
$absentDateDurations[$object_property_key] = array('date' => $fromDate->format('Y-m-d 00:00:00'), 'duration' => $object_property_value, 'approval' => '1');
$fromDate->modify('+1 day');
}

}

foreach ($absentDateDurations as $object_key => $duration) {
$activityLeavesParam['activity_date_time'] = $duration['date'];
$activityLeavesParam['duration'] = $duration['duration'];
$activityLeavesParam['status_id'] = $duration['approval'];

civicrm_api3('Activity', 'create', $activityLeavesParam);

}

// @TODO -> This should provide success / failure value (email message should be based on this success or failure) -> If failure don't create activity

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['access CiviReport'] = array(
'name' => 'access CiviReport',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down Expand Up @@ -84,7 +85,10 @@ function civihr_default_permissions_user_default_permissions() {
// Exported permission: 'access Report Criteria'.
$permissions['access Report Criteria'] = array(
'name' => 'access Report Criteria',
'roles' => array(),
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
);

Expand All @@ -103,6 +107,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['access Tasks and Assignments Files'] = array(
'name' => 'access Tasks and Assignments Files',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
'civihr_admin_local' => 'civihr_admin_local',
'civihr_manager' => 'civihr_manager',
Expand Down Expand Up @@ -136,6 +141,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['access all cases and activities'] = array(
'name' => 'access all cases and activities',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down Expand Up @@ -285,6 +291,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['access my cases and activities'] = array(
'name' => 'access my cases and activities',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down Expand Up @@ -423,6 +430,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['add cases'] = array(
'name' => 'add cases',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down Expand Up @@ -464,6 +472,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['administer CiviCase'] = array(
'name' => 'administer CiviCase',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand All @@ -473,6 +482,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['administer Reports'] = array(
'name' => 'administer Reports',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down Expand Up @@ -1272,6 +1282,7 @@ function civihr_default_permissions_user_default_permissions() {
$permissions['delete in CiviCase'] = array(
'name' => 'delete in CiviCase',
'roles' => array(
'administrator' => 'administrator',
'civihr_admin' => 'civihr_admin',
),
'module' => 'civicrm',
Expand Down
54 changes: 18 additions & 36 deletions civihr_employee_portal/js/ta-documents-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@

vm.modalDocument = modalDocument;
vm.openModalDocument = openModalDocument;
vm.cacheContacts = cacheContacts;

(function init() {
// Sets the date format for HR_settings.DATE_FORMAT
DateFormat.getDateFormat();
subscribeForEvents();
watchForChanges();
collectRequiredData();
})();

/**
* Collect required data for document modal
* Collect required contact and cache them for document modal
*
* @return {promise}
*/
function collectRequiredData () {
// Sets the date format for HR_settings.DATE_FORMAT
DateFormat.getDateFormat();

// Fetch and cache contacts and addignments
DocumentService.get().then(function (documents) {
DocumentService.cacheContactsAndAssignments(documents, 'contacts');
});
function cacheContacts (documents) {
return DocumentService.cacheContactsAndAssignments(documents, 'contacts');
};

/**
Expand All @@ -46,8 +43,9 @@
*
* @param {integer} id
* @param {string} role
* @param {string} mode
*/
function modalDocument (id, role) {
function modalDocument (id, role, mode) {
$rootScope.$broadcast('ct-spinner-show', 'document-' + id);
vm.loadingModalData = true;

Expand All @@ -57,7 +55,9 @@
throw new Error('Requested Document is not available');
}

vm.openModalDocument(data[0], role);
vm.cacheContacts(data).then(function () {
vm.openModalDocument(data[0], role, mode);
});
})
.catch(function(reason) {
CRM.alert(reason, 'Error', 'error');
Expand All @@ -69,16 +69,17 @@
*
* @param {object} data
* @param {string} role
* @param {string} mode
*/
function openModalDocument(data, role) {
function openModalDocument(data, role, mode) {
var modalInstance = $modal.open({
appendTo: $rootElement,
templateUrl: config.path.TPL + 'modal/document.html?v=3',
controller: 'ModalDocumentCtrl',
controller: 'ModalDocumentController',
controllerAs: 'documentModal',
resolve: {
modalMode: function () {
return '';
return mode;
},
role: function () {
return role;
Expand All @@ -100,7 +101,7 @@
$rootScope.$broadcast('ct-spinner-hide');
vm.loadingModalData = false;
});
};
}

/**
* All event subscribers
Expand All @@ -110,24 +111,5 @@
$window.location.reload();
});
};

/**
* All watchers for changes
*/
function watchForChanges () {
/**
* Watch for the changes in the list of $rootScope.cache.contact.arrSearch
* Display spinner and hide "open" button until the arrSearch is filled with contacts
*
* Note: $rootScope.cache.contact.arrSearch will always contain a
* contact data (curently logged in contact). So if there are documents,
* there must be more that one contacts conidering at aleast a target contact in a document
*/
$rootScope.$watch('cache.contact', function () {
availableContacts = $rootScope.cache.contact.arrSearch.length > 1;
$rootScope.$broadcast('ct-spinner-' + (availableContacts ? 'hide' : 'show'));
vm.loadingModalData = !availableContacts;
});
};
}
})(angular);
24 changes: 24 additions & 0 deletions civihr_employee_portal/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="CiviHR Employee Portal Tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 32022e2

Please sign in to comment.