1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Vtiger Web Services PHP Client Library |
4
|
|
|
* |
5
|
|
|
* The MIT License (MIT) |
6
|
|
|
* |
7
|
|
|
* Copyright (c) 2015, Zhmayev Yaroslav <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in |
17
|
|
|
* all copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25
|
|
|
* THE SOFTWARE. |
26
|
|
|
* |
27
|
|
|
* @author Zhmayev Yaroslav <[email protected]> |
28
|
|
|
* @copyright 2015-2016 Zhmayev Yaroslav |
29
|
|
|
* @license The MIT License (MIT) |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace Salaros\Vtiger\VTWSCLib; |
33
|
|
|
|
34
|
|
|
use Salaros\Vtiger\VTWSCLib\WSClient; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Vtiger Web Services PHP Client Session class |
38
|
|
|
* |
39
|
|
|
* Class Modules |
40
|
|
|
* @package Salaros\Vtiger\VTWSCLib |
41
|
|
|
*/ |
42
|
|
|
class Modules |
43
|
|
|
{ |
44
|
|
|
private $wsClient; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Class constructor |
48
|
|
|
* @param object $wsClient Parent WSClient instance |
49
|
|
|
*/ |
50
|
|
|
public function __construct($wsClient) |
51
|
|
|
{ |
52
|
|
|
$this->wsClient = $wsClient; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Lists all the Vtiger entity types available through the API |
57
|
|
|
* @access public |
58
|
|
|
* @return array List of entity types |
59
|
|
|
*/ |
60
|
|
|
public function getAll() |
61
|
|
|
{ |
62
|
|
|
$result = $this->wsClient->invokeOperation('listtypes', [ ], 'GET'); |
63
|
|
|
$modules = $result[ 'types' ]; |
64
|
|
|
|
65
|
|
|
$result = array(); |
66
|
|
|
foreach ($modules as $moduleName) { |
67
|
|
|
$result[ $moduleName ] = [ 'name' => $moduleName ]; |
68
|
|
|
} |
69
|
|
|
return $result; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the type information about a given VTiger entity type. |
74
|
|
|
* @access public |
75
|
|
|
* @param string $moduleName Name of the module / entity type |
76
|
|
|
* @return array Result object |
77
|
|
|
*/ |
78
|
|
|
public function getOne($moduleName) |
79
|
|
|
{ |
80
|
|
|
return $this->wsClient->invokeOperation('describe', [ 'elementType' => $moduleName ], 'GET'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Gets the entity ID prepended with module / entity type ID |
85
|
|
|
* @access private |
86
|
|
|
* @param string $moduleName Name of the module / entity type |
87
|
|
|
* @param string $entityID Numeric entity ID |
88
|
|
|
* @return boolean|string Returns false if it is not possible to retrieve module / entity type ID |
89
|
|
|
*/ |
90
|
|
|
public function getTypedID($moduleName, $entityID) |
91
|
|
|
{ |
92
|
|
|
if (stripos((string) $entityID, 'x') !== false) { |
93
|
|
|
return $entityID; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (empty($entityID) || intval($entityID) < 1) { |
97
|
|
|
throw new WSException('Entity ID must be a valid number'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$type = $this->getOne($moduleName); |
101
|
|
|
if (!is_array($type) || !array_key_exists('idPrefix', $type)) { |
102
|
|
|
$errorMessage = sprintf("The following module is not installed: %s", $moduleName); |
103
|
|
|
throw new WSException($errorMessage); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return "{$type[ 'idPrefix' ]}x{$entityID}"; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|