Drupal чат - вывод списка диалогов

Главные вкладки

Аватар пользователя Hoodognik Hoodognik 3 января 2013 в 22:03

Здравствуйте.
Столкнулся с такой проблемой - Установил drupal chat http://drupal.org/project/drupalchat
Всё вроде работает
Появилась необходимость выводить список диалогов наподобии как вконтакте, залез в код модуля и вроде как нашел то что требуется

<?php
function drupalchat_get_messages() {
  global 
$user;
  if((
$user->uid 0) || (_drupalchat_get_sid() != -1)) {
    
$output '';
    if (
variable_get('drupalchat_polling_method'DRUPALCHAT_LONGPOLL) == DRUPALCHAT_COMMERCIAL) {
      global 
$user;
      
$data json_encode(array(
        
'uid' => ($user->uid)?$user->uid:'0-'._drupalchat_get_sid(),
        
'api_key' => variable_get('drupalchat_external_api_key'NULL),));
      
$options = array(
        
'method' => 'POST',
        
'data' => $data,
        
'timeout' => 15,
        
'headers' => array('Content-Type' => 'application/json'),
      );

      

$result drupal_http_request(DRUPALCHAT_EXTERNAL_A_HOST ':' DRUPALCHAT_EXTERNAL_A_PORT '/r/'$options);
      
$query json_decode($result->data);
    }
    else {    
      
$guid = ($user->uid)?($user->uid):('0-'._drupalchat_get_sid());
      
$query db_query('SELECT u.name as name, g.uid as uid, g.message as message, g.TIMESTAMP as timestamp 
                         FROM (
                           SELECT uid, message, TIMESTAMP 
                             FROM (
                             (
                               SELECT m1.uid1 AS uid, m1.timestamp AS TIMESTAMP, m1.message AS message
                               FROM {drupalchat_msg} m1
                               INNER JOIN (
                                 SELECT MAX( t1.timestamp ) AS TIMESTAMP, t1.uid1
                                 FROM {drupalchat_msg} t1
                                 WHERE t1.uid2 =  :uid
                                 GROUP BY t1.uid1
                               ) recent ON recent.timestamp = m1.timestamp
                               AND recent.uid1 = m1.uid1
                               ORDER BY TIMESTAMP DESC
                             )
                             UNION (
                               SELECT m1.uid2 AS uid, m1.timestamp AS TIMESTAMP, m1.message AS message
                               FROM {drupalchat_msg} m1
                               INNER JOIN (
                                 SELECT MAX( t1.timestamp ) AS TIMESTAMP, t1.uid2
                                 FROM drupalchat_msg t1
                                 WHERE t1.uid1 =  :uid
                                 GROUP BY t1.uid2
                               )recent ON recent.timestamp = m1.timestamp
                               AND recent.uid2 = m1.uid2
                               ORDER BY TIMESTAMP DESC
                             )
                            ) AS f
                            ORDER BY 3 DESC
                          ) AS g INNER JOIN {str_drupalchat_users} u ON 
                          (g.uid = u.uid AND u.uid!= 0) OR (u.uid = 0 AND g.uid = CONCAT(\'0-\', u.session))
                        GROUP BY uid'
, array(':uid' => $guid));
    }
    foreach(
$query as $record) {
      
$output .= '<div style="display:block;border-bottom: 1px solid #ccc; padding: 10px;"><div style="font-size:130%; display: inline;">' l($record->name,'drupalchat/messages/message/' $record->uid) . '</div><div style="float:right;color:#AAA; font-size: 70%;">' format_date($record->timestamp,'long') . '</div><div style="display: block; padding: 10px;">' $record->message '</div></div>';
    }
    
//$output .= '</tbody></table>';
    //$user_item = user_load($user->uid);
    //$output .= '<pre>' . print_r($user_item,true) . '</pre>';
    //$output .= theme('user_picture', array('account' =>$user_item));    
  
}
  return 
$output;
}
?>

но при переходе по
http://домен/drupalchat/messages
показывает ошибку

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'egegia.drupalchat_msg' doesn't exist: SELECT u.name as name, g.uid as uid, g.message as message, g.TIMESTAMP as timestamp FROM ( SELECT uid, message, TIMESTAMP FROM ( ( SELECT m1.uid1 AS uid, m1.timestamp AS TIMESTAMP, m1.message AS message FROM {drupalchat_msg} m1 INNER JOIN ( SELECT MAX( t1.timestamp ) AS TIMESTAMP, t1.uid1 FROM {drupalchat_msg} t1 WHERE t1.uid2 = :uid GROUP BY t1.uid1 ) recent ON recent.timestamp = m1.timestamp AND recent.uid1 = m1.uid1 ORDER BY TIMESTAMP DESC ) UNION ( SELECT m1.uid2 AS uid, m1.timestamp AS TIMESTAMP, m1.message AS message FROM {drupalchat_msg} m1 INNER JOIN ( SELECT MAX( t1.timestamp ) AS TIMESTAMP, t1.uid2 FROM drupalchat_msg t1 WHERE t1.uid1 = :uid GROUP BY t1.uid2 )recent ON recent.timestamp = m1.timestamp AND recent.uid2 = m1.uid2 ORDER BY TIMESTAMP DESC ) ) AS f ORDER BY 3 DESC ) AS g INNER JOIN {str_drupalchat_users} u ON (g.uid = u.uid AND u.uid!= 0) OR (u.uid = 0 AND g.uid = CONCAT('0-', u.session)) GROUP BY uid; Array ( [:uid] => 1 ) в функции drupalchat_get_messages() (строка 981 в файле /home/www/hoodognik/data/www/egegia.roshoster.com/sites/all/modules/drupalchat/drupalchat.module).

Помогите если не сложно.

и ещё вопрос как можно осуществить такой запрос
SELECT * FROM tablename WHERE id IN (SELECT MAX(id) FROM tablename GROUP BY theme)
средствами 7 го друпала?

Комментарии