janoka képe

Szia!

Külön modul írásával egy hasonló feladatot így oldottam meg. A kódot lerövidítettem, hogy csak egy rövid példa maradjon.

pelda.module:

  1. function pelda_form_webform_client_form_641_alter(&$form, &$form_state, $form_id ) {
  2. drupal_add_js( drupal_get_path('module', 'pelda').'/js/pelda.js');
  3. }
  4.  
  5. function pelda_webform_submission_presave($node, &$submission) {
  6. // Kezdeti értékek, amelyekkel dolgozunk
  7. $fizetendo = 0;
  8.  
  9. // ....
  10. // Értéke: 32: 18 felett, 16: 14-18 év, 8: 14 alatt
  11. $kor = $submission->data[23]['value'][0];
  12. // Ha valaki elmúlt 14, akkor kell csak szállást és 18 után ifa-t számolni.
  13. switch ($kor) {
  14. case 32: $szallas=3930; break;
  15. case 16: $szallas=3600; break;
  16. default: $szallas=0; break;
  17. }
  18. // Szállásnapok száma
  19. $szallasnapok_szama = count( $submission->data[6]['value'] );
  20. // Szállás értéke
  21. $fizetendo += $szallasnapok_szama*$szallas;
  22.  
  23. // Fizetési összeg aktualizálása a beküldés előtt.
  24. $submission->data[22]['value'][0] = $fizetendo;
  25. }

pelda.js:

  1. function changeFizetendo() {
  2. $fizetendo = 0;
  3.  
  4. // Ha valaki elmúlt 14, akkor kell csak szállást és 18 után ifa-t számolni.
  5. if( $("#edit-submitted-kor-1").is(":checked") ) {
  6. $szallas=3930;
  7. }
  8. else if( $("#edit-submitted-kor-2").is(":checked") ) {
  9. $szallas=3600;
  10. }
  11. else {
  12. $szallas=0;
  13. }
  14.  
  15. // Szállás kiszámolása
  16. $fizetendo += ($("#edit-submitted-szallasnapok-1").is(":checked"))?$szallas:0;
  17. $fizetendo += ($("#edit-submitted-szallasnapok-2").is(":checked"))?$szallas:0;
  18. $fizetendo += ($("#edit-submitted-szallasnapok-3").is(":checked"))?$szallas:0;
  19.  
  20. // Számolás végén az érték beállítása, mint fiezetendő
  21. $("#edit-submitted-fizetendo").val($fizetendo);
  22.  
  23. // Abban az esetben, ha nincs a kor kitöltve, akkor a focust a korra teszi.
  24. //if( $("#edit-submitted-kor").is(":empty") ) {
  25. // $("#edit-submitted-kor").focus();
  26. //}
  27. };
  28.  
  29. jQuery(document).ready(
  30. function($) {
  31.  
  32. // Fizetendő mező kikapcsolása, hogy ne legyen szerkeszthető
  33. $("#edit-submitted-fizetendo").attr("disabled", "disabled");
  34.  
  35. // Annak figyelése, hogy ha valamelyik beviteli mező változik, akkor a fizetendő értékét is újraszámoljuk.
  36. $("input").bind('change', changeFizetendo);
  37. }
  38. );
2
0
Sk8erPeter képe

Javítom magam:

Figyelem, az alábbi kódban a mező nyelvsemlegessége "be van drótozva" (lásd 'und' kulcs)

Ez egy csúnya megoldás, ami elkerülhető a field_get_items() használatával.

Ehhez ezt a cikket nagyon tudom ajánlani:
http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
Aki a moduljában/sminkjében fieldekkel babrál, annak itt megfontolandó tanácsok vannak, konkrétan az előbb linkelt field_get_items() és a field_view_value(), ill. a field_view_field() használata javasolt.

Tehát ami ROSSZ:

  1. // ROSSZ
  2. $block['content'] = $node->field_name['und'][0]['safe_value'];

HELYETTE JÓ PÉLDÁK:

$output = field_view_field('node', $node, 'field_name');

  1. $node = node_load($nid);
  2. $field = field_get_items('node', $node, 'field_name');
  3. $output = field_view_value('node', $node, 'field_name', $field[$delta]);

  1. $node = node_load($nid);
  2. $image = field_get_items('node', $node, 'field_image');
  3. $output = field_view_value('node', $node, 'field_image', $image[0], array(
  4. 'type' => 'image',
  5. 'settings' => array(
  6. 'image_style' => 'thumbnail',
  7. 'image_link' => 'content',
  8. ),
  9. ));

=========================

Ezek alapján a javított kód:
(a kód első fele jó, tehát a hook_ds_fields_info() implementálása ugyanaz marad)

http://drupal.stackexchange.com/questions/45198/how-to-output-get-locati...

  1. /**
  2.  * Generate GPS coordinates as a DS field
  3.  * Example: 46° 2' 27.24" N 18° 40' 37.2" E
  4.  */
  5. function MYMODULE_mytestbundle_ds_field_gps($field, $title = NULL){
  6. $output = '';
  7.  
  8. // http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
  9. // instead of the ugly $on_the_map_getlocations_field_data = $field['entity']->field_teststuff_on_the_map['und'][0];
  10. $on_the_map_getlocations_field = field_get_items('node', $field['entity'], 'field_teststuff_on_the_map');
  11.  
  12.  
  13. if(isset($on_the_map_getlocations_field[0])){
  14. $on_the_map_getlocations_field_data = $on_the_map_getlocations_field[0];
  15.  
  16. if(isset($on_the_map_getlocations_field_data['latitude']) && isset($on_the_map_getlocations_field_data['latitude'])){
  17. $output .= theme('getlocations_latitude_dms', $on_the_map_getlocations_field_data);
  18. $output .= ' ';
  19. $output .= theme('getlocations_longitude_dms', $on_the_map_getlocations_field_data);
  20. }
  21. }
  22.  
  23. return $output;
  24. }
2
0
mat323 képe

Sziasztok!

Drupal 5.3, Date 5.x-1.8, Calendar 5.x-1.7 és magyarosítani szeretném a naptár dátumkezelését.
Ez előző hozzászólások alapján próbálkoztam, de az eredmény csak félsiker lett.
Ha kiteszem a naptárat egy jobb oldali blokkba, akkor "április 2008" lesz a blokk címe (ami randa), viszont a naptár fejlécében már (helyesen) "2008. ápr" lesz.
Ha rákattintok mondjuk egy beküldött eseményre, ami április 12-én van, akkor a bejövő node címe "szombat, április 12 2008" lesz (csúnyán), alatta a keretes naptár fejlécében "2008. április 13., vasárnap" szerepel (helyesen és szépen).

Természetesen a Calendar telepítése után létrehoztam egy Nézetet, a megfelelő paraméterekkel (Calendar: Year, Calendar: Month, Calendar: Day - Összes érték megjelenítése - Cím: %1, %2, %3) ahogy a Nagykönyvben meg van írva, tehát működik a naptár, a beküldött időpontokat megjelöli)

Ezt szúrtam be a template.php végére:

function phptemplate_calendar_nav_title($field_type, $view) {
  calendar_load_date_api();
  switch ($field_type) {
    case 'YEAR':
      return $view->year;
    case 'MONTH':
      // Month navigation titles are used as links in blocks and in the year view.
      // For the timestamp, use the second day of the month because gm functions sometimes return the previous month
      $timestamp = date_array2unix(array('year' => $view->year, 'mon' => $view->month, 'mday' => 1));
      if ($view->build_type == 'block' || $view->calendar_type == 'year') {
          return l(date_format_date('Y. M', $timestamp), $view->real_url .'/'. $view->year .'/'. $view->month, array(), calendar_url_append($view));
      }
      else {
          return date_format_date('Y. F', $timestamp);
      }
    case 'DAY':
      $timestamp = date_array2unix(array('year' => $view->year, 'mon' => $view->month, 'mday' => $view->day, 'hours' => 24));
      return date_format_date('Y. F j., l', $timestamp);
    case 'WEEK':
        return t("Week of @date", array('@date' => date_format_date('Y. F j.', calendar_week('start_timestamp', $view, $view->week))));
   }
}
0
0
gdavid képe

en csinalnek egy uj node tipust, peldaul hirdetes.
a /themes/garland/ ala betehetsz egy node-hirdetes.tpl.php file-t amit a node.tpl.php atmasolasaval csinalod meg. miutan atmasoltad, megszerkeszted a node-hirdetes.tpl.php -t, hogy megjeleniteskor tegye bele valahova az adott node "nid"-jet.

<?php phptemplate_comment_wrapper(NULL, $node->type); ?>
 
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
 
<?php print $picture ?>
 
<?php if ($page == 0): ?>
  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>
 
  <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date — !username', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?></
  <?php endif; ?>
 
  <div class="content">
    <?php print $content ?>
    <?php print t('hiredetes kodja: %kod',array('%kod'=>$node->nid)); ?>
  </div>
 
  <div class="clear-block clear">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>
 
    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>
 
</div>
?>

ezt hiszem igy valahogy, (ez drupal 5 -alatt asszem jo. drupal6 eseten csak merem remelni)

0
0
zoliky képe

Egy "tpl.php" fajlal dolgozok, csak egy valtozo tobb adatot tartalmaz. Peldaul a $user_info_pane valtozo minden felhasznaloval kapcsolatos adatot kinyom, a sorrendet pedig, idegesito modon, o hataroza meg.

/**
 * Implementation of hook_theme().
 */
function flatforum_theme() {
  $items = array();
  $items['forum_user'] = array(
      'template' => 'flatforum-user',
      'path' => drupal_get_path('module', 'flatforum'),
      'arguments' => array('accountid' => NULL),
  );
  return $items;
}
 
/**
 * Preprocesses template variables for the comment template.
 */
function flatforum_preprocess_comment(&$vars) {
  // Use our combined node/comment template file
  $vars['template_files'][] = 'flatforum-comment';
 
  // Just use the date for the submitted on.
  $vars['submitted'] = format_date($vars['comment']->timestamp);
 
  // User information
  $accountid = $vars['comment']->uid;
  $vars['account'] = user_load(array('uid' => $vars['comment']->uid));
 
  // Create the user info pane
  $vars['user_info_pane'] = theme('forum_user', $vars['account']); 
}
 
 
/**
 * Preprocesses template variables for the user info template.
 */
function template_preprocess_forum_user(&$variables) {
  // The passed in $variables['account'] refers to the user who's info is in the pane.
  $account = $variables['accountid'];
  $accountid = $account->uid;
 
  // Get a reference to the currently logged in user.
  global $user;
 
  // Avatar
  $variables['picture'] = theme('user_picture', $account);
 
  // Username
  $variables['name_raw'] =  theme('username', $account);
  $variables['name'] =  '<div class="username">' .$variables['name_raw'] . '</div>';

Ket fuggveny egy "tpl.php" fajlot hasznal az adatok kilistazasara. A tpl fajlban csak a $user_info_pane valtozot printelem.

Ha tudnal segiteni nagyon halas lennek, a tobbivel boldogulok egyedul ! Elore is koszonom!

0
0
zserno képe

Ím:

$output = "<div class=\"fields\">";
$time_period = variable_get('user_block_seconds_online', 2700);
 
// Itt a pp altal is javasolt biztonsagos megoldas.
$uid = arg(1); // get the current userid that is being viewed.
$users = db_query("SELECT uid, name, access FROM {users} WHERE access >= %d AND uid = %d", time() - $time_period, $uid);
 
$total_users = db_result($users);
 
if ($total_users == 1) {
  $output .= t('A felhasznalo jelenleg online');
}
else {
  $output .= t('A felhasznalo jelenleg offline');    
}
 
$output .= "</div>";
 
// Innentol ez mar az eredeti theme_user_profile() tartalma.
$output .= '<div class="profile">';
$output .= theme('user_picture', $account);
foreach ($fields as $category => $items) {
  if (strlen($category) > 0) {
    $output .= '<h2 class="title">'. check_plain($category) .'</h2>';
  }
  $output .= '<dl>';
  foreach ($items as $item) {
    if (isset($item['title'])) {
      $output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
    }
    $output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
  }
  $output .= '</dl>';
}
$output .= '</div>';
 
echo $output;  

Ezután még a bio hozzácsapja a saját tartalmát és kész.
Megjegyzés: A t() függvényt csak angol szöveggel szabad használni. Majd ezt lehet később magyarítani. Így is működik, de nem ajánlott.

0
0
medwex képe

nem tudom, h azóta megoldottad-e, de jó irányba keresgélsz, csak ahhoz hogy működjön szükséges néhány lépés.

Első, hogy a formodnak fogadnia kell a $form_state változót első paraméterként:

function pelda_szuro_form(&$form_state = NULL) {
  //form definíció...
}

A következő lépés, hogy meg kell kérned a FAPI-t, hogy építse újra a formodat beküldés után. Erre két lehetőséged van: vagy a $form_state['rebuild']-et állítod TRUE-ra, vagy a $form_state['storage']-ba teszel valamit:
hivatalos:

function pelda_szuro_form_submit($form, &$form_state) {
  //eredémyek összegyűjtése $eredmenyek-be....
 
  //küldjük vissza magunknak
  $form_state['storage']['pelda_eredmenyek'] = $eredmenyek;
}

de ez is működik:

function pelda_szuro_form_submit($form, &$form_state) {
  //eredémyek összegyűjtése $eredmenyek-be....
 
  //küldjük vissza magunknak
  $form_state['pelda_eredmenyek'] = $eredmenyek;
  $form_state['rebuild'] = TRUE;
}

Bármelyket választod a _submit() után a FAPI újra meghívja a formod, csak mostmár nem egy "üres" $form_state-el, hanem azzal, amit a _submit() "visszaadott":

function pelda_szuro_form(&$form_state = NULL) {
  //rövidítsünk:
  $values = &$form_state['values'];
 
  $form['szuro_elem'] = array(
    '#type' => 'textfield',
    '#title' => t('Example filter'),//hogy fordítható legyen
    //ez azért kell, hogy beküldés után megjelenjen a beküldött érték
    '#default_value' => isset($values['szuro_elem']) ? $values['szuro_elem'] : '',
  );
 
  //feltéve hogy a storage-ot használtad és $eredmenyek egy link lista
  $storage = &$form_state['storage'];
  if (isset($storage['pelda_eredmenyek']) && !empty($storage['pelda_eredmenyek'])) {
    $form['eredmenyek'] = array(
      '#type' => 'markup',
      '#value' => theme('item_list', $storage['pelda_eredmenyek']),
    );
  }
 
  return $form;
}

Egyébként ugyan ezzel a megoldással működnek a többoldalas űrlapok is, csak akkor küldönböző form definíciót adsz vissza a $form_state állapotának függvényében, bár ha úgy vesszük, akkor ez is egy többoldalas űrlap: az első oldalon nincs eredmény, a másodikon pedig van.

SEO: remélem ez így most elég aboros barát. :D

0
0
makgab képe

A .module menüjében:

<?php
  $items['base/rendszer/szotar/szotarlista/lista/edit/%'] = array(
    'title' => 'Szótár szerkesztés',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('szotar_edit', 6),
    'access callback' => user_access('administer szotar'),
    'file' => 'admin.szotar.inc',
    'type' => MENU_CALLBACK,
  ); 
?>

szotar.inc:

<?php
function szotar_row($szotar) {
  $form['SZOTARID'] = array(
    '#type' => 'markup',
    '#value' => $szotar->SZOTARID,
  );
  $form['NEV'] = array(
    '#type' => 'markup',
    '#value' => $szotar->NEV,
  );
  $edit_link = (0) ? '' : l(t('Edit'), 'base/rendszer/szotar/szotarlista/lista/edit/'. $szotar->SZOTARID);
  $form['edit_szotar'] = array(
    '#type' => 'markup',
    '#value' => $edit_link,
  ); 
 
...
 
function szotar_edit(&$form_state, $szotar) {
 
  $form['szotarid'] = array(
  '#type' => 'markup',
  '#title' => 'Szótár ID',
  '#value' => $szotar['SZOTARID'],       // ez jó
  );
  $form['nev'] = array(
  '#type' => 'textfield',
  '#title' => 'Szótár név',
  '#size' => 50,
  '#maxlength' => 50,
  '#required' => TRUE,
  '#value' => $szotar['NEV'],               // ide kerül bele a SZOTARID értéke ugyanúgy!
  ); 
...
?>

Nem látom hogy miért kerül bele a NEV-be az ID. :)

G.

0
0
wildface86 képe

igen node refernce van hasznalva

es itt az export
$view = new view;
$view->name = 'kapcsolat';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'field_sz_telepules_nid' => array(
'label' => 'Населенный пункт',
'required' => 0,
'delta' => -1,
'id' => 'field_sz_telepules_nid',
'table' => 'node_data_field_sz_telepules',
'field' => 'field_sz_telepules_nid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'title' => array(
'label' => 'Cím',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'nid' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'Minden',
'title' => '',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'node',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
),
'relationship' => 'field_sz_telepules_nid',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'telepulesek' => 'telepulesek',
'image' => 0,
'prog_gallery' => 0,
'book' => 0,
'latnivalok' => 0,
'page' => 0,
'story' => 0,
'szallasok' => 0,
'terkep' => 0,
),
'validate_argument_node_access' => 1,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'27' => 0,
'26' => 0,
'28' => 0,
'23' => 0,
'1' => 0,
'21' => 0,
'8' => 0,
'11' => 0,
'10' => 0,
'25' => 0,
'12' => 0,
'17' => 0,
'18' => 0,
'14' => 0,
'16' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'telepulesek' => 'telepulesek',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => 'type_op',
'label' => 'Tartalom: Típus',
'use_operator' => 0,
'identifier' => 'type',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 0,
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler = $view->new_display('block', 'Blokk', 'block_2');
$handler->override_option('arguments', array(
'nid' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'Minden',
'title' => '',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'node',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
),
'relationship' => 'field_sz_telepules_nid',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'telepulesek' => 'telepulesek',
'image' => 0,
'prog_gallery' => 0,
'book' => 0,
'latnivalok' => 0,
'page' => 0,
'story' => 0,
'szallasok' => 0,
'terkep' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'27' => 0,
'26' => 0,
'28' => 0,
'23' => 0,
'1' => 0,
'21' => 0,
'8' => 0,
'11' => 0,
'10' => 0,
'25' => 0,
'12' => 0,
'17' => 0,
'18' => 0,
'14' => 0,
'16' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
'override' => array(
'button' => 'Use default',
),
),
));
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

0
0
kkwx képe

sikerült megoldanom néhány problémát: több formot csináltam, adatbázis fel/letöltés, validálás, submit... de a hozzáférés-kezelés valahogy nem akar működni :S

ez a kódom:

function room_reserver_perm() {
  return array('access reservation form', 'administrate own reservastions', 'administration');
}
 
function room_reserver_menu() {
  $items = array();
 
  $items['reservation'] = array(
    'title' => 'Foglalás',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('room_reserver_myform'),
    'type' => MENU_NORMAL_ITEM,
    'access arguments' => array('access reservation form'), 
  );
  $items['reservations'] = array(
    'title' => 'Foglalás',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('room_reserver_reserve'),
    'type' => MENU_NORMAL_ITEM,
    'access arguments' => array('administrate own reservastions'), 
  );
 
  return $items;
}
 
 
function room_reserver_myform() {
 
  $form = array();
  $form['#submit'] = array('room_reserver_myform_submit');
 
$form['nev'] = array(
    '#type'=> 'textfield',
    '#title' => t('Név'),
    '#required' => TRUE,
    '#description' => t('Adja meg a nevét!'),
  );
 
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Foglalás elküldése'),
  );
  return $form;
}

Meg is jelennek a beállított pontok ('access reservation form', 'administrate own reservastions', 'administration') a Jogosultságoknál, de nincs jelentősége, hogy be vannak-e kapcsolva, mert alapból ki van kapcsolva mind és mégis megjelenik az űrlap mindenkinek :(. Tudna valaki segíteni, hogy mi lehet a gond?

0
0