Skip to content

Commit 9be4076

Browse files
author
Mark
committed
initial commit
0 parents  commit 9be4076

15 files changed

+1474
-0
lines changed

cm_crew_connect.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.page-node-add-crew-connect-application h1{
2+
Display: none;
3+
}
4+
5+
.page-node-delete.node-type-crew-connect-request h1{
6+
Display: none;
7+
}
8+
9+
.page-node-delete.node-type-crew-connect-request .tabs-primary {
10+
Display: none;
11+
}
12+
13+
.page-node-delete.node-type-crew-connect-application h1{
14+
Display: none;
15+
}
16+
17+
.page-node-delete.node-type-crew-connect-application .tabs-primary {
18+
Display: none;
19+
}
20+
21+

cm_crew_connect.info

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name = "CMA Crew Connect"
2+
description = "Provides helper files for managing crew connections. Relies on the Crew Request and Crew Application content types"
3+
4+
files[] = includes/computed_field.inc
5+
files[] = includes/civicrm.inc
6+
files[] = includes/form_alter.inc
7+
files[] = includes/form.inc
8+
files[] = includes/menu.inc
9+
files[] = includes/misc.inc
10+
files[] = includes/page.inc
11+
files[] = includes/phpfields.inc
12+
files[] = includes/postsave.inc
13+
files[] = includes/presave.inc
14+
files[] = includes/validate.inc
15+
files[] = includes/view_util.inc
16+
17+
18+
package = "Community Media Advanced"
19+
version = "7.x-1.x"
20+
core = "7.x"
21+
project = "cm_crew_connect"
22+
project_status_url = https://github.com/cm-advanced/cm_crew_connect

cm_crew_connect.module

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* @file
4+
* Implementes the CM Crew Connect Module
5+
*/
6+
7+
/**
8+
* Implements hook_menu()
9+
*/
10+
function cm_crew_connect_menu() {
11+
$items = array();
12+
13+
$items['user/%/cm_crew_connect'] =
14+
array(
15+
'title' => 'Crew Connect',
16+
'description' => 'Crew Connect',
17+
'access arguments' => array('access content'),
18+
'page callback' => 'cm_crew_connect_page',
19+
'page arguments' => array(1),
20+
'type' => MENU_LOCAL_TASK,
21+
);
22+
23+
$items['crew-connect/requests-search'] =
24+
array(
25+
'title' => 'Crew Connect Search',
26+
'description' => 'Crew Connect Search',
27+
'access arguments' => array('access content'),
28+
'page callback' => 'cm_crew_connect_search_page',
29+
'page arguments' => array(1),
30+
'type' => MENU_CALLBACK,
31+
);
32+
33+
return $items;
34+
}
35+
36+
/**
37+
* Implements hook_init().
38+
*
39+
* Loads all the include files
40+
*/
41+
function cm_crew_connect_init() {
42+
drupal_add_css(drupal_get_path('module', 'cm_crew_connect') .
43+
'/cm_crew_connect.css');
44+
45+
module_load_include('inc', 'cm_crew_connect', 'includes/computed_field');
46+
module_load_include('inc', 'cm_crew_connect', 'includes/civicrm');
47+
module_load_include('inc', 'cm_crew_connect', 'includes/form_alter');
48+
module_load_include('inc', 'cm_crew_connect', 'includes/form');
49+
module_load_include('inc', 'cm_crew_connect', 'includes/menu');
50+
module_load_include('inc', 'cm_crew_connect', 'includes/misc');
51+
module_load_include('inc', 'cm_crew_connect', 'includes/page');
52+
module_load_include('inc', 'cm_crew_connect', 'includes/phpfields');
53+
module_load_include('inc', 'cm_crew_connect', 'includes/postsave');
54+
module_load_include('inc', 'cm_crew_connect', 'includes/presave');
55+
module_load_include('inc', 'cm_crew_connect', 'includes/validate');
56+
module_load_include('inc', 'cm_crew_connect', 'includes/view_util');
57+
}
58+
59+
60+

includes/civicrm.inc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?
2+
/**
3+
* Get the the display name of the contact of the contact
4+
*/
5+
function cm_crew_connect_get_display_name($uid) {
6+
7+
$cid = cm_crew_connect_get_cid($uid);
8+
9+
if ($cid) {
10+
civicrm_initialize();
11+
12+
$result = civicrm_api3('Contact', 'get', array(
13+
'sequential' => 1,
14+
'id' => $cid,
15+
));
16+
17+
$display_name = (isset($result) && isset($result['values']) &&
18+
isset($result['values'][0])) ?
19+
$result['values'][0]['display_name'] : NULL;
20+
21+
return $display_name;
22+
}
23+
return "";
24+
}
25+
26+
/**
27+
* Get the the public email address of the contact
28+
*/
29+
function cm_crew_connect_get_public_email($uid) {
30+
31+
//dpm($uid);
32+
33+
$cid = cm_crew_connect_get_cid($uid);
34+
35+
if ($cid) {
36+
$result = civicrm_api3('Email', 'get', array(
37+
'sequential' => 1,
38+
'contact_id' => $cid,
39+
'location_type_id' => 6,
40+
));
41+
42+
//dpm($result, 'email');
43+
44+
$public_email = (isset($result) && isset($result['values'][0])) ?
45+
$result['values'][0]['email'] : NULL;
46+
return $public_email;
47+
}
48+
return "";
49+
50+
}
51+
52+
/**
53+
* Get the cid for a givin Drupal uid
54+
*/
55+
function cm_crew_connect_get_cid($uid) {
56+
civicrm_initialize();
57+
$result = civicrm_api3('UFMatch', 'get', array(
58+
'sequential' => 1,
59+
'uf_id' => $uid,
60+
));
61+
62+
$cid = (isset($result) && isset($result['values']) &&
63+
isset($result['values'][0])) ? $result['values'][0]['contact_id'] :
64+
NULL;
65+
66+
return $cid;
67+
}

includes/computed_field.inc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?
2+
/*
3+
function computed_field_field_civicrm_event_link_display($field, $entity_field_item, $entity_lang, $langcode) {
4+
dsm($field, 'field');
5+
dsm($entity_field_item, 'item');
6+
dsm($entity, 'ent');
7+
return l('hi mom', '');
8+
}*/
9+
10+
function computed_field_field_civicrm_event_link_compute(&$entity_field,
11+
$entity_type,
12+
$entity, $field,
13+
$instance,
14+
$langcode, $items) {
15+
16+
//SEE IF WE HAVE A CIVI EVENT
17+
$event_id =
18+
cm_crew_connect_get_single_field_value($entity,
19+
'field_crew_civievent_id');
20+
$link = '';
21+
if ($event_id) {
22+
$deleting_application = $_SESSION['cm_crew_connect_deleting_application'];
23+
24+
$_SESSION['cm_crew_connect_deleting_application'] = FALSE;
25+
if (!$deleting_application) {
26+
27+
//find applicant node
28+
$view = views_get_view('crew_connect_application_for_request');
29+
$view->set_arguments(array($entity->nid));
30+
$view->execute();
31+
32+
$results = $view->result;;
33+
34+
if ($results) {
35+
$result = array_pop($results);
36+
$nid = $result->nid;
37+
}
38+
else {
39+
$nid = $_SESSION['cm_crew_connect_request_nid'];
40+
}
41+
$_SESSION['cm_crew_connect_request_nid'] = NULL;
42+
43+
if ($nid) {
44+
$applicant = node_load($nid);
45+
46+
if ($applicant) {
47+
$participant_id =
48+
cm_crew_connect_get_single_field_value($applicant,
49+
'field_app_participant_id');
50+
51+
}
52+
}
53+
}
54+
55+
//if it exists, find particpant id and contact id, and build link
56+
if ($participant_id) {
57+
$result = civicrm_api3('Participant', 'get', array(
58+
'sequential' => 1,
59+
'id' => $participant_id,
60+
));
61+
if ($result && isset($result['values']) && $result['values'] &&
62+
isset($result['values'][0]) && $result['values'][0]) {
63+
$contact_id = $result['values'][0]['contact_id'];
64+
$query = array(
65+
'reset' => 1,
66+
'action' => 'update',
67+
'id' => $participant_id,
68+
'cid' => $contact_id,
69+
);
70+
71+
//contact/view/participant?reset=1&action=update&id=44639&cid=24432&context=search&compContext=participant&key=df0c891182920977f805756b43ddd75a_158 [^]
72+
73+
$link = l(t("Manage CiviCRM Event"),
74+
'civicrm/contact/view/participant',array('query'=>$query));
75+
}
76+
77+
78+
}
79+
//link will be as it was
80+
else {
81+
$query = array('id'=>$event_id,
82+
'action'=>'update',
83+
'reset'=>1);
84+
85+
$link = l(t("Manage CiviCRM Event"),
86+
'civicrm/event/manage/settings', array('query'=>$query));
87+
}
88+
89+
90+
91+
92+
}
93+
$entity_field[0]['value'] = $link;
94+
return $link;
95+
}

includes/form.inc

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?
2+
/**
3+
*
4+
*/
5+
function cm_crew_connect_project_alert_form($form, &$form_state,
6+
$project_nid) {
7+
$form = array();
8+
9+
$needs = array('yes'=>'Yes', 'no'=>'No', 'not_applicable'=>'N/A');
10+
11+
$form['cm_crew_connect_project_nid'] =
12+
array(
13+
'#type' => 'hidden',
14+
'#value'=> $project_nid,
15+
);
16+
17+
$project = node_load($project_nid);
18+
$title = $project ? $project->title : "";
19+
20+
$label = t("Do you need a Crew For !title?", array('!title'=>$title));
21+
22+
$form['cm_crew_connect_project_needs'] =
23+
array(
24+
'#type' => 'select',
25+
'#options'=> $needs,
26+
'#required' => TRUE,
27+
'#prefix'=> "<table><tr><td>$label</td><td>",
28+
'#suffix'=>"</td>",
29+
);
30+
31+
$form['cm_crew_connect_project_alert_submit'] =
32+
array(
33+
'#type' => 'submit',
34+
'#value'=> t("Update"),
35+
'#prefix' => "<td>",
36+
'#suffix' => "</tr></table>",
37+
);
38+
return $form;
39+
}
40+
41+
function cm_crew_connect_project_alert_form_submit($form, &$form_state) {
42+
$project_nid = $form['cm_crew_connect_project_nid']['#value'];
43+
44+
$needed = $form['cm_crew_connect_project_needs']['#value'];
45+
46+
$project = node_load($project_nid);
47+
$project->field_is_crew_needed[LANGUAGE_NONE][0]['value'] = $needed;
48+
node_save($project);
49+
50+
//FIXME ADD AS A REAL FORM VARIABLE
51+
$dashboard = variable_get('cm_crew_connect_dashboard_page', 'user');
52+
$dashboard .= $project ? "/".$project->uid : "";
53+
$dashboard_query_args = array();
54+
55+
$submit_request_page = "node/add/crew-connect-request";
56+
$submit_query_args = array('field_crew_project_id'=>$project->nid,
57+
'destination'=>$dashboard);
58+
59+
switch ($needed) {
60+
case 'yes':
61+
$destination = $submit_request_page;
62+
$query_args = $submit_query_args;
63+
break;
64+
case 'no':
65+
$destination = $dashboard;
66+
$query_args = $dashboard_query_args;
67+
break;
68+
case 'not_applicable':
69+
$destination = $dashboard;
70+
$query_args = $dashboard_query_args;
71+
break;
72+
}
73+
drupal_goto($destination, array('query'=>$query_args));
74+
return;
75+
}

0 commit comments

Comments
 (0)