Esempio n. 1
0
 /**
  * 
  * @return Brand_Model
  */
 public static function &instance()
 {
     if (!is_object(Brand_Model::$instances)) {
         // Create a new instance
         Brand_Model::$instances = new Brand_Model();
     }
     return Brand_Model::$instances;
 }
Esempio n. 2
0
    /**
     *
     * 获取所有设备最新备份记录
     * @param $user_id
     * @return array
     */
    public function get_latest_history($user_id)
    {
        $history = array();
        $table = $this->get_table($user_id, 'backup_history');
        $sql = sprintf('SELECT device_id, batch_number, phone_model, backup_total_sms, dateline
FROM (
SELECT *
FROM %s
WHERE uid = %d
ORDER BY dateline DESC
) AS tmp
GROUP BY device_id ORDER BY dateline DESC', $table, $user_id);
        $query = $this->db->query($sql);
        $result = $query->result_array(FALSE);
        if ($query->count() > 0) {
            foreach ($result as $key => $var) {
                $history[$key] = $var;
                $history[$key]['device_alias'] = Brand_Model::instance()->get_by_model($var['phone_model']);
            }
        }
        return array_values($history);
    }
Esempio n. 3
0
 public function __construct()
 {
     parent::__construct();
     $this->model = Brand_Model::instance();
     //$this->user_id = 10614401;
 }
Esempio n. 4
0
 /**
  * 获取联系人变更历史
  * @param int $user_id 用户ID
  * @param int $offset   起始记录数
  * @param int $limit     获取记录数
  * @return array
  */
 public function get_history($user_id, $offset = 0, $limit = 100)
 {
     $key = $this->cache_pre . 'history_list_' . $user_id . '_' . $offset . '_' . $limit;
     $update_key = $this->cache_pre . 'history_list_update_' . $user_id;
     $list = $this->cache->get($key);
     $update_time = $this->cache->get($update_key);
     if (empty($list) or (double) $list['update'] < (double) $update_time) {
         $history = $this->contact_mapper->get_history($user_id, $offset, $limit);
         $result = array();
         if ($history) {
             $brand_model = Brand_Model::instance();
             foreach ($history as $val) {
                 $add_ids = unserialize($val['added_ids']);
                 $update_ids = unserialize($val['updated_ids']);
                 $delete_ids = unserialize($val['deleted_ids']);
                 //兼容旧数据
                 if (is_null($val['count'])) {
                     $res = $this->contact_mapper->get_snapshot_count($user_id, $val['dateline']);
                     $val['count'] = $res['count'];
                     $val['category_count'] = $res['category_count'];
                 }
                 $val['device_id'] = $val['device_id'] !== NULL ? $val['device_id'] : '';
                 $val['phone_model'] = $val['phone_model'] !== NULL ? $val['phone_model'] : '';
                 $device_alias = $val['phone_model'] ? $brand_model->get_by_model($val['phone_model']) : '';
                 $result[] = array('user_id' => (int) $val['uid'], 'dateline' => (int) $val['dateline'], 'app_name' => api::get_app_name($val['appid']), 'source' => api::get_source_name($val['source']), 'device_id' => $val['device_id'], 'phone_model' => $val['phone_model'], 'device_alias' => $device_alias, 'operation' => substr($val['operation'], 0, 2) != 'u:' ? Kohana::lang('contact.' . $val['operation']) : substr($val['operation'], 2), 'count' => (int) $val['count'], 'category_count' => (int) $val['category_count'], 'add_count' => count($add_ids), 'update_count' => count($update_ids), 'delete_count' => count($delete_ids));
             }
         }
         $list = array('data' => $result, 'update' => microtime(TRUE));
         $this->cache->set($key, $list);
     }
     return !empty($list) ? $list['data'] : array();
 }