diff --git a/user_relationships_panels/plugins/access/ur_relationship.inc b/user_relationships_panels/plugins/access/ur_relationship.inc new file mode 100644 index 0000000..e869c72 --- /dev/null +++ b/user_relationships_panels/plugins/access/ur_relationship.inc @@ -0,0 +1,94 @@ + t("User Relationship"), + 'description' => t('Control access based on relationship between two users'), + 'callback' => 'user_relationships_panels_ctools_access_check', + 'default' => array('ur_relationship' => array()), + 'settings form' => 'user_relationships_panels_ctools_access_settings', + 'summary' => 'user_relationships_panels_ctools_access_summary', + 'required context' => array( + new ctools_context_required(t('First User'), 'user'), + new ctools_context_required(t('Second User'), 'user') + ), +); + +/** + * Settings form for the user relationships access plugin + */ +function user_relationships_panels_ctools_access_settings(&$form, &$form_state, $conf) { + + $relationships = user_relationship_types_load(); + $options = array(); + foreach ($relationships as $key => $relationship) { + $options[$key] = $relationship->name; + } + + $form['settings']['ur_relationship'] = array( + '#type' => 'checkboxes', + '#options' => $options, + '#title' => t('Allow if relationship between users is'), + '#default_value' => $conf['ur_relationship'], + ); +} + +/** + * Check for access based on relationship. + */ +function user_relationships_panels_ctools_access_check($conf, $context) { + + if (empty($context) || count($context) != 2 || empty($context[0]->data) || empty($context[1]->data)) { + return FALSE; + } + $account1 = $context[0]->data; + $account2 = $context[1]->data; + + $relationships = user_relationship_load(array("between" => array($account1->uid, $account2->uid))); + foreach ($relationships as $relationship) { + // If this relationship is in the conf file + if (!empty($conf['ur_relationship'][$relationship->rtid])) { + // If no approval required, or approval has been granted + if ( !$relationship->requires_approval || ($relationship->requires_approval && $relationship->approved) ) { + // If not a oneway, or else it is a oneway requested by this user + if (!$relationship->is_oneway || ($relationship->requester_id == $account1->uid)) { + return TRUE; + } + } + } + } + return FALSE; + +} + + +/** + * Provide a summary description based upon the checked relationships. + */ +function user_relationships_panels_visibility_ctools_access_summary($conf, $context) { + if (!isset($conf['ur_relationship'])) { + return t('Error, unset permission'); + } + + $relationship_types = user_relationship_types_load(); + + $names = array(); + foreach (array_filter($conf['ur_relationship']) as $rtid) { + $names[] = check_plain($relationship_types[$rtid]->name); + } + + if (empty($names)) { + return t('@id1 can have any relationship to @id2', array('@id1' => $context[0]->identifier, '@id2' => $context[1]->identifier)); + } + + return format_plural(count($names), '@id1 must have relationship "@rtids" to @id2', '@id1 can have relationships: "@rtids" to @id2', array('@rtids' => implode(', ', $names), '@id1' => $context[0]->identifier, '@id2' => $context[1]->identifier)); +} + + diff --git a/user_relationships_panels/user_relationships_panels.info b/user_relationships_panels/user_relationships_panels.info new file mode 100644 index 0000000..c16f8c4 --- /dev/null +++ b/user_relationships_panels/user_relationships_panels.info @@ -0,0 +1,7 @@ +name = UR-Panels +description = "Provide contexts for panels panes and page visibility based on relationships between users." +core = 7.x +dependencies[] = user_relationships +dependencies[] = ctools +dependencies[] = panels +package = "User Relationships" diff --git a/user_relationships_panels/user_relationships_panels.module b/user_relationships_panels/user_relationships_panels.module new file mode 100644 index 0000000..d8f69f0 --- /dev/null +++ b/user_relationships_panels/user_relationships_panels.module @@ -0,0 +1,13 @@ + t("User Relationship"), - 'description' => t('Control access based on relationship between two users'), - 'callback' => 'user_relationships_panels_visibility_ctools_access_check', - 'default' => array('ur_relationship' => array()), - 'settings form' => 'user_relationships_panels_visibility_ctools_access_settings', - 'summary' => 'user_relationships_panels_visibility_ctools_access_summary', - 'required context' => array( - new ctools_context_required(t('First User'), 'user'), - new ctools_context_required(t('Second User'), 'user')), - ); - - return $args; -} - -/** - * Settings form for the user relationships access plugin - */ -function user_relationships_panels_visibility_ctools_access_settings(&$form, &$form_state, $conf) { - - $relationships = user_relationships_types_load(); - $options = array(); - foreach ($relationships as $key => $relationship) { - $options[$key] = $relationship->name; - } - - $form['settings']['ur_relationship'] = array( - '#type' => 'checkboxes', - '#options' => $options, - '#title' => t('Allow if relationship between users is'), - '#default_value' => $conf['ur_relationship'], - ); -} - -/** - * Check for access based on relationship. - */ -function user_relationships_panels_visibility_ctools_access_check($conf, $context) { - - if (empty($context) || count($context) != 2 || empty($context[0]->data) || empty($context[1]->data)) { - return FALSE; - } - $account1 = $context[0]->data; - $account2 = $context[1]->data; - - $relationships = user_relationships_load(array("between" => array($account1->uid, $account2->uid))); - foreach ($relationships as $relationship) { - // If this relationship is in the conf file - if (!empty($conf['ur_relationship'][$relationship->rtid])) { - // If no approval required, or approval has been granted - if ( !$relationship->requires_approval || ($relationship->requires_approval && $relationship->approved) ) { - // If not a oneway, or else it is a oneway requested by this user - if (!$relationship->is_oneway || ($relationship->requester_id == $account1->uid)) { - return TRUE; - } - } - } - } - return FALSE; - -} - - -/** - * Provide a summary description based upon the checked relationships. - */ -function user_relationships_panels_visibility_ctools_access_summary($conf, $context) { - if (!isset($conf['ur_relationship'])) { - return t('Error, unset permission'); - } - - $relationship_types = user_relationships_types_load(); - - $names = array(); - foreach (array_filter($conf['ur_relationship']) as $rtid) { - $names[] = check_plain($relationship_types[$rtid]->name); - } - - if (empty($names)) { - return t('@id1 can have any relationship to @id2', array('@id1' => $context[0]->identifier, '@id2' => $context[1]->identifier)); - } - - return format_plural(count($names), '@id1 must have relationship "@rtids" to @id2', '@id1 can have relationships: "@rtids" to @id2', array('@rtids' => implode(', ', $names), '@id1' => $context[0]->identifier, '@id2' => $context[1]->identifier)); -} - - diff --git a/user_relationships_panels_visibility/user_relationships_panels_visibility.info b/user_relationships_panels_visibility/user_relationships_panels_visibility.info deleted file mode 100644 index 0118fc0..0000000 --- a/user_relationships_panels_visibility/user_relationships_panels_visibility.info +++ /dev/null @@ -1,6 +0,0 @@ -name = UR-Panels Visibility -description = "Provide visibility for panels panes and pages based on User Relationships" -dependencies[] = user_relationships -dependencies[] = ctools -core = 6.x -package = "User Relationships" diff --git a/user_relationships_panels_visibility/user_relationships_panels_visibility.module b/user_relationships_panels_visibility/user_relationships_panels_visibility.module deleted file mode 100644 index 7a34604..0000000 --- a/user_relationships_panels_visibility/user_relationships_panels_visibility.module +++ /dev/null @@ -1,14 +0,0 @@ -