Exemple #1
0
 public static function get_vendor($vendor_id, $skip_permissions = false, $basic_for_link = false)
 {
     $vendor_id = (int) $vendor_id;
     $vendor = false;
     if ($vendor_id > 0) {
         $cache_key_args = func_get_args();
         $cache_key = self::_vendor_cache_key($vendor_id, $cache_key_args);
         $cache_timeout = module_config::c('cache_objects', 60);
         if ($cached_item = module_cache::get('vendor', $cache_key)) {
             return $cached_item;
         }
         $vendor = get_single("vendor", "vendor_id", $vendor_id);
         // get their address.
         if ($vendor && isset($vendor['vendor_id']) && $vendor['vendor_id'] == $vendor_id) {
             if (!$basic_for_link) {
                 $vendor['vendor_address'] = module_address::get_address($vendor_id, 'vendor', 'physical', true);
             }
             switch (self::get_vendor_data_access()) {
                 case _VENDOR_ACCESS_ALL:
                     break;
                 case _VENDOR_ACCESS_ALL_COMPANY:
                 case _VENDOR_ACCESS_CONTACTS:
                 case _VENDOR_ACCESS_TASKS:
                     $is_valid_vendor = self::get_vendors(array('vendor_id' => $vendor['vendor_id']));
                     if (!$is_valid_vendor || !isset($is_valid_vendor[$vendor['vendor_id']])) {
                         if ($skip_permissions) {
                             $vendor['_no_access'] = true;
                             // set a flag for custom processing. we check for this when calling get_vendor with the skip permissions argument. (eg: in the ticket file listing link)
                         } else {
                             $vendor = false;
                         }
                     }
                     break;
             }
         }
     }
     if (!$vendor) {
         $vendor = array('vendor_id' => 'new', 'vendor_name' => '', 'vendor_status' => _VENDOR_STATUS_PAID, 'primary_user_id' => '', 'credit' => '0', 'vendor_address' => array());
     }
     if (class_exists('module_company', false) && module_company::is_enabled() && !$basic_for_link) {
         $vendor['company_ids'] = array();
         if (isset($vendor['vendor_id']) && (int) $vendor['vendor_id'] > 0) {
             foreach (module_company::get_companys_by_vendor($vendor['vendor_id']) as $company) {
                 $vendor['company_ids'][$company['company_id']] = $company['name'];
             }
         }
     }
     //$vendor['vendor_industry_id'] = get_multiple('vendor_industry_rel',array('vendor_id'=>$vendor_id),'vendor_industry_id');
     //echo $vendor_id;print_r($vendor);exit;
     if (isset($cache_key) && isset($cache_timeout)) {
         module_cache::put('vendor', $cache_key, $vendor, $cache_timeout);
     }
     return $vendor;
 }