本文整理汇总了PHP中waContact::add方法的典型用法代码示例。如果您正苦于以下问题:PHP waContact::add方法的具体用法?PHP waContact::add怎么用?PHP waContact::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waContact
的用法示例。
在下文中一共展示了waContact::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: merge
/**
* Merge given contacts into master contact, save, send merge event, then delete slaves.
*
* !!! Probably should move it into something like contactsHelper
*
* @param array $merge_ids list of contact ids
* @param int $master_id contact id to merge others into
* @return array
*/
public static function merge($merge_ids, $master_id)
{
$merge_ids[] = $master_id;
// List of contacts to merge
$collection = new contactsCollection('id/' . implode(',', $merge_ids));
$contacts_data = $collection->getContacts('*');
// Master contact data
if (!$master_id || !isset($contacts_data[$master_id])) {
throw new waException('No contact to merge into.');
}
$master_data = $contacts_data[$master_id];
unset($contacts_data[$master_id]);
$master = new waContact($master_id);
$result = array('total_requested' => count($contacts_data) + 1, 'total_merged' => 0, 'error' => '', 'users' => 0);
if ($master_data['photo']) {
$filename = wa()->getDataPath(waContact::getPhotoDir($master_data['id']) . "{$master_data['photo']}.original.jpg", true, 'contacts');
if (!file_exists($filename)) {
$master_data['photo'] = null;
}
}
$data_fields = waContactFields::getAll('enabled');
$check_duplicates = array();
// field_id => true
$update_photo = null;
// if need to update photo here it is file paths
// merge loop
foreach ($contacts_data as $id => $info) {
if ($info['is_user'] > 0) {
$result['users']++;
unset($contacts_data[$id]);
continue;
}
foreach ($data_fields as $f => $field) {
if (!empty($info[$f])) {
if ($field->isMulti()) {
$master->add($f, $info[$f]);
$check_duplicates[$f] = true;
} else {
// Field does not allow multiple values.
// Set value if no value yet.
if (empty($master_data[$f])) {
$master[$f] = $master_data[$f] = $info[$f];
}
}
}
}
// photo
if (!$master_data['photo'] && $info['photo'] && !$update_photo) {
$filename_original = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.original.jpg", true, 'contacts');
if (file_exists($filename_original)) {
$update_photo = array('original' => $filename_original);
$filename_crop = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.jpg", true, 'contacts');
if (file_exists($filename_crop)) {
$update_photo['crop'] = $filename_crop;
}
}
}
// birthday parts
if (!empty($data_fields['birthday'])) {
foreach (array('birth_day', 'birth_month', 'birth_year') as $f) {
if (empty($master_data[$f]) && !empty($info[$f])) {
$master[$f] = $master_data[$f] = $info[$f];
}
}
}
}
// Remove duplicates
foreach (array_keys($check_duplicates) as $f) {
$values = $master[$f];
if (!is_array($values) || count($values) <= 1) {
continue;
}
$unique_values = array();
// md5 => true
foreach ($values as $k => $v) {
if (is_array($v)) {
if (isset($v['value']) && is_string($v['value'])) {
$v = $v['value'];
} else {
unset($v['ext'], $v['status']);
ksort($v);
$v = serialize($v);
}
}
$hash = md5(mb_strtolower($v));
if (!empty($unique_values[$hash])) {
unset($values[$k]);
continue;
}
$unique_values[$hash] = true;
}
//.........这里部分代码省略.........