本文整理汇总了PHP中Contacts::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Contacts::instance方法的具体用法?PHP Contacts::instance怎么用?PHP Contacts::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contacts
的用法示例。
在下文中一共展示了Contacts::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: countAllowedContacts
function countAllowedContacts()
{
$conditions = "";
if (!can_manage_contacts(logged_user())) {
$conditions .= "e.user_type>0 OR e.object_id IN (\r\n\t\t\t\tSELECT st.object_id FROM " . TABLE_PREFIX . "sharing_table st WHERE st.group_id IN (\r\n\t\t\t\t\tSELECT pg.id FROM " . TABLE_PREFIX . "permission_groups pg WHERE pg.type='permission_groups' AND pg.contact_id = " . logged_user()->getId() . "\r\n\t\t\t\t)\r\n\t\t\t)";
}
return Contacts::instance()->count($conditions);
}
示例2: getAllowedContacts
/**
* Returns an array containing only the contacts that logged_user can read.
*
* @return array
*/
function getAllowedContacts($extra_conds = null)
{
$result = array();
foreach ($contacts = Contacts::instance()->findAll(array('conditions' => array($extra_conds))) as $c) {
/* @var $c Contact */
if ($c->canView(logged_user())) {
$result[] = $c;
}
}
return $result;
}
示例3: getAllowedContacts
/**
* Returns an array containing only the contacts that logged_user can read.
*
* @return array
*/
function getAllowedContacts($extra_conds = null) {
$result = array();
$conditions = $extra_conds ? "$extra_conds AND " : "";
$conditions .= "e.object_id IN (
SELECT st.object_id FROM ".TABLE_PREFIX."sharing_table st WHERE st.group_id IN (
SELECT pg.id FROM ".TABLE_PREFIX."permission_groups pg WHERE pg.type='permission_groups' AND pg.contact_id = ".logged_user()->getId()."
)
)";
$contacts = Contacts::instance()->findAll(array('conditions' => $conditions));
return $contacts;
}
示例4: addToSharingTable
/**
* Override defaults.
* Also adds mail to sharing table if is not categorized.
* Only permissions for the account owner.
*
* @see ContentDataObject::addToSharingTable()
*/
function addToSharingTable() {
parent::addToSharingTable();
$id = $this->getId();
if(!$this->getAccount() instanceof MailAccount) return;
$macs = MailAccountContacts::instance()->getByAccount($this->getAccount());
foreach ($macs as $mac) {
$contactId = $mac->getContactId();
$contact = Contacts::instance()->findById($contactId);
if (!$contact instanceof Contact) continue;
$group_id = $contact->getPermissionGroupId();
if ($group_id) {
$sql = "INSERT INTO ".TABLE_PREFIX."sharing_table ( object_id, group_id ) VALUES ('$id','$group_id') ON DUPLICATE KEY UPDATE group_id = group_id ";
DB::execute($sql);
}
}
}
示例5: paginate
/**
* This function will return paginated result. Result is an array where first element is
* array of returned object and second populated pagination object that can be used for
* obtaining and rendering pagination data using various helpers.
*
* Items and pagination array vars are indexed with 0 for items and 1 for pagination
* because you can't use associative indexing with list() construct
*
* @access public
* @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
* @param integer $items_per_page Number of items per page
* @param integer $current_page Current page number
* @return array
*/
function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
{
if (isset($this) && instance_of($this, 'Contacts')) {
return parent::paginate($arguments, $items_per_page, $current_page);
} else {
return Contacts::instance()->paginate($arguments, $items_per_page, $current_page);
}
// if
}
示例6: stylesheet_tag
echo stylesheet_tag('event/day.css');
$today = DateTimeValueLib::now();
$today->add('h', logged_user()->getTimezone());
$currentday = $today->format("j");
$currentmonth = $today->format("n");
$currentyear = $today->format("Y");
$drawHourLine = $day == $currentday && $month == $currentmonth && $year == $currentyear;
$dtv = DateTimeValueLib::make(0, 0, 0, $month, $day, $year);
$result = ProjectEvents::getDayProjectEvents($dtv, $tags, active_project(), $user_filter, $status_filter);
if (!$result) {
$result = array();
}
$alldayevents = array();
$milestones = ProjectMilestones::getRangeMilestonesByUser($dtv, $dtv, $user_filter != -1 ? $user : null, $tags, active_project());
$tasks = ProjectTasks::getRangeTasksByUser($dtv, $dtv, $user_filter != -1 ? $user : null, $tags, active_project());
$birthdays = Contacts::instance()->getRangeContactsByBirthday($dtv, $dtv);
foreach ($result as $key => $event) {
if ($event->getTypeId() > 1) {
$alldayevents[] = $event;
unset($result[$key]);
}
}
if ($milestones) {
$alldayevents = array_merge($alldayevents, $milestones);
}
if ($tasks) {
$tmp_tasks = array();
$dtv_end = new DateTimeValue($dtv->getTimestamp() + 60 * 60 * 24);
foreach ($tasks as $task) {
$tmp_tasks = array_merge($tmp_tasks, replicateRepetitiveTaskForCalendar($task, $dtv, $dtv_end));
}
示例7: lang
<table><tr><th></th><th><?php
echo $import_type == 'contact' ? lang('contact fields') : lang('company fields');
?>
</th><th><?php
echo lang('fields from file');
?>
</th></tr>
<?php
if ($import_type == 'contact') {
$contact_fields = Contacts::getContactFieldNames();
} else {
$contact_fields = Contacts::getCompanyFieldNames();
}
$custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(Contacts::instance()->getObjectTypeId());
+($isAlt = false);
$i = 0;
$label_w = $label_h = $label_o = false;
foreach ($contact_fields as $c_field => $c_label) {
if (str_starts_with($c_field, 'contact[w') && !$label_w) {
?>
<tr><td colspan="3" style="text-align:center;"><b><?php
echo lang('work');
?>
</b></td></tr> <?php
$label_w = true;
} else {
if (str_starts_with($c_field, 'contact[h') && !$label_h) {
?>
<tr><td colspan="3" style="text-align:center;"><b><?php
示例8: IN
}
}
$contacts = Contacts::findAll(array(
'conditions' => 'object_id IN ('.implode(',',$intersection).') AND `is_company` = 0 AND disabled = 0',
'limit' => $limit,
'order' => 'last_activity, updated_on',
'order_dir' => 'desc',
));
$total = count($contacts);
$widget_title = lang("people in", implode(", ", $mnames));
} else {
$result = Contacts::instance()->listing(array(
"order" => "last_activity, updated_on",
"order_dir" => "desc",
"extra_conditions" => " AND `is_company` = 0 AND disabled = 0 AND user_type > 0",
"start" => 0,
"limit" => $limit
));
$total = $result->total ;
$contacts = $result->objects;
}
$render_add = can_manage_security(logged_user());
$genid = gen_id();
if ($total > 0 || $render_add) {
include_once 'template.php';
示例9: canAdd
function canAdd(Contact $user, $context, &$notAllowedMember = '')
{
return can_manage_contacts($user) || can_add($user, $context, Contacts::instance()->getObjectTypeId(), $notAllowedMember);
}
示例10: get_contacts_for_selector
function get_contacts_for_selector()
{
ajx_current("empty");
$name_condition = "";
$name_filter = trim(array_var($_REQUEST, 'query'));
if ($name_filter != "") {
$name_condition = " AND o.name LIKE '%{$name_filter}%'";
}
// by default list only contacts
$type_condition = " AND is_company=0";
$extra_conditions = "";
if ($filters = array_var($_REQUEST, 'filters')) {
$filters = json_decode($filters, true);
foreach ($filters as $col => $val) {
if (Contacts::instance()->columnExists($col)) {
$extra_conditions .= " AND " . DB::escapeField($col) . " = " . DB::escape($val);
} else {
if ($col == 'is_user') {
$extra_conditions .= " AND `user_type`" . ($val == 1 ? " > 0" : " = 0");
} else {
if ($col == 'has_permissions') {
$extra_conditions .= " AND `user_type`>0 AND EXISTS(\r\n\t\t\t\t\t\t\tSELECT * FROM " . TABLE_PREFIX . "contact_member_permissions cmp\r\n\t\t\t\t\t\t\tWHERE cmp.permission_group_id IN (SELECT x.permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups x WHERE x.contact_id=o.id)\r\n\t\t\t\t\t\t\t\tAND cmp.member_id='{$val}'\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT tp.object_type_id FROM " . TABLE_PREFIX . "tab_panels tp WHERE tp.enabled=0)\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id NOT IN (SELECT oott.id FROM " . TABLE_PREFIX . "object_types oott WHERE oott.name IN ('comment','template'))\r\n\t\t\t\t\t\t\t\tAND cmp.object_type_id IN (SELECT oott2.id FROM " . TABLE_PREFIX . "object_types oott2 WHERE oott2.type IN ('content_object','dimension_object'))\r\n\t\t\t\t\t\t)";
} else {
if ($col == 'only_companies') {
if ($val == 1) {
$type_condition = " AND is_company=1";
}
} else {
if ($col == 'include_companies') {
if ($val == 1) {
$type_condition = "";
}
}
}
}
}
}
}
}
if ($plugin_filters = array_var($_REQUEST, 'plugin_filters')) {
$plugin_filters = json_decode($plugin_filters, true);
$plugin_conditions = "";
Hook::fire('contact_selector_plugin_filters', $plugin_filters, $plugin_conditions);
$extra_conditions .= $plugin_conditions;
}
$info = array();
$pg_ids = logged_user()->getPermissionGroupIds();
if (count($pg_ids) > 0) {
$permissions_condition = " AND (o.id=" . logged_user()->getId() . " OR EXISTS (SELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh WHERE sh.object_id=o.id AND group_id IN (" . implode(',', $pg_ids) . ")))";
$conditions = "o.trashed_by_id=0 AND o.archived_by_id=0 {$name_condition} {$permissions_condition} {$type_condition} {$extra_conditions}";
$query_params = array('condition' => $conditions, 'order' => 'o.name ASC');
$count = Contacts::count($conditions);
$limit = 30;
$query_params['limit'] = $limit;
$contacts = Contacts::findAll($query_params);
foreach ($contacts as $c) {
$info[] = array("id" => $c->getId(), "name" => $c->getObjectName());
}
if ($name_filter == "" && $count >= $limit) {
//$info[] = array('id' => -1, 'name' => lang('write the first letters of the name or surname of the person to select'));
$info[] = array('id' => -2, 'name' => '<a href="#" class="db-ico ico-expand" style="color:blue;text-decoration:underline;padding-left:20px;">' . lang('show more') . '</a>');
}
}
ajx_extra_data(array('contacts' => $info));
}
示例11: create_user
function create_user($user_data, $permissionsString) {
// try to find contact by some properties
$contact_id = array_var($user_data, "contact_id") ;
$contact = Contacts::instance()->findById($contact_id) ;
if (!is_valid_email(array_var($user_data, 'email'))) {
throw new Exception(lang("email value is required"));
}
if (!$contact instanceof Contact) {
// Create a new user
$contact = new Contact();
$contact->setUsername(array_var($user_data, 'username'));
$contact->setDisplayName(array_var($user_data, 'display_name'));
$contact->setCompanyId(array_var($user_data, 'company_id'));
$contact->setUserType(array_var($user_data, 'type'));
$contact->setTimezone(array_var($user_data, 'timezone'));
$contact->setFirstname($contact->getObjectName() != "" ? $contact->getObjectName() : $contact->getUsername());
$contact->setObjectName();
} else {
// Create user from contact
$contact->setUserType(array_var($user_data, 'type'));
if (array_var($user_data, 'company_id')) {
$contact->setCompanyId(array_var($user_data, 'company_id'));
}
$contact->setUsername(array_var($user_data, 'username'));
$contact->setTimezone(array_var($user_data, 'timezone'));
}
$contact->save();
if (is_valid_email(array_var($user_data, 'email'))) {
$contact->addEmail(array_var($user_data, 'email'), 'personal', true);
}
//permissions
$permission_group = new PermissionGroup();
$permission_group->setName('User '.$contact->getId().' Personal');
$permission_group->setContactId($contact->getId());
$permission_group->setIsContext(false);
$permission_group->setType("permission_groups");
$permission_group->save();
$contact->setPermissionGroupId($permission_group->getId());
$contact_pg = new ContactPermissionGroup();
$contact_pg->setContactId($contact->getId());
$contact_pg->setPermissionGroupId($permission_group->getId());
$contact_pg->save();
if ( can_manage_security(logged_user()) ) {
$sp = new SystemPermission();
$rol_permissions=SystemPermissions::getRolePermissions(array_var($user_data, 'type'));
foreach($rol_permissions as $pr){
$sp->setPermission($pr);
}
$sp->setPermissionGroupId($permission_group->getId());
$sp->setCanManageSecurity(array_var($user_data, 'can_manage_security'));
$sp->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration'));
$sp->setCanManageTemplates(array_var($user_data, 'can_manage_templates'));
$sp->setCanManageTime(array_var($user_data, 'can_manage_time'));
$sp->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts'));
$sp->setCanManageDimensions(array_var($user_data, 'can_manage_dimensions'));
$sp->setCanManageDimensionMembers(array_var($user_data, 'can_manage_dimension_members'));
$sp->setCanManageTasks(array_var($user_data, 'can_manage_tasks'));
$sp->setCanTasksAssignee(array_var($user_data, 'can_task_assignee'));
$sp->setCanManageBilling(array_var($user_data, 'can_manage_billing'));
$sp->setCanViewBilling(array_var($user_data, 'can_view_billing'));
Hook::fire('add_user_permissions', $sp, $other_permissions);
if (!is_null($other_permissions) && is_array($other_permissions)) {
foreach ($other_permissions as $k => $v) {
$sp->setColumnValue($k, array_var($user_data, $k));
}
}
$sp->save();
if ($contact->isAdminGroup()) {
// allow all un all dimensions if new user is admin
$dimensions = Dimensions::findAll();
$permissions = array();
foreach ($dimensions as $dimension) {
if ($dimension->getDefinesPermissions()) {
$cdp = ContactDimensionPermissions::findOne(array("conditions" => "`permission_group_id` = ".$contact->getPermissionGroupId()." AND `dimension_id` = ".$dimension->getId()));
if (!$cdp instanceof ContactDimensionPermission) {
$cdp = new ContactDimensionPermission();
$cdp->setPermissionGroupId($contact->getPermissionGroupId());
$cdp->setContactDimensionId($dimension->getId());
}
$cdp->setPermissionType('allow all');
$cdp->save();
// contact member permisssion entries
$members = $dimension->getAllMembers();
foreach ($members as $member) {
$ots = DimensionObjectTypeContents::getContentObjectTypeIds($dimension->getId(), $member->getObjectTypeId());
$ots[]=$member->getObjectId();
foreach ($ots as $ot) {
//.........这里部分代码省略.........
示例12: addToSharingTable
/**
* Override defaults.
* Also adds mail to sharing table if is not categorized.
* Only permissions for the account owner.
*
* @see ContentDataObject::addToSharingTable()
*/
function addToSharingTable()
{
parent::addToSharingTable();
$id = $this->getId();
if (!$this->getAccount() instanceof MailAccount) {
return;
}
$contactId = $this->getAccount()->getContactId();
$contact = Contacts::instance()->findById($contactId);
if (!$contact instanceof Contact) {
return;
}
$group_id = $contact->getPermissionGroupId();
if ($group_id) {
$sql = "INSERT INTO " . TABLE_PREFIX . "sharing_table ( object_id, group_id ) VALUES ({$id},{$group_id}) ON DUPLICATE KEY UPDATE group_id = group_id ";
DB::execute($sql);
}
}
示例13: getDashboardObjectQueries
/**
* Returns array of queries that will return Dashboard Objects
*
* @param string $proj_ids
* @param string $tag
* @param boolean $count if false the query will return objects, if true it will return object count
*/
static function getDashboardObjectQueries($project = null, $tag = null, $count = false, $trashed = false, $linkedObject = null, $order = 'updatedOn', $filterName = '', $archived = false, $filterManager = '')
{
if ($trashed && $trashed !== 'all') {
$order = 'trashedOn';
} else {
if ($archived) {
$order = 'archivedOn';
}
}
switch ($order) {
case 'dateCreated':
$order_crit_companies = '`created_on`';
$order_crit_contacts = '`created_on`';
$order_crit_file_revisions = '`created_on`';
$order_crit_calendar = '`created_on`';
$order_crit_tasks = '`created_on`';
$order_crit_milestones = '`created_on`';
$order_crit_webpages = '`created_on`';
$order_crit_files = '`created_on`';
$order_crit_emails = '`received_date`';
$order_crit_comments = '`created_on`';
$order_crit_messages = '`created_on`';
$order_crit_workspaces = '`created_on`';
break;
case 'trashedOn':
$order_crit_companies = '`trashed_on`';
$order_crit_contacts = '`trashed_on`';
$order_crit_file_revisions = '`trashed_on`';
$order_crit_calendar = '`trashed_on`';
$order_crit_tasks = '`trashed_on`';
$order_crit_milestones = '`trashed_on`';
$order_crit_webpages = '`trashed_on`';
$order_crit_files = '`trashed_on`';
$order_crit_emails = '`trashed_on`';
$order_crit_comments = '`trashed_on`';
$order_crit_messages = '`trashed_on`';
$order_crit_workspaces = '`updated_on`';
break;
case 'archivedOn':
$order_crit_companies = '`archived_on`';
$order_crit_contacts = '`archived_on`';
$order_crit_file_revisions = '`updated_on`';
$order_crit_calendar = '`archived_on`';
$order_crit_tasks = '`archived_on`';
$order_crit_milestones = '`archived_on`';
$order_crit_webpages = '`archived_on`';
$order_crit_files = '`archived_on`';
$order_crit_emails = '`archived_on`';
$order_crit_comments = '`updated_on`';
$order_crit_messages = '`archived_on`';
$order_crit_workspaces = '`completed_on`';
break;
case 'name':
$order_crit_companies = '`name`';
$order_crit_contacts = "TRIM(CONCAT(' ', `lastname`, `firstname`, `middlename`))";
$order_crit_file_revisions = "'zzzzzzzzzzzzzz'";
//Revisar
$order_crit_calendar = '`subject`';
$order_crit_tasks = '`title`';
$order_crit_milestones = '`name`';
$order_crit_webpages = '`title`';
$order_crit_files = '`filename`';
$order_crit_emails = '`subject`';
$order_crit_comments = '`text`';
$order_crit_messages = '`title`';
$order_crit_workspaces = '`name`';
break;
default:
$order_crit_companies = '`updated_on`';
$order_crit_contacts = '`updated_on`';
$order_crit_file_revisions = '`updated_on`';
$order_crit_calendar = '`updated_on`';
$order_crit_tasks = '`updated_on`';
$order_crit_milestones = '`updated_on`';
$order_crit_webpages = '`updated_on`';
$order_crit_files = '`updated_on`';
$order_crit_emails = '`received_date`';
$order_crit_comments = '`updated_on`';
$order_crit_messages = '`updated_on`';
$order_crit_workspaces = '`updated_on`';
break;
}
if ($project instanceof Project) {
$proj_ids = $project->getAllSubWorkspacesQuery(true);
$proj_cond_companies = Companies::getWorkspaceString($proj_ids);
$proj_cond_messages = ProjectMessages::getWorkspaceString($proj_ids);
$proj_cond_documents = ProjectFiles::getWorkspaceString($proj_ids);
$proj_cond_emails = MailContents::getWorkspaceString($proj_ids);
$proj_cond_events = ProjectEvents::getWorkspaceString($proj_ids);
$proj_cond_tasks = ProjectTasks::getWorkspaceString($proj_ids);
$proj_cond_charts = ProjectCharts::getWorkspaceString($proj_ids);
$proj_cond_milestones = ProjectMilestones::getWorkspaceString($proj_ids);
$proj_cond_weblinks = ProjectWebpages::getWorkspaceString($proj_ids);
//.........这里部分代码省略.........
示例14: get_allowed_addresses
function get_allowed_addresses()
{
$extra_conds = null;
if ($filter = array_var($_POST, 'name_filter')) {
$filter = mysql_real_escape_string($filter, DB::connection()->getLink());
$extra_conds = "(e.first_name like '%{$filter}%' || e.surname like '%{$filter}%' || \r\n\t\t\t\t(select count(id) from " . TABLE_PREFIX . "contact_emails ce where ce.contact_id=e.object_id and ce.email_address like '%{$filter}%'))";
$addresses = $this->getAllowedAddresses($extra_conds);
} else {
$return_values = true;
$max = array_var($_POST, 'max');
if ($max > 0) {
$return_values = Contacts::instance()->countAllowedContacts() <= $max;
}
if ($return_values) {
$addresses = $this->getAllowedAddresses();
} else {
$addresses = array();
}
}
ajx_current("empty");
ajx_extra_data(array('addresses' => $addresses));
}
示例15: allowed_users_in_context
/**
* Returns the users with permissions for the object type $object_type for the context $context
*
* @param $object_type_id Object Type
* @param $context Context
* @param $access_level (ACCESS_LEVEL_READ, ACCESS_LEVEL_WRITE, ACCESS_LEVEL_DELETE)
* @param $extra_conditions Extra conditions to add to the users query
* @param $to_assign true if this function is called to fill the "assigned to" combobox when editing a task
*/
function allowed_users_in_context($object_type_id, $context = null, $access_level = ACCESS_LEVEL_READ, $extra_conditions = "")
{
$result = array();
$members = array();
if (isset($context) && is_array($context)) {
foreach ($context as $selection) {
if ($selection instanceof Member) {
$members[] = $selection;
}
}
}
if (count($members) == 0) {
$logged_user_pgs = logged_user()->getPermissionGroupIds();
if (count($logged_user_pgs) > 0) {
$dimensions = Dimensions::getAllowedDimensions($object_type_id);
foreach ($dimensions as $d) {
$dim = Dimensions::getDimensionById(array_var($d, 'dimension_id'));
if ($dim instanceof Dimension && $dim->getDefinesPermissions() && $dim->getCode() != 'feng_persons' && $dim->getCode() != 'feng_users') {
if ($dim->hasAllowAllForContact(implode(",", $logged_user_pgs))) {
$permission_conditions = "";
} else {
$permission_conditions = " AND EXISTS (SELECT cmp.permission_group_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp \n\t\t\t\t\t\t\t\tWHERE cmp.permission_group_id IN (" . implode(",", $logged_user_pgs) . ") AND cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.object_type_id={$object_type_id})";
}
$members = array_merge($members, $dim->getAllMembers(false, null, true, $permission_conditions));
}
}
}
}
$all_permission_groups = array();
$rows = DB::executeAll("SELECT DISTINCT permission_group_id FROM " . TABLE_PREFIX . "contact_permission_groups");
foreach ($rows as $row) {
$all_permission_groups[] = $row['permission_group_id'];
}
$allowed_permission_groups = can_access_pgids($all_permission_groups, $members, $object_type_id, $access_level);
if (count($allowed_permission_groups) > 0) {
$result = Contacts::instance()->findAll(array('conditions' => "id IN (SELECT DISTINCT contact_id FROM " . TABLE_PREFIX . "contact_permission_groups\n\t\t\t\t\t\t\t\tWHERE permission_group_id IN (" . implode(",", $allowed_permission_groups) . ") {$extra_conditions})", 'order' => 'name'));
}
return $result;
}