Exemplo n.º 1
0
 public function insert(Connection $conn)
 {
     $this->status = AreaStatus::fetchDefault($conn, $this->project);
     $groupName = null;
     if (null !== $this->group) {
         $groupName = $this->group->getName();
     }
     if (null !== $this->group) {
         DataMappers::recount($conn, CoreTables::GROUP_TBL, null, $this->group, 'areaNum', 'id');
     }
     DataMappers::recount($conn, CoreTables::AREA_STATUS_TBL, null, $this->status, 'areaNum', 'id');
     DataMappers::recount($conn, CoreTables::TERRITORY_TBL, null, $this->territory, 'areaNum', 'id');
     $this->entity = new Entity();
     $this->entity->setType('Area');
     $this->entity->setName($this->name);
     $this->entity->insert($conn);
     $this->createdAt = $this->lastUpdatedAt = time();
     $this->percentCompleteness = 0;
     $this->slug = DataMappers::generateSlug($conn, CoreTables::GROUP_TBL);
     $conn->insert(CoreTables::AREA_TBL, DataMappers::pick($this, ['name', 'slug', 'project', 'group', 'territory', 'status', 'reporter', 'entity', 'createdAt', 'lastUpdatedAt', 'percentCompleteness'], ['customData' => json_encode($this->customData), 'groupName' => $groupName]));
     return $this->id = $conn->lastInsertId();
 }