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