Now all modules are in core modules folder

This commit is contained in:
Manuel Cillero 2017-08-08 12:14:45 +02:00
parent 5ba1cdfa0b
commit 05b6a91b0c
1907 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,397 @@
<?php
/**
* @file
*/
function stormevent_list() {
$breadcrumb = array();
$breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
drupal_set_breadcrumb($breadcrumb);
if (array_key_exists('organization_nid', $_GET)) {
if ($_SESSION['stormevent_list_filter']['organization_nid'] != $_GET['organization_nid']) {
$_SESSION['stormevent_list_filter']['organization_nid'] = $_GET['organization_nid'];
}
unset($_SESSION['stormevent_list_filter']['project_nid']);
unset($_SESSION['stormevent_list_filter']['task_nid']);
}
if (array_key_exists('project_nid', $_GET)) {
if ($_SESSION['stormevent_list_filter']['project_nid'] != $_GET['project_nid']) {
$_SESSION['stormevent_list_filter']['project_nid'] = $_GET['project_nid'];
}
$p = node_load($_GET['project_nid']);
$_SESSION['stormevent_list_filter']['organization_nid'] = $p->organization_nid;
unset($_SESSION['stormevent_list_filter']['task_nid']);
}
if (array_key_exists('task_nid', $_GET)) {
if ($_SESSION['stormevent_list_filter']['task_nid'] != $_GET['task_nid']) {
$_SESSION['stormevent_list_filter']['task_nid'] = $_GET['task_nid'];
}
$t = node_load($_GET['task_nid']);
$_SESSION['stormevent_list_filter']['organization_nid'] = $t->organization_nid;
$_SESSION['stormevent_list_filter']['project_nid'] = $t->project_nid;
}
$i = new stdClass();
$i->type = 'stormevent';
$params = $_GET;
if (isset($_SESSION['stormevent_list_filter']['organization_nid'])) {
$params['organization_nid'] = $_SESSION['stormevent_list_filter']['organization_nid'];
}
$header = array(
array(
'data' => ' ',
),
array(
'data' => t('Event') . ' / ' . t('Organization') . ' » ' . t('Project') . ' » ' . t('Task'),
'field' => 'n.title',
),
array(
'data' => ' ',
),
array(
'data' => t('Date'),
'field' => 'dini',
'class' => 'storm_list_date',
),
array(
'data' => t('Modified'),
'field' => 'n.changed',
'class' => 'storm_list_date',
'sort' => 'desc',
),
array(
'data' => t('Rev.'),
'field' => 'sev.version',
'class' => 'storm_list_version',
),
array(
'data' => storm_icon_add_node($i, $params),
'class' => 'storm_list_operations',
),
);
$s = "SELECT n.*, sev.*, nre.format, tev.*,
fda.field_stormevent_date_value AS dini,
fda.field_stormevent_date_value2 AS dend,
fda.field_stormevent_date_rrule AS drule,
fev.field_stormevent_attach_list AS clip FROM {node} AS n
INNER JOIN {stormevent} AS sev ON n.vid=sev.vid
INNER JOIN {node_revisions} AS nre ON n.vid = nre.vid
INNER JOIN {content_type_stormevent} AS tev ON n.vid = tev.vid
INNER JOIN {content_field_stormevent_date} AS fda ON n.vid = fda.vid AND fda.delta = 0
LEFT JOIN {content_field_stormevent_attach} AS fev ON n.vid = fev.vid AND fev.field_stormevent_attach_list = 1 AND fev.delta = 0
WHERE n.status=1 AND n.type='stormevent'";
$where = array();
$args = array();
$filterfields = array();
if (isset($_SESSION['stormevent_list_filter']['organization_nid']) && $_SESSION['stormevent_list_filter']['organization_nid'] != 0) {
$where[] = 'sev.organization_nid=%d';
$args[] = $_SESSION['stormevent_list_filter']['organization_nid'];
$filterfields[] = t('Organization');
}
if (isset($_SESSION['stormevent_list_filter']['project_nid']) && $_SESSION['stormevent_list_filter']['project_nid'] != 0) {
$where[] = 'sev.project_nid=%d';
$args[] = $_SESSION['stormevent_list_filter']['project_nid'];
$filterfields[] = t('Project');
}
if (isset($_SESSION['stormevent_list_filter']['task_nid']) && $_SESSION['stormevent_list_filter']['task_nid'] != 0) {
$where[] = 'sev.task_nid=%d';
$args[] = $_SESSION['stormevent_list_filter']['task_nid'];
$filterfields[] = t('Task');
}
$type_list = storm_attributes_bydomain('event type search');
$eventtype = isset($_SESSION['stormevent_list_filter']['eventtype']) ? $_SESSION['stormevent_list_filter']['eventtype'] : $type_list['default'];
$_SESSION['stormevent_list_filter']['eventtype'] = $eventtype;
if ($eventtype != '-') {
$where[] = "sev.eventtype='%s'";
$args[] = $eventtype;
$filterfields[] = t('Type');
}
if (isset($_SESSION['stormevent_list_filter']['title']) && $_SESSION['stormevent_list_filter']['title'] != '') {
$where[] = "LOWER(n.title) LIKE LOWER('%s')";
$args[] = $_SESSION['stormevent_list_filter']['title'];
$filterfields[] = t('Title');
}
if (isset($_SESSION['stormevent_list_filter']['datebeginfrom'])) {
$datebeginfrom = $_SESSION['stormevent_list_filter']['datebeginfrom'];
$datebeginfrom['hour'] = 0;
$datebeginfrom['minute'] = 0;
$date_timestamp = _storm_datetime_to_gmtimestamp($datebeginfrom);
if ($datebeginfrom['year']>0 && $date_timestamp>=0) {
$wherebeginfrom = "field_stormevent_date_value>='%s'";
$args[] = date_convert($date_timestamp, DATE_UNIX, DATE_ISO);
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormevent_list_filter']['datebeginto'])) {
$datebeginto = $_SESSION['stormevent_list_filter']['datebeginto'];
$datebeginto['hour'] = 23;
$datebeginto['minute'] = 59;
$date_timestamp = _storm_datetime_to_gmtimestamp($datebeginto);
if ($datebeginto['year']>0 && $date_timestamp>=0) {
$wherebeginto = "field_stormevent_date_value<='%s'";
$args[] = date_convert($date_timestamp, DATE_UNIX, DATE_ISO);
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormevent_list_filter']['dateendfrom'])) {
$dateendfrom = $_SESSION['stormevent_list_filter']['dateendfrom'];
$dateendfrom['hour'] = 0;
$dateendfrom['minute'] = 0;
$date_timestamp = _storm_datetime_to_gmtimestamp($dateendfrom);
if ($dateendfrom['year']>0 && $date_timestamp>=0) {
$whereendfrom = "field_stormevent_date_value2>='%s'";
$args[] = date_convert($date_timestamp, DATE_UNIX, DATE_ISO);
$filterfields[] = t('Date');
}
}
if (isset($_SESSION['stormevent_list_filter']['dateendto'])) {
$dateendto = $_SESSION['stormevent_list_filter']['dateendto'];
$dateendto['hour'] = 23;
$dateendto['minute'] = 59;
$date_timestamp = _storm_datetime_to_gmtimestamp($dateendto);
if ($dateendto['year']>0 && $date_timestamp>=0) {
$whereendto = "field_stormevent_date_value2<='%s'";
$args[] = date_convert($date_timestamp, DATE_UNIX, DATE_ISO);
$filterfields[] = t('Date');
}
}
if (isset($wherebeginfrom) || isset($wherebeginto) || isset($whereendfrom) || isset($whereendto)) {
$wheredate = "SELECT vid FROM {content_field_stormevent_date} WHERE vid = n.vid";
$wheredate .= isset($wherebeginfrom) ? " AND $wherebeginfrom" : '';
$wheredate .= isset($wherebeginto) ? " AND $wherebeginto" : '';
$wheredate .= isset($whereendfrom) ? " AND $whereendfrom" : '';
$wheredate .= isset($whereendto) ? " AND $whereendto" : '';
$where[] = "EXISTS ($wheredate)";
}
// This section only provides the value for the fieldset label, doesn't control actual filter
$itemsperpage = isset($_SESSION['stormevent_list_filter']['itemsperpage']) ? $_SESSION['stormevent_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
if (count($filterfields) == 0) {
$filterdesc = t('Not filtered');
}
else {
$filterdesc = t('Filtered by !fields', array('!fields' => implode(", ", array_unique($filterfields))));
}
$filterdesc .= ' | '. t('!items items per page', array('!items' => $itemsperpage));
$o = drupal_get_form('stormevent_list_filter', $filterdesc);
$s = stormevent_access_sql($s, $where);
$s = db_rewrite_sql($s);
$tablesort = tablesort_sql($header);
$r = pager_query($s . $tablesort, $itemsperpage, 0, NULL, $args);
$events = array();
while ($item = db_fetch_object($r)) {
$events[] = $item;
}
$o .= theme('stormevent_list', $header, $events);
$o .= theme('pager', NULL, $itemsperpage, 0);
print theme('page', $o);
}
function stormevent_list_filter(&$form_state, $filterdesc = 'Filter') {
$organization_nid = isset($_SESSION['stormevent_list_filter']['organization_nid']) ? $_SESSION['stormevent_list_filter']['organization_nid'] : 0;
$project_nid = isset($_SESSION['stormevent_list_filter']['project_nid']) ? $_SESSION['stormevent_list_filter']['project_nid'] : 0;
$task_nid = isset($_SESSION['stormevent_list_filter']['task_nid']) ? $_SESSION['stormevent_list_filter']['task_nid'] : 0;
$type_list = storm_attributes_bydomain('event type search');
$eventtype = isset($_SESSION['stormevent_list_filter']['eventtype']) ? $_SESSION['stormevent_list_filter']['eventtype'] : $type_list['default'];
$title = isset($_SESSION['stormevent_list_filter']['title']) ? $_SESSION['stormevent_list_filter']['title'] : '';
$datebeginfrom = isset($_SESSION['stormevent_list_filter']['datebeginfrom']) ? $_SESSION['stormevent_list_filter']['datebeginfrom'] : NULL;
$datebeginto = isset($_SESSION['stormevent_list_filter']['datebeginto']) ? $_SESSION['stormevent_list_filter']['datebeginto'] : NULL;
$dateendfrom = isset($_SESSION['stormevent_list_filter']['dateendfrom']) ? $_SESSION['stormevent_list_filter']['dateendfrom'] : NULL;
$dateendto = isset($_SESSION['stormevent_list_filter']['dateendto']) ? $_SESSION['stormevent_list_filter']['dateendto'] : NULL;
$itemsperpage = isset($_SESSION['stormevent_list_filter']['itemsperpage']) ? $_SESSION['stormevent_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
$_SESSION['stormevent_list_filter']['itemsperpage'] = $itemsperpage;
$form = array();
$form['filter'] = array(
'#type' => 'fieldset',
'#title' => $filterdesc,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['filter']['group1'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
);
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormorganization} AS sor ON sor.vid=n.vid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title";
$s = stormorganization_access_sql($s);
$s = db_rewrite_sql($s);
$r = db_query($s);
$organizations = array();
while ($organization = db_fetch_object($r)) {
$organizations[$organization->nid] = $organization->title;
}
$organizations = array(0 => t('All')) + $organizations;
$form['filter']['group1']['organization_nid'] = array(
'#type' => 'select',
'#title' => t('Organization'),
'#default_value' => $organization_nid,
'#options' => $organizations,
'#attributes' => array('onchange' => "stormtask_organization_project_tasks(this, 'edit-project-nid', 'edit-task-nid', '', true, '" . t('All') . "')"),
);
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormproject} AS spr ON spr.vid=n.vid
WHERE n.status=1 AND spr.organization_nid=%d AND n.type='stormproject' ORDER BY n.title";
$s = stormproject_access_sql($s);
$s = db_rewrite_sql($s);
$r = db_query($s, $organization_nid);
$projects = array();
while ($project = db_fetch_object($r)) {
$projects[$project->nid] = $project->title;
}
$projects = array(0 => t('All')) + $projects;
$form['filter']['group1']['project_nid'] = array(
'#type' => 'select',
'#title' => t('Project'),
'#default_value' => $project_nid,
'#options' => $projects,
'#process' => array('storm_dependent_select_process'),
'#attributes' => array('onchange' => "stormtask_project_tasks('edit-organization-nid', this, 'edit-task-nid', '', true, '" . t('All') . "')"),
);
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormtask} AS sta ON sta.nid=n.nid WHERE n.status=1 AND n.type='stormtask' AND sta.project_nid=%d ORDER BY title ";
$s = stormtask_access_sql($s);
$s = db_rewrite_sql($s);
$r = db_query($s, $project_nid);
$tasks = array();
while ($task = db_fetch_object($r)) {
$tasks[$task->nid] = $task->title;
}
$tasks = array(0 => t('All')) + $tasks;
$form['filter']['group1']['task_nid'] = array(
'#type' => 'select',
'#title' => t('Task'),
'#default_value' => $task_nid,
'#options' => $tasks,
);
$form['filter']['group2'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
);
$form['filter']['group2']['eventtype'] = array(
'#type' => 'select',
'#title' => t('Type'),
'#default_value' => $eventtype,
'#options' => $type_list['values'],
);
$form['filter']['group2']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $title,
);
$form['filter']['group3'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
);
$form['filter']['group3']['datebeginfrom'] = array(
'#type' => 'dateext',
'#withnull' => 'true',
'#title' => t('Date begin from'),
'#default_value' => $datebeginfrom,
);
$form['filter']['group3']['datebeginto'] = array(
'#type' => 'dateext',
'#withnull' => 'true',
'#title' => t('Date begin to'),
'#default_value' => $datebeginto,
);
$form['filter']['group4'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
);
$form['filter']['group4']['dateendfrom'] = array(
'#type' => 'dateext',
'#withnull' => 'true',
'#title' => t('Date end from'),
'#default_value' => $dateendfrom,
);
$form['filter']['group4']['dateendto'] = array(
'#type' => 'dateext',
'#withnull' => 'true',
'#title' => t('Date end to'),
'#default_value' => $dateendto,
);
$form['filter']['group5'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
'#attributes' => array('class' => 'formgroup-submit'),
);
$form['filter']['group5']['submit'] = array(
'#type' => 'submit',
'#value' => t('Filter'),
'#submit' => array('stormevent_list_filter_filter'),
);
$form['filter']['group5']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
'#submit' => array('stormevent_list_filter_reset'),
);
$form['filter']['group5']['itemsperpage'] = array(
'#type' => 'textfield',
'#title' => t('Items'),
'#size' => 10,
'#default_value' => $itemsperpage,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
return $form;
}
function stormevent_list_filter_reset($form, &$form_state) {
unset($_SESSION['stormevent_list_filter']);
}
function stormevent_list_filter_filter($form, &$form_state) {
$_SESSION['stormevent_list_filter']['organization_nid'] = $form_state['values']['organization_nid'];
$_SESSION['stormevent_list_filter']['project_nid'] = $form_state['values']['project_nid'];
$_SESSION['stormevent_list_filter']['task_nid'] = $form_state['values']['task_nid'];
$_SESSION['stormevent_list_filter']['eventtype'] = $form_state['values']['eventtype'];
$_SESSION['stormevent_list_filter']['title'] = $form_state['values']['title'];
$_SESSION['stormevent_list_filter']['datebeginfrom'] = $form_state['values']['datebeginfrom'];
$_SESSION['stormevent_list_filter']['datebeginto'] = $form_state['values']['datebeginto'];
$_SESSION['stormevent_list_filter']['dateendfrom'] = $form_state['values']['dateendfrom'];
$_SESSION['stormevent_list_filter']['dateendto'] = $form_state['values']['dateendto'];
$_SESSION['stormevent_list_filter']['itemsperpage'] = $form_state['values']['itemsperpage'];
}

View file

@ -0,0 +1,10 @@
name = Storm Event
description = "Allows creation of events and personal calendar."
dependencies[] = storm
dependencies[] = stormorganization
dependencies[] = stormproject
dependencies[] = stormtask
package = Storm
core = 6.x
version = "6.x-2.2"

View file

@ -0,0 +1,78 @@
<?php
/**
* @file
*/
function stormevent_install() {
drupal_install_schema('stormevent');
variable_set('node_options_stormevent', array('status'));
$attributes = array();
$attributes['Event type'] = array(
'event' => 'event',
'diary' => 'diary',
'plan' => 'plan',
'meeting' => 'meeting',
'call' => 'call',
'email' => 'email',
);
$attributes['Event type search'] = array(
'-' => 'all',
'event' => 'event',
'diary' => 'diary',
'plan' => 'plan',
'meeting' => 'meeting',
'call' => 'call',
'email' => 'email',
);
$s = "INSERT INTO {stormattribute} (domain, akey, avalue, weight) VALUES ('%s', '%s', '%s', %d)";
$prevdomain = '';
$weight = 0;
foreach ($attributes as $domain => $attribute) {
if ($domain != $prevdomain) $weight=0;
foreach ($attribute as $key => $value) {
db_query($s, $domain, $key, $value, $weight);
$weight++;
}
$prevdomain = $domain;
}
}
function stormevent_disable() {
drupal_set_message(t('Nodes of type "event" have not been deleted on disabling SuiteDesk event. Please note that they will now have reduced functionality, and will not be protected by SuiteDesk event access controls.'), 'warning');
}
function stormevent_uninstall() {
drupal_uninstall_schema('stormevent');
}
function stormevent_schema() {
$schema['stormevent'] = array(
'fields' => array(
'vid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'organization_nid' => array('type' => 'int'),
'organization_title' => array('type' => 'varchar', 'length' => 128),
'project_nid' => array('type' => 'int'),
'project_title' => array('type' => 'varchar', 'length' => 128),
'task_nid' => array('type' => 'int'),
'task_title' => array('type' => 'varchar', 'length' => 128),
'eventtype' => array('type' => 'varchar', 'length' => 100),
'version' => array('type' => 'varchar', 'length' => 12),
'event_access' => array('type' => 'int', 'default' => 0),
),
'primary key' => array('vid'),
'indexes' => array(
'nid' => array('nid'),
'organization_nid' => array('organization_nid'),
'project_nid' => array('project_nid'),
'task_nid' => array('task_nid'),
),
);
return $schema;
}

View file

@ -0,0 +1,643 @@
<?php
/**
* @file
*/
function stormevent_help($path, $arg) {
$o = '';
switch ($path) {
case "admin/help#stormevent":
$o = '<p>'. t("Provides events and calendar support for SuiteDesk") .'</p>';
break;
}
return $o;
}
function stormevent_perm() {
return array(
'Storm event: access',
'Storm event: add',
'Storm event: delete all',
'Storm event: delete own',
'Storm event: delete of user organization',
'Storm event: edit all',
'Storm event: edit own',
'Storm event: edit of user organization',
'Storm event: edit if assigned to project',
'Storm event: view all',
'Storm event: view own',
'Storm event: view of user organization',
'Storm event: view publics of user organization',
'Storm event: view if assigned to project',
'Storm event: view authorised if assigned to project',
);
}
function stormevent_access($op, $node, $account = NULL) {
if (empty($account)) {
global $user;
$account = $user;
}
if ($op == 'create') {
return user_access('Storm event: add');
}
if (is_numeric($node)) {
$node = node_load($node);
}
if (!isset($account->stormorganization_nid) && module_exists('stormperson')) {
_stormperson_user_load($account);
}
if ($op == 'delete') {
if (user_access('Storm event: delete all') && ($node->event_access != 3)) {
return TRUE;
}
elseif (user_access('Storm event: delete own') && ($account->uid == $node->uid)) {
return TRUE;
}
elseif (user_access('Storm event: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->event_access == 0)) {
return TRUE;
}
}
if ($op == 'update') {
if (user_access('Storm event: edit all') && ($node->event_access != 3)) {
return TRUE;
}
elseif (user_access('Storm event: edit own') && ($account->uid == $node->uid)) {
return TRUE;
}
elseif (user_access('Storm event: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->event_access == 0)) {
return TRUE;
}
elseif (user_access('Storm event: edit if assigned to project') && module_exists('stormteam') && ($node->event_access == 0)) {
$project = node_load($node->project_nid);
if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
return TRUE;
}
elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
return TRUE;
}
}
}
if ($op == 'view') {
if (user_access('Storm event: view all') && ($node->event_access != 3)) {
return TRUE;
}
elseif (user_access('Storm event: view own') && ($account->uid == $node->uid)) {
return TRUE;
}
elseif (user_access('Storm event: view of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->event_access != 3)) {
return TRUE;
}
elseif (user_access('Storm event: view publics of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->event_access == 1)) {
return TRUE;
}
elseif (user_access('Storm event: view if assigned to project') && module_exists('stormteam') && ($node->event_access != 3)) {
$project = node_load($node->project_nid);
if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
return TRUE;
}
elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
return TRUE;
}
}
elseif (user_access('Storm event: view authorised if assigned to project') && module_exists('stormteam') && ($node->event_access == 2)) {
$project = node_load($node->project_nid);
if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
return TRUE;
}
elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
return TRUE;
}
}
}
return FALSE;
}
function stormevent_access_sql($sql, $where = array()) {
if (user_access('Storm event: view all')) {
$where[] = 'sev.event_access != 3';
$where[] = "'storm_access' = 'storm_access'";
return storm_rewrite_sql($sql, $where);
}
global $user;
$cond = '';
$join = array();
if (user_access('Storm event: view own')) {
$cond .= 'n.uid = ' . $user->uid;
}
if (user_access('Storm event: view of user organization')) {
$cond .= !empty($cond) ? ' OR ' : '';
$cond .= 'sev.organization_nid = ' . $user->stormorganization_nid . ' AND sev.event_access != 3)';
}
if (user_access('Storm event: view publics of user organization')) {
$cond .= !empty($cond) ? ' OR ' : '';
$cond .= '(sev.organization_nid = ' . $user->stormorganization_nid . ' AND sev.event_access = 1)';
}
$user_access_authorised = user_access('Storm event: view authorised if assigned to project');
if (user_access('Storm event: view if assigned to project') || $user_access_authorised) {
$join[] = 'LEFT JOIN {node} npr ON npr.nid = sev.project_nid';
$join[] = 'LEFT JOIN {stormproject} spr ON spr.vid = npr.vid';
$cond .= !empty($cond) ? ' OR ' : '';
$cond .= '(sev.event_access';
$cond .= $user_access_authorised ? ' = 2' : ' != 3';
$cond .= ' AND (spr.assigned_nid = ' . $user->stormperson_nid;
if (module_exists('stormteam')) {
// Load teams that the account belongs to:
$belonged_teams = stormteam_user_return_teams();
// Allow access if any of those teams is the one in question:
foreach ($belonged_teams as $belonged_team) {
$cond .= ' OR spr.assigned_nid = ' . $belonged_team;
}
}
$cond .= '))';
}
$where[] = empty($cond) ? '0 = 1' : $cond;
$where[] = "'storm_access' = 'storm_access'";
return storm_rewrite_sql($sql, $where, $join);
}
function stormevent_storm_rewrite_where_sql($query, $primary_table, $account) {
static $conds = array();
if (isset($conds[$primary_table][$account->uid])) {
return $conds[$primary_table][$account->uid];
}
$cond = '';
if (!preg_match("/'storm_access' = 'storm_access'/", $query)) {
$from = '{stormevent} sev1';
if (user_access('Storm event: view all', $account)) {
$cond = 'sev1.event_access != 3';
} else {
if (user_access('Storm event: view own', $account)) {
$cond .= "${primary_table}.uid = " . $account->uid;
}
if (user_access('Storm event: view of user organization', $account)) {
$cond .= !empty($cond) ? ' OR ' : '';
# If function is called without viewing an organization, this variable
# may not be set. These lines check for that and set the organization
# node id to zero if not otherwise set.
if (!isset($account->stormorganization_nid)) {
$account->stormorganization_nid = 0;
}
$cond .= ' (sev1.organization_nid = ' . $account->stormorganization_nid . ' AND sev1.event_access != 3)';
}
if (user_access('Storm event: view publics of user organization', $account)) {
$cond .= !empty($cond) ? ' OR ' : '';
# If function is called without viewing an organization, this variable
# may not be set. These lines check for that and set the organization
# node id to zero if not otherwise set.
if (!isset($account->stormorganization_nid)) {
$account->stormorganization_nid = 0;
}
$cond .= ' (sev1.organization_nid = ' . $account->stormorganization_nid . ' AND sev1.event_access = 1)';
}
$user_access_authorised = user_access('Storm event: view authorised if assigned to project');
if (user_access('Storm event: view if assigned to project') || $user_access_authorised) {
$from .= ' LEFT JOIN {node} npr1 ON npr1.nid = sev1.project_nid LEFT JOIN {stormproject} spr1 ON spr1.vid = npr1.vid';
$cond .= !empty($cond) ? ' OR ' : '';
$cond .= '(sev1.event_access';
$cond .= $user_access_authorised ? ' = 2' : ' != 3';
$cond .= ' AND (spr1.assigned_nid = ' . $account->stormperson_nid;
if (module_exists('stormteam')) {
// Load teams that the account belongs to:
$belonged_teams = stormteam_user_return_teams($account);
// Allow access if any of those teams is the one in question:
foreach ($belonged_teams as $belonged_team) {
$cond .= ' OR spr1.assigned_nid = '. $belonged_team;
}
}
$cond .= '))';
}
}
if ($cond) {
$cond = " WHEN 'stormevent' THEN (SELECT IF($cond, 1, 0) FROM ${from} WHERE sev1.vid = ${primary_table}.vid) ";
} else {
$cond = " WHEN 'stormevent' THEN 0 ";
}
}
$conds[$primary_table][$account->uid] = $cond;
return $cond;
}
function stormevent_menu() {
$items = array();
$items['events'] = array(
'title' => 'Events',
'description' => 'SuiteDesk events',
'page callback' => 'stormevent_list',
'access arguments' => array('Storm event: access'),
'type' => MENU_NORMAL_ITEM,
'file' => 'stormevent.admin.inc',
'weight' => 7,
);
return $items;
}
function stormevent_theme() {
return array(
'stormevent_list' => array(
'file' => 'stormevent.theme.inc',
'arguments' => array('header', 'events'),
),
'stormevent_view' => array(
'file' => 'stormevent.theme.inc',
'arguments' => array('node', 'teaser', 'page'),
),
);
}
function stormevent_node_info() {
return array(
'stormevent' => array(
'name' => t('Event'),
'module' => 'stormevent',
'description' => t("An event for SuiteDesk."),
'has_body' => TRUE,
)
);
}
function stormevent_content_extra_fields($type_name) {
if ($type_name == 'stormevent') {
return array(
'group1' => array('label' => 'Type/Organization/Project/Task Group', 'weight' => -20),
'group2' => array('label' => 'Access Group', 'weight' => -19),
'groupv' => array('label' => 'New revision', 'weight' => -18),
);
}
}
function stormevent_stormorganization_change($organization_nid, $organization_title) {
$s = "UPDATE {stormevent} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'";
db_query($s, $organization_title, $organization_nid, $organization_title);
}
function stormevent_stormproject_change($project_nid, $project_title) {
$s = "UPDATE {stormevent} SET project_title='%s' WHERE project_nid=%d AND project_title <> '%s'";
db_query($s, $project_title, $project_nid, $project_title);
}
function stormevent_stormtask_change($task_nid, $task_title, $task_stepno) {
$s = "UPDATE {stormevent} SET task_title='%s' WHERE task_nid=%d AND task_title<>'%s'";
db_query($s, $task_title, $task_nid, $task_title);
}
function stormevent_stormproject_change_hierarchy($project_nid, $organization_nid, $organization_title) {
$s = "UPDATE {stormevent} SET organization_nid=%d, organization_title='%s' WHERE project_nid=%d";
db_query($s, $organization_nid, $organization_title, $project_nid);
}
function stormevent_stormtask_change_hierarchy($task_nid, $organization_nid, $organization_title, $project_nid, $project_title) {
$s = "UPDATE {stormevent} SET organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s' WHERE task_nid=%d";
db_query($s, $organization_nid, $organization_title, $project_nid, $project_title, $task_nid);
}
function stormevent_form(&$node) {
$breadcrumb = array();
$breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
$breadcrumb[] = l(t('Events'), 'events');
drupal_set_breadcrumb($breadcrumb);
if (arg(1)=='add') {
if (array_key_exists('organization_nid', $_GET) && !$node->organization_nid) {
$node->organization_nid = $_GET['organization_nid'];
}
if (array_key_exists('project_nid', $_GET) && !$node->project_nid) {
$node->project_nid = $_GET['project_nid'];
$p = node_load($node->project_nid);
$node->organization_nid = $p->organization_nid;
if (!stormorganization_access('view', $node->organization_nid)) {
drupal_set_message(t("You cannot add an event for this project, as you do not have access to view the organization's profile"));
drupal_goto('node/'. $node->project_nid);
}
}
if (array_key_exists('task_nid', $_GET) && !$node->task_nid) {
$node->task_nid = $_GET['task_nid'];
$t = node_load($node->task_nid);
$node->organization_nid = $t->organization_nid;
$node->project_nid = $t->project_nid;
// $project_access deals with the case whereby the project could be blank, hence access rules not required
$project_access = $node->project_nid ? stormproject_access('view', $node->project_nid) : TRUE;
if (!stormorganization_access('view', $node->organization_nid) || !stormproject_access('view', $node->project_nid)) {
drupal_set_message(t("You cannot add an event for this task, as you do not have access to view the both the organization and project's profile"));
drupal_goto('node/'. $node->task_nid);
}
}
if (!empty($_SESSION['stormevent_list_filter']['organization_nid']) && !$node->organization_nid) {
$node->organization_nid = $_SESSION['stormevent_list_filter']['organization_nid'];
}
if (!empty($_SESSION['stormevent_list_filter']['project_nid']) && !$node->project_nid) {
$node->project_nid = $_SESSION['stormevent_list_filter']['project_nid'];
}
if (!empty($_SESSION['stormevent_list_filter']['task_nid']) && !$node->task_nid) {
$node->task_nid = $_SESSION['stormevent_list_filter']['task_nid'];
}
$s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
ON so.nid=n.nid WHERE n.status=1 AND so.isactive=1 AND n.type='stormorganization' ORDER BY n.title";
}
else {
$s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
ON so.nid=n.nid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title";
}
$type = node_get_types('type', $node);
$form['group1'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group1') : -20,
);
$type_list = storm_attributes_bydomain('Event type');
$form['group1']['eventtype'] = array(
'#type' => 'select',
'#title' => t('Type'),
'#required' => TRUE,
'#default_value' => $node->eventtype,
'#options' => $type_list['values'],
);
$s_org = stormorganization_access_sql($s_org);
$s_org = db_rewrite_sql($s_org);
$r = db_query($s_org);
$organizations = array();
while ($organization = db_fetch_object($r)) {
$organizations[$organization->nid] = $organization->title;
/* if (!isset($node->organization_nid)) {
$node->organization_nid = $organization->nid;
} */
}
$form['group1']['organization_nid'] = array(
'#type' => 'select',
'#title' => t('Organization'),
'#default_value' => $node->organization_nid,
'#options' => array(0 => '-') + $organizations,
'#attributes' => array('onchange' => "stormtask_organization_project_tasks(this, 'edit-project-nid', 'edit-parent-nid', '', true, '-')"),
);
$s = "SELECT n.nid, n.title FROM {node} n INNER JOIN {stormproject} spr ON spr.vid=n.vid WHERE spr.organization_nid=%d AND n.status=1 AND n.type='stormproject' ORDER BY n.title";
$s = stormproject_access_sql($s);
$s = db_rewrite_sql($s);
$r = db_query($s, $node->organization_nid);
$projects = array();
while ($project = db_fetch_object($r)) {
$projects[$project->nid] = $project->title;
}
$form['group1']['project_nid'] = array(
'#type' => 'select',
'#title' => t('Project'),
'#default_value' => isset($node->project_nid) ? $node->project_nid : NULL,
'#options' => array(0 => '-') + $projects,
'#process' => array('storm_dependent_select_process'),
'#attributes' => array('onchange' => "stormtask_project_tasks('edit-organization-nid', this, 'edit-task-nid', '', true, '-')"),
);
$tree = isset($node->project_nid) ? _stormtask_get_tree($node->project_nid) : array();
$tasks = _stormtask_plain_tree($tree);
$form['group1']['task_nid'] = array(
'#type' => 'select',
'#title' => t('Task'),
'#default_value' => isset($node->task_nid) ? $node->task_nid : NULL,
'#options' => array(0 => '-') + $tasks,
'#process' => array('storm_dependent_select_process'),
);
$form['group2'] = array(
'#type' => 'markup',
'#theme' => 'storm_form_group',
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group2') : -19,
'#attributes' => array('class' => 'formgroup_access'),
);
$event_access = array();
$event_access[1] = '<strong>' . t('Public') . '</strong><div class="description">' . t('Visible for all users of organization. Organization required.') . '</div>';
$event_access[0] = '<strong>' . t('Default access') . '</strong><div class="description">' . t('Visible and editable for staff assigned to project. Project required.') . '</div>';
$event_access[2] = '<strong>' . t('Authorised') . '</strong><div class="description">' . t('Visible for all users assigned to project. Project required.') . '</div>';
$event_access[3] = '<strong>' . t('Private') . '</strong><div class="description">' . t('For my eyes only.') . '</div>';
$form['group2']['event_access'] = array(
'#type' => 'radios',
'#default_value' => isset($node->event_access) ? $node->event_access : 0,
'#required' => TRUE,
'#options' => $event_access,
'#weight' => 1,
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'title') : -16,
);
$form['groupv'] = array(
'#type' => 'markup',
'#title' => t('New review'),
'#theme' => 'storm_form_group',
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'groupv') : -12,
);
$options = array();
$options['no review'] = t('Don\'t create any revision (change the current)');
$options['minor review'] = t('Create a new review due to a minor modification');
$options['major review'] = t('Create a new version by a major modification');
$form['groupv']['review'] = array(
'#type' => 'radios',
'#options' => $options,
'#default_value' => 'no review',
);
$form['groupv']['reviewlog'] = array(
'#title' => t('Log message'),
'#type' => 'textfield',
'#size' => 255,
'#default_value' => NULL,
);
if ($type->has_body) {
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
}
return $form;
}
function stormevent_insert($node) {
_stormevent_beforesave($node);
db_query("INSERT INTO {stormevent}
(vid, nid,
organization_nid, organization_title,
project_nid, project_title,
task_nid, task_title,
eventtype,
version, event_access
) VALUES
(%d, %d,
%d, '%s',
%d, '%s',
%d, '%s',
'%s',
'%s', %d
)",
$node->vid, $node->nid,
$node->organization_nid, $node->organization_title,
$node->project_nid, $node->project_title,
$node->task_nid, $node->task_title,
$node->eventtype,
$node->version, $node->event_access
);
}
function stormevent_update($node) {
// if this is a new node or we're adding a new revision,
if ($node->revision) {
stormevent_insert($node);
} else {
_stormevent_beforesave($node);
db_query("UPDATE {stormevent} SET
organization_nid=%d, organization_title='%s',
project_nid=%d, project_title='%s',
task_nid=%d, task_title='%s',
eventtype='%s',
version='%s', event_access=%d
WHERE vid = %d",
$node->organization_nid, $node->organization_title,
$node->project_nid, $node->project_title,
$node->task_nid, $node->task_title,
$node->eventtype,
$node->version, $node->event_access,
$node->vid);
}
}
function _stormevent_beforesave(&$node) {
$s = "SELECT n.title FROM {node} n INNER JOIN {stormorganization} o ON n.nid=o.nid
WHERE type='stormorganization' AND n.nid=%d";
$r = db_query($s, $node->organization_nid);
$o = db_fetch_object($r);
$node->organization_title = $o->title;
$s = "SELECT n.title FROM {node} n INNER JOIN {stormproject} p ON n.nid=p.nid
WHERE type='stormproject' AND n.nid=%d";
$r = db_query($s, $node->project_nid);
$p = db_fetch_object($r);
$node->project_title = isset($p->title) ? $p->title : '';
$s = "SELECT n.title FROM {node} n INNER JOIN {stormtask} p ON n.nid=p.nid
WHERE type='stormtask' AND n.nid=%d";
$r = db_query($s, $node->task_nid);
$t = db_fetch_object($r);
$node->task_title = isset($t->title) ? $t->title : '';
}
function stormevent_nodeapi(&$node, $op, $teaser, $page) {
global $user;
if ($node->type != 'stormevent') {
return;
}
// Suffix for public (U+00B0), authorised (U+207B) and private (U+00AA) nodes:
$event_suffix = array(1 => '°', 2 => 'ª', 3 => '⁻');
switch ($op) {
case 'prepare':
$pos_suffix = strpos($node->title, $event_suffix[$node->event_access]);
if ($node->event_access >= 1 && $node->event_access <= 3 && $pos_suffix) {
$node->title = substr($node->title, 0, $pos_suffix);
}
break;
case 'validate';
if ($node->event_access == 0 && empty($node->project_nid)) {
$field_nid = empty($node->organization_nid) ? 'organization_nid' : 'project_nid';
$field_msg = empty($node->organization_nid) ? 'Organization and Project' : 'Project';
form_set_error($field_nid, t($field_msg . ' required in default access for staff assigned to the project.'));
}
if ($node->event_access == 1 && empty($node->organization_nid)) {
form_set_error('organization_nid', t('Organization required in public view for all users of the organization.'));
}
if ($node->event_access == 2 && empty($node->project_nid)) {
$field_nid = empty($node->organization_nid) ? 'organization_nid' : 'project_nid';
$field_msg = empty($node->organization_nid) ? 'Organization and Project' : 'Project';
form_set_error($field_nid, t($field_msg . ' required in authorised view for all users assigned to the project.'));
}
break;
case 'presave':
if ($node->event_access >= 1 && $node->event_access <= 3 && !strpos($node->title, $event_suffix[$node->event_access])) {
$node->title .= $event_suffix[$node->event_access];
}
break;
case 'delete revision':
// Notice that we're matching a single revision based on the node's vid.
db_query('DELETE FROM {stormevent} WHERE vid = %d', $node->vid);
break;
}
}
function stormevent_delete($node) {
db_query('DELETE FROM {stormevent} WHERE nid = %d', $node->nid);
}
function stormevent_load($node) {
$additions = db_fetch_object(db_query('SELECT * FROM {stormevent} WHERE vid = %d', $node->vid));
return $additions;
}
function stormevent_view($node, $teaser = FALSE, $page = FALSE) {
$breadcrumb = array();
$breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
$breadcrumb[] = l(t('Events'), 'events');
drupal_set_breadcrumb($breadcrumb);
return theme('stormevent_view', $node, $teaser, $page);
}
function stormevent_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'stormevent'),
);
}
function stormevent_storm_dashboard_links($type) {
$links = array();
if ($type == 'page' || $type == 'block') {
$links[] = array(
'theme' => 'storm_dashboard_link',
'title' => t('Events'),
'icon' => 'stormevent-item',
'path' => 'events',
'params' => array(),
'access_arguments' => 'Storm event: access',
'node_type' => 'stormevent',
'add_type' => 'stormevent',
'map' => array(),
'weight' => 9,
);
}
return $links;
}

View file

@ -0,0 +1,192 @@
<?php
/**
* @file
* Test definitions for the SuiteDesk event module
*/
class StormeventTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('SuiteDesk event Functionality'),
'description' => t('Test the functionality of the SuiteDesk event module'),
'group' => 'Storm',
);
}
public function setUp() {
parent::setUp('storm', 'stormorganization', 'stormproject', 'stormtask', 'stormevent', 'stormperson');
}
public function testStormeventAccess() {
$this->drupalGet('events');
$this->assertResponse(403, t('Make sure access is denied to SuiteDesk events list for anonymous user'));
$basic_user = $this->drupalCreateUser();
$this->drupalLogin($basic_user);
$this->drupalGet('events');
$this->assertResponse(403, t('Make sure access is denied to SuiteDesk events list for basic user'));
$privileged_user = $this->drupalCreateUser(array('Storm event: access'));
$this->drupalLogin($privileged_user);
$this->drupalGet('events');
$this->assertText(t('events'), t('Make sure the correct page has been displayed by checking that the title is "events".'));
}
public function testStormeventCreate() {
// Create and login user
$user = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm project: add', 'Storm project: view all', 'Storm task: add', 'Storm task: view all', 'Storm event: add', 'Storm event: view all'));
$this->drupalLogin($user);
// Create organization and invoice
$org = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$prj = array(
'title' => $this->randomName(32),
'organization_nid' => '1',
);
$task = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$event = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$this->drupalPost('node/add/stormorganization', $org, t('Save'));
$this->drupalPost('node/add/stormproject', $prj, t('Save'));
$this->drupalPost('node/add/stormtask', $task, t('Save'));
$this->drupalPost('node/add/stormevent', $event, t('Save'));
$this->assertText(t('event @title has been created.', array('@title' => $event['title'])));;
}
public function testStormeventList() {
// Create and login user
$userAll = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm event: access', 'Storm event: add', 'Storm event: view all', 'Storm event: edit all', 'Storm event: delete all', 'Storm person: add'));
$userOrg = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm event: access', 'Storm event: add', 'Storm event: view of user organization', 'Storm event: edit of user organization', 'Storm event: delete of user organization'));
$userOwn = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm event: access', 'Storm event: add', 'Storm event: view own', 'Storm event: edit own', 'Storm event: delete own'));
$userViewAllEditOwn = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm event: access', 'Storm event: add', 'Storm event: view all', 'Storm event: edit own', 'Storm event: delete own'));
$this->drupalLogin($userAll);
// Create organization
$org = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$this->drupalPost('node/add/stormorganization', $org, t('Save'));
$org = node_load(array('title' => $org['title']));
// Create organization
$org2 = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$this->drupalPost('node/add/stormorganization', $org2, t('Save'));
$org2 = node_load(array('title' => $org2['title']));
// Create stormperson with organization to userOrg
$personOrg = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
'organization_nid' => $org->nid,
'user_name' => $userOrg->name,
);
$this->drupalPost('node/add/stormperson', $personOrg, t('Save'));
// Create events
$event1 = array(
'organization_nid' => $org->nid,
'title' => $this->randomName(32),
'body' => $this->randomName(64),
);
$this->drupalPost('node/add/stormevent', $event1, t('Save'));
$event1 = node_load(array('title' => $event1['title']));
$this->drupalLogin($userOwn);
$event2 = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
'organization_nid' => $org->nid,
);
$this->drupalPost('node/add/stormevent', $event2, t('Save'));
$event2 = node_load(array('title' => $event2['title']));
$this->drupalLogin($userViewAllEditOwn);
$event3 = array(
'title' => $this->randomName(32),
'body' => $this->randomName(64),
'organization_nid' => $org2->nid,
);
$this->drupalPost('node/add/stormevent', $event3, t('Save'));
$event3 = node_load(array('title' => $event3['title']));
// Test for 'Storm event: view all'
$this->drupalLogin($userAll);
$this->drupalGet('events');
$this->assertLink($event1->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event1->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event1->nid .'/delete', 'The event delete icon appears on the list');
$this->assertLink($event2->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event2->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event2->nid .'/delete', 'The event delete icon appears on the list');
$this->assertLink($event3->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event3->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event3->nid .'/delete', 'The event delete icon appears on the list');
// Test for 'Storm event: view of user organization'
$this->drupalLogin($userOrg);
$this->drupalGet('events');
$this->assertLink($event1->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event1->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event1->nid .'/delete', 'The event delete icon appears on the list');
$this->assertLink($event2->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event2->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event2->nid .'/delete', 'The event delete icon appears on the list');
$this->assertNoLink($event3->title, 'The event does not appear on the list');
$this->assertNoRaw('node/'. $event3->nid .'/edit', 'The event edit icon does not appear on the list');
$this->assertNoRaw('node/'. $event3->nid .'/delete', 'The event delete icon does not appear on the list');
// Test for 'Storm event: view own'
$this->drupalLogin($userOwn);
$this->drupalGet('events');
$this->assertNoLink($event1->title, 'The event does not appear on the list');
$this->assertNoRaw('node/'. $event1->nid .'/edit', 'The event edit icon does not appear on the list');
$this->assertNoRaw('node/'. $event1->nid .'/delete', 'The event delete icon does not appear on the list');
$this->assertLink($event2->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event2->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event2->nid .'/delete', 'The event delete icon appears on the list');
$this->assertNoLink($event3->title, 'The event does not appear on the list');
$this->assertNoRaw('node/'. $event3->nid .'/edit', 'The event edit icon does not appear on the list');
$this->assertNoRaw('node/'. $event3->nid .'/delete', 'The event delete icon does not appear on the list');
// Test for 'Storm event: view all', 'Storm event: edit own'
$this->drupalLogin($userViewAllEditOwn);
$this->drupalGet('events');
$this->assertLink($event1->title, 0, 'The event appears on the list');
$this->assertNoRaw('node/'. $event1->nid .'/edit', 'The event edit icon does not appear on the list');
$this->assertNoRaw('node/'. $event1->nid .'/delete', 'The event edit icon does not appear on the list');
$this->assertLink($event2->title, 0, 'The event appears on the list');
$this->assertNoRaw('node/'. $event2->nid .'/edit', 'The event edit icon does not appear on the list');
$this->assertNoRaw('node/'. $event2->nid .'/delete', 'The event delete icon does not appear on the list');
$this->assertLink($event3->title, 0, 'The event appears on the list');
$this->assertRaw('node/'. $event3->nid .'/edit', 'The event edit icon appears on the list');
$this->assertRaw('node/'. $event3->nid .'/delete', 'The event delete icon appears on the list');
}
}

View file

@ -0,0 +1,132 @@
<?php
/**
* @file
*/
function theme_stormevent_list($header, $events) {
$rows = array();
foreach ($events as $event) {
$dini_unix = date_convert($event->dini, DATE_ISO, DATE_UNIX);
$dini_date = format_date($dini_unix, 'small', NULL, 0);
$dini_day = substr($dini_date, 0, strrpos($dini_date, ' ') - 2);
$dini_hour = substr($dini_date, strrpos($dini_date, ' ') + 1);
$eventdate = $dini_day . ($event->drule ? '<sup>r</sup>' : '');
if ($event->dini != $event->dend) {
$dend_unix = date_convert($event->dend, DATE_ISO, DATE_UNIX);
$dend_date = format_date($dend_unix, 'small', NULL, 0);
$dend_day = substr($dend_date, 0, strrpos($dend_date, ' ') - 2);
$dend_hour = substr($dend_date, strrpos($dend_date, ' ') + 1);
if ($dini_day == $dend_day) {
$eventdate .= " $dini_hour&nbsp;-&nbsp;$dend_hour";
} elseif ($dini_hour == '00:00' && $dend_hour == '00:00') {
$eventdate .= "&nbsp;- $dend_day";
} else {
$eventdate = "$dini_date $dend_date";
}
}
$rows[] = array(
storm_icon('eventtype_'. $event->eventtype, storm_attribute_value('Event type', $event->eventtype)),
'<span class="event-title status_' . str_replace(' ', '_', strtolower($event->field_stormevent_status_value)) . '">' . l($event->title, 'node/'. $event->nid) . theme('mark', node_mark($event->nid, $event->changed)) . '</span><br />' .
l($event->organization_title, 'node/'. $event->organization_nid) .
(!empty($event->project_title) ? ' » ' . l($event->project_title, 'node/'. $event->project_nid) : '' ) .
(!empty($event->task_title) ? ' » ' . l($event->task_title, 'node/'. $event->task_nid) : '' ),
$event->clip ? storm_icon('attached', t('Has attached files')) : '&nbsp;',
$eventdate,
format_date($event->changed, 'small'),
$event->version,
array(
'data' => storm_icon_edit_node($event, $_GET) . storm_icon_delete_node($event, $_GET),
'class' => 'storm_list_operations',
),
);
}
$o = theme('table', $header, $rows, array('id' => 'stormevents'));
return $o;
}
function theme_stormevent_view($node, $teaser = FALSE, $page = FALSE) {
drupal_add_css(drupal_get_path('module', 'storm') . '/storm-node.css', 'module');
$node = node_prepare($node, $teaser);
$l_pos = 1; // Used to increase the link position number (see issue 814820)
$node->content['links'] = array(
'#prefix' => '<div class="stormlinks"><dl>',
'#suffix' => '</dl></div>',
'#weight' => $l_pos++,
);
$node->content['group1'] = array(
'#prefix' => '<div class="stormfields">',
'#suffix' => '</div>',
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group1') : -20,
);
$node->content['group1']['eventtype'] = array(
'#prefix' => '<div class="eventtype">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Event type'), check_plain(storm_attribute_value('Event type', $node->eventtype))),
'#weight' => 1,
);
if (!empty($node->organization_nid)) {
$node->content['group1']['organization'] = array(
'#prefix' => '<div class="organization">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Organization'), l($node->organization_title, 'node/'. $node->organization_nid)),
'#weight' => 2,
);
}
if (!empty($node->project_nid)) {
$node->content['group1']['project'] = array(
'#prefix' => '<div class="project">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Project'), l($node->project_title, 'node/'. $node->project_nid)),
'#weight' => 3,
);
}
if (!empty($node->task_nid)) {
$node->content['group1']['task'] = array(
'#prefix' => '<div class="task">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Task'), l($node->task_title, 'node/'. $node->task_nid)),
'#weight' => 4,
);
}
$node->content['group1']['author'] = array(
'#prefix' => '<div class="author">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Submitted by'), theme('username', $node)),
'#weight' => 11,
);
$node->content['group1']['created'] = array(
'#prefix' => '<div class="created">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Created'), format_date($node->created, 'small')),
'#weight' => 12,
);
if ($node->changed != $node->created) {
$node->content['group1']['modified'] = array(
'#prefix' => '<div class="modified">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Modified'), format_date($node->changed, 'small')),
'#weight' => 13,
);
}
$node->content['group1']['version'] = array(
'#prefix' => '<div class="version">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', t('Revision'), $node->version),
'#weight' => 14,
);
$node->content['body_field'] = array(
'#prefix' => '<div class="stormbody">',
'#suffix' => '</div>',
'#value' => theme('storm_view_item', NULL, $node->content['body']['#value']),
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'body_field') : -18,
);
unset($node->content['body']);
return $node;
}

View file

@ -0,0 +1,143 @@
<?php
/**
* @file
* Functions to expose storm event module data to views
*/
function stormevent_views_data() {
$data['stormevent']['table']['group'] = t('SuiteDesk event');
$data['stormevent']['table']['join'] = array(
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['stormevent']['organization_nid'] = array(
'title' => t('Organization'),
'help' => t('event -> Organization'),
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('event -> Organization'),
),
);
$data['stormevent']['organization_title'] = array(
'title' => t('Organization'),
'help' => t('SuiteDesk event Organization (title only)'),
'field' => array(
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['stormevent']['project_nid'] = array(
'title' => t('Project'),
'help' => t('event -> Project'),
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('event -> Project'),
),
);
$data['stormevent']['project_title'] = array(
'title' => t('Project'),
'help' => t('SuiteDesk event Project (title only)'),
'field' => array(
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['stormevent']['task_nid'] = array(
'title' => t('Task'),
'help' => t('event -> Task'),
'relationship' => array(
'base' => 'node',
'field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('event -> Task'),
),
);
$data['stormevent']['task_stepno'] = array(
'title' => t('Task step number'),
'help' => t('SuiteDesk event Task Step Number'),
'field' => array(
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['stormevent']['task_title'] = array(
'title' => t('Task'),
'help' => t('SuiteDesk event Task (title only)'),
'field' => array(
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['stormevent']['operation'] = array(
'field' => array(
'title' => t('Edit/Delete link'),
'help' => t('Provide a simple link to edit and delete the node.'),
'handler' => 'storm_handler_field_operation',
'type' => 'stormevent',
),
);
return $data;
}
function stormevent_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'storm'),
),
'handlers' => array(
'storm_handler_filter_attributes_domain' => array(
'parent' => 'views_handler_filter_in_operator',
),
'storm_handler_field_operation' => array(
'parent' => 'views_handler_field_node_link',
'path' => drupal_get_path('module', 'storm'),
),
),
);
}