Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckProfid.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Checking family profid property
8  * @class CheckProfid
9  * @brief Check family profid property when importing definition
10  * @see ErrorCodePRFD
11  */
12 class CheckProfid extends CheckData
13 {
14  /**
15  * profil name
16  * @var string
17  */
18  private $prfName = '';
19  /**
20  * profil doccument
21  * @var Doc
22  */
23  private $profil = '';
24  /**
25  * @param array $data
26  * @return CheckProfid
27  */
28  function check(array $data, &$extra = null)
29  {
30  $this->prfName = $data[1];
31  $this->checkUnknow();
32  if (!$this->hasErrors()) {
33  $this->checkIsAFamilyProfil();
34  }
35 
36  return $this;
37  }
38 
39  private function checkUnknow()
40  {
41  if ($this->prfName) {
42  try {
43  $this->profil = new_doc(getDbAccess() , $this->prfName);
44  }
45  catch(Exception $e) {
46  // due to no test validity of the family now
47  $fam = getTDoc(getDbAccess() , $this->prfName);
48  if (!$fam) throw $e;
49  if ($fam["doctype"] == "C") {
50  $this->profil = new DocFam();
51  $this->profil->affect($fam);
52  }
53  }
54  if (!$this->profil->isAlive()) {
55  $this->addError(ErrorCode::getError('PRFD0001', $this->prfName));
56  }
57  }
58  }
59 
60  private function checkIsAFamilyProfil()
61  {
62  if (!is_a($this->profil, "PFam")) {
63  $this->addError(ErrorCode::getError('PRFD0002', $this->prfName));
64  }
65  }
66 }
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
static getError($code, $args=null)
Definition: ErrorCode.php:27
check(array $data, &$extra=null)
Definition: CheckProfid.php:28
addError($msg)
Definition: CheckData.php:29
getDbAccess()
Definition: Lib.Common.php:368
Check family profid property when importing definition.
Definition: CheckProfid.php:12
$data
← centre documentaire © anakeen