View source
<?php
function organigrams_entity_info() {
$entities = array();
$entities['organigrams_item'] = array(
'label' => t('Organigram item'),
'controller class' => 'OrganigramsItemController',
'base table' => 'organigrams_item_data',
'fieldable' => FALSE,
'entity keys' => array(
'id' => 'iid',
'bundle' => 'organigrams_machine_name',
'label' => 'name',
),
'bundle keys' => array(
'bundle' => 'machine_name',
),
'bundles' => array(),
'module' => 'organigrams',
);
foreach (organigrams_get_names() as $machine_name => $organigrams) {
$entities['organigrams_item']['bundles'][$machine_name] = array(
'label' => $organigrams->name,
'admin' => array(
'path' => 'admin/structure/organigrams/%organigrams_machine_name',
'real path' => "admin/structure/organigrams/{$machine_name}",
'bundle argument' => 3,
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
),
);
}
$entities['organigrams'] = array(
'label' => t('Organigram'),
'controller class' => 'OrganigramsController',
'base table' => 'organigrams_data',
'entity keys' => array(
'id' => 'oid',
'label' => 'name',
),
'fieldable' => TRUE,
'bundles' => array(
'organigrams' => array(
'label' => t('Organigram'),
'admin' => array(
'path' => 'admin/structure/organigrams',
),
),
),
'view modes' => array(
'organigram' => array(
'label' => t('Organigram'),
'custom settings' => TRUE,
),
'organigram_block' => array(
'label' => t('Organigram block'),
'custom settings' => TRUE,
),
),
'access callback' => 'organigrams_entity_access',
'module' => 'organigrams',
);
return $entities;
}
function organigrams_entity_property_info() {
$info = array();
$properties =& $info['organigrams_item']['properties'];
$properties['iid'] = array(
'label' => t('Organigram item ID'),
'description' => t('The unique ID of the organigram item.'),
'type' => 'integer',
'schema field' => 'iid',
);
$properties['name'] = array(
'label' => t('Name'),
'description' => t('The name of the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
'schema field' => 'name',
);
$properties['parent'] = array(
'label' => t('Parent item'),
'description' => t('The parent terms of the taxonomy term.'),
'setter callback' => 'organigrams_metadata_organigrams_item_setter',
'type' => 'organigrams_item',
'schema field' => 'parent',
);
$properties['position'] = array(
'label' => t('Position'),
'description' => t('The position of the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
'schema field' => 'position',
);
$properties['url'] = array(
'label' => t('URL'),
'description' => t('Add a link to this URL to the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'url',
);
$properties['border_color'] = array(
'label' => t('Border color'),
'description' => t('The border color of the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'border_color',
);
$properties['border_color_hover'] = array(
'label' => t('Border color hover'),
'description' => t('The border color of the organigram item when hovering over it if it has a URL.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'border_color_hover',
);
$properties['background_color'] = array(
'label' => t('Background color'),
'description' => t('The background color of the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'background_color',
);
$properties['background_color_hover'] = array(
'label' => t('Background color hover'),
'description' => t('The background color of the organigram item when hovering over it if it has a URL.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'background_color_hover',
);
$properties['font_color'] = array(
'label' => t('Font color'),
'description' => t('The font color of the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_color',
);
$properties['font_color_hover'] = array(
'label' => t('Font color hover'),
'description' => t('The font color of the organigram item when hovering over it if it has a URL.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_color_hover',
);
$properties['bold_border'] = array(
'label' => t('Bold border'),
'description' => t('Emphasize the organigram item with an extra border.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'bold_border',
);
$properties['image_url'] = array(
'label' => t('Image URL'),
'description' => t('The image URL of an image to add to the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'image_url',
);
$properties['image_alignment'] = array(
'label' => t('Image alignment'),
'description' => t('The alignment of the image in the organigram item.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'image_alignment',
);
$properties['weight'] = array(
'label' => t('Weight'),
'description' => t('The weight of the organigram item, which is used for ordering items during display.'),
'setter callback' => 'entity_property_verbatim_set',
'schema field' => 'weight',
);
$properties['organigram'] = array(
'label' => t('organigram'),
'description' => t('The organigram the organigram item belongs to.'),
'setter callback' => 'organigrams_metadata_organigrams_item_setter',
'type' => 'organigrams',
'required' => TRUE,
'schema field' => 'oid',
);
$properties =& $info['organigrams']['properties'];
$properties['oid'] = array(
'label' => t('Organigram ID'),
'description' => t('The unique ID of the organigram.'),
'type' => 'integer',
'schema field' => 'oid',
);
$properties['name'] = array(
'label' => t('Name'),
'description' => t('The name of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
'schema field' => 'name',
);
$properties['machine_name'] = array(
'label' => t('Machine name'),
'description' => t('The machine name of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'type' => 'token',
'required' => TRUE,
'schema field' => 'machine_name',
);
$properties['description'] = array(
'label' => t('Description'),
'description' => t('The optional description of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'sanitize' => 'filter_xss',
'schema field' => 'description',
);
$properties['status'] = array(
'label' => t('status'),
'description' => t('The published status of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'status',
);
$properties['canvas_width'] = array(
'label' => t('Canvas width'),
'description' => t('Specify the width in pixels of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'canvas_width',
);
$properties['canvas_height'] = array(
'label' => t('Canvas height'),
'description' => t('Specify the height in pixels of the organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'canvas_height',
);
$properties['center'] = array(
'label' => t('Center'),
'description' => t('Boolean indicating whether the organigram should align on the center of the page.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'center',
);
$properties['fit'] = array(
'label' => t('Fit in given width'),
'description' => t('Boolean indicating whether the organigram should rescale to the given width.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'fit',
);
$properties['node_width'] = array(
'label' => t('Node width'),
'description' => t('Specify the width in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'node_width',
);
$properties['node_height'] = array(
'label' => t('Node height'),
'description' => t('Specify the height in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'node_height',
);
$properties['top_radius'] = array(
'label' => t('Top radius'),
'description' => t('Specify the radius of the top corners in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'top_radius',
);
$properties['bottom_radius'] = array(
'label' => t('Bottom radius'),
'description' => t('Specify the radius of the bottom corners in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'bottom_radius',
);
$properties['shadow_offset'] = array(
'label' => t('Shadow offset'),
'description' => t('Specify the shadow offset in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'shadow_offset',
);
$properties['horizontal_space'] = array(
'label' => t('Horizontal space'),
'description' => t('Specify the horizontal space in pixels between the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'horizontal_space',
);
$properties['vertical_space'] = array(
'label' => t('Vertical space'),
'description' => t('Specify the vertical space in pixels between the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'vertical_space',
);
$properties['horizontal_offset'] = array(
'label' => t('Horizontal offset'),
'description' => t('Specify the horizontal offset in pixels between the l and r items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'horizontal_offset',
);
$properties['line_color'] = array(
'label' => t('Line color'),
'description' => t('Specify the connection lines color in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'line_color',
);
$properties['border_color'] = array(
'label' => t('Border color'),
'description' => t('Specify the border color of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'border_color',
);
$properties['border_color_hover'] = array(
'label' => t('Border color hover'),
'description' => t('Specify the border color of the items with URL in this organigram when hovering over them.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'border_color_hover',
);
$properties['background_color'] = array(
'label' => t('Background color'),
'description' => t('Specify the background color of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'background_color',
);
$properties['background_color_hover'] = array(
'label' => t('Background color hover'),
'description' => t('Specify the background color of the items with URL in this organigram when hovering over them.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'background_color_hover',
);
$properties['font_color'] = array(
'label' => t('Font color'),
'description' => t('Specify the font color of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_color',
);
$properties['font_color_hover'] = array(
'label' => t('Font color hover'),
'description' => t('Specify the font color of the items with in this organigram when hovering over them.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_color_hover',
);
$properties['font_name'] = array(
'label' => t('Font name'),
'description' => t('Specify the font name of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_name',
);
$properties['font_size'] = array(
'label' => t('Font size'),
'description' => t('Specify the font size in pixels of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'font_size',
);
$properties['line_height'] = array(
'label' => t('Line height'),
'description' => t('Specify the line height in pixels for the text in the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'line_height',
);
$properties['vertical_alignment'] = array(
'label' => t('Vertical text alignment'),
'description' => t('Specify the vertical text alignment of the items in this organigram.'),
'setter callback' => 'entity_property_verbatim_set',
'required' => FALSE,
'schema field' => 'vertical_alignment',
);
return $info;
}
function organigrams_entity_view($entity, $type, $view_mode, $langcode) {
$extrafields = field_extra_fields_get_display('organigrams', $type, $view_mode);
if (isset($extrafields['name']) && !empty($extrafields['name']['visible'])) {
$entity->content['name'] = array(
'#markup' => check_plain($entity->name),
'#weight' => $extrafields['name']['weight'],
);
}
if (isset($extrafields['description']) && !empty($extrafields['description']['visible'])) {
$entity->content['description'] = array(
'#markup' => nl2br(check_plain($entity->description)),
'#weight' => $extrafields['description']['weight'],
);
}
if (isset($extrafields['organigram']) && !empty($extrafields['organigram']['visible'])) {
$entity->unique_id = drupal_hash_base64(uniqid(mt_rand(), TRUE) . mt_rand());
$organigram = organigrams_compose_organigrams($entity, $langcode);
$entity->content['organigram'] = array(
'#markup' => render($organigram),
'#weight' => $extrafields['organigram']['weight'],
);
}
}
function organigrams_field_extra_fields() {
$return = array();
$info = entity_get_info('organigrams');
foreach (array_keys($info['bundles']) as $bundle) {
$return['organigrams'] = array(
$bundle => array(
'form' => array(
'name' => array(
'label' => t('Name'),
'description' => t('Text'),
'weight' => -6,
),
'description' => array(
'label' => t('Description'),
'description' => t('Long text'),
'weight' => -5,
),
'status' => array(
'label' => t('Published'),
'description' => t('Checkbox'),
'weight' => -4,
),
'organigram_settings' => array(
'label' => t('Organigram settings'),
'description' => t('Fieldgroup'),
'weight' => -3,
),
'item_settings' => array(
'label' => t('Organigram item settings'),
'description' => t('Fieldgroup'),
'weight' => -2,
),
'font_settings' => array(
'label' => t('Organigram font settings'),
'description' => t('Fieldgroup'),
'weight' => -1,
),
),
'display' => array(
'name' => array(
'label' => t('Name'),
'weight' => -5,
),
'description' => array(
'label' => t('Description'),
'weight' => -4,
),
'organigram' => array(
'label' => t('Organigram'),
'weight' => -3,
),
),
),
);
}
return $return;
}
function organigrams_block_info() {
$blocks = array();
foreach (organigrams_get_names() as $organigram) {
$blocks[$organigram->oid] = array(
'info' => t('Organigram: !organigram', array(
'!organigram' => $organigram->name,
)),
);
}
return $blocks;
}
function organigrams_block_view($delta = '') {
$block = array(
'subject' => NULL,
'content' => NULL,
);
$organigram = organigrams_load((int) $delta);
if (!empty($organigram) && organigrams_entity_access('view', $organigram)) {
$organigram_renderable_array = entity_view('organigrams', array(
$organigram,
), 'organigram_block');
if (is_array($organigram_renderable_array)) {
$block['content'] = drupal_render($organigram_renderable_array);
}
}
return $block;
}
function organigrams_redirect_to_view_page($organigram) {
if (empty($organigram)) {
drupal_not_found();
}
$machine_name = '';
if (is_string($organigram)) {
$machine_name = $organigram;
}
elseif (isset($organigram->machine_name)) {
$machine_name = $organigram->machine_name;
}
else {
drupal_not_found();
}
drupal_goto('organigram/' . $machine_name);
}
function organigrams_view_page($organigram) {
if (empty($organigram)) {
drupal_not_found();
}
if (!is_numeric($organigram) && is_string($organigram)) {
$organigram = organigrams_machine_name_load($organigram);
}
elseif (is_numeric($organigram)) {
$organigram = organigrams_load($organigram);
}
if (empty($organigram)) {
drupal_not_found();
}
if (!organigrams_entity_access('view', $organigram)) {
drupal_access_denied();
}
$content = entity_view('organigrams', array(
$organigram,
), 'organigram');
return $content;
}
function organigrams_rdf_mapping() {
return array(
array(
'type' => 'organigrams_item',
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
'rdftype' => array(
'skos:Concept',
),
'name' => array(
'predicates' => array(
'rdfs:label',
'skos:prefLabel',
),
),
'oid' => array(
'predicates' => array(
'skos:inScheme',
),
'type' => 'rel',
),
'parent' => array(
'predicates' => array(
'skos:broader',
),
'type' => 'rel',
),
),
),
array(
'type' => 'organigrams',
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
'rdftype' => array(
'skos:ConceptScheme',
),
'name' => array(
'predicates' => array(
'dc:title',
),
),
'description' => array(
'predicates' => array(
'rdfs:comment',
),
),
),
),
);
}
function organigrams_menu() {
$items = array();
$items['admin/structure/organigrams'] = array(
'title' => 'Organigrams',
'description' => 'Create and manage organigrams.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_overview_organigrams',
),
'access arguments' => array(
'administer organigrams',
),
'file' => 'organigrams.admin.inc',
);
$items['admin/structure/organigrams/list'] = array(
'title' => 'List organigrams',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/structure/organigrams/add'] = array(
'title' => 'Add organigram',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_organigrams',
),
'access arguments' => array(
'administer organigrams',
),
'type' => MENU_LOCAL_ACTION,
'file' => 'organigrams.admin.inc',
);
$items['admin/structure/organigrams/import'] = array(
'title' => 'Import organigram',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_import',
),
'access arguments' => array(
'administer organigrams',
),
'file' => 'organigrams.admin.inc',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/structure/organigrams/%organigrams_machine_name'] = array(
'title callback' => 'organigrams_title',
'title arguments' => array(
3,
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_overview_organigrams_items',
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams_item.admin.inc',
);
$items['admin/structure/organigrams/%organigrams_machine_name/list'] = array(
'title' => 'List items',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 2,
);
$items['admin/structure/organigrams/%organigrams_machine_name/add'] = array(
'title' => 'Add item',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_organigrams_item',
array(),
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams_item.admin.inc',
'type' => MENU_LOCAL_ACTION,
'weight' => 1,
);
$items['admin/structure/organigrams/%organigrams_machine_name/import'] = array(
'title' => 'Import items',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_import_items',
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams.admin.inc',
'type' => MENU_LOCAL_ACTION,
'weight' => 2,
);
$items['admin/structure/organigrams/%organigrams_machine_name/export'] = array(
'title' => 'Export items',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_export',
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams.admin.inc',
'type' => MENU_LOCAL_ACTION,
'weight' => 3,
);
$items['admin/structure/organigrams/%organigrams_machine_name/view'] = array(
'title' => 'View',
'page callback' => 'organigrams_redirect_to_view_page',
'page arguments' => array(
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'view',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['admin/structure/organigrams/%organigrams_machine_name/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_organigrams',
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/structure/organigrams/%organigrams_machine_name/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_confirm_delete_organigrams',
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'delete',
3,
),
'file' => 'organigrams.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 6,
);
$items['admin/structure/organigrams/%organigrams_machine_name/item/%organigrams_item'] = array(
'title callback' => 'organigrams_item_title',
'title arguments' => array(
5,
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_organigrams_item',
5,
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams_item.admin.inc',
);
$items['admin/structure/organigrams/%organigrams_machine_name/item/%organigrams_item/edit'] = array(
'title' => 'Edit item',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/structure/organigrams/%/item/%/view_organigram'] = array(
'title' => 'View organigram',
'page callback' => 'organigrams_redirect_to_organigrams_view',
'page arguments' => array(
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams_item.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => -10,
);
$items['admin/structure/organigrams/%/item/%/list'] = array(
'title' => 'List items',
'page callback' => 'organigrams_redirect_to_organigrams_item_overview',
'page arguments' => array(
3,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
3,
),
'file' => 'organigrams_item.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => -9,
);
$items['admin/structure/organigrams/%organigrams_machine_name/item/%organigrams_item/delete'] = array(
'title' => 'Delete item',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'organigrams_form_confirm_delete_organigrams_item',
5,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'delete',
5,
),
'type' => MENU_LOCAL_TASK,
'file' => 'organigrams_item.admin.inc',
'weight' => 10,
);
$items['organigram/%organigrams_machine_name'] = array(
'title callback' => 'organigrams_title',
'title arguments' => array(
1,
),
'page callback' => 'organigrams_view_page',
'page arguments' => array(
1,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'view',
1,
),
'type' => MENU_CALLBACK,
);
$items['organigram/%organigrams_machine_name/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['organigram/%/edit'] = array(
'title' => 'Edit',
'page callback' => 'organigrams_redirect_to_organigrams_item_overview',
'page arguments' => array(
1,
),
'access callback' => 'organigrams_user_access',
'access arguments' => array(
'edit',
1,
),
'file' => 'organigrams_item.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
function organigrams_permission() {
$permissions = array(
'administer organigrams' => array(
'title' => t('Administer organigrams and items'),
),
);
foreach (organigrams_get_names() as $machine_name => $organigrams_info) {
$t_args = array(
'%organigram' => $organigrams_info->name,
);
$permissions['edit organigram ' . $machine_name] = array(
'title' => t('Edit organigram and items in %organigram', $t_args),
);
$permissions['delete organigram ' . $machine_name] = array(
'title' => t('Delete organigram items from %organigram', $t_args),
);
}
return $permissions;
}
function organigrams_help($path, $arg) {
switch ($path) {
case 'admin/structure/organigrams':
$help = t('Organigrams represent visualizations of hierarchies in organizations. An organigram contains multiple items which can be related in various ways to each other.');
$help .= '<p>';
$help .= t('Organigrams have multiple display options:');
$help .= '<ol>';
$help .= '<li>' . t('<strong>Dedicated page</strong><br />A dedicated page is available at <i>/organigram/%machine_name</i>.') . '</li>';
$help .= '<li>' . t('<strong>Block</strong><br />The organigram blocks can be found in the !block_list.', array(
'!block_list' => l(t('block list'), 'admin/structure/block'),
)) . '</li>';
$help .= '<li>' . t('<strong>Token</strong> (requires <a href="@token_filter">Token filter</a>)<br />Tokens can be used to insert organigrams in content fields. The token names are displayed beneath the names in this list and look like this: <i>[organigrams:%machine_name]</i>. Just copy and paste this token in your content to insert the organigram.', array(
'@token_filter' => 'https://www.drupal.org/project/token_filter',
)) . '</li>';
$help .= '</ol></p>';
return '<p>' . $help . '</p>';
}
}
function organigrams_library() {
$libraries = array();
$libraries['orgchart'] = array(
'title' => 'Orgchart',
'version' => '1.14',
'js' => array(
drupal_get_path('module', 'organigrams') . '/libraries/orgchart/orgchart.js' => array(),
),
'dependencies' => array(
array(
'system',
'jquery',
),
),
);
return $libraries;
}
function organigrams_libraries_info() {
$libraries = array();
$libraries['excanvas'] = array(
'name' => 'ExplorerCanvas',
'vendor url' => 'https://github.com/arv/explorercanvas',
'download url' => 'https://github.com/arv/ExplorerCanvas/archive/aa989ea9d9bac748638f7c66b0fc88e619715da6.zip',
'version' => 'aa989ea9d9bac748638f7c66b0fc88e619715da6',
'files' => array(
'js' => array(
'excanvas.js',
),
),
);
$libraries['colorpicker'] = array(
'name' => 'ColorPicker',
'vendor url' => 'https://github.com/evoluteur/colorpicker/tree/233e15e4368b0d1eb30f8036a1f5970f09e8ed9e',
'download url' => 'https://github.com/evoluteur/colorpicker/archive/233e15e4368b0d1eb30f8036a1f5970f09e8ed9e.zip',
'version' => '233e15e4368b0d1eb30f8036a1f5970f09e8ed9e',
'files' => array(
'js' => array(
'js/evol-colorpicker.min.js',
),
'css' => array(
'css/evol-colorpicker.min.css',
),
),
);
return $libraries;
}
function organigrams_theme() {
return array(
'organigrams_form_overview_organigrams' => array(
'render element' => 'form',
'path' => drupal_get_path('module', 'organigrams') . '/theme',
'file' => 'organigrams.theme.inc',
),
'organigrams_form_overview_organigrams_items' => array(
'render element' => 'form',
'path' => drupal_get_path('module', 'organigrams') . '/theme',
'file' => 'organigrams.theme.inc',
),
'organigrams' => array(
'render element' => 'elements',
'base hook' => 'entity',
'template' => 'organigrams',
'path' => drupal_get_path('module', 'organigrams') . '/theme',
),
);
}
function organigrams_user_access($operation, $object, $account = NULL) {
static $valid_operations = array(
'view',
'edit',
'delete',
);
if (!($granted = user_access('administer organigrams', $account)) && in_array($operation, $valid_operations)) {
if (is_string($object)) {
$object = organigrams_machine_name_load($object);
}
elseif (is_numeric($object)) {
$object = organigrams_load($object);
}
if ($operation == 'view' && $object->status) {
$granted = user_access('access content', $account);
}
else {
if ($operation == 'view') {
$operation = 'edit';
}
$machine_name = isset($object->machine_name) ? $object->machine_name : $object->organigrams_machine_name;
$granted = user_access("{$operation} organigram {$machine_name}", $account);
}
}
return $granted;
}
function organigrams_title($organigrams) {
return $organigrams->name;
}
function organigrams_item_title($organigrams_item) {
return $organigrams_item->name;
}
function organigrams_entity_access($op, $entity, $account = NULL) {
return organigrams_user_access($op, $entity, $account);
}
function organigrams_metadata_organigrams_item_setter($organigrams_item, $name, $value) {
switch ($name) {
case 'organigram':
$organigrams = organigrams_load($value);
$organigrams_item->organigrams_machine_name = $organigrams->machine_name;
return $organigrams_item->oid = $value;
case 'parent':
return $organigrams_item->parent = $value;
}
}
function organigrams_compose_organigrams($organigram, $langcode = NULL) {
$output = array();
if (!$organigram) {
return $output;
}
$organigram_settings = array(
'organigram_settings' => (object) array(
'canvas_width' => $organigram->canvas_width,
'canvas_height' => $organigram->canvas_height,
'center' => $organigram->center,
'fit' => $organigram->fit,
'node_width' => $organigram->node_width,
'node_height' => $organigram->node_height,
'top_radius' => $organigram->top_radius,
'bottom_radius' => $organigram->bottom_radius,
'shadow_offset' => $organigram->shadow_offset,
'horizontal_space' => $organigram->horizontal_space,
'vertical_space' => $organigram->vertical_space,
'horizontal_offset' => $organigram->horizontal_offset,
'line_color' => $organigram->line_color,
'border_color' => $organigram->border_color,
'border_color_hover' => $organigram->border_color_hover,
'background_color' => $organigram->background_color,
'background_color_hover' => $organigram->background_color_hover,
'font_color' => $organigram->font_color,
'font_color_hover' => $organigram->font_color_hover,
'font_name' => $organigram->font_name,
'font_size' => $organigram->font_size,
'line_height' => $organigram->line_height,
'vertical_alignment' => $organigram->vertical_alignment,
),
'nodes' => array(),
);
$organigram_tree = organigrams_get_tree($organigram->oid, 0, NULL, TRUE);
if (empty($organigram_tree)) {
return $output;
}
$hierarchical_list = array();
foreach ($organigram_tree as $tree_item) {
$parent = 0;
if (!empty($tree_item->parent)) {
$parent = $tree_item->parent;
}
if (!isset($hierarchical_list[$parent])) {
$hierarchical_list[$parent] = array();
}
$hierarchical_list[$parent][] = $tree_item;
}
$output = array(
'#theme' => 'item_list',
'#type' => 'ul',
'#items' => organigrams_generate_items_list($hierarchical_list),
);
$output['#attached']['libraries_load'][] = array(
'excanvas',
);
$output['#attached']['library'][] = array(
'organigrams',
'orgchart',
);
$output['#attached']['js'][] = drupal_get_path('module', 'organigrams') . '/js/organigrams.js';
$output['#attached']['js'][] = array(
'data' => array(
'organigrams' => array(
'organigrams' => array(
$organigram->unique_id => $organigram_settings,
),
),
),
'type' => 'setting',
);
return $output;
}
function organigrams_generate_items_list($hierarchical_list = array(), $parent = 0) {
$ul_list = array();
if (isset($hierarchical_list[$parent])) {
foreach ($hierarchical_list[$parent] as $item) {
$html_name = str_replace('[br]', '<br />', check_plain($item->name));
if (!empty($item->url)) {
$attributes = array(
'html' => TRUE,
'attributes' => array(),
);
if (strtolower(substr($item->url, 0, 4)) == 'http') {
$attributes['attributes']['target'] = '_blank';
}
$html_name = l($html_name, $item->url, $attributes);
}
$ul_list[] = array(
'data' => $html_name,
'children' => organigrams_generate_items_list($hierarchical_list, $item->iid),
'item_id' => check_plain($item->iid),
'parent' => empty($item->parent) ? '' : check_plain($item->parent),
'position' => check_plain($item->position),
'text' => decode_entities(check_plain($item->name)),
'bold_border' => check_plain($item->bold_border),
'url' => decode_entities(check_plain($item->url)),
'border_color' => check_plain($item->border_color),
'border_color_hover' => check_plain($item->border_color_hover),
'background_color' => check_plain($item->background_color),
'background_color_hover' => check_plain($item->background_color_hover),
'font_color' => check_plain($item->font_color),
'font_color_hover' => check_plain($item->font_color_hover),
'image_url' => check_plain($item->image_url),
'image_alignment' => check_plain($item->image_alignment),
);
}
}
return $ul_list;
}
function organigrams_get_names() {
$names = db_query('SELECT name, machine_name, oid FROM {organigrams_data}')
->fetchAllAssoc('machine_name');
return $names;
}
function organigrams_get_organigrams() {
return organigrams_load_multiple(FALSE, array());
}
function organigrams_get_tree($oid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) {
$children =& drupal_static(__FUNCTION__, array());
$parents =& drupal_static(__FUNCTION__ . ':parents', array());
$organigrams_items =& drupal_static(__FUNCTION__ . ':organigrams_items', array());
if (!isset($children[$oid])) {
$children[$oid] = array();
$parents[$oid] = array();
$organigrams_items[$oid] = array();
$query = db_select('organigrams_item_data', 'oid');
$result = $query
->addTag('translatable')
->addTag('organigrams_item_access')
->fields('oid')
->condition('oid.oid', $oid)
->orderBy('oid.weight')
->orderBy('oid.name')
->execute();
foreach ($result as $organigrams_item) {
if (($organigrams_item_children =& $children[$oid][$organigrams_item->parent]) === NULL) {
$organigrams_item_children = array();
}
if (($organigrams_item_parents =& $parents[$oid][$organigrams_item->iid]) === NULL) {
$organigrams_item_parents = array();
}
$organigrams_item_children[] = $organigrams_item->iid;
$organigrams_item_parents[] = $organigrams_item->parent;
$organigrams_items[$oid][$organigrams_item->iid] = $organigrams_item;
}
}
if ($load_entities) {
$organigrams_item_entities = organigrams_item_load_multiple(array_keys($organigrams_items[$oid]));
}
$max_depth = isset($max_depth) ? $max_depth : count($children[$oid]);
$tree = array();
$process_parents = array(
$parent,
);
while (count($process_parents)) {
$parent = array_pop($process_parents);
$depth = count($process_parents);
if ($max_depth > $depth && !empty($children[$oid][$parent])) {
$has_children = FALSE;
$child = current($children[$oid][$parent]);
do {
if (empty($child)) {
break;
}
$organigrams_item = $organigrams_items[$oid][$child];
if ($load_entities && isset($organigrams_item_entities[$child])) {
$organigrams_item = $organigrams_item_entities[$child];
}
$organigrams_item->depth = $depth;
$tree[] = $organigrams_item;
if (!empty($children[$oid][$organigrams_item->iid])) {
$has_children = TRUE;
$process_parents[] = $parent;
$process_parents[] = $organigrams_item->iid;
reset($children[$oid][$organigrams_item->iid]);
next($children[$oid][$parent]);
break;
}
} while ($child = next($children[$oid][$parent]));
if (!$has_children) {
reset($children[$oid][$parent]);
}
}
}
return $tree;
}
function organigrams_machine_name_load($name) {
$organigrams = organigrams_load_multiple(FALSE, array(
'machine_name' => $name,
));
return reset($organigrams);
}
function organigrams_check_machine_name($name) {
$index = 0;
$new_name = $name;
while (organigrams_machine_name_load($new_name)) {
$new_name = $name . '_' . $index++;
}
return $new_name;
}
function organigrams_get_item_by_name($name) {
return organigrams_item_load_multiple(FALSE, array(
'name' => trim($name),
));
}
function organigrams_load($oid) {
$organigrams = FALSE;
if (is_numeric($oid)) {
$organigrams = organigrams_load_multiple(array(
$oid,
), array());
$organigrams = reset($organigrams);
}
return $organigrams;
}
function organigrams_item_load($iid) {
$organigrams_item = FALSE;
if (is_numeric($iid)) {
$organigrams_items = organigrams_item_load_multiple(array(
$iid,
), array());
$organigrams_item = reset($organigrams_items);
}
return $organigrams_item;
}
function organigrams_load_multiple($oids = array(), $conditions = array()) {
return entity_load('organigrams', $oids, $conditions);
}
function organigrams_item_load_multiple($iids = array(), $conditions = array()) {
return entity_load('organigrams_item', $iids, $conditions);
}
function organigrams_save($organigrams) {
$organigrams->name = trim($organigrams->name);
if (!empty($organigrams->oid)) {
if (!isset($organigrams->original)) {
$organigrams->original = entity_load_unchanged('organigrams', $organigrams->oid);
}
$organigrams->old_machine_name = $organigrams->original->machine_name;
}
if (!isset($organigrams->module)) {
$organigrams->module = 'organigrams';
}
field_attach_presave('organigrams', $organigrams);
module_invoke_all('organigrams_presave', $organigrams);
module_invoke_all('entity_presave', $organigrams, 'organigrams');
$status = NULL;
if (!empty($organigrams->oid) && !empty($organigrams->name)) {
$status = drupal_write_record('organigrams_data', $organigrams, 'oid');
if ($organigrams->old_machine_name != $organigrams->machine_name) {
field_attach_rename_bundle('organigrams_item', $organigrams->old_machine_name, $organigrams->machine_name);
}
field_attach_update('organigrams', $organigrams);
module_invoke_all('organigrams_update', $organigrams);
module_invoke_all('entity_update', $organigrams, 'organigrams');
}
elseif (empty($organigrams->oid)) {
$status = drupal_write_record('organigrams_data', $organigrams);
field_attach_create_bundle('organigrams_item', $organigrams->machine_name);
field_attach_insert('organigrams', $organigrams);
module_invoke_all('organigrams_insert', $organigrams);
module_invoke_all('entity_insert', $organigrams, 'organigrams');
}
unset($organigrams->original);
unset($organigrams->old_machine_name);
cache_clear_all();
entity_get_controller('organigrams')
->resetCache(array(
$organigrams->oid,
));
return $status;
}
function organigrams_item_save($organigrams_item) {
$organigrams_item->name = trim($organigrams_item->name);
if (!isset($organigrams_item->organigrams_machine_name)) {
$organigrams = organigrams_load($organigrams_item->oid);
$organigrams_item->organigrams_machine_name = $organigrams->machine_name;
}
if (!empty($organigrams_item->iid) && !isset($organigrams_item->original)) {
$organigrams_item->original = entity_load_unchanged('organigrams_item', $organigrams_item->iid);
}
field_attach_presave('organigrams_item', $organigrams_item);
module_invoke_all('organigrams_item_presave', $organigrams_item);
module_invoke_all('entity_presave', $organigrams_item, 'organigrams_item');
if (empty($organigrams_item->iid)) {
$op = 'insert';
$status = drupal_write_record('organigrams_item_data', $organigrams_item);
field_attach_insert('organigrams_item', $organigrams_item);
}
else {
$op = 'update';
$status = drupal_write_record('organigrams_item_data', $organigrams_item, 'iid');
field_attach_update('organigrams_item', $organigrams_item);
}
organigrams_items_static_reset();
module_invoke_all("organigrams_item_{$op}", $organigrams_item);
module_invoke_all("entity_{$op}", $organigrams_item, 'organigrams_item');
unset($organigrams_item->original);
return $status;
}
function organigrams_delete($oid) {
$organigrams = organigrams_load($oid);
$transaction = db_transaction();
try {
$result = db_query('SELECT iid FROM {organigrams_item_data} WHERE oid = :oid', array(
':oid' => $oid,
))
->fetchCol();
foreach ($result as $iid) {
organigrams_item_delete($iid);
}
db_delete('organigrams_data')
->condition('oid', $oid)
->execute();
field_attach_delete_bundle('organigrams_item', $organigrams->machine_name);
module_invoke_all('organigrams_delete', $organigrams);
module_invoke_all('entity_delete', $organigrams, 'organigrams');
cache_clear_all();
entity_get_controller('organigrams')
->resetCache();
return SAVED_DELETED;
} catch (Exception $ex) {
$transaction
->rollback();
watchdog_exception('organigrams', $ex);
throw $ex;
}
}
function organigrams_item_delete($iid) {
$transaction = db_transaction();
try {
$iids = array(
$iid,
);
while (!empty($iids)) {
$orphans = array();
foreach ($iids as $iid) {
$orphans = array_keys(organigrams_item_get_children($iid));
if (($organigrams_item = organigrams_item_load($iid)) !== NULL) {
db_delete('organigrams_item_data')
->condition('iid', $iid)
->execute();
field_attach_delete('organigrams_item', $organigrams_item);
module_invoke_all('organigrams_item_delete', $organigrams_item);
module_invoke_all('entity_delete', $organigrams_item, 'organigrams_item');
organigrams_items_static_reset();
}
}
$iids = $orphans;
}
} catch (Exception $ex) {
$transaction
->rollback();
watchdog_exception('organigrams', $ex);
throw $ex;
}
}
function organigrams_item_get_children($iid) {
$children =& drupal_static(__FUNCTION__, array());
if ($iid && !isset($children[$iid])) {
$query = db_select('organigrams_item_data', 'oid');
$query
->addTag('organigrams_item_access');
$query
->addField('oid', 'iid');
$query
->condition('oid.parent', $iid);
$query
->orderBy('oid.weight');
$query
->orderBy('oid.name');
$iids = $query
->execute()
->fetchCol();
$children[$iid] = organigrams_item_load_multiple($iids);
}
return isset($children[$iid]) ? $children[$iid] : array();
}
function organigrams_item_get_parent($iid) {
$parent_organigrams_item = NULL;
if (($organigrams_item = organigrams_item_load($iid)) !== NULL && !empty($organigrams_item->parent)) {
$parent_organigrams_item = organigrams_item_load($organigrams_item->parent);
}
return $parent_organigrams_item;
}
function organigrams_item_get_suitable_parents_options($iid, $oid) {
$parent_relation_options = array();
$children = organigrams_get_tree($oid, $iid);
$excluded_iids = array();
foreach ($children as $child) {
$excluded_iids[] = $child->iid;
}
$excluded_iids[] = $iid;
foreach (organigrams_get_tree($oid) as $tree_item) {
if (!in_array($tree_item->iid, $excluded_iids)) {
$parent_relation_options[$tree_item->iid] = str_repeat('-', $tree_item->depth) . filter_xss_admin($tree_item->name);
}
}
return $parent_relation_options;
}
function organigrams_import_items($oid, $import) {
$organigram = organigrams_load($oid);
if (empty($organigram)) {
watchdog('organigrams', 'Failed importing organigram items because no organigram was found.');
return t('Failed importing organigram items because no organigram was found.');
}
if (empty($import)) {
watchdog('organigrams', 'Failed importing organigram items because no import was found.');
return t('Failed importing organigram items because no import was found.');
}
$old_data = organigrams_get_tree($oid, 0, NULL, TRUE);
foreach ($old_data as $old_item) {
organigrams_item_delete($old_item->iid);
}
$needs_resave = array();
foreach ($import as $new_item) {
$orig_iid = $new_item->iid;
if (isset($needs_resave[$orig_iid])) {
unset($needs_resave[$orig_iid]);
}
unset($new_item->iid);
$new_item->oid = $oid;
$new_item->organigrams_machine_name = $organigram->machine_name;
$result = organigrams_item_save($new_item);
if (!$result) {
watchdog('organigrams', 'An error occurred importing item %name. Old values are restored.', array(
'%name' => $new_item->name,
));
organigrams_import_items($oid, $old_data);
return t('An error occurred importing item %name. Old values are restored.', array(
'%name' => $new_item->name,
));
}
foreach ($import as $key => $value) {
if ($value->parent == $orig_iid) {
$import[$key]->parent = $new_item->iid;
$needs_resave[$value->iid] = $import[$key];
}
}
}
if (!empty($needs_resave)) {
foreach ($needs_resave as $item) {
organigrams_item_save($item);
}
}
watchdog('organigrams', 'Successfully imported items in organigram %name', array(
'%name' => $organigram->name,
));
return TRUE;
}
function organigrams_token_info() {
$types['organigrams'] = array(
'name' => t('Organigrams'),
'description' => t('Tokens for inserting organigram blocks.'),
);
$organigrams = array();
foreach (organigrams_get_names() as $organigram) {
$organigrams[$organigram->machine_name] = array(
'name' => t('Organigram: !organigram', array(
'!organigram' => $organigram->name,
)),
'description' => t('Insert the organigram !organigram.', array(
'!organigram' => $organigram->name,
)),
);
}
return array(
'types' => $types,
'tokens' => array(
'organigrams' => $organigrams,
),
);
}
function organigrams_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'organigrams') {
foreach ($tokens as $name => $original) {
$organigram = organigrams_machine_name_load($name);
if (!empty($organigram)) {
$organigram_renderable_array = entity_view('organigrams', array(
$organigram,
), 'organigram_block');
$replacements[$original] = render($organigram_renderable_array);
}
}
}
return $replacements;
}
function organigrams_items_static_reset() {
drupal_static_reset('organigrams_item_get_children');
drupal_static_reset('organigrams_get_tree');
drupal_static_reset('organigrams_get_tree:parents');
drupal_static_reset('organigrams_get_tree:organigrams_items');
}
class OrganigramsController extends EntityAPIController {
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
$query
->addTag('translatable');
$query
->orderBy('base.weight');
$query
->orderBy('base.name');
return $query;
}
}
class OrganigramsItemController extends EntityAPIController {
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
$query
->addTag('translatable');
$query
->addTag('organigrams_item_access');
if (isset($conditions['name'])) {
$query_conditions =& $query
->conditions();
foreach ($query_conditions as $key => $condition) {
if ($condition['field'] == 'base.name') {
$query_conditions[$key]['operator'] = 'LIKE';
$query_conditions[$key]['value'] = db_like($query_conditions[$key]['value']);
}
}
}
$query
->innerJoin('organigrams_data', 'o', 'base.oid = o.oid');
$query
->addField('o', 'machine_name', 'organigrams_machine_name');
return $query;
}
protected function cacheGet($ids, $conditions = array()) {
$organigrams_items = parent::cacheGet($ids, $conditions);
foreach ($organigrams_items as $organigrams_item) {
$organigrams_item_values = (array) $organigrams_item;
if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($organigrams_item_values['name']))) {
unset($organigrams_items[$organigrams_item->iid]);
}
}
return $organigrams_items;
}
}
function organigrams_entity_presave($entity, $type) {
switch ($type) {
case 'organigrams_item':
if (module_exists('rules')) {
rules_invoke_event('organigrams_item_presave--' . $entity->organigrams_machine_name, $entity);
rules_invoke_event('organigrams_item_presave', $entity);
}
break;
}
}
function organigrams_entity_update($entity, $type) {
switch ($type) {
case 'organigrams_item':
if (module_exists('rules')) {
rules_invoke_event('organigrams_item_update--' . $entity->organigrams_machine_name, $entity);
rules_invoke_event('organigrams_item_update', $entity);
}
break;
}
}
function organigrams_entity_insert($entity, $type) {
switch ($type) {
case 'organigrams_item':
if (module_exists('rules')) {
rules_invoke_event('organigrams_item_insert--' . $entity->organigrams_machine_name, $entity);
rules_invoke_event('organigrams_item_insert', $entity);
}
break;
}
}
function organigrams_entity_delete($entity, $type) {
switch ($type) {
case 'organigrams_item':
if (module_exists('rules')) {
rules_invoke_event('organigrams_item_delete--' . $entity->organigrams_machine_name, $entity);
rules_invoke_event('organigrams_item_delete', $entity);
}
break;
}
}