Commit cea8cbd6 authored by bgm's avatar bgm Committed by info@symbiotic.coop
Browse files

Proof of concept, see the README.md

parent 696cd1de
<?php
class CRM_Activityprofile_APIWrappers_Profile {
/**
*
*/
public function fromApiInput($apiRequest) {
$params = $apiRequest['params'];
$profile_id = _civicrm_api3_profile_getProfileID($params['profile_id']);
$isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profile_id);
if (!$isContactActivityProfile || !empty($params['activity_id'])) {
return $apiRequest;
}
// This is a profile with activity fields, but without an activity_id
// Let's create a new contact and a new activity.
// We only do the minimum and let profile.submit do the rest.
$contact = civicrm_api3('Contact', 'create', [
'contact_type' => 'Individual',
'display_name' => 'activityprofile-temp-contact',
]);
// Setting the contact_id is necessary so that we can pass through
// CRM_Profile_Form::validateContactActivityProfile()
// which is called by civicrm_api3_profile_submit().
$apiRequest['params']['contact_id'] = $contact['id'];
// We default to setting the subject to the profile title,
// if no subject field was included in the profile.
$title = $params['subject'] ?? '';
if (empty($title)) {
$title = civicrm_api3('UFGroup', 'getsingle', [
'id' => $profile_id,
])['title'];
}
$activity = civicrm_api3('Activity', 'create', [
'activity_type_id' => 1, // FIXME
'source_contact_id' => $contact['id'],
'target_contact_id' => $contact['id'],
'subject' => $title,
]);
$apiRequest['params']['activity_id'] = $activity['id'];
return $apiRequest;
}
/**
*
*/
public function toApiOutput($apiRequest, $result) {
if (empty($result['id'])) {
return $result;
}
// Civi::log()->debug('toApiOutput: ' . print_r($apiRequest, 1) . ' --- ' . print_r($result, 1));
return $result;
}
}
# activityprofile
# Activity Profile
![Screenshot](/images/screenshot.png)
Makes it possible to create new activities using standard CiviCRM Profiles.
This works nicely with the [remoteforms](https://github.com/progressivetech/net.ourpowerbase.remoteform/)
extension, so we can embed simple contact forms in other websites with minimal configuration.
(*FIXME: In one or two paragraphs, describe what the extension does and why one would download it. *)
Known issues:
The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Requirements
* PHP v5.4+
* CiviCRM (*FIXME: Version number*)
## Installation (Web UI)
* Profile submissions will always create a new contact. Your profile should include at least one of: first_name, last_name, email or display_name. The creation of a new contact is required to workaround checks in CiviCRM core to validate that a given contact can update an activity.
This extension has not yet been published for installation via the web UI.
Roadmap:
## Installation (CLI, Zip)
* Blocker: Profile Admin UI: add an option to associate a profile to an activity type. Currently the DB must be manually changed so that group_type allows the activity type.
* Wishlist: Profile Admin UI: option to automatically assign the activity to a specific contact (ex: for a contact form, assign to the person who handles the contact form).
* Wishlist: Auto-dedupe (according to the profile settings).
Sysadmins and developers may download the `.zip` file for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
The extension is licensed under [AGPL-3.0](LICENSE.txt).
```bash
cd <extension-dir>
cv dl activityprofile@https://github.com/FIXME/activityprofile/archive/master.zip
```
## Requirements
## Installation (CLI, Git)
* PHP v7.0+
* CiviCRM 5.10+
Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
## Installation
```bash
git clone https://github.com/FIXME/activityprofile.git
cv en activityprofile
```
Install as a regular CiviCRM extension.
## Usage
(* FIXME: Where would a new user navigate to get started? What changes would they see? *)
## Known Issues
(* FIXME *)
......@@ -87,19 +87,6 @@ function activityprofile_civicrm_managed(&$entities) {
_activityprofile_civix_civicrm_managed($entities);
}
/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function activityprofile_civicrm_caseTypes(&$caseTypes) {
_activityprofile_civix_civicrm_caseTypes($caseTypes);
}
/**
* Implements hook_civicrm_angularModules().
*
......@@ -124,40 +111,24 @@ function activityprofile_civicrm_alterSettingsFolders(&$metaDataFolders = NULL)
}
/**
* Implements hook_civicrm_entityTypes().
* Implements hook_civicrm_apiWrappers().
*
* Declare entity types provided by this module.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_apiWrappers/
*/
function activityprofile_civicrm_entityTypes(&$entityTypes) {
_activityprofile_civix_civicrm_entityTypes($entityTypes);
function activityprofile_civicrm_apiWrappers(&$wrappers, $apiRequest) {
// The APIWrapper is conditionally registered so that it runs only when appropriate
if ($apiRequest['entity'] == 'Profile' && $apiRequest['action'] == 'submit') {
$wrappers[] = new CRM_Activityprofile_APIWrappers_Profile();
}
}
// --- Functions below this ship commented out. Uncomment as required. ---
/**
* Implements hook_civicrm_preProcess().
* Implements hook_civicrm_buildForm().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*
function activityprofile_civicrm_preProcess($formName, &$form) {
} // */
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/
*/
function activityprofile_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Profile_Form_FIXME') {
/**
* Implements hook_civicrm_navigationMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*
function activityprofile_civicrm_navigationMenu(&$menu) {
_activityprofile_civix_insert_navigation_menu($menu, 'Mailings', array(
'label' => E::ts('New subliminal message'),
'name' => 'mailing_subliminal_message',
'url' => 'civicrm/mailing/subliminal',
'permission' => 'access CiviMail',
'operator' => 'OR',
'separator' => 0,
));
_activityprofile_civix_navigationMenu($menu);
} // */
}
}
<?xml version="1.0"?>
<extension key="activityprofile" type="module">
<file>activityprofile</file>
<name>FIXME</name>
<description>FIXME</description>
<name>Activity Profile</name>
<description>Create activities using CiviCRM Profiles</description>
<license>AGPL-3.0</license>
<maintainer>
<author>info@symbiotic.coop</author>
<email>Aegir</email>
<author>mathieu@symbiotic.coop</author>
<email>Mathieu Lutfy</email>
</maintainer>
<urls>
<url desc="Main Extension Page">http://FIXME</url>
......@@ -18,9 +18,9 @@
<version>1.0</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.0</ver>
<ver>5.10</ver>
</compatibility>
<comments>This is a new, undeveloped module</comments>
<comments></comments>
<civix>
<namespace>CRM/Activityprofile</namespace>
</civix>
......
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