Commit 58f3fe30 authored by jaapjansma's avatar jaapjansma
Browse files

update for my page

parent d0ea1f90
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\BarnekreftMyPage\ActionProvider;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_Barnekreftmypage_ExtensionUtil as E;
class MyPageGetHousehold extends AbstractAction {
protected $relationshipTypes = array();
protected $relationshipTypeIds = array();
public function __construct() {
parent::__construct();
$relationshipTypesApi = civicrm_api3('RelationshipType', 'get', array('is_active' => 1, 'options' => array('limit' => 0)));
$this->relationshipTypes = array();
$this->relationshipTypeIds = array();
foreach($relationshipTypesApi['values'] as $relType) {
$this->relationshipTypes[$relType['name_a_b']] = $relType['label_a_b'];
$this->relationshipTypeIds[$relType['name_a_b']] = $relType['id'];
}
}
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
*
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$email = $parameters->getParameter('email');
$householdRelationshipTypes = [];
foreach ($this->configuration->getParameter('household_relationship_type_id') as $rel_type) {
$householdRelationshipTypes[] = $this->relationshipTypeIds[$rel_type];
}
$sql = "
SELECT r.contact_id_b as contact_id
FROM civicrm_email e
INNER JOIN `civicrm_relationship` `r` ON `r`.`contact_id_a` = `e`.`contact_id`
AND `r`.`relationship_type_id` IN (".implode(",", $householdRelationshipTypes).")
AND `r`.`is_active` = '1'
AND (`r`.`start_date` <= NOW() OR `r`.`start_date` IS NULL)
AND (`r`.`end_date` <= NOW() OR `r`.`end_date` IS NULL)
WHERE e.email = %1 AND e.is_primary =1
ORDER BY r.contact_id_b ASC
LIMIT 0,1";
$sqlParams[1] = [$email, 'String'];
$houseHoldId = \CRM_Core_DAO::singleValueQuery($sql, $sqlParams);
$output->setParameter('household_id', $houseHoldId);
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('household_relationship_type_id', 'String', E::ts('Household Relationship Types'), true, null, null, $this->relationshipTypes, true),
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('email', 'String', E::ts('E-mail'), true),
));
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag([new Specification('household_id', 'Integer', E::ts('Household ID'), false)]);
}
}
......@@ -82,10 +82,10 @@ class MyPageValidateEmailAndMembershipId extends AbstractAction {
UNION SELECT COUNT(*) as `count`
FROM civicrm_email e
INNER JOIN `civicrm_relationship` `r` ON `r`.`contact_id_a` = `e`.`contact_id`
AND `r`.`relationship_type_id` IN (".implode(",", $householdRelationshipTypes)."
AND `r`.`relationship_type_id` IN (".implode(",", $householdRelationshipTypes).")
AND `r`.`is_active` = '1'
AND (`r`.`start_date` <= NOW() OR `r`.`start_date` IS NULL)
AND (`r`.`end_date` <= NOW() OR `r`.`end_date` IS NULL))
AND (`r`.`end_date` <= NOW() OR `r`.`end_date` IS NULL)
INNER JOIN civicrm_membership m ON m.contact_id = r.contact_id_b
WHERE (m.id = %1) AND e.email = %2 AND e.is_primary =1
";
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\BarnekreftMyPage\ActionProvider;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Exception\InvalidParameterException;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_Barnekreftmypage_ExtensionUtil as E;
class MyPageValidateHouseholdMember extends AbstractAction {
protected $relationshipTypes = array();
protected $relationshipTypeIds = array();
public function __construct() {
parent::__construct();
$relationshipTypesApi = civicrm_api3('RelationshipType', 'get', array('is_active' => 1, 'options' => array('limit' => 0)));
$this->relationshipTypes = array();
$this->relationshipTypeIds = array();
foreach($relationshipTypesApi['values'] as $relType) {
$this->relationshipTypes[$relType['name_a_b']] = $relType['label_a_b'];
$this->relationshipTypeIds[$relType['name_a_b']] = $relType['id'];
}
}
/**
* Returns a help text for this action.
*
* The help text is shown to the administrator who is configuring the action.
* Override this function in a child class if your action has a help text.
*
* @return string|false
*/
public function getHelpText() {
return E::ts('Checks whether the contact with this e-mail address is part of the same household as the specified contact.');
}
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
*
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$contact_id = $parameters->getParameter('contact_id');
$output->setParameter('contact_id', $contact_id);
}
/**
* @return bool
* @throws \Civi\ActionProvider\Exception\InvalidParameterException
*/
protected function validateParameters(ParameterBagInterface $parameters) {
$email = $parameters->getParameter('email');
$contact_id = $parameters->getParameter('contact_id');
$householdRelationshipTypes = [];
foreach ($this->configuration->getParameter('household_relationship_type_id') as $rel_type) {
$householdRelationshipTypes[] = $this->relationshipTypeIds[$rel_type];
}
$householdMemberRelationshipTypes = [];
foreach ($this->configuration->getParameter('household_member_relationship_type_id') as $rel_type) {
$householdMemberRelationshipTypes[] = $this->relationshipTypeIds[$rel_type];
}
$sql = "
SELECT count(*)
FROM civicrm_email e
INNER JOIN `civicrm_relationship` `r` ON `r`.`contact_id_a` = `e`.`contact_id`
AND `r`.`relationship_type_id` IN (".implode(",", $householdRelationshipTypes).")
AND `r`.`is_active` = '1'
AND (`r`.`start_date` <= NOW() OR `r`.`start_date` IS NULL)
AND (`r`.`end_date` <= NOW() OR `r`.`end_date` IS NULL)
INNER JOIN `civicrm_relationship` `r2` ON `r2`.`contact_id_b` = `r`.`contact_id_b`
AND `r2`.`relationship_type_id` IN (".implode(",", $householdMemberRelationshipTypes).")
AND `r2`.`is_active` = '1'
AND (`r2`.`start_date` <= NOW() OR `r2`.`start_date` IS NULL)
AND (`r2`.`end_date` <= NOW() OR `r2`.`end_date` IS NULL)
WHERE e.email = %1 AND e.is_primary =1 and r2.contact_id_a = %2
ORDER BY r.contact_id_b ASC
";
$sqlParams[1] = [$email, 'String'];
$sqlParams[2] = [$contact_id, 'Integer'];
$count = \CRM_Core_DAO::singleValueQuery($sql, $sqlParams);
if (!$count) {
throw new InvalidParameterException('Invalid e-mail address or contact id');
}
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('household_relationship_type_id', 'String', E::ts('Household Relationship Types'), true, null, null, $this->relationshipTypes, true),
new Specification('household_member_relationship_type_id', 'String', E::ts('Household Member Relationship Types'), true, null, null, $this->relationshipTypes, true),
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('email', 'String', E::ts('E-mail'), true),
new Specification('contact_id', 'Integer', E::ts('Contact ID'), true),
));
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag([new Specification('contact_id', 'Integer', E::ts('Contact ID'), true)]);
}
}
......@@ -30,7 +30,9 @@ class CompilerPass implements CompilerPassInterface {
$actionTypeFactoryDefinition = $container->getDefinition('action_provider');
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_validate_email_contact_id', 'Civi\BarnekreftMyPage\ActionProvider\MyPageValidateEmailAndContactId', E::ts('Validate E-mail address and Contact ID (Barnekreft My Page)'), array()));
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_validate_email_membership_id', 'Civi\BarnekreftMyPage\ActionProvider\MyPageValidateEmailAndMembershipId', E::ts('Validate E-mail address and Membership ID (Barnekreft My Page)'), array()));
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_validate_householdmember', 'Civi\BarnekreftMyPage\ActionProvider\MyPageValidateHouseholdMember', E::ts('Validate Household Member (Barnekreft My Page)'), array()));
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_get_address', 'Civi\BarnekreftMyPage\ActionProvider\MyPageGetAddress', E::ts('Get Address (Household or Individual - Barnekreft My Page)'), array()));
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_get_household', 'Civi\BarnekreftMyPage\ActionProvider\MyPageGetHousehold', E::ts('Get Household by E-mail (Barnekreft My Page)'), array()));
$actionTypeFactoryDefinition->addMethodCall('addAction', array('bkfmypage_change_varebarn', 'Civi\BarnekreftMyPage\ActionProvider\MyPageChangeVareBarn', E::ts('Change Vare Barn (Barnekreft My Page')));
}
}
......
{
"name": "my_page_my_household_members",
"title": "My Page: My Household Members",
"type": "default",
"configuration": {
"default_sort": [
"desc_by_age"
]
},
"is_active": "1",
"description": "This data processor shows all people in a household.",
"storage_configuration": [],
"data_sources": [
{
"weight": "1",
"name": "e_mail",
"title": "E-mail",
"type": "email",
"configuration": {
"filter": {
"is_primary": {
"op": "=",
"value": "1"
}
}
},
"join_configuration": []
},
{
"weight": "2",
"name": "relationship",
"title": "My Household Relationship",
"type": "relationship",
"configuration": {
"filter": {
"relationship_type_id": {
"op": "IN",
"value": [
"Head of Household for",
"Household Member of"
]
},
"is_active": {
"op": "=",
"value": "1"
}
}
},
"join_type": "simple_join",
"join_configuration": {
"left_prefix": "relationship",
"left_field": "relationship_contact_id_a",
"right_prefix": "e_mail",
"right_field": "e_mail_contact_id"
}
},
{
"weight": "3",
"name": "household",
"title": "Household",
"type": "household",
"configuration": {
"filter": {
"is_deleted": {
"op": "=",
"value": "0"
}
}
},
"join_type": "simple_join",
"join_configuration": {
"left_prefix": "household",
"left_field": "household_id",
"right_prefix": "relationship",
"right_field": "relationship_contact_id_b"
}
},
{
"weight": "4",
"name": "relationship_2",
"title": "Householdmembers relationship",
"type": "relationship",
"configuration": {
"filter": {
"relationship_type_id": {
"op": "IN",
"value": [
"Head of Household for",
"Child_of_household",
"Household Member of"
]
},
"is_active": {
"op": "=",
"value": "1"
}
}
},
"join_type": "simple_join",
"join_configuration": {
"left_prefix": "relationship_2",
"left_field": "relationship_2_contact_id_b",
"right_prefix": "household",
"right_field": "household_id"
}
},
{
"weight": "5",
"name": "person",
"title": "Person",
"type": "individual",
"configuration": {
"filter": {
"is_deceased": {
"op": "=",
"value": "0"
},
"is_deleted": {
"op": "=",
"value": "0"
}
}
},
"join_type": "simple_join",
"join_configuration": {
"left_prefix": "person",
"left_field": "person_id",
"right_prefix": "relationship_2",
"right_field": "relationship_2_contact_id_a"
}
},
{
"weight": "6",
"name": "telefon",
"title": "Telefon",
"type": "phone",
"configuration": {
"filter": {
"is_primary": {
"op": "=",
"value": "1"
}
}
},
"join_type": "simple_non_required_join",
"join_configuration": {
"left_prefix": "telefon",
"left_field": "telefon_contact_id",
"right_prefix": "person",
"right_field": "person_id"
}
},
{
"weight": "8",
"name": "person_email",
"title": "Person Email",
"type": "email",
"configuration": {
"filter": {
"is_primary": {
"op": "=",
"value": "1"
}
}
},
"join_type": "simple_non_required_join",
"join_configuration": {
"left_prefix": "person_email",
"left_field": "person_email_contact_id",
"right_prefix": "person",
"right_field": "person_id"
}
}
],
"filters": [
{
"weight": "1",
"name": "email",
"title": "Email",
"type": "simple_sql_filter",
"is_required": "1",
"is_exposed": "1",
"configuration": {
"field": "e_mail_email",
"datasource": "e_mail"
},
"filter_value": []
},
{
"weight": "2",
"name": "contact_type",
"title": "Contact Type",
"type": "contact_type_filter",
"is_required": "0",
"is_exposed": "1",
"configuration": {
"field": "person_id",
"datasource": "person"
},
"filter_value": []
}
],
"fields": [
{
"weight": "1",
"name": "kontakt_id",
"title": "Kontakt-ID",
"type": "raw",
"configuration": {
"field": "person_id",
"datasource": "person",
"is_aggregate": ""
}
},
{
"weight": "2",
"name": "household_id",
"title": "Household ID",
"type": "raw",
"configuration": {
"field": "household_id",
"datasource": "household",
"is_aggregate": ""
}
},
{
"weight": "3",
"name": "navn",
"title": "Navn",
"type": "raw",
"configuration": {
"field": "person_display_name",
"datasource": "person",
"is_aggregate": ""
}
},
{
"weight": "4",
"name": "telefon",
"title": "Telefon",
"type": "raw",
"configuration": {
"field": "telefon_phone",
"datasource": "telefon",
"is_aggregate": ""
}
},
{
"weight": "5",
"name": "e_post",
"title": "E-post",
"type": "raw",
"configuration": {
"field": "person_email_email",
"datasource": "person_email",
"is_aggregate": ""
}
},
{
"weight": "6",
"name": "foedselsnummer",
"title": "F\u00f8dselsnummer",
"type": "raw",
"configuration": {
"field": "person_foedselnr_foedselnr",
"datasource": "person",
"is_aggregate": ""
}
},
{
"weight": "7",
"name": "birth_date",
"title": "Birth Date",
"type": "date",
"configuration": {
"field": "person_birth_date",
"datasource": "person",
"is_aggregate": "",
"function": "",
"format": "d.m.Y"
}
},
{
"weight": "8",
"name": "age",
"title": "Age",
"type": "age",
"configuration": {
"field": "person_birth_date",
"datasource": "person",
"is_aggregate": ""
}
},
{
"weight": "9",
"name": "birth_year",
"title": "Birth Year",
"type": "date",
"configuration": {
"field": "person_birth_date",
"datasource": "person",
"is_aggregate": "",
"function": "",
"format": "Y"
}
},
{
"weight": "10",
"name": "kjoenn",
"title": "Kj\u00f8nn",
"type": "option_label",
"configuration": {
"field": "person_gender_id",
"datasource": "person",
"is_aggregate": ""
}
},
{
"weight": "11",
"name": "contact_type",
"title": "Contact Type",
"type": "option_label",
"configuration": {
"field": "person_contact_sub_type",
"datasource": "person",
"is_aggregate": ""