/
Describe.php
87 lines (83 loc) · 3.48 KB
/
Describe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* Modified by crm-now GmbH, www.crm-now.com
************************************************************************************/
include_once 'include/Webservices/DescribeObject.php';
include_once __DIR__ . '/Utils.php';
class crmtogo_WS_Describe extends crmtogo_WS_Controller {
protected function cacheDescribeInfo($describeInfo) {
$this->_cachedDescribeInfo = $describeInfo;
$this->_cachedDescribeFieldInfo = array();
if(!empty($describeInfo['fields'])) {
foreach($describeInfo['fields'] as $describeFieldInfo) {
$this->_cachedDescribeFieldInfo[$describeFieldInfo['name']] = $describeFieldInfo;
}
}
}
public static function process(crmtogo_API_Request $request) {
global $current_user;
$module = $request->get('module');
$newrecord = self::transformToBlocks($module);
$response = new crmtogo_API_Response();
$response->setResult(array('record' => $newrecord));
return $response;
}
protected static function transformToBlocks($module) {
global $current_language,$current_user;
if(empty($current_language))
$current_language = crmtogo_WS_Controller::sessionGet('language');
$moduleFieldGroups = crmtogo_WS_Utils::gatherModuleFieldGroupInfo($module);
$describeInfo = vtws_describe($module, $current_user);
crmtogo_WS_Utils::fixDescribeFieldInfo($module, $describeInfo,$current_user);
$modifiedResult = array();
$blocks = array();
$labelFields = false;
foreach($moduleFieldGroups as $blocklabel => $fieldgroups) {
$fields = array();
foreach($fieldgroups as $fieldname => $fieldinfo) {
$field['name'] = $fieldname;
$field['value'] = '';
$field['label'] = $fieldinfo['label'];
$field['uitype'] = $fieldinfo['uitype'];
$field['typeofdata'] = $fieldinfo['typeofdata'];
foreach($describeInfo['fields'] as $describeField) {
if ($describeField['name']== $fieldname) {
$field['type'] = '';
if (!empty($describeField['type']) && !empty($describeField['type']['picklistValues'])) {
$picklistValues = $describeField['type']['picklistValues'];
$field['type']['value'] = array ('value' =>$picklistValues,'name' => $fieldname);
}
if (isset($describeField['type']) && $describeField['type']!='') {
$field['quickcreate'] = $describeField['quickcreate'];
$field['displaytype'] = $describeField['displaytype'];
}
}
}
if ($field['uitype'] == '51' || $field['uitype'] == '10') {
$field['relatedmodule'] = crmtogo_WS_Utils::getEntityName($field['name'], $module);
}
$fields[] = $field;
}
$blocks[] = array( 'label' => $blocklabel, 'fields' => $fields );
}
$sections = array();
$moduleFieldGroupKeys = array_keys($moduleFieldGroups);
foreach($moduleFieldGroupKeys as $blocklabel) {
// eliminate empty blocks
if(isset($groups[$blocklabel]) && !empty($groups[$blocklabel])) {
$sections[] = array( 'label' => $blocklabel, 'count' => count($groups[$blocklabel]) );
}
}
$modifiedResult = array('blocks' => $blocks, 'id' => '');
if($labelFields) {
$modifiedResult['labelFields'] = $labelFields;
}
return $modifiedResult;
}
}