Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Pixel Humain
survey
Commits
69fb7303
Commit
69fb7303
authored
Jun 17, 2020
by
Anatole Rakotoson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coform community
parent
64c4cb37
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
417 deletions
+0
-417
controllers/answer/mail/SendAction.php
controllers/answer/mail/SendAction.php
+0
-28
models/Answer.php
models/Answer.php
+0
-389
No files found.
controllers/answer/mail/SendAction.php
deleted
100644 → 0
View file @
64c4cb37
<?php
class
SendAction
extends
CAction
{
public
function
run
(
$msg
=
""
,
$to
=
""
)
{
$controller
=
$this
->
getController
();
$msg
=
null
;
$infos
=
array
();
if
(
isset
(
$_POST
[
"tpl"
]))
$tpl
=
$_POST
[
"tpl"
];
if
(
isset
(
$_POST
[
"step"
]))
$step
=
$_POST
[
"step"
];
// ALL infos
if
(
isset
(
$_POST
[
"tplObject"
]))
$infos
[
"tplObject"
]
=
$_POST
[
"tplObject"
];
if
(
isset
(
$_POST
[
"html"
]))
$infos
[
"html"
]
=
$_POST
[
"html"
];
if
(
isset
(
$_POST
[
"msg"
]))
$infos
[
"msg"
]
=
$_POST
[
"msg"
];
if
(
isset
(
$_POST
[
"tplMail"
]))
$infos
[
"emails"
]
=
$_POST
[
"tplMail"
];
if
(
isset
(
$_POST
[
"listContact"
]))
$infos
[
"community"
]
=
$_POST
[
"listContact"
]
S
$mailParams
=
Answer
::
mailProcessOne
(
$to
,
$msg
);
Rest
::
json
(
array
(
"result"
=>
true
,
"msg"
=>
"Ok : webhook handdled"
));
}
}
models/Answer.php
deleted
100644 → 0
View file @
64c4cb37
<?php
class
Answer
{
const
COLLECTION
=
"answers"
;
const
CONTROLLER
=
"answer"
;
const
ICON
=
"fa-calendar-check-o"
;
public
static
function
getById
(
$id
,
$fields
=
array
()){
return
PHDB
::
findOne
(
self
::
COLLECTION
,
array
(
"_id"
=>
new
MongoId
((
string
)
$id
)
),
$fields
);
}
public
static
function
generateAnswer
(
$form
,
$draft
=
false
){
$costum
=
[];
//Rest::json($costum); exit;
$ans
=
[
"user"
=>
Yii
::
app
()
->
session
[
"userId"
],
"links"
=>
[
"answered"
=>
[
Yii
::
app
()
->
session
[
"userId"
]
]
,
//proposed,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated
//each actor is connectable to his activitystream
],
"created"
=>
time
()
];
if
(
$draft
===
true
)
$ans
[
"draft"
]
=
true
;
$formList
=
null
;
if
(
!
empty
(
$form
)
){
$ans
[
"form"
]
=
(
String
)
$form
[
"_id"
];
if
(
!
empty
(
$form
[
"subForms"
])){
$formList
=
$form
[
"subForms"
];
$ans
[
"formId"
]
=
implode
(
"|"
,
$formList
);
$ans
[
"formList"
]
=
count
(
$formList
);
}
//$ans["step"] = $formList[0];
}
//Rest::json($costum); exit;
if
(
!
empty
(
$costum
)
&&
!
empty
(
$costum
[
"slug"
])
)
{
$ans
[
"source"
]
=
Costum
::
getSource
(
$costum
[
"slug"
]);
}
//Rest::json($ans); exit;
if
(
Costum
::
isSameFunction
(
"generateAnswerBeforeSave"
)){
$paramBeforeSave
=
Costum
::
sameFunction
(
"generateAnswerBeforeSave"
,
array
(
"answer"
=>
$ans
,
"formList"
=>
$formList
)
);
$ans
=
$paramBeforeSave
[
"answer"
];
}
PHDB
::
insert
(
Answer
::
COLLECTION
,
$ans
);
$answer
=
PHDB
::
findOne
(
Answer
::
COLLECTION
,
[
"_id"
=>
new
MongoId
(
$ans
[
"_id"
])
]
)
;
return
$answer
;
}
public
static
function
canAdmin
(
$ans
,
$form
=
null
){
if
(
Form
::
canAdmin
((
string
)
$form
[
"_id"
],
$form
))
return
true
;
else
if
(
Costum
::
isSameFunction
(
"canAdminAnswer"
,
array
(
"answer"
=>
$ans
)))
return
Costum
::
sameFunction
(
"canAdminAnswer"
,
array
(
"answer"
=>
$ans
));
return
false
;
}
public
static
function
canEdit
(
$ans
,
$form
=
null
,
$userId
=
null
,
$parent
=
null
){
if
(
ctype_xdigit
(
$ans
)){
$ans
=
self
::
getById
(
$ans
);
$form
=
Form
::
getByIdMongo
(
$ans
[
"form"
]);
$parent
=
Slug
::
getElementBySlug
(
$form
[
"id"
]);
$userId
=
Yii
::
app
()
->
session
[
"userId"
];
}
if
(
$ans
[
"user"
]
==
$userId
)
return
true
;
else
if
(
Form
::
canAdmin
((
string
)
$form
[
"_id"
],
$form
))
return
true
;
else
if
(
Costum
::
isSameFunction
(
"canEditAnswer"
,
array
(
"answer"
=>
$ans
)))
return
Costum
::
sameFunction
(
"canEditAnswer"
,
array
(
"answer"
=>
$ans
));
return
false
;
}
public
static
function
canAccess
(
$answer
,
$form
=
null
,
$userId
=
null
,
$parentForm
=
null
){
if
(
ctype_xdigit
(
$answer
)){
$answer
=
self
::
getById
(
$answer
);
$form
=
Form
::
getByIdMongo
(
$answer
[
"form"
]);
$parent
=
Slug
::
getElementBySlug
(
$form
[
"id"
]);
}
if
(
self
::
canEdit
(
$answer
,
$form
,
$userId
,
$parentForm
))
return
true
;
else
if
(
Costum
::
isSameFunction
(
"canAccessAnswer"
,
array
(
"answer"
=>
$answer
)))
return
Costum
::
sameFunction
(
"canAccessAnswer"
,
array
(
"answer"
=>
$answer
));
return
false
;
}
public
static
function
getListBy
(
$form
=
null
,
$costum
=
null
,
$userId
=
null
,
$cond
=
null
){
$where
=
array
();
$lists
=
array
();
if
(
!
empty
(
$form
))
$where
[
"form"
]
=
$form
;
if
(
!
empty
(
$costum
))
$where
[
"source.keys"
]
=
array
(
'$in'
=>
array
(
$costum
)
);
if
(
!
empty
(
$userId
))
$where
[
"user"
]
=
$userId
;
if
(
!
empty
(
$cond
)){
$where
=
array
(
'$and'
=>
array
(
$where
,
$cond
));
}
if
(
!
empty
(
$where
))
$lists
=
PHDB
::
find
(
Answer
::
COLLECTION
,
$where
);
return
$lists
;
}
public
static
function
globalAutocomplete
(
$form
,
$searchParams
){
$searchParams
[
"indexMin"
]
=
(
isset
(
$searchParams
[
"indexMin"
]))
?
$searchParams
[
"indexMin"
]
:
0
;
$searchParams
[
"indexStep"
]
=
(
isset
(
$searchParams
[
"indexStep"
]))
?
$searchParams
[
"indexStep"
]
:
100
;
$mappingData
=
(
isset
(
$form
[
"mapping"
]))
?
$form
[
"mapping"
]
:
array
(
"name"
=>
"name"
,
"address"
=>
"address"
);
$query
=
array
(
"form"
=>
(
string
)
$form
[
"_id"
]);
if
(
!
empty
(
$searchParams
[
"userId"
])){
$query
=
array
(
'$and'
=>
array
(
$query
,
array
(
"user"
=>
$searchParams
[
"userId"
]
)
)
)
;
}
if
(
!
empty
(
$searchParams
[
"name"
])){
$searchRegExp
=
Search
::
accentToRegex
(
trim
(
urldecode
(
$searchParams
[
'name'
])));
$query
=
array
(
'$and'
=>
array
(
$query
,
array
(
$mappingData
[
"name"
]
=>
new
MongoRegex
(
"/.*
{
$searchRegExp
}
.*/i"
))
)
)
;
}
if
(
!
empty
(
$searchParams
[
"filters"
][
"address"
])){
$searchRegExp
=
Search
::
accentToRegex
(
trim
(
urldecode
(
$searchParams
[
"filters"
][
'address'
])));
$query
=
array
(
'$and'
=>
array
(
$query
,
array
(
'$or'
=>
array
(
array
(
$mappingData
[
"address"
]
.
".postalCode"
=>
new
MongoRegex
(
"/.*
{
$searchRegExp
}
.*/i"
)),
array
(
$mappingData
[
"address"
]
.
".cityName"
=>
new
MongoRegex
(
"/.*
{
$searchRegExp
}
.*/i"
))
))
)
)
;
}
if
(
!
empty
(
$searchParams
[
'filters'
])){
$query
=
Search
::
searchFilters
(
$searchParams
[
'filters'
],
$query
);
}
$res
=
array
();
//var_dump($query);exit;
$res
[
"results"
]
=
PHDB
::
findAndLimitAndIndex
(
self
::
COLLECTION
,
$query
,
$searchParams
[
"indexStep"
],
$searchParams
[
"indexMin"
]);
if
(
isset
(
$searchParams
[
"count"
]))
$res
[
"count"
][
self
::
COLLECTION
]
=
PHDB
::
count
(
self
::
COLLECTION
,
$query
);
return
$res
;
}
public
static
function
getMappingValues
(
$mapping
,
$ans
){
foreach
(
$mapping
as
$k
=>
$path
){
$mapping
[
$k
]
=
self
::
getValueByPath
(
$path
,
$ans
);
}
return
$mapping
;
}
public
static
function
getValueByPath
(
$indexes
,
$arrayToAccess
){
if
(
is_string
(
$indexes
))
$indexes
=
explode
(
"."
,
$indexes
);
if
(
isset
(
$arrayToAccess
[
$indexes
[
0
]])){
if
(
count
(
$indexes
)
>
1
)
return
self
::
getValueByPath
(
array_slice
(
$indexes
,
1
),
$arrayToAccess
[
$indexes
[
0
]]);
else
return
$arrayToAccess
[
$indexes
[
0
]];
}
}
public
static
function
getDataAnswers
(
$answerList
,
$subForms
,
$form
){
$globalLinks
=
[];
$gUids
=
[];
if
(
!
empty
(
$answerList
)){
foreach
(
$answerList
as
$key
=>
$ans
)
{
if
(
isset
(
$form
[
"mapping"
])){
$answerList
[
$key
][
"mappingValues"
]
=
Answer
::
getMappingValues
(
$form
[
"mapping"
],
$ans
);
}
$answerList
[
$key
][
"countComment"
]
=
PHDB
::
count
(
Comment
::
COLLECTION
,
array
(
"contextId"
=>
$key
,
"contextType"
=>
Form
::
ANSWER_COLLECTION
));
$localLinks
=
[];
$uids
=
[];
$todo
=
0
;
$done
=
0
;
$tasksPerson
=
[];
if
(
!
isset
(
$ans
[
"answers"
]))
{
$percent
=
0
;
}
else
{
$totalInputs
=
0
;
$answeredInputs
=
0
;
foreach
(
$subForms
as
$fid
=>
$f
){
$totalInputs
+=
count
(
$f
[
"inputs"
]);
if
(
isset
(
$ans
[
"answers"
][
$fid
]
)
){
$answeredInputs
+=
count
(
$ans
[
"answers"
][
$fid
]
);
}
//todo lists are on depense for the moment
//todo genereaclly not with a fixed input ID
if
(
isset
(
$ans
[
"answers"
][
$fid
][
"depense"
]
)
){
foreach
(
$ans
[
"answers"
][
$fid
][
"depense"
]
as
$ix
=>
$dep
)
{
if
(
isset
(
$dep
[
"todo"
]
)
){
foreach
(
$dep
[
"todo"
]
as
$ixx
=>
$t
)
{
if
(
!
isset
(
$t
[
"done"
])
||
$t
[
"done"
]
==
"0"
){
$todo
++
;
$whos
=
(
is_array
(
$t
[
"who"
]))
?
$t
[
"who"
]
:
explode
(
","
,
$t
[
"who"
]);
foreach
(
$whos
as
$whoix
=>
$who
)
{
if
(
!
isset
(
$tasksPerson
[
$who
]
)
)
$tasksPerson
[
$who
]
=
[];
$tasksPerson
[
$who
][]
=
$t
[
"what"
];
}
}
else
$done
++
;
}
}
}
}
}
if
(
isset
(
$ans
[
"links"
])){
foreach
(
$ans
[
"links"
]
as
$type
=>
$ls
){
if
(
!
isset
(
$localLinks
[
$type
]))
$localLinks
[
$type
]
=
[];
if
(
!
isset
(
$globalLinks
[
$type
]))
$globalLinks
[
$type
]
=
[];
foreach
(
$ls
as
$uid
=>
$time
)
{
if
(
is_string
(
$uid
)
&&
strlen
(
$uid
)
==
24
&&
ctype_xdigit
(
$uid
)){
if
(
!
in_array
(
$uid
,
$localLinks
[
$type
]
))
$localLinks
[
$type
][]
=
$uid
;
if
(
!
in_array
(
$uid
,
$uids
))
$uids
[]
=
new
MongoId
(
$uid
);
if
(
!
in_array
(
$uid
,
$globalLinks
[
$type
]
))
$globalLinks
[
$type
][]
=
$uid
;
if
(
!
in_array
(
$uid
,
$gUids
))
$gUids
[]
=
new
MongoId
(
$uid
);
}
}
}
}
$percent
=
floor
(
$answeredInputs
*
100
/
$totalInputs
);
}
$answerList
[
$key
][
"percent"
]
=
$percent
;
$answerList
[
$key
][
"uids"
]
=
$uids
;
$answerList
[
$key
][
"todo"
]
=
$todo
;
$answerList
[
$key
][
"done"
]
=
$done
;
$answerList
[
$key
][
"tasksPerson"
]
=
$tasksPerson
;
$answerList
[
$key
][
"canEdit"
]
=
self
::
canEdit
(
$ans
,
$form
,
Yii
::
app
()
->
session
[
"userId"
])
;
}
}
return
$answerList
;
}
public
static
function
csv
(
$elements
,
$idElt
,
$valElt
,
$forms
){
$elements
[
$idElt
][
"id"
]
=
$idElt
;
$elements
[
$idElt
][
"user"
]
=
$valElt
[
"user"
];
$elements
[
$idElt
][
"created"
]
=
date
(
"d/m/Y"
,
$valElt
[
"created"
]);
if
(
!
empty
(
$valElt
[
"answers"
])){
foreach
(
$forms
as
$keyF
=>
$valF
)
{
if
(
!
empty
(
$valF
[
"id"
])
&&
!
empty
(
$valElt
[
"answers"
][
$valF
[
"id"
]])){
foreach
(
$valElt
[
"answers"
][
$valF
[
"id"
]]
as
$keyAns
=>
$valAns
)
{
if
(
!
empty
(
$valF
[
"inputs"
])
&&
!
empty
(
$valF
[
"inputs"
][
$keyAns
])
&&
!
empty
(
$valF
[
"inputs"
][
$keyAns
][
"label"
])){
$elements
[
$idElt
][
$valF
[
"inputs"
][
$keyAns
][
"label"
]]
=
$valAns
;
}
}
}
}
}
return
$elements
;
}
public
static
$mailConfig
=
array
(
"validation"
=>
[
"tpl"
=>
"answer.validation"
,
"subject"
=>
"La candidature
{
what
}
a été validée"
],
"rejected"
=>
[
"tpl"
=>
"answer.rejected"
,
"subject"
=>
"La candidature
{
what
}
a été rejetée"
],
"default"
=>
[
"tpl"
=>
"answer.default"
,
"subject"
=>
""
]
);
public
static
function
getCommunityToNotify
(
$answer
,
$entry
=
null
){
$arrayMail
=
array
();
if
(
!
empty
(
$answer
[
"links"
])){
foreach
(
$answer
[
"links"
]
as
$k
=>
$v
){
if
(
$k
==
"answered"
&&
(
empty
(
$entry
)
||
in_array
(
"answered"
,
$entry
))){
foreach
(
$v
as
$id
){
$people
=
Element
::
getElementById
(
$id
,
Person
::
COLLECTION
,
null
,
array
(
"email"
,
"name"
,
"slug"
)
);
array_push
(
$arrayMail
,
$people
);
}
}
}
if
(
Costum
::
isSameFunction
(
"getAnswerCommunityToNotify"
)){
// CARREFUL $costumUserArray need to be return as result : return $params["costumUserArray"]
array_merge
(
$arrayMail
,
Costum
::
sameFunction
(
"getAnswerCommunityToNotify"
,
array
(
"answer"
=>
$answer
)));
}
}
return
$arrayMail
;
}
public
static
function
mailProcess
(
$id
,
$tpl
,
$step
,
$infos
){
$costum
=
[];
$answer
=
self
::
getById
(
$id
);
$mailsCommunity
=
array
();
if
(
isset
(
$infos
[
"emails"
])
&&
!
empty
(
$infos
[
"emails"
])){
foreach
(
$infos
[
"emails"
]
as
$v
){
array_push
(
$mailsCommunity
,
Element
::
getElementByWhere
(
Person
::
COLLECTION
,
array
(
"email"
=>
$v
),
array
(
"email"
,
"name"
,
"slug"
)
)
);
}
}
if
(
isset
(
$infos
[
"community"
])
&&
!
empty
(
$infos
[
"community"
])){
$mailsCommunity
=
array
();
foreach
(
$infos
[
"community"
]
as
$k
=>
$v
){
if
(
$v
[
"type"
]
==
Person
::
COLLECTION
){
array_push
(
$mailsCommunity
,
Element
::
getElementById
(
$k
,
Person
::
COLLECTION
,
null
,
array
(
"email"
,
"name"
,
"slug"
)
));
}
else
{
$community
=
Element
::
getCommunityByTypeAndId
(
Organization
::
COLLECTION
,
$k
,
Person
::
COLLECTION
,
"isAdmin"
);
foreach
(
$community
as
$e
=>
$val
){
array_push
(
$mailsCommunity
,
Element
::
getElementById
(
$e
,
Person
::
COLLECTION
,
null
,
array
(
"email"
,
"name"
,
"slug"
)
));
}
}
}
}
if
(
empty
(
$mailsCommunity
))
$mailsCommunity
=
self
::
getCommunityToNotify
(
$answer
);
$answer
[
"mappingValues"
]
=
array
();
$form
=
Form
::
getByIdMongo
(
$answer
[
"form"
]);
if
(
isset
(
$form
[
"mapping"
]))
$answer
[
"mappingValues"
]
=
self
::
getMappingValues
(
$form
[
"mapping"
],
$answer
);
$nameAnsw
=
(
isset
(
$answer
[
"mappingValues"
][
"name"
]))
?
$answer
[
"mappingValues"
][
"name"
]
:
""
;
$objMail
=
"["
.
Mail
::
getAppName
()
.
"] "
.
Yii
::
t
(
"mail"
,
self
::
$mailConfig
[
$tpl
][
"subject"
],
array
(
"
{
what
}
"
=>
$nameAnsw
));
if
(
isset
(
$infos
[
"tplObject"
]))
$objMail
=
"["
.
Mail
::
getAppName
()
.
"] "
.
$infos
[
"tplObject"
];
foreach
(
$mailsCommunity
as
$c
){
$params
=
array
(
"type"
=>
Cron
::
TYPE_MAIL
,
"tpl"
=>
self
::
$mailConfig
[
$tpl
][
"tpl"
],
"subject"
=>
$objMail
,
"from"
=>
Yii
::
app
()
->
params
[
'adminEmail'
],
"to"
=>
$c
[
"email"
],
"tplParams"
=>
array
(
"user"
=>
$c
,
"title"
=>
Mail
::
getAppName
()
,
"answer"
=>
$answer
,
"form"
=>
$form
,
"msg"
=>@
$infos
));
if
(
isset
(
$infos
[
"msg"
]))
$params
[
"tplParams"
][
"msg"
]
=
$infos
[
"msg"
];
if
(
isset
(
$infos
[
"html"
]))
$params
[
"tplParams"
][
"html"
]
=
$infos
[
"html"
];
$params
=
Mail
::
getCustomMail
(
$params
);
Mail
::
schedule
(
$params
);
}
if
(
Costum
::
isSameFunction
(
"AnswerMailProcess"
)){
// CARREFUL $costumUserArray need to be return as result : return $params["costumUserArray"]
Costum
::
sameFunction
(
"AnswerMailProcess"
,
array
(
"tpl"
=>
$tpl
,
"step"
=>
$step
,
"infos"
=>
$infos
,
"form"
=>
$form
,
"answer"
=>
$answer
)
);
}
}
public
static
function
mailProcessOne
(
$to
,
$msg
){
$params
=
array
(
"type"
=>
Cron
::
TYPE_MAIL
,
"tpl"
=>
"basic"
,
"subject"
=>
"invitation"
,
"from"
=>
Yii
::
app
()
->
params
[
'adminEmail'
],
"to"
=>
$to
,
"tplParams"
=>
array
(
"user"
=>
"user"
,
"title"
=>
"title"
,
"answer"
=>
"answer"
,
"form"
=>
Yii
::
app
()
->
params
[
'adminEmail'
],
"msg"
=>
"helloword"
));
if
(
isset
(
$infos
[
"msg"
]))
$params
[
"tplParams"
][
"msg"
]
=
$infos
[
"msg"
];
if
(
isset
(
$infos
[
"html"
]))
$params
[
"tplParams"
][
"html"
]
=
$infos
[
"html"
];
$params
=
Mail
::
getCustomMail
(
$params
);
//Rest::json($params);exit();
Mail
::
schedule
(
$params
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment