Commit 9c0acbd9 authored by jaapjansma's avatar jaapjansma

initial commit

parents
<?php
use CRM_Sharepoint_ExtensionUtil as E;
/**
* Form controller class
*
* @see https://wiki.civicrm.org/confluence/display/CRMDOC/QuickForm+Reference
*/
class CRM_Sharepoint_Form_Settings extends CRM_Admin_Form {
public function buildQuickForm() {
// add form elements
$this->add(
'text', // field type
'url', // field name
E::ts('Url'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'site', // field name
E::ts('Site'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'username', // field name
E::ts('Username'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'password', // field type
'password', // field name
E::ts('Passowrd'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'library', // field name
E::ts('Library name'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'contact_id_field_name', // field name
E::ts('Contact ID field name'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'case_id_field_name', // field name
E::ts('Case ID field name'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'civicrm_link_field_name', // field name
E::ts('Link To CiviCRM field name'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'title_field', // field name
E::ts('Title field name'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'contact_documentset_contenttype_id', // field name
E::ts('Content Type ID for the contact documentset'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
$this->add(
'text', // field type
'case_documentset_contenttype_id', // field name
E::ts('Content Type ID for the case documentset'), // field label
array(
'class' => 'huge40',
),
TRUE // is required,
);
parent::buildQuickForm();
}
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
$settings = _sharepoint_settings();
return array_merge($defaults, $settings);
}
public function postProcess() {
$values = $this->exportValues();
$settings = _sharepoint_settings();
foreach($settings as $setting_name => $old_value) {
if (isset($values[$setting_name])) {
CRM_Core_BAO_Setting::setItem($values[$setting_name], 'sharepoint', $setting_name);
}
}
CRM_Core_Session::setStatus(E::ts('Saved sharepoint settings'), '', 'success');
parent::postProcess();
}
}
This diff is collapsed.
# Sharepoint
![Screenshot](/images/screenshot.gif)
This extension does the following:
- Creates a document set in Sharepoint for each contact in CiviCRM
- CReate a document set in Sharepoint for each case in CiviCRM
- Provides a link to the sharepoint document set on the contact summary screen
- Provides a link to the sharepoint document set on the case summary screen
The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Requirements
* PHP v5.6+
* CiviCRM 5.3+
* Administrator access to a sharepoint environment
* Enabled document sets in sharepoint
## Configuration of Sharepoint
Before you can use this extension you have to configure sharepoint.
## Custom fields
Create the following fields:
* contact_id a numeric field
* case_id a numeric field
* link_to_civicrm a Hyperlink field
## Document sets
Make sure you have enabled document sets in sharepoint. If you dont know how to do this google it and feel free to update this manual.
After you have enabled the document sets you have to create the content types for the document set for _contacts_ and _casess_.
You can do that by navigating to site settings --> Site Content Types and add a new one, select _Document Set Content Type_ at the parent type.
After you have created the content type go to edit the content type and add the created fields to the content type. At the settings of the content type you can
configure which fields should be shown at the start page of the content type. Possibly you want here the field _link_to_civicrm_
![sharepoint 1](/images/sharepoint_content_type1.png)
![sharepoint 2](/images/sharepoint_content_type2.png)
### Note the content type id
Whilst editing a content type, you can see in the url the ID of the content type, which looks like _&ctype=0x0120D5...._ Note this ID because you need this in your CiviCRM settings later on.
# CiviCRM configuration
Install and enable this extension. You can then go to http://yoursite.com/civicrm/admin/sharepoint?reset=1 and fill in all the settings.
![Settings](/images/settings.png)
## Installation (Web UI)
This extension has not yet been published for installation via the web UI.
## Installation (CLI, Zip)
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).
```bash
cd <extension-dir>
cv dl sharepoint@https://lab.civicrm.org/extensions/sharepoint/-/archive/master/form-procesor-master.zip
```
## Installation (CLI, Git)
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).
```bash
git clone https://lab.civicrm.org/extensions/form-procesor.git
cv en sharepoint
```
## Usage
(* FIXME: Where would a new user navigate to get started? What changes would they see? *)
## Known Issues
(* FIXME *)
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "03e558b8a7fe9340c94a19032b87e4ae",
"packages": [
{
"name": "vgrem/php-spo",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/vgrem/phpSPO.git",
"reference": "1f4a9c5ca2a964fa1c415e4d16486667ed39c637"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vgrem/phpSPO/zipball/1f4a9c5ca2a964fa1c415e4d16486667ed39c637",
"reference": "1f4a9c5ca2a964fa1c415e4d16486667ed39c637",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Office365\\PHP\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0+"
],
"authors": [
{
"name": "Vadim Gremyachev",
"email": "vvgrem@gmail.com"
}
],
"description": "The library provides a Office 365 REST client for PHP. It allows to performs CRUD operations against Office 365 resources via an REST/OData based API",
"keywords": [
"Office365",
"api",
"curl",
"rest",
"sharepoint"
],
"time": "2018-06-29T21:49:34+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"vgrem/php-spo": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
<?xml version="1.0"?>
<extension key="sharepoint" type="module">
<file>sharepoint</file>
<name>Sharepoint</name>
<description>Creates a link to sharepoint document set on the contact summary screen and a link to a sharepoint document set on the case summary screen. Also ensures that the document set ecists for the contact or the case.</description>
<license>AGPL-3.0</license>
<maintainer>
<author>Jaap Jansma</author>
<email>jaap.jansma@civicoop.org</email>
</maintainer>
<urls>
<url desc="Main Extension Page">https://lab.civicrm.org/extensions/sharepoint</url>
<url desc="Documentation">https://lab.civicrm.org/extensions/sharepoint/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2018-07-12</releaseDate>
<version>1.0</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.3</ver>
</compatibility>
<comments>Funded by Bindkracht 10</comments>
<civix>
<namespace>CRM/Sharepoint</namespace>
</civix>
</extension>
<?php
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
class CRM_Sharepoint_ExtensionUtil {
const SHORT_NAME = "sharepoint";
const LONG_NAME = "sharepoint";
const CLASS_PREFIX = "CRM_Sharepoint";
/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
}
return ts($text, $params);
}
/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function url($file = NULL) {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}
/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function path($file = NULL) {
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}
/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public static function findClass($suffix) {
return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}
}
use CRM_Sharepoint_ExtensionUtil as E;
/**
* (Delegated) Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function _sharepoint_civix_civicrm_config(&$config = NULL) {
static $configured = FALSE;
if ($configured) {
return;
}
$configured = TRUE;
$template =& CRM_Core_Smarty::singleton();
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = array($extDir, $template->template_dir);
}
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
/**
* (Delegated) Implements hook_civicrm_xmlMenu().
*
* @param $files array(string)
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function _sharepoint_civix_civicrm_xmlMenu(&$files) {
foreach (_sharepoint_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
$files[] = $file;
}
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function _sharepoint_civix_civicrm_install() {
_sharepoint_civix_civicrm_config();
if ($upgrader = _sharepoint_civix_upgrader()) {
$upgrader->onInstall();
}
}
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/
function _sharepoint_civix_civicrm_postInstall() {
_sharepoint_civix_civicrm_config();
if ($upgrader = _sharepoint_civix_upgrader()) {
if (is_callable(array($upgrader, 'onPostInstall'))) {
$upgrader->onPostInstall();
}
}
}
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function _sharepoint_civix_civicrm_uninstall() {
_sharepoint_civix_civicrm_config();
if ($upgrader = _sharepoint_civix_upgrader()) {
$upgrader->onUninstall();
}
}
/**
* (Delegated) Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function _sharepoint_civix_civicrm_enable() {
_sharepoint_civix_civicrm_config();
if ($upgrader = _sharepoint_civix_upgrader()) {
if (is_callable(array($upgrader, 'onEnable'))) {
$upgrader->onEnable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
* @return mixed
*/
function _sharepoint_civix_civicrm_disable() {
_sharepoint_civix_civicrm_config();
if ($upgrader = _sharepoint_civix_upgrader()) {
if (is_callable(array($upgrader, 'onDisable'))) {
$upgrader->onDisable();
}
}
}
/**
* (Delegated) Implements hook_civicrm_upgrade().
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function _sharepoint_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _sharepoint_civix_upgrader()) {
return $upgrader->onUpgrade($op, $queue);
}
}
/**
* @return CRM_Sharepoint_Upgrader
*/
function _sharepoint_civix_upgrader() {
if (!file_exists(__DIR__ . '/CRM/Sharepoint/Upgrader.php')) {
return NULL;
}
else {
return CRM_Sharepoint_Upgrader_Base::instance();
}
}
/**
* Search directory tree for files which match a glob pattern
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
* Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
*
* @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt"
* @return array(string)
*/
function _sharepoint_civix_find_files($dir, $pattern) {
if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
return CRM_Utils_File::findFiles($dir, $pattern);
}
$todos = array($dir);
$result = array();
while (!empty($todos)) {
$subdir = array_shift($todos);
foreach (_sharepoint_civix_glob("$subdir/$pattern") as $match) {
if (!is_dir($match)) {
$result[] = $match;
}
}
if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry{0} == '.') {
}
elseif (is_dir($path)) {
$todos[] = $path;
}
}
closedir($dh);
}
}
return $result;
}
/**
* (Delegated) Implements hook_civicrm_managed().
*
* Find any *.mgd.php files, merge their content, and return.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
*/
function _sharepoint_civix_civicrm_managed(&$entities) {
$mgdFiles = _sharepoint_civix_find_files(__DIR__, '*.mgd.php');
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = E::LONG_NAME;
}
$entities[] = $e;
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
}
}
}
/**
* (Delegated) Implements hook_civicrm_caseTypes().
*
* Find any and return any files matching "xml/case/*.xml"
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function _sharepoint_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {