当前位置: 首页>>代码示例>>PHP>>正文


PHP Companies::getIdNameMap方法代码示例

本文整理汇总了PHP中Companies::getIdNameMap方法的典型用法代码示例。如果您正苦于以下问题:PHP Companies::getIdNameMap方法的具体用法?PHP Companies::getIdNameMap怎么用?PHP Companies::getIdNameMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Companies的用法示例。


在下文中一共展示了Companies::getIdNameMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: smarty_function_select_company

/**
 * Render select company box
 * 
 * Parameters:
 * 
 * - value - Value of selected company
 * - optional - Is value of this field optional or not
 * - exclude - Array of company ID-s that will be excluded
 * - can_create_new - Should this select box offer option to create a new 
 *   company from within the list
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_company($params, &$smarty)
{
    static $ids = array();
    $companies = Companies::getIdNameMap(array_var($params, 'companies'));
    $value = array_var($params, 'value', null, true);
    $id = array_var($params, 'id', null, true);
    if (empty($id)) {
        $counter = 1;
        do {
            $id = "select_company_dropdown_{$counter}";
            $counter++;
        } while (in_array($id, $ids));
    }
    // if
    $ids[] = $id;
    $params['id'] = $id;
    $optional = array_var($params, 'optional', false, true);
    $exclude = array_var($params, 'exclude', array(), true);
    if (!is_array($exclude)) {
        $exclude = array();
    }
    // if
    $can_create_new = array_var($params, 'can_create_new', true, true);
    if ($optional) {
        $options = array(option_tag(lang('-- None --'), ''), option_tag('', ''));
    } else {
        $options = array();
    }
    // if
    foreach ($companies as $company_id => $company_name) {
        if (in_array($company_id, $exclude)) {
            continue;
        }
        // if
        $option_attributes = array('class' => 'object_option');
        if ($value == $company_id) {
            $option_attributes['selected'] = true;
        }
        // if
        $options[] = option_tag($company_name, $company_id, $option_attributes);
    }
    // if
    if ($can_create_new) {
        $logged_user = get_logged_user();
        if (instance_of($logged_user, 'User') && Company::canAdd($logged_user)) {
            $params['add_object_url'] = assemble_url('people_companies_quick_add');
            $params['object_name'] = 'company';
            $params['add_object_message'] = lang('Please insert new company name');
            $options[] = option_tag('', '');
            $options[] = option_tag(lang('New Company...'), '', array('class' => 'new_object_option'));
        }
        // if
    }
    // if
    return select_box($options, $params) . '<script type="text/javascript">$("#' . $id . '").new_object_from_select();</script>';
}
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:71,代码来源:function.select_company.php

示例2: findUsersDetails

 /**
  * Fetch user details from database for provided user id-s
  *
  * @param array $user_ids
  * @return array
  */
 function findUsersDetails($user_ids)
 {
     if (!is_foreachable($user_ids)) {
         return false;
     }
     // if
     $users_table = TABLE_PREFIX . 'users';
     $users = array();
     $users = db_execute_all("SELECT {$users_table}.id, {$users_table}.first_name, {$users_table}.email, {$users_table}.last_name, {$users_table}.company_id FROM {$users_table} WHERE {$users_table}.id IN (?)", $user_ids);
     if (!is_foreachable($users)) {
         return false;
     }
     // if
     $companies = Companies::getIdNameMap();
     // Create a result array and make sure that owner company is the first
     // element in it
     $result = array(first($companies) => array());
     foreach ($users as $user) {
         if ($user['first_name'] && $user['last_name']) {
             $user['display_name'] = $user['first_name'] . ' ' . $user['last_name'];
         } elseif ($user['first_name']) {
             $user['display_name'] = $user['first_name'];
         } elseif ($user['last_name']) {
             $user['display_name'] = $user['last_name'];
         } else {
             $user['display_name'] = $user['email'];
         }
         // if
         $company_name = array_var($companies, $user['company_id']);
         if ($company_name) {
             if (isset($result[$company_name])) {
                 $result[$company_name][] = $user;
             } else {
                 $result[$company_name] = array($user);
             }
             // if
         }
         // if
     }
     // if
     ksort($result);
     return $result;
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:49,代码来源:Users.class.php


注:本文中的Companies::getIdNameMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。