Commit bd38ef15 authored by jaapjansma's avatar jaapjansma

Updated membership actions

parent 887bcb1b
......@@ -33,6 +33,9 @@ abstract class AbstractAction implements \JsonSerializable {
// Use this tag if the action works with multieple contacts.
const MULTIPLE_CONTACTS_ACTION_TAG = 'action-on-multiple-contacts';
// Use this tag if the action works without a contact.
const WITHOUT_CONTACT_ACTION_TAG = 'act-without-a-contact';
const SEND_MESSAGES_TO_CONTACTS = 'send-messages';
/**
......
......@@ -90,13 +90,14 @@ class CreateOrUpdateMembership extends AbstractAction {
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
// Get the contact and the event.
$membership_type = civicrm_api3('MembershipType', 'getvalue', array('name' => $this->configuration->getParameter('membership_type'), 'return' => 'id'));
$apiParams = array();
if ($parameters->doesParameterExists('membership_id')) {
$apiParams['id'] = $parameters->getParameter('membership_id');
}
$apiParams['contact_id'] = $parameters->getParameter('contact_id');
$apiParams['membership_type_id'] = $this->configuration->getParameter('membership_type');
$apiParams['membership_type_id'] = $membership_type;
foreach($this->getParameterSpecification() as $spec) {
if (stripos($spec->getName(), 'custom_')!==0) {
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Membership;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Action\Membership\Parameter\MembershipTypeSpecification;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_ActionProvider_ExtensionUtil as E;
class GetMembershipType extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get membership type data');
}
/**
* Returns the specification of the configuration options for the actual
* action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new MembershipTypeSpecification('membership_type', E::ts('Membership Type'), TRUE),
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag();
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
$bag = new SpecificationBag();
foreach(\CRM_Member_BAO_MembershipType::fields() as $field) {
$type = \CRM_Utils_Type::typeToString($field['type']);
switch($type) {
case 'Int':
$type = 'Integer';
break;
}
$spec = new Specification($field['name'], $type, $field['title']);
$bag->addSpecification($spec);
}
return $bag;
}
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
* @return void
* @throws \Exception
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$membershipType = new \CRM_Member_BAO_MembershipType();
$membershipType->name = $this->configuration->getParameter('membership_type');
if ($membershipType->find(true)) {
foreach(\CRM_Member_BAO_MembershipType::fields() as $field) {
$key = $field['name'];
$output->setParameter($key, $membershipType->$key);
}
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::WITHOUT_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ class MembershipTypeSpecification extends Specification {
$options = array();
$optionsApi = civicrm_api3('MembershipType', 'get', array('is_active' => 1, 'options' => array('limit' => 0)));
foreach($optionsApi['values'] as $optionValue) {
$options[$optionValue['id']] = $optionValue['name'];
$options[$optionValue['name']] = $optionValue['name'];
}
return $options;
}
......
......@@ -73,6 +73,7 @@ class Provider {
new \Civi\ActionProvider\Action\Phone\CreateUpdatePhone(),
new \Civi\ActionProvider\Action\Phone\GetPhone(),
new \Civi\ActionProvider\Action\Membership\CreateOrUpdateMembership(),
new \Civi\ActionProvider\Action\Membership\GetMembershipType(),
);
$conditions = array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment