You are here

function patron_user in Library 6

Same name and namespace in other branches
  1. 5.2 patron/patron.module \patron_user()

Implementation of hook_user().

File

patron/patron.module, line 518

Code

function patron_user($op, &$edit, &$user, $category = NULL) {
  if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER) {
    switch ($op) {
      case 'load':
        $user->patron = patron_load_by_uid($user->uid);
        break;
      case 'after_update':

        //If the user email has changed, update the patron email to match
        $node = patron_load_by_uid($user->uid);
        if (!empty($node) && $node->email != $user->mail) {
          $node->email = $user->mail;
          node_save($node);
        }
        break;
      case 'view':
        $patron = patron_load_by_uid($user->uid);
        $cur_user = $GLOBALS['user'];
        if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && !empty($patron) && (node_access('view', 'patron') || $cur_user->uid == $user->uid)) {
          $user->content['patron_name'] = array(
            '#type' => 'user_profile_item',
            '#title' => 'Patron Name',
            '#value' => l($patron->name_first . ' ' . $patron->name_last, 'node/' . $patron->nid),
            '#attributes' => array(
              'class' => 'profile-patron',
            ),
          );
        }
        break;
      case 'register':
        if (variable_get('patron_autocreate', 0) == 1) {
          return patron_register_form();
        }
        break;
      case 'insert':
        if (variable_get('patron_autocreate', 0) == 1 && isset($edit['name_last'])) {
          return patron_create_patron($edit, $user);
        }
        break;
      case 'delete':

        //$patron = patron_load_by_uid($user->uid);

        //if (variable_get('patron_autocreate', 0) == 1 && !empty($patron) && is_numeric($patron->nid)) {

        //node_delete($patron->nid);

        //}
        break;
    }
  }
}