-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMembers.gs
106 lines (92 loc) · 2.61 KB
/
Members.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function getNoOfMembers() {
return memberArray.length;
}
function getMemberCodeFromName(firstName, surname) {
return memberArray.filter(memberArrayFilter(firstName,surname))[0][0];
}
function memberArrayFilter(firstName,surname) {
return function(element) {
if ((element[1] == firstName) && (element[2] == surname))
{
return true;
}
else
{
return false;
}
}
}
function populateMemberDutyArray() {
var sheet = spreadsheet.getSheetByName('Members');
var sheetArray = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();
for (var i = 0; i < getNoOfMembers(); i++) {
for (var j = 0; j < getNoOfDutiesSetup(); j++) {
if (sheetArray[i + 1][j + 6] == 'Yes') {
//member code, duty code, number of instances
memberDutyArray.push([sheetArray[i + 1][0],sheetArray[0][j + 6],getDutiesByMemberAndDutyCode(sheetArray[i + 1][0],sheetArray[0][j + 6]).length]);
}
}
}
}
function memberDoesDuty(memberCode, dutyCode) {
var filteredMemberDutyArray = memberDutyArray.filter(filterMemberDutiesByMemberAndDutyCode(memberCode, dutyCode));
return filteredMemberDutyArray.length > 0;
}
function filterMemberDutiesByMemberAndDutyCode(memberCode, dutyCode) {
return function(element) {
if ((element[0] == memberCode) && (element[1] == dutyCode)) {
return true;
}
else {
return false;
}
}
}
function getDutiesByMemberAndDutyCode(memberCode,dutyCode) {
return dutyArray.filter(filterDutiesByMemberAndDutyCode(memberCode,dutyCode));
}
function filterDutiesByMemberAndDutyCode(memberCode,dutyCode) {
return function(element) {
if ((element[1] == dutyCode) && (element[4] == memberCode)) {
return true;
}
else {
return false;
}
}
}
function getDutiesByMemberCode(memberCode) {
return memberDutyArray.filter(memberDutyFilter(memberCode));
}
function memberDutyFilter(memberCode) {
return function(element) {
if (element[0] == memberCode) {
return true;
}
else {
return false;
}
}
}
function getMembersByDutyCode(dutyCode) {
return memberDutyArray.filter(memberByDutyCodeFilter(dutyCode));
}
function memberByDutyCodeFilter(dutyCode) {
return function(element) {
if (element[1] == dutyCode) {
return true;
}
else {
return false;
}
}
}
function getIndexOfMemberDuty(memberCode,dutyCode) {
for (var i = 0; i < memberDutyArray.length; i++) {
if ((memberDutyArray[i][0] == memberCode) && (memberDutyArray[i][1] == dutyCode)) {
return i;
}
}
Logger.log(['No member duty code found: ',memberCode,dutyCode]);
return -1;
}