$account->name, '!queue' => $queue->title))); return drupal_get_form('smartqueue_users_subqueue_edit_form', $account, $queue); } /** * Delete the supplied subqueue from the supplied queue that belongs * to the supplied user. */ function smartqueue_users_subqueue_remove($account, $queue, $subqueue) { _smartqueue_users_sanity_check($account, $queue, $subqueue); return drupal_get_form('smartqueue_users_subqueue_remove_form', $account, $subqueue); } /** * Edit the supplied subqueue in the supplied queue that belongs to * the supplied user. */ function smartqueue_users_subqueue_edit($account, $queue, $subqueue) { _smartqueue_users_sanity_check($account, $queue, $subqueue); drupal_set_title(t("Edit subqueue !subqueue", array('!subqueue' => $subqueue->title))); return drupal_get_form('smartqueue_users_subqueue_edit_form', $account, $queue, $subqueue); } /** * Form to add or edit a new subqueue. */ function smartqueue_users_subqueue_edit_form(&$form_state, $account, $queue, $subqueue = NULL) { $form = array(); $form['uid'] = array( '#type' => 'value', '#value' => $account->uid, ); $form['qid'] = array( '#type' => 'value', '#value' => $queue->qid, ); if (!empty($subqueue)) { $form['sqid'] = array( '#type' => 'value', '#value' => $subqueue->sqid, ); } $form['subqueue_title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#description' => t('The title of the new subqueue.'), '#default_value' => (!empty($subqueue->title) ? $subqueue->title : ''), '#required' => TRUE, ); if(_smartqueue_users_settings_get('subqueue_privacy_changeable', $queue->qid)) { $form['subqueue_privacy'] = array( '#type' => 'radios', '#title' => t('Privacy'), '#description' => t("Select the privacy for this subqueue. Public means that everyone can see the content of this subqueue. Private means that only the owner can see the content."), '#options' => _smartqueue_users_form_privacy_options(), '#default_value' => (int)(!empty($subqueue) ? smartqueue_users_subqueue_get_privacy($subqueue) : _smartqueue_users_settings_get('subqueue_privacy_default', $queue->qid)), ); } $form['submit'] = array( '#type' => 'submit', '#value' => t(empty($subqueue) ? 'Add subqueue' : 'Save changes'), ); $form['#redirect'] = "user/$account->uid/queue"; return $form; } /** * Validation for the form to add or edit a new subqueue. */ function smartqueue_users_subqueue_edit_form_validate($form, &$form_state) { // Only check if this a new subqueue, not an edited one. if (!isset($form_state['values']['sqid'])) { $uid = $form_state['values']['uid']; $qid = $form_state['values']['qid']; // Check that the subqueue limit hasn't been reached. if (smartqueue_users_reached_subqueue_limit($uid, $qid)) { drupal_set_message(t('This queue has reached the subqueue limit for this user.'), 'error'); drupal_goto($form['#redirect']); } } } /** * Submittion for the form to add or edit a new subqueue. */ function smartqueue_users_subqueue_edit_form_submit($form, &$form_state) { $qid = $form_state['values']['qid']; $queue = nodequeue_load($qid); $title = $form_state['values']['subqueue_title']; if (isset($form_state['values']['sqid'])) { // Editing an existing subqueue. $sqid = $form_state['values']['sqid']; $subqueue = subqueue_load($sqid); nodequeue_subqueue_update_title($sqid, $title); drupal_set_message(t('Saved changes to subqueue !subqueue_title in !queue_title', array('!subqueue_title' => $subqueue->title, '!queue_title' => $queue->title))); } else { // Adding a new subqueue. $uid = $form_state['values']['uid']; $subqueue = nodequeue_add_subqueue($queue, $title, smartqueue_users_get_next_reference_string($uid, $qid)); drupal_set_message(t('Added subqueue !subqueue_title to !queue_title', array('!subqueue_title' => $subqueue->title, '!queue_title' => $queue->title))); } // Save the subqueue specific privacy setting, where relevant. if (isset($form_state['values']['subqueue_privacy'])) { smartqueue_users_subqueue_set_privacy($subqueue, $form_state['values']['subqueue_privacy']); } } /** * Form to remove a subqueue. */ function smartqueue_users_subqueue_remove_form(&$form_state, $account, $subqueue) { $path = "user/$account->uid/queue"; return confirm_form( array( 'sqid' => array( '#type' => 'value', '#value' => $subqueue->sqid, ), '#redirect' => $path, ), t('Are you sure you want to remove the subqueue %subqueue?', array('%subqueue' => $subqueue->title)), $path, t('This will remove all content from the subqueue. This action cannot be undone.'), t('Delete') ); } /** * Submittion for the form to remove a subqueue. */ function smartqueue_users_subqueue_remove_form_submit($form, &$form_state) { $sqid = $form_state['values']['sqid']; smartqueue_users_remove_subqueue($sqid); drupal_set_message(t('The subqueue has been removed.')); }