table_common_member_profile.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_common_member_profile.php 31536 2012-09-06 06:32:03Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_member_profile extends discuz_table_archive
  12. {
  13. private $_fields;
  14. public function __construct() {
  15. $this->_table = 'common_member_profile';
  16. $this->_pk = 'uid';
  17. $this->_pre_cache_key = 'common_member_profile_';
  18. $this->_fields = array('uid', 'realname', 'gender', 'birthyear', 'birthmonth', 'birthday', 'constellation',
  19. 'zodiac', 'telephone', 'mobile', 'idcardtype', 'idcard', 'address', 'zipcode', 'nationality', 'birthprovince', 'birthcity', 'birthdist',
  20. 'birthcommunity', 'resideprovince', 'residecity', 'residedist', 'residecommunity', 'residesuite', 'graduateschool', 'education', 'company',
  21. 'occupation', 'position', 'revenue', 'affectivestatus', 'lookingfor', 'bloodtype', 'height', 'weight', 'alipay', 'icq', 'qq',
  22. 'yahoo', 'msn', 'taobao', 'site', 'bio', 'interest', 'field1', 'field2', 'field3', 'field4', 'field5', 'field6', 'field7', 'field8');
  23. parent::__construct();
  24. }
  25. public function fetch_all($uids, $force_from_db = false, $fetch_archive = 1) {
  26. $data = array();
  27. if(!empty($uids)) {
  28. if($force_from_db || ($data = $this->fetch_cache($uids)) === false || count($uids) != count($data)) {
  29. if(is_array($data) && !empty($data)) {
  30. $uids = array_diff($uids, array_keys($data));
  31. }
  32. if($data === false) $data =array();
  33. if(!empty($uids)) {
  34. $query = DB::query('SELECT '.implode(',', $this->_fields).' FROM '.DB::table($this->_table).' WHERE '.DB::field($this->_pk, $uids));
  35. while($value = DB::fetch($query)) {
  36. $data[$value[$this->_pk]] = $value;
  37. $this->store_cache($value[$this->_pk], $value);
  38. }
  39. }
  40. }
  41. if(isset($this->membersplit) && $fetch_archive && count($data) != count($uids)) {
  42. $data = $data + C::t($this->_table.'_archive')->fetch_all(array_diff($uids, array_keys($data)), null, 0);
  43. }
  44. }
  45. return $data;
  46. }
  47. public function count_by_field($field, $val) {
  48. $count = 0;
  49. if(in_array($field, $this->_fields, true)) {
  50. $count = DB::result_first('SELECT COUNT(*) as cnt FROM '.DB::table('common_member_profile').' WHERE '.DB::field($field, $val));
  51. }
  52. return $count;
  53. }
  54. public function fetch_all_field_value($field) {
  55. return in_array($field, $this->_fields, true) ? DB::fetch_all('SELECT DISTINCT(`'.$field.'`) FROM '.DB::table($this->_table), null, $field) : array();
  56. }
  57. public function fetch_all_will_birthday_by_uid($uids) {
  58. $birthlist = array();
  59. if(!empty($uids)) {
  60. $uids = explode(',', (string)$uids);
  61. $uids = dimplode(dintval($uids, true));
  62. list($s_month, $s_day) = explode('-', dgmdate(TIMESTAMP-3600*24*3, 'n-j'));
  63. list($n_month, $n_day) = explode('-', dgmdate(TIMESTAMP, 'n-j'));
  64. list($e_month, $e_day) = explode('-', dgmdate(TIMESTAMP+3600*24*7, 'n-j'));
  65. if($e_month == $s_month) {
  66. $wheresql = "sf.birthmonth='$s_month' AND sf.birthday>='$s_day' AND sf.birthday<='$e_day'";
  67. } else {
  68. $wheresql = "(sf.birthmonth='$s_month' AND sf.birthday>='$s_day') OR (sf.birthmonth='$e_month' AND sf.birthday<='$e_day' AND sf.birthday>'0')";
  69. }
  70. $query = DB::query("SELECT sf.uid,sf.birthyear,sf.birthmonth,sf.birthday,s.username
  71. FROM ".DB::table('common_member_profile')." sf
  72. LEFT JOIN ".DB::table('common_member')." s USING(uid)
  73. WHERE (sf.uid IN ($uids)) AND ($wheresql)");
  74. while ($value = DB::fetch($query)) {
  75. $value['istoday'] = 0;
  76. if($value['birthmonth'] == $n_month && $value['birthday'] == $n_day) {
  77. $value['istoday'] = 1;
  78. }
  79. $key = sprintf("%02d", $value['birthmonth']).sprintf("%02d", $value['birthday']);
  80. $birthlist[$key][] = $value;
  81. ksort($birthlist);
  82. }
  83. }
  84. return $birthlist;
  85. }
  86. }
  87. ?>