| Conditions | 9 |
| Paths | 9 |
| Total Lines | 34 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 13 | public function create(array $data) { |
||
| 14 | |||
| 15 | if (0 !== $this->id) return false; |
||
| 16 | |||
| 17 | $set = $this->getDataset($data, true); |
||
| 18 | |||
| 19 | if (isset($set['id']) && !($set['id'] > 0)) return false; |
||
| 20 | |||
| 21 | # Insert entity |
||
| 22 | |||
| 23 | DB::insert(static::$table, $set); |
||
| 24 | |||
| 25 | if (!(DB::last() && DB::last()->status)) return false; |
||
| 26 | |||
| 27 | # Re-init entity |
||
| 28 | |||
| 29 | $this->error = false; $this->id = DB::last()->id; |
||
| 30 | |||
| 31 | foreach ($set as $name => $value) if ($name !== 'id') $this->data[$name] = $value; |
||
| 32 | |||
| 33 | if (static::$nesting) $this->data['path'] = $this->getPath(); |
||
| 34 | |||
| 35 | # Implement entity |
||
| 36 | |||
| 37 | $this->implement(); |
||
| 38 | |||
| 39 | # Cache entity |
||
| 40 | |||
| 41 | self::$cache[static::$type][$this->id] = $this; |
||
| 42 | |||
| 43 | # ------------------------ |
||
| 44 | |||
| 45 | return true; |
||
| 46 | } |
||
| 47 | |||
| 61 |