Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckOrder.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 class CheckOrder extends CheckData
8 {
9  /**
10  * @var string family reference
11  */
12  protected $famName;
13  /**
14  * @var array
15  */
16  protected $attrIds;
17  /**
18  * @var DocFam
19  */
20  protected $family;
21  /**
22  * @param array $data
23  * @param Doc $doc
24  * @return CheckDoc
25  */
26  function check(array $data, &$extra = null)
27  {
28 
29  $this->famName = isset($data[1]) ? trim($data[1]) : null;
30  $this->attrIds = getOrder($data);
31 
32  $this->CheckOrderFamily();
33  if (!$this->hasErrors()) $this->CheckOrderAttribute();
34 
35  return $this;
36  }
37  /**
38  * Get the parsed family name or bool(false) if family name could
39  * not be parsed.
40  *
41  * @return bool|string
42  */
43  public function getParsedFamName()
44  {
45  return (isset($this->famName) ? $this->famName : false);
46  }
47  /**
48  * Get the parsed attributes ids or bool(false) if attributes ids
49  * could not be parsed.
50  *
51  * @return array|bool
52  */
53  public function getParsedAttrIds()
54  {
55  return (isset($this->attrIds) ? $this->attrIds : false);
56  }
57  /**
58  * check
59  * check
60  * @return void
61  */
62  protected function CheckOrderFamily()
63  {
64  if ($this->famName) {
65  if (!$this->checkName($this->famName)) {
66  $this->addError(ErrorCode::getError('ORDR0001', $this->famName));
67  } else {
68  try {
69  $this->family = new_doc(getDbAccess() , $this->famName);
70  if (!$this->family->isAlive()) {
71  $this->addError(ErrorCode::getError('ORDR0002', $this->famName));
72  } else {
73  if ($this->family->doctype != 'C') {
74  $this->addError(ErrorCode::getError('ORDR0003', $this->famName));
75  } else {
76  $canCreateError = $this->family->control('create');
77  if ($canCreateError) $this->addError(ErrorCode::getError('ORDR0004', $this->famName));
78  }
79  }
80  }
81  catch(Exception $e) {
82  $this->addError(ErrorCode::getError('ORDR0005', $this->famName, $e->getMessage()));
83  }
84  }
85  } else {
86 
87  $this->addError(ErrorCode::getError('ORDR0006'));
88  }
89  }
90  /**
91  * check logical name
92  * @return void
93  */
94  protected function CheckOrderAttribute()
95  {
96  if ($this->family) {
97  foreach ($this->attrIds as $aid) {
98  if ($aid && (!$this->family->getAttribute($aid)) && (strpos($aid, "extra:") !== 0)) {
99  $this->addError(ErrorCode::getError('ORDR0100', $aid, $this->family->name));
100  }
101  }
102  }
103  }
104 
105  private function checkName($name)
106  {
107  if ($name && (!is_numeric($name))) {
108  if (!preg_match('/^[a-z][a-z0-9_]*$/i', $name)) {
109  return false;
110  }
111  }
112  return true;
113  }
114 }
getParsedFamName()
Definition: CheckOrder.php:43
CheckOrderAttribute()
Definition: CheckOrder.php:94
CheckOrderFamily()
Definition: CheckOrder.php:62
static getError($code, $args=null)
Definition: ErrorCode.php:27
getOrder(array $orderdata)
Definition: import_file.php:97
getParsedAttrIds()
Definition: CheckOrder.php:53
addError($msg)
Definition: CheckData.php:29
getDbAccess()
Definition: Lib.Common.php:368
check(array $data, &$extra=null)
Definition: CheckOrder.php:26
$data
← centre documentaire © anakeen