Completed
Push — work-fleets ( 4ec5b3...fe2ede )
by SuperNova.WS
10:06
created

KeyedModel::exportRowNoId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 3
b 0
f 0
ccs 0
cts 6
cp 0
crap 6
1
<?php
2
/**
3
 * Created by Gorlum 19.08.2016 21:26
4
 */
5
6
namespace Entity;
7
8
9
class KeyedModel extends EntityModel {
10
11
  /**
12
   * Name of key field field in this table
13
   *
14
   * @var string $idFieldName
15
   */
16
  protected $idFieldName = 'id';
17
18
  public function __construct(\Common\GlobalContainer $gc) {
19
    parent::__construct($gc);
20
    $this->extendProperties(
21
      array(
22
        'dbId' => array(
23
          P_DB_FIELD => $this->getIdFieldName(),
24
        )
25
      )
26
    );
27
  }
28
29
  /**
30
   * Exports object properties to DB row state WITHOUT ID
31
   *
32
   * Useful for INSERT operations
33
   *
34
   * @param \Entity\KeyedContainer $cEntity
35
   */
36
  protected function exportRowNoId($cEntity) {
37
    $this->exportRow($cEntity);
38
39
    if ($this->getIdFieldName() != '') {
40
      unset($cEntity->row[$this->getIdFieldName()]);
41
    }
42
  }
43
44
  /**
45
   * @param int|string $dbId
46
   *
47
   * @return EntityContainer|false
48
   */
49
  public function loadById($dbId) {
50
    $row = $this->rowOperator->getById($this, $dbId);
51
    if (empty($row)) {
52
      return false;
53
    } else {
54
      $cEntity = $this->fromArray($row);
55
    }
56
57
    return $cEntity;
58
  }
59
60
61
  /**
62
   * @param string $value
63
   */
64
  public function setIdFieldName($value) {
65
    $this->idFieldName = $value;
66
  }
67
68
  /**
69
   * Gets entity's DB ID field name (which is unique within entity set)
70
   *
71
   * @return string
72
   */
73
  public function getIdFieldName() {
74
    return $this->idFieldName;
75
  }
76
77
}
78