/** * 读取用户列表 * SELECT contact_id AS contactid, unique_id AS uniqueid, true_name AS truename, pinyin, email, mobile, * affinity, last_contact_time AS lastcontacttime, groups * FROM td_contact * WHERE .. * ORDER BY * LIMIT .. * * @param $condition * @param $filter * @param $sort * @param $maxCount */ public function getContacts(array $condition, $filter = null, $sort = null, $maxCount = null) { $table = 'td_contact AS c '; $columns = 'c.contact_id AS contactid, c.unique_id AS uniqueid, true_name AS truename, pinyin, email, mobile, ' . 'affinity, last_contact_time AS lastcontacttime, groups, from_user AS fromuser, ISNULL(c.avatars) AS isavatars'; $where = array(); $order = ''; $limit = ''; $recordClass = 'Dao_Td_Contact_Record_Contact'; if (!empty($condition['contactid'])) { $where[] = 'c.contact_id = ' . $this->_db->quote($condition['contactid']); } if (!empty($condition['uniqueid'])) { $where[] = 'c.unique_id = ' . $this->_db->quote($condition['uniqueid']); } if (!empty($condition['keyword'])) { $keyword = $this->_db->quote("%{$condition['keyword']}%"); $like[] = "true_name LIKE {$keyword}"; if (!Oray_Function::hasCnChar($keyword)) { $like[] = "pinyin LIKE {$keyword}"; $like[] = "email LIKE {$keyword}"; } $where[] = '(' . implode(' OR ', $like) . ')'; } if (!empty($condition['pinyin'])) { $keyword = $this->_db->quote($condition['pinyin'] . '%'); $where[] = "(true_name LIKE {$keyword} OR pinyin LIKE {$keyword})"; } if (array_key_exists('groupid', $condition)) { if (!empty($condition['groupid'])) { $table .= ' LEFT JOIN td_contact_group_member AS gm ON c.contact_id = gm.contact_id AND c.unique_id = gm.unique_id'; $where[] = 'gm.group_id = ' . $this->_db->quote($condition['groupid']); } else { $where[] = 'c.groups = \'\''; } } if (isset($filter['isshow'])) { if (null !== $condition['isshow']) { $where[] = 'c.is_show = ' . $condition['isshow'] ? 1 : 0; } } else { $where[] = 'c.is_show = 1'; } // WHERE $where = implode(' AND ', $where); if ($where) { $where = 'WHERE ' . $where; } // 格式化排序参数 $sort = $this->_formatSort($sort); foreach ($sort as $key => $val) { switch ($key) { case 'lastcontacttime': $key = 'last_contact_time'; break; case 'affinity': default: continue 2; break; } $order[] = $key . ' ' . $val; } if ($order) { $order = 'ORDER BY ' . implode(', ', $order); } if (is_int($maxCount) && $maxCount > 0) { $limit = 'LIMIT ' . $maxCount; } $sql = "SELECT {$columns} FROM {$table} {$where} {$order} {$limit}"; try { $records = $this->_db->fetchAll($sql); return new Oray_Dao_Recordset($records, $recordClass); } catch (Zend_Db_Exception $e) { $this->_catchException($e, __METHOD__); return false; } }
/** * 获取构架可见的用户列表 * * @param array $condition * @param array $filter * @param array $sort * @param int $maxCount * @return Oray_Dao_Recordset */ public function getCastUsers(array $condition, $filter = null, $sort = null, $maxCount = null) { $table = 'v_cast_user AS V'; $columns = 'V.org_id AS orgid, V.true_name AS truename, V.user_id AS userid, V.mobile, V.tel, V.last_update_time AS lastupdatetime, ' . 'V.dept_id AS deptid, V.domain_name AS domainname, V.pinyin, V.unique_id AS uniqueid'; $where = array(); $order = array(); $limit = ''; if (isset($condition['orgid'])) { $where[] = 'V.org_id = ' . $this->_db->quote($condition['orgid']); } if (isset($condition['castid'])) { $where[] = 'V.cast_id = ' . $this->_db->quote($condition['castid']); } if (!empty($condition['keyword'])) { $keyword = $this->_db->quote('%' . $condition['keyword'] . '%'); $like[] = "V.true_name LIKE {$keyword}"; if (!Oray_Function::hasCnChar($keyword)) { $like[] = "V.pinyin LIKE {$keyword}"; $like[] = "V.user_id LIKE {$keyword}"; } $where[] = '(' . implode(' OR ', $like) . ')'; } if (!empty($condition['deptid'])) { if (is_array($condition['deptid'])) { $condition['deptid'] = array_map(array($this->_db, 'quote'), $condition['deptid']); $where[] = 'V.dept_id IN (' . implode(',', $condition['deptid']) . ')'; } else { $where[] = 'V.dept_id = ' . $this->_db->quote($condition['deptid']); } } if (!empty($condition['pinyin'])) { $keyword = $this->_db->quote($condition['pinyin'] . '%'); $where[] = "(V.true_name LIKE {$keyword} OR V.pinyin LIKE {$keyword})"; } // WHERE $where = implode(' AND ', $where); // 排序 $sort = $this->_formatSort($sort); foreach ($sort as $key => $val) { switch ($key) { default: continue 2; break; } $order[] = $key . ' ' . $val; } // ORDER $order = implode(', ', $order); if (is_int($maxCount) && $maxCount > 0) { $limit = 'LIMIT ' . $maxCount; } $sql = "SELECT {$columns} FROM {$table} WHERE {$where} {$order} {$limit}"; $records = $this->_db->fetchAll($sql); return new Oray_Dao_Recordset($records, 'Dao_Md_Cast_Record_Users'); }