本文整理汇总了PHP中waContact::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP waContact::exists方法的具体用法?PHP waContact::exists怎么用?PHP waContact::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waContact
的用法示例。
在下文中一共展示了waContact::exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gen
/**
* @param $id
* @param array $params
* @return shopCouponPluginCoupon
*/
public static function gen($id, $params = array())
{
$m = new shopCouponModel();
$tm = new shopCouponPluginTemplateModel();
if (!($gen = $tm->getById($id))) {
return new shopCouponPluginCoupon();
}
if (!($candidates = self::_candidates($gen))) {
return new shopCouponPluginCoupon();
}
// Кто-то читает код? :)
// Стоит проверять в цикле, чтоб наверняка?
//do{
$exists = $m->select('code')->where('code IN(?)', $candidates)->fetchAll(null, true);
$candidates = array_diff($candidates, $exists);
$code = reset($candidates);
//} while(empty($code));
$comment = $gen['comment'];
if (!empty($params['contact_id'])) {
$contact = new waContact($params['contact_id']);
if ($contact->exists()) {
$comment .= "\n" . _wp('for') . ' ' . $contact->getName();
}
$comment = trim($comment);
}
try {
$code = mb_substr($code, 0, 32);
$coupon = array('code' => $code, 'type' => $gen['type'], 'limit' => $gen['limit'], 'value' => $gen['value'], 'comment' => $comment, 'expire_datetime' => $gen['expire_hours'] ? date('Y-m-d H:i:s', time() + $gen['expire_hours'] * 3600) : null, 'create_datetime' => date('Y-m-d H:i:s'), 'create_contact_id' => $gen['create_contact_id']);
$m->insert($coupon);
} catch (waDbException $e) {
$coupon = array();
}
return new shopCouponPluginCoupon($coupon);
}
示例2: getContactInfo
/** Using $this->id get waContact and save it in $this->contact;
* Load vars into $this->view specific to waContact. */
protected function getContactInfo()
{
$system = wa();
if ($this->id == $system->getUser()->getId()) {
$this->contact = $system->getUser();
$this->view->assign('own_profile', true);
} else {
$this->contact = new waContact($this->id);
$this->view->assign('own_profile', false);
}
$exists = $this->contact->exists();
if ($exists) {
$this->view->assign('contact', $this->contact);
// who created this contact and when
$this->view->assign('contact_create_time', waDateTime::format('datetime', $this->contact['create_datetime'], $system->getUser()->getTimezone()));
if ($this->contact['create_contact_id']) {
try {
$author = new waContact($this->contact['create_contact_id']);
if ($author['name']) {
$this->view->assign('author', $author);
}
} catch (Exception $e) {
// Contact not found. Ignore silently.
}
}
$this->view->assign('top', $this->contact->getTopFields());
// Main contact editor data
$fieldValues = $this->contact->load('js', true);
$m = new waContactModel();
if (isset($fieldValues['company_contact_id'])) {
if (!$m->getById($fieldValues['company_contact_id'])) {
$fieldValues['company_contact_id'] = 0;
$this->contact->save(array('company_contact_id' => 0));
}
}
$contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', true);
// Only show fields that are allowed in own profile
if (!empty($this->params['limited_own_profile'])) {
$allowed = array();
foreach (waContactFields::getAll('person') as $f) {
if ($f->getParameter('allow_self_edit')) {
$allowed[$f->getId()] = true;
}
}
$fieldValues = array_intersect_key($fieldValues, $allowed);
$contactFields = array_intersect_key($contactFields, $allowed);
}
contactsHelper::normalzieContactFieldValues($fieldValues, $contactFields);
$this->view->assign('contactFields', $contactFields);
$this->view->assign('contactFieldsOrder', array_keys($contactFields));
$this->view->assign('fieldValues', $fieldValues);
// Contact categories
$cm = new waContactCategoriesModel();
$this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id)));
} else {
$this->view->assign('contact', array('id' => $this->id));
}
return $exists;
}
示例3: execute
public function execute()
{
// only allowed to admin
if ($this->getRights('backend') <= 1) {
throw new waRightsException(_w('Access denied'));
}
$ids = waRequest::request('ids', array(), 'array_int');
$collection = new contactsCollection('id/' . implode(',', $ids));
$collection->orderBy('~data', 'DESC');
$contacts = $collection->getContacts('*,photo_url_96', 0, 500);
foreach ($contacts as &$c) {
$c['name'] = waContactNameField::formatName($c);
}
unset($c);
// Field names
$fields = array();
// field id => field name
foreach (waContactFields::getAll('enabled') as $field_id => $field) {
$fields[$field_id] = $field->getName();
// Format data for template if needed
foreach ($contacts as &$c) {
if (empty($c[$field_id])) {
continue;
}
if (!is_array($c[$field_id]) || $this->is_assoc($c[$field_id])) {
$c[$field_id] = $field->format($c[$field_id], 'html');
} else {
foreach ($c[$field_id] as &$v) {
$v = $field->format($v, 'html');
}
unset($v);
$c[$field_id] = implode(', ', $c[$field_id]);
}
}
unset($c);
}
// skip some fields in the list
$fields = array_diff_key($fields, array('title' => true, 'name' => true, 'photo' => true, 'firstname' => true, 'middlename' => true, 'lastname' => true, 'locale' => true, 'timezone' => true));
// Initialize 'master_only' key
foreach ($contacts as &$c) {
$c['master_only'] = '';
}
unset($c);
// Event to allow other applications to add their data if needed
$params = array_keys($contacts);
$links = wa()->event('links', $params);
$apps = wa()->getApps();
foreach ($links as $app_id => $app_links) {
foreach ($app_links as $contact_id => $contact_links) {
foreach ($contact_links as $l) {
// Show information about links
$field_name = $apps[$app_id]['name'] . '/' . $l['role'];
$fields[$field_name] = $field_name;
$contacts[$contact_id][$field_name] = _w("%d link", "%d links", $l['links_number']);
// Show warning if this contact cannot be merged into other contacts.
if (!empty($l['forbid_merge_reason'])) {
if (!empty($contacts[$contact_id]['master_only'])) {
$contacts[$contact_id]['master_only'] .= '<br>';
} else {
$contacts[$contact_id]['master_only'] = '';
}
$contacts[$contact_id]['master_only'] .= $l['forbid_merge_reason'];
}
}
}
}
// List of contacts that can be safely merged into other contacts
$slave_ids = array();
foreach ($contacts as &$c) {
if ($c['is_user'] > 0) {
$c['master_only'] = ($c['master_only'] ? $c['master_only'] . '<br>' : '') . _w('Users can not be merged into other contacts.');
} else {
if (empty($c['master_only'])) {
$slave_ids[] = $c['id'];
}
}
$author = array('name' => '');
if ($c['create_contact_id']) {
$author_contact = new waContact($c['create_contact_id']);
if ($author_contact->exists()) {
$author = $author_contact;
}
}
$c['author'] = $author;
}
unset($c);
$this->view->assign('slave_ids', $slave_ids);
$this->view->assign('contacts', $contacts);
$this->view->assign('fields', $fields);
}