diff --git a/module/program/model.php b/module/program/model.php index 3df689e5ce..c1942e0368 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -94,11 +94,8 @@ class programModel extends model $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($programID * 5)->where('id')->eq($programID)->exec(); $this->file->updateObjectID($this->post->uid, $programID, 'project'); - if($project->parent > 0) - { - $this->dao->update(TABLE_PROJECT)->set('isCat')->eq(1)->where('id')->eq($project->parent)->exec(); - $this->fixPath($programID); - } + if($project->parent > 0) $this->dao->update(TABLE_PROJECT)->set('isCat')->eq(1)->where('id')->eq($project->parent)->exec(); + $this->setTreePath($programID); /* Add program admin.*/ $groupPriv = $this->dao->select('t1.*')->from(TABLE_USERGROUP)->alias('t1') @@ -221,24 +218,20 @@ class programModel extends model return $count > 0; } - public function fixPath($programID) + public function setTreePath($programID) { - $path = array(); $program = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($programID)->fetch(); - if($program->parent == 0) - { - $path['path'] = ",{$program->id},"; - $path['grade'] = 1; - $this->dao->update(TABLE_PROJECT)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); - } - else - { - $path = $this->fixPath($program->parent); - $path['path'] .= "{$program->id},"; - $path['grade'] += 1; - $this->dao->update(TABLE_PROJECT)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); - } - return $path; + $path['path'] = ",{$program->id},"; + $path['grade'] = 1; + + if($program->parent) + { + $parent = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($program->parent)->fetch(); + + $path['path'] = $parent->path . "{$program->id},"; + $path['grade'] = $parent->grade + 1; + } + $this->dao->update(TABLE_PROJECT)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); } }