Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckDocATag.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 class CheckDocATag extends CheckData
8 {
9  protected $tagAction;
10  protected $docid;
11  /**
12  * @var Doc
13  */
14  protected $doc;
15  protected $firstATag = '';
16  /**
17  * @param array $data
18  * @param Doc $doc
19  * @return CheckDocATag
20  */
21  function check(array $data, &$doc = null)
22  {
23  if (!isset($data[3])) {
24  $this->addError(ErrorCode::getError('ATAG0004'));
25  } else {
26  $this->tagAction = $data[3];
27  $this->docid = $data[1];
28  if (isset($data[4])) {
29  $this->firstATag = $data[4];
30  }
31  $this->checkDocid();
32  if (!$this->errors) {
33  $this->checkAction();
34  $this->checkTagContent($data);
35  }
36  }
37  return $this;
38  }
39  /**
40  * check if doc is alive
41  * @return void
42  */
43  protected function checkDocid()
44  {
45  if (!$this->docid) {
46  $this->addError(ErrorCode::getError('ATAG0002', $this->firstATag));
47  }
48 
49  $this->doc = new_doc("", $this->docid);
50  if (!$this->doc->isAlive()) {
51 
52  $this->addError(ErrorCode::getError('ATAG0003', $this->docid));
53  }
54  }
55  /**
56  * check if action is available
57  * @return void
58  */
59  protected function checkAction()
60  {
61  $allowedAction = ["ADD", "DELETE", "SET"];
62  if ($this->tagAction && !in_array($this->tagAction, $allowedAction)) {
63  $this->addError(ErrorCode::getError('ATAG0001', $this->tagAction, $this->doc->getTitle() , implode(",", $allowedAction)));
64  }
65  }
66 
67  protected function checkTagContent($data)
68  {
69  $i = 4;
70  while (!empty($data[$i])) {
71  if (strpos($data[$i], "\n") !== false) {
72  $this->addError(ErrorCode::getError('ATAG0005', $this->doc->getTitle() , $data[$i]));
73  }
74  $i++;
75  }
76  }
77 }
checkTagContent($data)
static getError($code, $args=null)
Definition: ErrorCode.php:27
print docid
Definition: migrEnum.php:33
check(array $data, &$doc=null)
addError($msg)
Definition: CheckData.php:29
$data
← centre documentaire © anakeen