Mercurial > hg > digitalobjects
diff digitalobjects.collections.inc @ 0:6f6e07baad80 default tip
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 02 Jun 2015 08:57:48 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/digitalobjects.collections.inc Tue Jun 02 08:57:48 2015 +0200 @@ -0,0 +1,262 @@ +<?php + + + +function digitalobjects_user_admin_collection_submit($form,$formstate){ + $userid = $formstate['values']['userid']; + + + + drupal_goto("user/".$userid.'/collections'); + +} +function digitalobjects_user_admin_collection($key){ + + ctools_add_js('auto-submit'); + + + $form['digitalobjects_user_admin_form'] = drupal_get_form("digitalobjects_user_admin_form"); + #$form = drupal_get_form("digitalobjects_user_admin_form"); + + $user_full=user_load($key); + if (isset($user_full->field_digitalobjects_cid[LANGUAGE_NONE])){ + $val = $user_full->field_digitalobjects_cid[LANGUAGE_NONE][0]['objid']; + } else { + $val=""; + } + + $form['digitalobjects_user_admin_form']['digitalcollection']['#default_value']=""; + $form['digitalobjects_user_admin_form']['digitalcollection']['#value']=$val; + $form['digitalobjects_user_admin_form']['userid']['#value']=$key; + + //$form['digitalcollection_chooser'] = drupal_get_form("digitalcollection_chooser"); + + + # $element = $form; + + $form['chooser']=drupal_get_form("digitalcollection_chooser"); + + $form['chooser']['pager'] = array('#markup' => theme('pager')); + $form['chooser']['userid']['#value']=$key; + + #$element += $form3; + + # + #$element += $form2; + + return $form; +} + +function digitalcollection_chooser(array $form){ + // Build the sortable table header. + $header = array( + 'title' => array('data' => t('Title'), 'field' => 'n.title'), + 'nid' => array('data' => t('nid'), 'field' => 'n.nid') + ); + + + #$result = db_query("SELECT nid FROM node WHERE type = :ntype ", array ('ntype' => 'digitalcollection'))->extend('PagerDefault'); + $query = db_select("node","n")->fields('n',array("nid"))->condition('type', 'digitalcollection')->orderby("n.title")->extend('PagerDefault')->limit(20); + $result = $query->execute(); + #$result = db_query("SELECT n.nid FROM {node} n "); + + $nids = array(); + foreach ($result as $record) { + $nids[] = $record->nid; + } + //Get the node data. + //$nids = $query + //->fields('n',array('nid')) + //->limit(50) + //->orderByHeader($header) + //->execute() + //->fetchCol(); + + + $nodes = node_load_multiple($nids); + + //Build the rows. + $options = array(); + $l_options=array(""); + $destination = drupal_get_destination(); + $languages = language_list(); + foreach ($nodes as $node) { + $langcode = entity_language('node', $node); + $l_options = $langcode != LANGUAGE_NONE && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array(); + + $options[$node->nid] = array( + 'title' => array( + 'data' => array( + '#type' => 'link', + '#title' => $node->title, + '#href' => 'node/' . $node->nid, + '#options' => $l_options, + '#suffix' => ' ' , + ), + ), + 'nid' => $node->nid, + ); + + } + + $destination = drupal_get_destination(); + + /* + $operations = array(); + if (node_access('update', $node)) { + $operations['edit'] = array( + 'title' => t('edit'), + 'href' => 'node/' . $node->nid . '/edit', + 'query' => $destination, + ); + } + if (node_access('delete', $node)) { + $operations['delete'] = array( + 'title' => t('delete'), + 'href' => 'node/' . $node->nid . '/delete', + 'query' => $destination, + ); + } + $options[$node->nid]['operations'] = array(); + $options[$node->nid]['operations'] = array( + 'data' => array( + '#theme' => 'links__node_operations', + '#links' => $operations, + '#attributes' => array('class' => array('links', 'inline')), + ), + ); + + + */ + + + + + $form['digitalcollection_chooser'] = array( + '#type' => 'tableselect', + '#header' => $header, + '#options' => $options, + '#empty' => t('No content available.'), + '#attributes' => array('class' => array('search-form', 'ctools-auto-submit-full-form')), + '#multiple' => False, + + ); + + #form['chooser']['change'] = array('#type' => 'actions'); + $form+= $form['submit2'] = array('#type' => 'submit', '#value' => t('Choose')); + #$form['chooser']['#submit'][] = 'digitalobjects_user_change_form_submit'; + $form['submit2']['#submit'][] = 'digitalobjects_user_change_form_submit'; + #$form['chooser']['#attributes']= array('class' => array('ctools-use-ajax', 'ctools-auto-submit-click')); + + $form['userid'] = array( + '#type' => 'hidden', + ); + + return $form; +} + + +function digitalobjects_user_change_form_submit($form,$formstate){ + $input = $formstate['input']['digitalcollection_chooser']; + $userid = $formstate['values']['userid']; + + $user=user_load($userid); + + + $user->field_digitalobjects_cid['und'][0]['objid'] = $input; + + user_save($user); + +} +#füge objid zur aktuelle sammlung hinzu +function digitalobjects_addToCurrentCollection($objid){ + + global $user; + #hole current collection + $user_full = user_load($user->uid); + $val = $user_full->field_digitalobjects_cid['und'][0]['objid']; + + #hole sammlung + + $node = node_load($val); + + foreach ( $node->field_objid['und'] as $obj){ + if ($obj['objid']==$objid){ + return drupal_set_message(t("Already in the current collection"),"error"); + } + + } + + $node->field_objid['und'][]['objid']=$objid; + + $node = node_submit($node); + + node_save($node); + + drupal_goto("node/".$node->nid); +} + + + +function digitalobjects_digitalcollectionsManage($data = NULL){ + + $data = ($data==NULL) ? $_GET : $data; + + + global $user; + #hole current collection + $user_full = user_load($user->uid); + $val = $user_full->field_digitalobjects_cid['und'][0]['objid']; + + #hole sammlung + + $node = node_load($val); + + foreach ($data['digitalobjects_items_select'] as $objid){ + /*foreach ( $node->field_objid['und'] as $obj){ + if ($obj['objid']==$objid){ + return drupal_set_message(t("Already in the current collection"),"error"); + } + + } + */ + $node->field_objid['und'][]['objid']=$objid; + + } + + + $node = node_submit($node); + + node_save($node); + + if (isset($data['redirect'])){ + + drupal_goto(urldecode($data['redirect'])); + } else { + drupal_goto("node/".$node->nid); + } + +/* + $output['digitalobjects_item']= array( + '#theme' => 'digitalobjects_item', + '#objid' => ''); + return $output; + */ +} + +/* suche wo wo eine digitalecollection benutzt wird */ +function digitalcollection_used_id($nid){ + $results = db_query("SELECT * FROM {field_data_field_collid} n where field_collid_objid ='node/" . $nid . "'"); + + $nids = array(); + foreach($results as $result){ + + + $nids[] = $result->entity_id; + } + + $entities = entity_load("node",$nids); + + return $entities; + +}