/[drupal]/contributions/modules/smartqueue_og/smartqueue_og.module
ViewVC logotype

Diff of /contributions/modules/smartqueue_og/smartqueue_og.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3, Wed Jul 30 13:46:28 2008 UTC revision 1.1.2.4, Fri Aug 1 01:48:03 2008 UTC
# Line 2  Line 2 
2  /**  /**
3   * Implementation of hook_nodequeue_info()   * Implementation of hook_nodequeue_info()
4   */   */
5    
6    function smartqueue_og_perm() {
7      return array('manipulate og node queues');
8    }
9  function smartqueue_og_nodequeue_info() {  function smartqueue_og_nodequeue_info() {
10    return array('smartqueue_og' =>    return array('smartqueue_og' =>
11      array(      array(
# Line 18  function smartqueue_og_nodequeue_form($q Line 22  function smartqueue_og_nodequeue_form($q
22    $form['eligible_group_types'] = array(    $form['eligible_group_types'] = array(
23      '#type' => 'checkboxes',      '#type' => 'checkboxes',
24      '#title' => t("Group types which are eligible for a Node Queue"),      '#title' => t("Group types which are eligible for a Node Queue"),
25      '#description' => t("Select the Organic Group types for which node queues be automatically created."),      '#description' => t("Select the Organic Group types for which node queues should be automatically created."),
26      '#options' => $og_types,      '#options' => $og_types,
27      '#default_value' => variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array()),      '#default_value' => variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array()),
28      '#weight' => 1,      '#weight' => 1,
29    );    );
30    $form['manipulate_by'] = array(    //TODO: Fix these radios
31      $form['manipulate_restrict'] = array(
32        '#type' => 'radios',
33        '#title' => t('Who can access manipulate this node queue?'),
34        '#options' => array(
35          'members' => t('All Groups Members can manipulate this node queue.'),
36          'admins' => t('Only Group Administrators can manipulate this node queue.'),
37        ),
38        //'#default_value' => variable_get('smartqueue_og_manipulate_restrict'. $queue->qid, array()),
39    );    );
40      //
41    
42      $form['node_restrict'] = array(
43        '#type' => 'checkbox',
44        '#title' => t('Restrict to posts within a group'),
45        '#description'=> t("When checked, only posts which are part of the Organic Group can be added to the group's node queue."),
46        '#default_value' => variable_get('smartqueue_og_node_restrict_'. $queue->qid, array()),
47      );
48    
49    $form['submit_actions'] = array(    $form['submit_actions'] = array(
50      '#type' => 'fieldset',      '#type' => 'fieldset',
51      '#title' => t('Batch operations to perform when this form is submitted:'),      '#title' => t('Batch operations to perform when this form is submitted:'),
# Line 54  function smartqueue_og_nodequeue_form($q Line 73  function smartqueue_og_nodequeue_form($q
73    
74  function smartqueue_og_nodequeue_form_submit(&$queue, $form_values) {  function smartqueue_og_nodequeue_form_submit(&$queue, $form_values) {
75    variable_set('smartqueue_og_'. $queue->qid . '_eligible_group_types', $form_values['eligible_group_types']);    variable_set('smartqueue_og_'. $queue->qid . '_eligible_group_types', $form_values['eligible_group_types']);
76  if ($form_values['submit_actions']['create'] == 1) {    variable_set('smartqueue_og_node_restrict_'. $queue->qid, $form_values['node_restrict']);
77    $eligible_groups = smartqueue_og_eligible_groups();    variable_set('smartqueue_og_manipulate_restrict'. $queue->qid, $form_values['manipulate_restrict']);
78    $existing_subqueues = smartqueue_og_existing_subqueues();    if ($form_values['submit_actions']['create'] == 1) {
79    $groups_without_subqueues = array_diff_key($eligible_groups, $existing_subqueues);      $eligible_groups = smartqueue_og_eligible_groups();
80    smartqueue_og_batch_add_subqueues($groups_without_subqueues);      $existing_subqueues = smartqueue_og_existing_subqueues();
81        $groups_without_subqueues = array_diff_key($eligible_groups, $existing_subqueues);
82    //get eligible gorups      smartqueue_og_batch_add_subqueues($groups_without_subqueues);
83    //get existing subqueues    }
   //get groups without subquques  
   //batch add  
 /*  
     $groups = smartqueue_og_get_eligible_groups();  
     $existing_subqueues = smartqueue_users_get_all_user_subqueues();  
     $accounts_without_subqueues = array_diff_key($accounts, $existing_subqueues);  
     smartqueue_users_batch_add_subqueues($accounts_without_subqueues);  
 */  
 }  
84    
85    switch ($form_values['values']['submit_actions']['destroy']) {    switch ($form_values['values']['submit_actions']['destroy']) {
86      case 'delete':      case 'delete':
# Line 123  function smartqueue_og_all_group_subqueu Line 133  function smartqueue_og_all_group_subqueu
133  }  }
134    
135  function smartqueue_og_eligible_group_types() {  function smartqueue_og_eligible_group_types() {
136    
137    $var = variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array());    $var = variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array());
138    return array_intersect($var, og_get_types('group'));    return array_intersect($var, og_get_types('group'));
139  }  }
140    
141  function smartqueue_og_eligible_group_type($type) {  function smartqueue_og_eligible_group_type($type) {
142    if (in_array(variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array()), $type)) {     //drupal_set_message(dprint_r(debug_backtrace(), TRUE));
143       drupal_set_message("eligible called with type $type");
144       //TODO: verify this syntax when I get an internet conectio
145      if (in_array($type, variable_get('smartqueue_og_'. smartqueue_og_get_qid() .'_eligible_group_types', array()))) {
146      return TRUE;      return TRUE;
147    }    }
148    else {    else {
# Line 142  function smartqueue_og_form_alter($form_ Line 156  function smartqueue_og_form_alter($form_
156      //drupal_set_message(dprint_r($form, TRUE));      //drupal_set_message(dprint_r($form, TRUE));
157    }    }
158  }  }
159    
160  function smartqueue_og_nodequeue_subqueues(&$queue, $node) {  function smartqueue_og_nodequeue_subqueues(&$queue, $node) {
161    global $user;    global $user;
162    if (!is_array($user->og_groups)) {    //TODO: proof of concept. replace these hard coded values with configurable variables
163      $only_admins = 1;
164      $only_in_group = 1;
165      if (empty($user->og_groups) || !user_access('manipulate og node queues')) {
166      return;      return;
167    }    }
168    $references = array_keys($user->og_groups);    $groups = $user->og_groups;
169    //$subqueues = nodequeue_load_subqueues_by_reference(array($qid => $group_nids));  
170    drupal_set_message("SQ_OG returns". dprint_r($references, TRUE));    if ($only_admins) {
171    return $references;      foreach ($user->og_groups as $nid => $this_group) {
172          if ($this_group['is_admin'] != 1) {
173    //Does the current user have access to manipulate queues?          unset($groups[$nid]);
174    //is the current user a member of a (matching?) group?        }
175        }
176    //is this a group node?    }
177    //are there any subqueues associated with it?  
178    //Are members allowed to edit the nodequeue or are group admins?  
179    //    //only add posts already in an organic group
180    //Later: Does this nodequeue (or og?) specify whether posts in this nodequeue are restricted to those within the group or not?    if ($only_in_group) {
181        if (!is_array($node->og_groups_both)) {
182          return;
183        }
184        $groups = array_intersect_key($groups, $node->og_groups_both);
185      }
186    
187      $groups = array_keys($groups);
188      drupal_set_message("SQ_OG returns". dprint_r($groups, TRUE));
189      return $groups;
190  }  }
191    
192  function smartqueue_og_queue_access($queue, $account = NULL) {  function smartqueue_og_queue_access($queue, $account = NULL) {

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.2