public static function sort($cates = null, $field, $sort = SORT_ASC)
 {
     if (!isset($cates)) {
         $cates = self::getCates();
     }
     return multi_array_sort($cates, $field, $sort);
 }
 /**
  * Get all languages by browser  `Accept-Language` request header.
  */
 public function parse_accept_language()
 {
     $locales = [];
     $accept_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
     $accept_language = str_replace(' ', '', $accept_language);
     $re = preg_match_all('/(.*?);q=([0-9.]+)(?:,?)/i', $accept_language, $matches);
     if ($re) {
         $locales = $this->get_languages($matches[1], $matches[2]);
         $locales = multi_array_sort($locales, 'priority', 'desc');
     }
     return $locales;
 }
 public function get($uid = 0, $reIndex = true)
 {
     $uid = $uid ? $uid : getCurrentUid();
     $data = $this->where("uid=" . $uid)->getField("data");
     $data = json_decode($data, true);
     if (!$data) {
         return array();
     }
     if ($reIndex) {
         $data["blocks"] = reIndex($data["blocks"]);
     }
     $data["btns"] = multi_array_sort($data["btns"], "listorder", SORT_ASC);
     return $data;
 }
示例#4
0
        }
        exit;
    } else {
        if (empty($_B['setting']['nav'])) {
            $navinfos = J::t('nav')->fetch_all();
            foreach ($navinfos as $k => $v) {
                if ($v['pid'] == 0) {
                    $pinfos[$v['id']] = $v;
                } else {
                    $group[$v['pid']][] = $v;
                }
            }
            foreach (multi_array_sort($pinfos, 'displayorder') as $k => $v) {
                $sortpinfos[$v['id']] = $v;
            }
            foreach ($group as $k => $v) {
                $sortpinfos[$k]['downnav'] = multi_array_sort($v, 'displayorder');
            }
            $nav = $sortpinfos;
        } else {
            $nav = $_B['setting']['nav'];
        }
    }
} elseif ($do == 'seo') {
}
$limit = 10;
$start = $_B['page'] * $limit;
//$articles=J::t('article')->fetch_all($start,$limit);
$menu_active[$action] = 'class="myactive"';
$side_active[$do] = 'class="myactive"';
include display('header', 1);
 public function on_list()
 {
     $data = parent::on_list(true);
     switch (I('get._mf')) {
         case "ContactsCompany.id":
             $head_log = D('Crm/CustomerHeadLog', 'Model')->get_by_customer(I('get._mv'), true);
             break;
         case "crm_clue_id":
         default:
             return $this->response($data, 'customer_communicate', true);
     }
     if ($head_log) {
         foreach ($head_log as $k => $v) {
             $head_log[$k]['content'] = __('crm.Customer Head Log Type ' . $v['type']);
         }
         $data = array_merge((array) $data, $head_log);
         // 按时间排序
         $data = multi_array_sort($data, 'created', SORT_DESC);
     }
     return $this->response($data, 'customer_communicate', true);
 }
示例#6
0
文件: email.php 项目: bgreiner/orsee
function email__expsess_select($email, $session = array(), $experiment = array(), $participant = array())
{
    global $lang;
    if (isset($session['session_id'])) {
        $selected = $session['experiment_id'] . ',' . $session['session_id'];
    } elseif (isset($experiment['experiment_id'])) {
        $selected = $experiment['experiment_id'] . ',0';
    } elseif (!$email['mailbox']) {
        $selected = '0,0';
    } else {
        $selected = '';
    }
    $pars = array();
    $query = "SELECT " . table('experiments') . ".*, " . table('sessions') . ".*\n            FROM " . table('experiments') . " LEFT JOIN " . table('sessions') . "\n            ON " . table('experiments') . ".experiment_id=" . table('sessions') . ".experiment_id\n            WHERE (" . table('experiments') . ".experiment_finished='n')";
    if (isset($session['experiment_id'])) {
        $query .= " OR (" . table('experiments') . ".experiment_id= :experiment_id) ";
        $pars[':experiment_id'] = $session['experiment_id'];
    } elseif (isset($experiment['experiment_id'])) {
        $query .= " OR (" . table('experiments') . ".experiment_id= :experiment_id) ";
        $pars[':experiment_id'] = $experiment['experiment_id'];
    }
    if (isset($participant['participant_id'])) {
        $query .= " OR (" . table('experiments') . ".experiment_id IN (\n                    SELECT experiment_id FROM " . table('participate_at') . "\n                    WHERE participant_id= :participant_id) ) ";
        $pars[':participant_id'] = $participant['participant_id'];
    }
    $query .= "ORDER BY session_start DESC ";
    $result = or_query($query, $pars);
    $experiments = array();
    while ($e = pdo_fetch_assoc($result)) {
        if ($e['session_id'] == NULL) {
            $e['session_id'] = 0;
        }
        $experiments[$e['experiment_id']]['sessions'][$e['session_id']] = $e;
        $experiments[$e['experiment_id']]['experiment_name'] = $e['experiment_name'];
        if (!isset($experiments[$e['experiment_id']]['lastsesstime']) || $e['session_start'] > $experiments[$e['experiment_id']]['lastsesstime']) {
            $experiments[$e['experiment_id']]['lastsesstime'] = $e['session_start'];
        }
    }
    // now order experiments by the date of the last session of the experiment, DESC!
    foreach ($experiments as $id => $arr) {
        $experiments[$id]['lastsesstime_reversed'] = 0 - $arr['lastsesstime'];
    }
    multi_array_sort($experiments, 'lastsesstime_reversed');
    echo '<SELECT name="expsess"><OPTION value="0,0">' . lang('select_none') . '</OPTION>';
    // list special mail boxes
    $mailboxes = email__load_mailboxes();
    foreach ($mailboxes as $k => $mb) {
        if ($k != 'trash' && $k != 'not_assigned') {
            echo '<OPTION value="box,' . $k . '"';
            if ($email['mailbox'] == $k) {
                echo ' SELECTED';
            }
            echo '>' . $mb . '</OPTION>';
        }
    }
    foreach ($experiments as $exp_id => $texperiment) {
        echo '<OPTION value="' . $exp_id . ',0"';
        if ($selected == $exp_id . ',0') {
            echo ' SELECTED';
        }
        echo '>' . $texperiment['experiment_name'] . '</OPTION>' . "\n";
        foreach ($texperiment['sessions'] as $tsession) {
            if ($tsession['session_id'] > 0) {
                $tsess_name = ortime__format(ortime__sesstime_to_unixtime($tsession['session_start']));
                echo '<OPTION value="' . $tsession['experiment_id'] . ',' . $tsession['session_id'] . '"';
                if ($selected == $tsession['experiment_id'] . ',' . $tsession['session_id']) {
                    echo ' SELECTED';
                }
                echo '>' . $tsession['experiment_name'] . ' - ' . $tsess_name . '</OPTION>';
            }
        }
    }
    if (isset($session['session_id']) && !isset($experiments[$session['experiment_id']]['sessions'][$session['session_id']])) {
        echo '<OPTION value="' . $session['experiment_id'] . ',' . $session['session_id'] . '" SELECTED>' . $experiment['experiment_name'] . ' - ' . ortime__format(ortime__sesstime_to_unixtime($session['session_start'])) . '</OPTION>';
    } elseif (isset($experiment['experiment_id']) && !isset($experiments[$experiment['experiment_id']])) {
        echo '<OPTION value="' . $experiment['experiment_id'] . ',0" SELECTED>' . $experiment['experiment_name'] . '</OPTION>';
    }
    echo '</SELECT>';
}
示例#7
0
文件: dlapp.php 项目: nanfs/lt
            }
        } else {
            $valapps['xtype'] = "{$lang_appdl3}{$valapps[7]}{$lang_appdl4}";
        }
    } else {
        $valapps['xtype'] = "<a href='http://www.metinfo.cn/web/product.htm' target='_blank'><img src='{$img_url}/dwn.png' /><p>{$mytype[$valapps[6]]}</p></a>";
    }
    $newapplist[] = $valapps;
}
function multi_array_sort($multi_array, $sort_key, $sort = SORT_ASC)
{
    if (is_array($multi_array)) {
        foreach ($multi_array as $row_array) {
            if (is_array($row_array)) {
                $key_array[] = $row_array[$sort_key];
            } else {
                return -1;
            }
        }
    } else {
        return -1;
    }
    array_multisort($key_array, $sort, $multi_array);
    return $multi_array;
}
$str_apps = $newapplist;
$str_apps = multi_array_sort($str_apps, '9', SORT_DESC);
$authinfo = $db->get_one("SELECT * FROM {$met_otherinfo} where id=1");
$listclass[2] = 'class="now"';
include template('app/dlapp/dlapp');
footer();
示例#8
0
/**
 * 通过关键字获取相关文章id
 * @params int $docId 	根据用户浏览的文章ID
 * @params int $num		需要返回的文章id的数量,最多是36(此参数暂时不用)
 * return 返回以带有文章数据和论坛数据的数组,  array('article'=>array(5315078=>43,...),'bbs'=>array())
 */
function get_arti_by_word($docIdArr, $num = 12)
{
    if (!$docIdArr) {
        return false;
    }
    global $db_guess, $randNum, $needNum, $propertyArr;
    /* $classArr = get_class_id_by_docid(array(
    		'articleIdArr'=>$docIdArr,
    	));
    	$classStr = implode(',',array_unique($classArr));
    	$classNum = count($classArr);
    	if($classNum>1){
    		$sqlClassStr = ' class_id in('.$classStr.') ';
    	}else if($classNum==1){
    		$sqlClassStr = ' class_id = '.$classStr.' ';
    	}else{
    		$sqlClassStr = '';
    	} */
    $wordArr = get_word_results($docIdArr);
    $wordStr = '"' . implode('","', $wordArr) . '"';
    $sqlWordStr = $wordArr ? ' AND t.word in(' . $wordStr . ') ' : '';
    #var_dump($classArr,$classStr);exit('#667-1#');
    if (is_array($docIdArr)) {
        $docIdStr = implode(',', $docIdArr);
        $docIdStr = ' article_id in (' . $docIdStr . ') ';
    } else {
        $docIdStr = ' article_id=' . $docIdStr . ' ';
    }
    # 查询的字段
    $fields1 = ' t.article_id,t.title,t.uv,count(article_id) as cnt,t.bbsUrl,t.flag ';
    $fields2 = ' t.article_id,t.title,t.uv,count(t.bbsUrl) as cnt,t.bbsUrl,t.flag ';
    $wheres1 = $sqlWordStr . ' AND t.bbsUrl="" ';
    $wheres2 = $sqlWordStr . ' AND t.bbsUrl<>"" AND page_type_id<>4 ';
    $order1 = $order2 = ' ORDER BY uv desc ';
    # 将小结果集放前边(小结果集驱动大结果集)
    # $wordStr = '"京东","苹果","手机","笔记本"';
    $sql = '(SELECT ' . $fields1 . ' from tongji_article_title_words t where 1 ' . $wheres1 . ' GROUP BY t.article_id,t.flag ' . $order1 . ' limit 120)
			UNION 
			(SELECT ' . $fields1 . ' from tongji_article_title_words t where 1 ' . $wheres2 . ' ' . $order2 . ' limit 2)';
    /**
     * @desc START 杨叔说搞一个缓存 add by 任新强 2015-12-30 11:20:21
     */
    if (!$sqlWordStr) {
        return array();
        $mongokey = 'zol:cms:guess:you:like:union:sql:mongo:nb:key';
        $mongoDate = ZOL_Api::run("Kv.MongoCenter.get", array('module' => 'cms', 'key' => $mongokey));
        if (!$mongoDate) {
            $resArr1 = $db_guess->get_results($sql);
            ZOL_Api::run("Kv.MongoCenter.set", array('module' => 'cms', 'key' => $mongokey, 'data' => $resArr1, 'life' => 1800));
        } else {
            $resArr1 = $mongoDate;
        }
    } else {
        $resArr1 = $db_guess->get_results($sql);
    }
    /**
     * @desc END
     */
    # 统计词频 + 分词权重
    $tmpArr1 = $tmpArr2 = $bbsData = $articleData = array();
    $resArr2 = $resArr1;
    $bbsDataEnough = false;
    # 方案1_1
    if ($resArr1) {
        foreach ($resArr1 as $k => $v) {
            # 只需要取1条论坛数据
            if ($v['bbsUrl'] && !$bbsDataEnough) {
                $bbsData[] = $v;
                if (count($bbsData) > 1) {
                    $bbsDataEnough = true;
                }
            }
            if ($v['article_id'] == 1) {
                continue;
            }
            if (!array_key_exists($v['article_id'], $tmpArr1)) {
                $tmpArr1[$v['article_id']]['word_power_val'] = $propertyArr[$v['flag']] * $v['cnt'];
            } else {
                $tmpArr1[$v['article_id']]['num']++;
                $tmpArr1[$v['article_id']]['word_power_val'] += $propertyArr[$v['flag']] * $v['cnt'];
            }
            $tmpArr1[$v['article_id']]['uv'] = $v['uv'];
            $tmpArr1[$v['article_id']]['article_id'] = $v['article_id'];
        }
        # 排除用于查找相关文章的文章id
        foreach ($docIdArr as $k => $v) {
            if (isset($tmpArr1[$v])) {
                unset($tmpArr1[$v]);
            }
        }
        # 对数据按照“分词权重”进行倒序
        $tmpArr1 = multi_array_sort($tmpArr1, 'word_power_val', SORT_DESC);
        $i = 1;
        # 每种相似度一个数组,存储“相似度相同”的数据
        foreach ($tmpArr1 as $k => $v) {
            $newKey = $v['word_power_val'] * 10000;
            $tmpArr2[$newKey][] = $v;
        }
        $tmpArr1 = array();
        # 相同相似度的数据按照uv倒序
        foreach ($tmpArr2 as $k => $v) {
            $tmpArr2[$k] = multi_array_sort($v, 'uv', SORT_DESC);
            $tmpArr1 = array_merge($tmpArr1, $tmpArr2[$k]);
        }
        $tmpArr1 = array_slice($tmpArr1, 0, 12, true);
        $tmpArr2 = array();
        foreach ($tmpArr1 as $k => $v) {
            $tmpArr2[$v['article_id']] = $v;
        }
        $articleData = $tmpArr2;
    }
    #var_dump($articleData,$bbsData);
    #echo $sql; exit('759-5');
    # 文章属性,优先展示第一类属性
    #$propertyArr1 = array('nproduct','nmanu','nsubcat','eng','nproperty','ntype','nbooktitle');
    #$propertyArr2 = array('n','nr','nz');
    if ($resArr1 && is_array($resArr1)) {
        # 数量是否足够
        $num = count($articleData);
        $newArr2 = $articleData;
        if ($num >= $needNum) {
            return array('article' => $newArr2, 'bbs' => $bbsData);
            //return get_from_rand($resArr3);
        } else {
            //exit('821_1');
            return array('article' => $newArr2, 'bbs' => $bbsData);
        }
    } else {
        //mail('*****@*****.**','【ZOL首页自"猜你喜欢"查出的数据不是数组】',"get_arti_by_word\r\n".'查出的数据不是数组'.$sql);
        return array();
    }
}
示例#9
0
文件: index.php 项目: jacoobwang/ecp
function getStaticsDataBycateId($start, $end, $rank_cate_id)
{
    $sql = "select SUM(require_final_cost) as price,require_type_id,type_name as name from tb_require,tb_type where require_start_date >= '" . $start . "' and require_finish_date <='" . $end . "' and require_rank_cate_id =" . $rank_cate_id . " and is_del = 0 and require_type_id=type_id group by require_type_id";
    //select SUM(`require_final_cost`) as money,require_type_id,type_name from tb_require,tb_type where require_rank_cate_id =133 and require_type_id=type_id group by require_type_id
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $s_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $db = null;
        if (empty($s_data)) {
            echo '{"statistics":[]}';
            return;
        }
        $tmp = array_sum(array_map(function ($val) {
            return $val['price'];
        }, $s_data));
        $s_data = multi_array_sort($s_data, 'price', SORT_DESC);
        foreach ($s_data as $k => $rs) {
            $s_data[$k]['per'] = number_format($rs['price'] / $tmp, 4, '.', '') * 100;
            $s_data[$k]['fmt_price'] = $rs['price'];
        }
        echo '{"statistics":' . json_encode($s_data) . '}';
    } catch (PDOException $e) {
        echo '{"error":{"text":"' . $e->getMessage() . '"}}';
    }
}
示例#10
0
 /**
  * 默认登录页
  * @return void
  */
 public function login()
 {
     if (model('Passport')->isLogged()) {
         U('weiba/Index/index', '', true);
     }
     // 获取邮箱后缀
     $registerConf = model('Xdata')->get('admin_Config:register');
     $this->assign('emailSuffix', explode(',', $registerConf['email_suffix']));
     $this->assign('register_type', $registerConf['register_type']);
     $data = model('Xdata')->get("admin_Config:seo_login");
     !empty($data['title']) && $this->setTitle($data['title']);
     !empty($data['keywords']) && $this->setKeywords($data['keywords']);
     !empty($data['des']) && $this->setDescription($data['des']);
     $this->assign('invite', $_GET['invite'] ? $_GET['invite'] : '');
     // 时间轴数据
     $domain = model('User')->getDomain();
     $map['is_del'] = 0;
     $limit = 10;
     $setlist = D('login_time_tree')->select();
     if ($setlist) {
         foreach ($setlist as $k => $v) {
             $tmp = D('weiba_post')->where('is_del = 0 and post_id=' . $v['post_id'])->field('post_uid, content, title')->find();
             $setlist[$k]['post_uname'] = D('user')->where('uid=' . $tmp['post_uid'])->getField('uname');
             $setlist[$k]['udomain'] = $domain[$tmp['post_uid']];
             $setlist[$k]['content'] = strip_tags($tmp['content']);
             $setlist[$k]['title'] = $tmp['title'];
             $str_ids .= $v['post_id'] . ',';
         }
         $str_ids = rtrim($str_ids, ',');
         $map['post_id'] = array('not in', $str_ids);
     } else {
         $setlist = array();
     }
     $limit1 = $limit - count($setlist);
     $postList = D('weiba_post')->where($map)->limit($limit1)->order('reply_all_count desc')->field('post_uid, content, title, post_id')->select();
     $i = 1;
     foreach ($postList as $k => $v) {
         $postList[$k]['post_uname'] = D('user')->where('uid=' . $v['post_uid'])->getField('uname');
         $postList[$k]['udomain'] = $domain[$v['post_uid']];
         $postList[$k]['content'] = strip_tags($v[content]);
         $postList[$k]['order'] = $i + 0.1;
         $i++;
     }
     $postList = array_merge($postList, $setlist);
     $postList = multi_array_sort($postList, 'order');
     $this->assign('postList', $postList);
     $this->assign('login', 1);
     $this->display('login');
 }
示例#11
0
 public function getLocation()
 {
     $i = 0;
     $push_num = 1;
     $infolbsModel = new Model_InfoLbs();
     $filter['where'] = " customer_id='{$this->customer_id}' and state='1' and x_dian!='' ";
     $sql = $infolbsModel->select($filter);
     $inforesult = $infolbsModel->fetchAll($sql);
     $infocount = count($inforesult);
     for ($i = 0; $i < $infocount; $i++) {
         $inforesult[$i]['location_desc'] = strip_tags($inforesult[$i]['location_desc']);
         $short_intro = cut_str(strip_tags($inforesult[$i]['location_intro']), 120, $start = 0, $code = 'UTF-8');
         $inforesult[$i]['location_desc'] = $inforesult[$i]['location_desc'] != '' ? $inforesult[$i]['location_desc'] : $short_intro;
         $inforesult[$i]['faraway'] = $this->get_distance($this->location_x, $this->location_y, $inforesult[$i]['x_dian'], $inforesult[$i]['y_dian']);
     }
     $newlocallist = multi_array_sort($inforesult, 'faraway', $sort = SORT_ASC);
     $customerconfigModel = new Model_CustomerConfig();
     $filter['where'] = " customer_id='{$this->customer_id}' and c_type='lbs_push' ";
     $sql = $customerconfigModel->select($filter);
     $inforesult = $customerconfigModel->fetchRow($sql);
     if ($inforesult['c_value']) {
         $push_num = $inforesult['c_value'];
     } else {
         if ($i >= 2) {
             $push_num = 2;
         }
     }
     $push_num = $push_num <= $i ? $push_num : $i;
     for ($j = 0; $j < $push_num; $j++) {
         if ($j >= 10) {
             $push_num = 10;
             break;
         }
         $sql = "update info_lbs set push_num=push_num+1 where id='" . $newlocallist[$j]['id'] . "' limit 1";
         $customerconfigModel->query($sql);
         $infolbsrecordModel = new Model_InfoLbsRecord();
         $row['lbs_id'] = $newlocallist[$j]['id'];
         $row['customer_id'] = $this->customer_id;
         $row['fromuser'] = $this->fromuser;
         $row['fromwhere'] = $this->fromwhere;
         $row['ip'] = $_WGT['IP'];
         $row['create_date'] = date("Y-m-d H:i:s");
         $infolbsrecordModel->insert($row);
         $url = 'http://' . $_SERVER['HTTP_HOST'] . "/mobile/info.php?t=location&id=" . $newlocallist[$j]['id'];
         $itemlist .= "<item>\n\t\t <Title><![CDATA[[" . $newlocallist[$j]['faraway'] . "公里]" . $newlocallist[$j]['location_name'] . "]]></Title>\n\t\t <Description><![CDATA[" . $newlocallist[$j]['location_desc'] . "]]></Description>\n\t\t <PicUrl><![CDATA[http://" . $_SERVER['HTTP_HOST'] . "/data/image_c/" . $newlocallist[$j]['location_pic'] . "]]></PicUrl>\n\t\t <Url><![CDATA[{$url}]]></Url>\n\t\t </item>";
     }
     if ($i > 0) {
         $Bodystr = "\n\t\t\t <ArticleCount>{$push_num}</ArticleCount>\n\t\t\t <Articles>\n\t\t\t {$itemlist}\n\t\t\t </Articles>";
         $data['msgtype'] = 'news';
         $data['bodystr'] = $Bodystr;
         return $data;
     }
 }
示例#12
0
 /**
  * 排序处理用于修改学生所属区域的教育背景信息.
  * 学位排名一样, 按毕业日期排序.
  * 
  * @access private
  * @param array $eduBackInfo 二维数组.
  * @return string 国家名称
  * @author Liuping <*****@*****.**> 
  */
 public function sortEduForModArea_bak($eduBackInfo)
 {
     // 学位排名, 数字越小排名越高
     //'Diploma', 'HND', 'Bachelor', 'Master', 'Other'
     $arrQua = [1 => 'Master', 2 => 'Bachelor', 3 => 'HND', 4 => 'Diploma', 5 => 'Other'];
     $newEduBackInfo = [];
     foreach ($eduBackInfo as $row) {
         $_qua = $row['qualification'];
         if (FALSE !== stripos($_qua, 'other')) {
             $_qua = 'Other';
         }
         // 该学位的排名
         $_index = array_search($_qua, $arrQua, TRUE);
         if (FALSE !== $_index) {
             $_gradtime = dateToTimestamp($row['graduation_date'], '/');
             $_new_row = ['country' => $row['institution_country'], 'qua' => $_index, 'gradetime' => $_gradtime];
             $newEduBackInfo[] = $_new_row;
         }
     }
     unset($eduBackInfo);
     // 排序, 先按
     multi_array_sort($newEduBackInfo, 'qua', SORT_ASC, 'gradetime', SORT_DESC);
     $newEduBackInfo = array_values($newEduBackInfo);
     $result = isset($newEduBackInfo[0]) ? $newEduBackInfo[0]['country'] : '';
     return $result;
 }
示例#13
0
function experiment__preload_experiments()
{
    global $lang, $preloaded_experiments;
    if (isset($preloaded_experiments) && is_array($preloaded_experiments) && count($preloaded_experiments) > 0) {
        return $preloaded_experiments;
    } else {
        $experiments = array();
        $query = "SELECT experiment_id, experiment_name, experimenter from " . table('experiments');
        $result = or_query($query);
        while ($line = pdo_fetch_assoc($result)) {
            $experiments[$line['experiment_id']] = array('time' => '', 'start_date' => '', 'end_date' => '', 'assigned' => 'n', 'participated' => 'n');
            $experiments[$line['experiment_id']]['experiment_id'] = $line['experiment_id'];
            $experiments[$line['experiment_id']]['experiment_name'] = $line['experiment_name'];
            $experiments[$line['experiment_id']]['experimenter'] = $line['experimenter'];
        }
        $query = "SELECT experiment_id, \n\t\t\t\tmin(session_start) as start_date,\n\t\t\t\tmax(session_start) as end_date \n\t\t\t\tFROM " . table('sessions') . " \n\t\t\t\tWHERE session_id>0\n\t\t\t\tGROUP BY experiment_id";
        $result = or_query($query);
        while ($line = pdo_fetch_assoc($result)) {
            $experiments[$line['experiment_id']]['time'] = 1000000000000 - $line['end_date'];
            $experiments[$line['experiment_id']]['start_date'] = $line['start_date'];
            $experiments[$line['experiment_id']]['end_date'] = $line['end_date'];
        }
        $query = "SELECT experiment_id FROM " . table('participate_at') . " GROUP BY experiment_id";
        $result = or_query($query);
        while ($line = pdo_fetch_assoc($result)) {
            $experiments[$line['experiment_id']]['assigned'] = 'y';
        }
        $participated_clause = expregister__get_pstatus_query_snippet("participated");
        $query = "SELECT experiment_id FROM " . table('participate_at') . " WHERE " . $participated_clause . " GROUP BY experiment_id";
        $result = or_query($query);
        while ($line = pdo_fetch_assoc($result)) {
            $experiments[$line['experiment_id']]['participated'] = 'y';
        }
        $sort_order = "time,experiment_name";
        multi_array_sort($experiments, $sort_order);
        $preloaded_experiments = $experiments;
        return $experiments;
    }
}
 function view()
 {
     $q = D('Question');
     $question = $q->relation(true)->where(array('id' => $this->get['qid']))->find();
     $is_me = $question['uid'] == $this->uid || $this->uid == 1 ? true : false;
     $f = M('focus');
     $focus_id = $f->where(array('qid' => $this->get['qid']))->field('qid,uid')->select();
     $focus_arr = array();
     foreach ($focus_id as $k => $v) {
         $focus_arr[$k] = $v['uid'];
     }
     if (in_array($this->uid, $focus_arr) && $focus_id[0]['uid'] != NULL) {
         $f->where(array('qid' => $this->get['qid'], 'uid' => $this->uid))->setField('newanswer', 0);
         //clear newnum
         $this->assign('focus_class', 'focus_press');
         $this->assign('focus_ini', 0);
     } else {
         $this->assign('focus_class', 'focus_btn');
         $this->assign('focus_ini', 1);
     }
     if ($question != NULL) {
         $q->where(array('id' => $this->get['qid']))->setInc('viewcount');
         $f->where(array('qid' => $this->get['qid']))->setInc('viewcount');
         $focus_uid = $f->where(array('qid' => $this->get['qid']))->select();
         if ($focus_uid) {
             $this->assign('focus_uid', $focus_uid);
         }
         $this->assign('question', $question);
         $p = $this->get['p'] ? $this->get['p'] : 1;
         switch ($this->get['order']) {
             case 'timeinc':
                 $answer = array_slice(multi_array_sort($question['answer'], 'bestanswer', SORT_DESC, 'id', SORT_ASC), ($p - 1) * $this->setting['reply_per_page'], $this->setting['reply_per_page']);
                 break;
             case 'agreedec':
                 $answer = array_slice(multi_array_sort($question['answer'], 'bestanswer', SORT_DESC, 'agreecount', SORT_DESC), ($p - 1) * $this->setting['reply_per_page'], $this->setting['reply_per_page']);
                 break;
             default:
                 $answer = array_slice(multi_array_sort($question['answer'], 'bestanswer', SORT_DESC, 'id', SORT_ASC), ($p - 1) * $this->setting['reply_per_page'], $this->setting['reply_per_page']);
         }
         $count = count($question['answer']);
         $Page = new Page($count, $this->setting['reply_per_page']);
         $show = $Page->show();
         $this->assign('is_me', $is_me);
         $this->assign('page', $show);
         $this->assign('answer', $answer);
         $this->assign('title', $question['title']);
         $this->assign('keywords', str_replace(' ', ',', $question['keywords']));
         $this->assign('description', strip_tags($question['detail']));
         /*related question code start*/
         $keywords = explode(",", $question['keywords']);
         $related_qid = array();
         $seachwords = M('searchwords');
         foreach ($keywords as $k => $v) {
             $qid = $seachwords->where(array('keywords' => $v))->select();
             foreach ($qid as $k2 => $v2) {
                 array_push($related_qid, $v2['qid']);
             }
         }
         $related_qid = array_count_values($related_qid);
         arsort($related_qid);
         $related_qid = array_slice(array_keys($related_qid), 1, 5);
         $related_question = '';
         if ($related_qid == NULL) {
             $related_question = S('side_no_reply');
             $related_title = '期待您来回答';
         } else {
             foreach ($related_qid as $k => $v) {
                 $t = $q->where(array('id' => $v))->getField('title');
                 $related_question .= '<a href="' . U('Question/view?qid=' . $v) . '" class="side_list">' . $t . '</a>';
             }
             $related_title = '相关的' . $this->sign;
         }
         $this->assign('related_question', $related_question);
         $this->assign('related_title', $related_title);
         /*related question code end*/
         $this->display();
     } else {
         $this->display('question_error');
     }
 }
示例#15
0
/**
 * 通过关键字获取相关文章id
 * 文章页的要排除:370(Z超值)
 * @params int $docId 	根据用户浏览的文章ID
 * @params int $num		需要返回的文章id的数量,最多是36(此参数暂时不用)
 */
function get_arti_by_word($docIdArr, $num2 = 36)
{
    global $randNum, $classId, $db_doc_read, $propertyArr;
    if (!$docIdArr) {
        return array();
    }
    $wordArr = get_word_results($docIdArr);
    $wordStr = '"' . implode('","', $wordArr) . '"';
    $sqlWordStr = $wordArr ? ' AND t.word in(' . $wordStr . ') ' : '';
    # 查询的字段
    $fields1 = ' t.article_id,t.title,t.uv,count(t.article_id) as cnt,t.bbsUrl,t.flag ';
    # 将小结果集放前边(小结果集驱动大结果集)
    $wheres1 = $sqlWordStr . ' AND t.bbsUrl="" ';
    if (!$sqlWordStr) {
        return array();
    }
    $wheres2 = $sqlWordStr . ' AND t.bbsUrl<>"" AND page_type_id<>4 ';
    $order1 = $order2 = ' ORDER BY uv desc ';
    $sql = '(SELECT ' . $fields1 . ' from tongji_article_title_words t where 1 ' . $wheres1 . ' GROUP BY t.article_id,t.flag ' . $order1 . ' limit 120)
			';
    #echo $sql;exit();
    $resArr1 = $db_doc_read->get_results($sql);
    //201601062133 suhy
    /**
     * @desc START 杨叔说搞一个缓存 add by 任新强 2015-12-29 20:37:21 
     */
    // 	if(!$sqlWordStr) {
    //     	$mongokey = 'zol:cms:keyword:relevance:get:docid:by:ry';
    //     	$mongoDate = ZOL_Api::run("Kv.MongoCenter.get" , array(
    //         	'module'         => 'cms',           #业务名
    //         	'key'            => $mongokey,   #key
    //         ));
    //     	if(!$mongoDate){
    //     	    $resArr1 = $db_doc_read->get_results($sql);
    //     	    ZOL_Api::run("Kv.MongoCenter.set" , array(
    //     	        'module'         => 'cms',           #业务名
    //     	        'key'            => $mongokey,   	 #key
    //     	        'data'           => $resArr1,       #数据
    //     	        'life'           => 60*60*2,        #生命期
    //     	    ));
    //     	} else {
    //     	    $resArr1 = $mongoDate;
    //     	}
    // 	}
    /**
     * @desc END
     */
    # 统计词频 + 分词权重
    $tmpArr1 = $tmpArr2 = $bbsData = $articleData = array();
    $resArr2 = $resArr1;
    $bbsDataEnough = false;
    # 方案1_1
    if ($resArr1) {
        foreach ($resArr1 as $k => $v) {
            # 只需要取1条论坛数据
            if ($v['bbsUrl'] && !$bbsDataEnough) {
                $bbsData[] = $v;
                if (count($bbsData) > 1) {
                    $bbsDataEnough = true;
                }
            }
            if ($v['article_id'] == 1) {
                continue;
            }
            if (!array_key_exists($v['article_id'], $tmpArr1)) {
                $tmpArr1[$v['article_id']]['word_power_val'] = $propertyArr[$v['flag']] * $v['cnt'];
            } else {
                $tmpArr1[$v['article_id']]['num']++;
                $tmpArr1[$v['article_id']]['word_power_val'] += $propertyArr[$v['flag']] * $v['cnt'];
            }
            $tmpArr1[$v['article_id']]['uv'] = $v['uv'];
            $tmpArr1[$v['article_id']]['article_id'] = $v['article_id'];
        }
        # 排除用于查找相关文章的文章id
        foreach ($docIdArr as $k => $v) {
            if (isset($tmpArr1[$v])) {
                unset($tmpArr1[$v]);
            }
        }
        # 对数据按照“分词权重”进行倒序
        $tmpArr1 = multi_array_sort($tmpArr1, 'word_power_val', SORT_DESC);
        $i = 1;
        # 每种相似度一个数组,存储“相似度相同”的数据
        foreach ($tmpArr1 as $k => $v) {
            $newKey = $v['word_power_val'] * 10000;
            $tmpArr2[$newKey][] = $v;
        }
        $tmpArr1 = array();
        # 相同相似度的数据按照uv倒序
        foreach ($tmpArr2 as $k => $v) {
            $tmpArr2[$k] = multi_array_sort($v, 'uv', SORT_DESC);
            $tmpArr1 = array_merge($tmpArr1, $tmpArr2[$k]);
        }
        $tmpArr1 = array_slice($tmpArr1, 0, 12, true);
        $tmpArr2 = array();
        foreach ($tmpArr1 as $k => $v) {
            $tmpArr2[$v['article_id']] = $v;
        }
        $articleData = $tmpArr2;
    }
    #var_dump($articleData);exit('#868-1#');
    if ($resArr1 && is_array($resArr1)) {
        # 数量是否足够
        $num = count($articleData);
        $newArr2 = $articleData;
        if ($num >= $needNum) {
            return array('article' => $newArr2, 'bbs' => $bbsData);
            //return get_from_rand($resArr3);
        } else {
            //exit('821_1');
            return array('article' => $newArr2, 'bbs' => $bbsData);
        }
    } else {
        //		mail('*****@*****.**','【ZOL首页自"猜你喜欢"查出的数据不是数组】',"get_arti_by_word\r\n".'查出的数据不是数组'.$sql);
        return array();
    }
}