function digest($uid, $digest, $start = 0, $limit = 0, $tableid = 0, $digestglue = '>=', $displayorder = 0, $glue = '>=')
{
    $thread_obj = C::t('forum_thread');
    $parameter = array($thread_obj->get_table_name($tableid), $digest, $displayorder);
    $digestglue = helper_util::check_glue($digestglue);
    $glue = helper_util::check_glue($glue);
    if ($uid) {
        $where = 'authorid=' . $uid . ' AND ';
    }
    $data = DB::fetch_all("SELECT * FROM %t WHERE " . $where . " digest{$digestglue}%d AND displayorder{$glue}%d" . DB::limit($start, $limit), $parameter, 'tid');
    $data[count] = DB::result_first("SELECT count(*) FROM %t WHERE " . $where . " digest{$digestglue}%d AND displayorder{$glue}%d", $parameter, 'tid');
    return $data;
}
 public function fetch_all_by_available_icon($available = null, $haveicon = false, $glue = '=', $order = 'displayorder', $sort = 'ASC')
 {
     $parameter = array($this->_table);
     if ($available !== null) {
         $parameter[] = $available;
         $glue = helper_util::check_glue($glue);
         $wherearr[] = "available{$glue}%d";
     }
     if ($haveicon) {
         $wherearr[] = "icon!=''";
     }
     $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE ' . implode(' AND ', $wherearr) : '';
     $ordersql = !empty($order) ? ' ORDER BY ' . DB::order($order, $sort) : '';
     return DB::fetch_all("SELECT * FROM %t {$wheresql} {$ordersql}", $parameter, $this->_pk);
 }
Exemple #3
0
 public function count_by_fid_typeid_displayorder($fid, $typeid = null, $displayorder = null, $glue = '=')
 {
     $parameter = array($this->get_table_name(), $fid);
     $wherearr = array();
     $fid = dintval($fid, true);
     $wherearr[] = is_array($fid) ? 'fid IN(%n)' : 'fid=%d';
     if ($typeid) {
         $parameter[] = $typeid;
         $wherearr[] = "typeid=%d";
     }
     if ($displayorder !== null) {
         $parameter[] = $displayorder;
         $glue = helper_util::check_glue($glue);
         $wherearr[] = "displayorder{$glue}%d";
     }
     $wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE ' . implode(' AND ', $wherearr) : '';
     return DB::result_first("SELECT COUNT(*) FROM %t {$wheresql}", $parameter);
 }
 public function fetch_all_by_flag($flag, $glue = '=', $sort = 'ASC')
 {
     $glue = helper_util::check_glue($glue);
     return DB::fetch_all("SELECT * FROM %t WHERE flag{$glue}%d ORDER BY " . DB::order('displayorder', $sort), array($this->_table, $flag), $this->_pk);
 }
 public function update_cache($tableid, $id, $idtype, $data, $condition = array(), $glue = 'merge')
 {
     if (!$this->_allowmem) {
         return;
     }
     if ($idtype == 'tid') {
         $memorydata = $this->fetch_cache($id, $this->_pre_cache_key . 'tid_');
         if (!$memorydata) {
             return;
         }
         if (!is_array($id)) {
             $memorydata = array($id => $memorydata);
             $id = (array) $id;
         }
         foreach ($id as $v) {
             if (!$memorydata[$v]) {
                 continue;
             }
             foreach ($memorydata[$v] as $pid => $post) {
                 $updateflag = true;
                 if ($condition) {
                     foreach ($condition as $ck => $cv) {
                         if ($cv !== null && !in_array($post[$ck], (array) $cv)) {
                             $updateflag = false;
                             break;
                         }
                     }
                 }
                 if ($updateflag) {
                     if ($glue == 'merge') {
                         $memorydata[$v][$pid] = array_merge($post, $data);
                     } else {
                         foreach ($data as $dk => $dv) {
                             $memorydata[$v][$pid][$dk] = helper_util::compute($memorydata[$v][$pid][$dk], $dv, $glue);
                         }
                     }
                 }
             }
             $this->store_cache($v, $memorydata[$v], $this->_cache_ttl, $this->_pre_cache_key . 'tid_');
         }
     } elseif ($idtype == 'pid') {
         $memorytid = array();
         $query = DB::query('SELECT pid, tid FROM %t WHERE ' . DB::field('pid', $id), array(self::get_tablename($tableid)));
         while ($post = DB::fetch($query)) {
             $memorytid[$post['pid']] = $post['tid'];
         }
         $memorydata = $this->fetch_cache($memorytid, $this->_pre_cache_key . 'tid_');
         if (!$memorydata) {
             return;
         }
         if (!is_array($id)) {
             $id = (array) $id;
         }
         foreach ($id as $v) {
             if ($memorydata[$memorytid[$v]][$v]) {
                 $updateflag = true;
                 if ($condition) {
                     foreach ($condition as $ck => $cv) {
                         if ($cv !== null && !in_array($memorydata[$memorytid[$v]][$v][$ck], (array) $cv)) {
                             $updateflag = false;
                             break;
                         }
                     }
                 }
                 if ($updateflag) {
                     if ($glue == 'merge') {
                         $memorydata[$memorytid[$v]][$v] = array_merge($memorydata[$memorytid[$v]][$v], $data);
                     } else {
                         foreach ($data as $dk => $dv) {
                             $memorydata[$memorytid[$v]][$v][$dk] = helper_util::compute($memorydata[$memorytid[$v]][$v][$dk], $dv, $glue);
                         }
                     }
                 }
             }
         }
         foreach ($memorydata as $tid => $postlist) {
             $this->store_cache($tid, $postlist, $this->_cache_ttl, $this->_pre_cache_key . 'tid_');
         }
     } elseif ($idtype == 'fid') {
     }
 }
 public function fetch_all_by_dateline($dateline, $glue = '>=')
 {
     $glue = helper_util::check_glue($glue);
     return DB::fetch_all("SELECT * FROM %t WHERE dateline{$glue}%d ORDER BY dateline", array($this->_table, $dateline), $this->_pk);
 }