modulo birthdays : Modificare il valore del campo

8 contenuti / 0 new
Ultimo contenuto
modulo birthdays : Modificare il valore del campo

Ciao a tutti,
ho installato il modulo birthdays ed ho inserito un blocco che visualizza il compleanno dell'utente, ora mi servirebbe modificarlo.

Nel blocco mi visualizza il campo username dell'utente, a me servirebbe visualizzare il nome ed il cognome prelevandoli dai campi che ho creato con il modulo Profile. Ho sbirciato nel file birthdays-block.tpl ed ho trovato dove fa il print del username

<?php
 
print $birthday['username']
?>

Il problema è che non so come prelevare le info che mi servono dal db e come poterle visualizzare

Nessun consiglio?

niente?

Mi dite almeno se è possibile fare questa modifica?

Io non credo che non sia possibile

Con
global $user;
recuperi l'oggetto user, poi con
profile_load_profile($user)
carichi i campi del profilo (che vengono aggiunti all'oggetto $user).

Quote:

Con
global $user;
recuperi l'oggetto user, poi con
profile_load_profile($user)
carichi i campi del profilo (che vengono aggiunti all'oggetto $user).

Scusa ma non ho capito

questo è il codice presente nel file birthdays-block.tpl

<?php if ($no_birthdays): ?>
  <p><?php print t('There are no birthdays soon.'); ?></p>
<?php else: ?>
  <table>
    <?php foreach($birthdays as $birthday): ?>
    <tr>
      <td>
        <?php print $birthday['username'] ?>
        <?php if ($birthday['show_age']): ?>
          &nbsp;<small>(<?php print $birthday['age'] ?>)</small>
        <?php endif; ?>
      </td>
      <td><?php print $birthday['date'] ?></td>
    </tr>
    <?php endforeach; ?>
  </table>
<?php endif; ?>
<? print $more; ?>

ho provato a sistemarlo in questo modo

<?php if ($no_birthdays): ?>
  <p><?php print t('There are no birthdays soon.'); ?></p>
<?php else: ?>
  <table>
    <?php
   
foreach($birthdays as $birthday): ?>

    <tr>
      <td>
        <?php //print $birthday['username']
         
global $user;
         
profile_load_profile($user);
          print
$user->profile_nome ." ". $user->profile_cognome;
       
?>

        <?php if ($birthday['show_age']): ?>
          &nbsp;<small>(<?php print $birthday['age'] ?>)</small>
        <?php endif; ?>
      </td>
      <td><?php print $birthday['date'] ?></td>
    </tr>
    <?php endforeach; ?>
  </table>
<?php endif; ?>
<? print $more; ?>

ma non mi stampa nulla, non ho capito molto bene come modificarlo :(

Mi pare che la risposta alla tua domanda sta nei commenti proprio dentro birthdays-block.tpl. Dice:

Quote:
* - $birthdays:      Associative array with the following data:
*   - 'username':      Themed username with link to account.
*   - 'age':           Age the user will be after his/her birthday, shown
*                      depending on the settings of the module or the user's
*                      preference.
*   - 'date':          Month and day of birth of the user, formatted according
*                      the system's "short date format".
*   - 'account':       Entire account, for user pictures and other ways to
*                      improve the birthdays block.
*   - 'starsign':      Themed star sign.

Quindi troverai certi valori che ti serve dentro $birthday['account']. Il codice (che trovi in birthdays.module, funzione template_preprocess_birthdays_block) usa user_load(...) per caricare l'account (cioè iinformazione di quel particolare utente), ma manca i dati di profilo.

Allora devi caricarli, come ha detto Pinolo, ma così:
profile_load_profile($birthday['account'])
dopodichè i tuoi campi saranno accessibile tramite $birthday['account']->profile_nome, ecc, ecc.

Qui un esempio, ma non testato (beh, qualcosa devo lascarti fare, o no ;-)

<?php if ($no_birthdays): ?>
  <p><?php print t('There are no birthdays soon.'); ?></p>
<?php else: ?>
  <table>
    <?php
   
foreach($birthdays as $birthday): ?>

    <tr>
      <td>
        <?php
          $birthday_user
= $birthday['account'];
         
profile_load_profile($birthday_user);
          print
$birthday_user->profile_nome ." ". $birthday_user->profile_cognome;
       
?>

        <?php if ($birthday['show_age']): ?>
          &nbsp;<small>(<?php print $birthday['age'] ?>)</small>
        <?php endif; ?>
      </td>
      <td><?php print $birthday['date'] ?></td>
    </tr>
    <?php endforeach; ?>
  </table>
<?php endif; ?>
<?php print $more; ?>

(Nota anche che ho corretto l'ultima riga - sbagliato anche nel template stesso)

John

Più imparo, più dubito.

OK perfetto

Grazie per l'aiuto ora fa quello che serve a me :)