123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- <?php
- class ChadoDataUIController extends EntityDefaultUIController {
-
- public function hook_menu() {
- $items = array();
-
- $this->id_count = count(explode('/', $this->path));
- $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
- $items[$this->path] = array(
- 'title' => 'Chado Data',
- 'description' => 'Add edit and update chado data.',
- 'page callback' => 'system_admin_menu_block_page',
- 'access arguments' => array('access administration pages'),
- 'file path' => drupal_get_path('module', 'system'),
- 'file' => 'system.admin.inc',
- );
-
- $items[$this->path]['type'] = MENU_LOCAL_TASK;
-
- $items[$this->path . '/add'] = array(
- 'title' => 'Add Chado Data',
- 'description' => 'Add a new chado data record',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('chado_data_form'),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('edit'),
- 'type' => MENU_LOCAL_ACTION,
- 'weight' => 20,
- );
-
- $items['data/add'] = array(
- 'title' => 'Add Chado data',
- 'description' => 'Add a new chado data record',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('chado_data_form'),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('edit'),
- 'type' => MENU_NORMAL_ITEM,
- 'weight' => 20,
- );
-
- $items['data/' . $wildcard] = array(
- 'title callback' => 'chado_data_title',
- 'title arguments' => array(1),
- 'page callback' => 'chado_data_view',
- 'page arguments' => array(1),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('view', 1),
- 'type' => MENU_CALLBACK,
- );
-
- $items['data/' . $wildcard . '/view'] = array(
- 'title' => 'View',
- 'page callback' => 'chado_data_view',
- 'page arguments' => array(1),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('view', 1),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
-
- $items['data/' . $wildcard . '/edit'] = array(
- 'title' => 'Edit',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('chado_data_form', 1),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('edit', 1),
- 'type' => MENU_LOCAL_TASK,
- );
-
- $items['data/' . $wildcard . '/delete'] = array(
- 'title' => 'Delete',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('chado_data_delete_form', 1),
- 'access callback' => 'chado_data_access',
- 'access arguments' => array('edit', 1),
- 'type' => MENU_CALLBACK,
- 'weight' => 10,
- );
- return $items;
- }
- }
- function chado_data_access($op, $entity = NULL, $account = NULL) {
- if (user_access('administer chado data', $account)) {
- return TRUE;
- }
- if (isset($entity) && $type_name = $entity->type) {
- $op = ($op == 'view') ? 'view' : 'edit';
- if (user_access("$op any $type_name data", $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function chado_data_form($form, &$form_state, $entity = NULL) {
-
- $cv_id = NULL;
- $term_name = NULL;
- $cvterm = NULL;
-
- if ($entity) {
- drupal_set_title('Edit ' . $entity->title);
- $entity_id = $entity->entity_id;
- $values = array('cvterm_id' => $entity->cvterm_id);
- $cvterm = chado_generate_var('cvterm', $values);
- $cv_id = $cvterm->cv_id->cv_id;
- $term_name = $cvterm->name;
- }
-
- if (array_key_exists('values', $form_state)) {
- $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : NULL;
- $term_name = array_key_exists('term_name', $form_state['values']) ? $form_state['values']['term_name'] : NULL;
-
- $values = array(
- 'cv_id' => $cv_id,
- 'name' => $term_name
- );
- $cvterm = chado_generate_var('cvterm', $values);
- }
-
-
- $cvs = tripal_get_cv_select_options();
- if (!$term_name) {
- $form['cv_id'] = array(
- '#type' => 'select',
- '#title' => t('Vocabulary'),
- '#options' => $cvs,
- '#required' => TRUE,
- '#description' => t('Select a vocabulary that contains the term for the type of data you want to add.'),
- '#default_value' => $cv_id,
- '#ajax' => array(
- 'callback' => "chado_data_form_ajax_callback",
- 'wrapper' => 'chado_data_form',
- 'effect' => 'fade',
- 'method' => 'replace'
- )
- );
- }
-
- if ($cv_id and !$term_name) {
- $form['cvterm_select']['term_name'] = array(
- '#title' => t('Record Type'),
- '#type' => 'textfield',
- '#description' => t("Enter the name of a term within the selected vocabulary for the record type you want to enter."),
- '#required' => TRUE,
- '#default_value' => $term_name,
- '#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/$cv_id",
- );
- $form['cvterm_select']['select_button'] = array(
- '#type' => 'submit',
- '#value' => t('Use this term'),
- '#name' => 'select_cvterm',
- );
- }
-
- if ($cvterm) {
- $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
- $form['cv_id'] = array(
- '#type' => 'hidden',
- '#value' => $cv_id,
- );
- $form['term_name'] = array(
- '#type' => 'hidden',
- '#value' => $term_name,
- );
- $form['cvterm_id'] = array(
- '#type' => 'hidden',
- '#value' => $cvterm->cvterm_id,
- );
- $form['type'] = array(
- '#type' => 'hidden',
- '#value' => $bundle_id,
- );
- $form['details'] = array(
- '#type' => 'fieldset',
- '#title' => 'Record Type',
- '#collapsable' => FALSE,
- '#weight' => -100,
- );
- $form['details']['cv_name_shown'] = array(
- '#type' => 'item',
- '#title' => 'Vocabulary',
- '#markup' => $cvterm->cv_id->name,
- );
- $form['details']['term_name_shown'] = array(
- '#type' => 'item',
- '#title' => 'Term',
- '#markup' => $cvterm->name,
- );
-
- if (!$entity) {
- $entity = entity_get_controller('chado_data')->create(array('type' => $bundle_id));
- field_attach_form('chado_data', $entity, $form, $form_state);
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Add a new ' . $cvterm->name),
- '#name' => 'add_data',
- '#weight' => 1000
- );
- }
- else {
- field_attach_form('chado_data', $entity, $form, $form_state);
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- '#name' => 'update_data',
- '#weight' => 1000
- );
- }
-
-
- $form_state['chado_data'] = $entity;
- }
- $form['#prefix'] = '<div id="chado_data_form">';
- $form['#suffix'] = '</div>';
- return $form;
- }
- function chado_data_form_ajax_callback($form, $form_state) {
-
- return $form;
- }
- function chado_data_form_validate($form, &$form_state) {
- if ($form_state['clicked_button']['#name'] == 'add_data') {
- $chado_data = (object) $form_state['values'];
- field_attach_form_validate('chado_data', $chado_data, $form, $form_state);
- }
- }
- function chado_data_form_submit($form, &$form_state) {
- if ($form_state['clicked_button']['#name'] == 'cancel') {
- if (array_key_exists('entity_id', $form_state['values'])){
- $entity = $form_state['values']['entity'];
- $form_state['redirect'] = "data/$entity->entity_id";
- }
- else {
- $form_state['redirect'] = "admin/structure/chado_data";
- }
- return;
- }
- if ($form_state['clicked_button']['#name'] == 'select_cvterm') {
-
- $form_state['rebuild'] = TRUE;
- }
- if ($form_state['clicked_button']['#name'] == 'update_data' or
- $form_state['clicked_button']['#name'] == 'add_data') {
-
-
- $entity = entity_ui_controller('chado_data')->entityFormSubmitBuildEntity($form, $form_state);
- $entity->save();
- $form_state['redirect'] = "data/$entity->entity_id";
- }
- }
- function chado_data_form_submit_delete(&$form, &$form_state) {
- $form_state['redirect'] = 'admin/content/chado_datas/chado_data/' . $form_state['chado_data']->chado_data_id . '/delete';
- }
- function chado_data_delete_form($form, &$form_state, $chado_data) {
- $form_state['chado_data'] = $chado_data;
- $form['#submit'][] = 'chado_data_delete_form_submit';
- $form = confirm_form($form,
- t('Are you sure you want to delete chado_data %name?', array('%name' => $chado_data->name)),
- 'admin/content/chado_datas/chado_data',
- '<p>' . t('This action cannot be undone.') . '</p>',
- t('Delete'),
- t('Cancel'),
- 'confirm'
- );
- return $form;
- }
- function chado_data_delete_form_submit($form, &$form_state) {
- $chado_data = $form_state['chado_data'];
- chado_data_delete($chado_data);
- drupal_set_message(t('The chado_data %name has been deleted.', array('%name' => $chado_data->name)));
- watchdog('chado_data', 'Deleted chado_data %name.', array('%name' => $chado_data->name));
- $form_state['redirect'] = 'admin/content/chado_datas';
- }
- function chado_data_set_breadcrumb() {
- $breadcrumb = array(
- l(t('Home'), '<front>'),
- l(t('Administration'), 'admin'),
- l(t('Content'), 'admin/content'),
- l(t('Chado Data'), 'admin/content/chado_data'),
- );
- drupal_set_breadcrumb($breadcrumb);
- }
- function chado_data_view($entity, $view_mode = 'full') {
- $controller = entity_get_controller('chado_data');
- $content = $controller->view(array($entity->entity_id => $entity));
- drupal_set_title($entity->title);
- return $content;
- }
- function chado_data_title(ChadoData $entity){
- return $entity->title;
- }
|