Offline Server
1.6
PHP API documentation
Main Page
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Pages
Class.DomainManager.php
Go to the documentation of this file.
1
<?php
2
/**
3
* Return offline domains where current user is affected
4
*
5
* @author Anakeen
6
* @version $Id: $
7
* @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
8
* @package OFFLINE
9
*/
10
/**
11
*/
12
13
include_once (
"FDL/Class.SearchDoc.php"
);
14
include_once (
"DATA/Class.Collection.php"
);
15
include_once (
"OFFLINE/Class.ExceptionCode.php"
);
16
17
class
DomainManager
18
{
19
private
static
$error =
''
;
20
private
static
function
getUserId()
21
{
22
return
Doc::getSystemUserId();
23
}
24
private
static
function
setError($err)
25
{
26
throw
new
Exception($err);
27
}
28
29
/**
30
* List all domain availables by current user
31
* @code
32
$domains=DomainManager::getDomains();
33
foreach ($domains as $domain) {
34
print $domain->getTitle()."\n";
35
}
36
* @endcode
37
* @return DocumentList search results
38
*/
39
public
static
function
getDomains
()
40
{
41
include_once (
"FDL/Class.DocumentList.php"
);
42
$userId = self::getUserId();
43
$s =
new
SearchDoc(getDbAccess(),
"OFFLINEDOMAIN"
);
44
$s->setObjectReturn();
45
$s->search();
46
$err = $s->getError();
47
48
if
($err) {
49
self::setError($err);
50
}
51
52
$s->search();
53
while
( $doc = $s->nextDoc() ) {
54
$users = array_keys($doc->getUserMembersInfo());
55
if
(!in_array($userId, $users)) {
56
$s->addFilter(
"initid != %d"
, $doc->initid);
57
}
58
}
59
$s->reset();
60
return
$s->getDocumentList();
61
}
62
63
64
65
/**
66
* create a new domain
67
* @code
68
$domain=DomainManager::createDomain("myDomain");
69
$err =$domain->addFamily("TST_ARTICLE");
70
$err.=$domain->addUserMember("john.doe");
71
$err.=$domain->insertUserDocument("1254","john.doe");
72
* @endcode
73
* @throws Exception if no habilities or if reference is already set by another
74
* @exception OfflineExceptionCode::referenceExists, OfflineExceptionCode::createForbidden
75
* @return _OFFLINEDOMAIN document
76
*/
77
public
static
function
createDomain
($reference)
78
{
79
$domain = createDoc(getDbAccess(),
"OFFLINEDOMAIN"
);
80
if
(!$domain) {
81
throw
new
Exception(_(
"no privilege to create offline domain"
),
OfflineExceptionCode::createForbidden
);
82
}
83
$domain->setValue(
"off_ref"
, $reference);
84
$err = $domain->verifyAllConstraints();
85
if
($err) {
86
throw
new
Exception($err,
OfflineExceptionCode::referenceInvalid
);
87
}
88
$err = $domain->add();
89
if
($err) {
90
throw
new
Exception($err,
OfflineExceptionCode::referenceExists
);
91
}
92
return
$domain;
93
}
94
95
96
97
}
98
?>
DomainManager\createDomain
static createDomain($reference)
Definition:
Class.DomainManager.php:77
DomainManager
Definition:
Class.DomainManager.php:17
OfflineExceptionCode\referenceExists
const referenceExists
domain reference must be unique
Definition:
Class.ExceptionCode.php:25
OfflineExceptionCode\createForbidden
const createForbidden
create is forbidden
Definition:
Class.ExceptionCode.php:23
OfflineExceptionCode\referenceInvalid
const referenceInvalid
domain reference accept onlyh alphanum characters
Definition:
Class.ExceptionCode.php:27
DomainManager\getDomains
static getDomains()
Definition:
Class.DomainManager.php:39
← centre documentaire
© anakeen
- published under
CC License
-
Dynacase