From 6c240f4b38da4038ea591336b336ba16a727bc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Mon, 15 Nov 2021 16:02:08 +0800 Subject: [PATCH] * code for task #44335. --- api/v1/entries/programs.php | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/api/v1/entries/programs.php b/api/v1/entries/programs.php index 42d3763dbd..7f6bb6c5f7 100644 --- a/api/v1/entries/programs.php +++ b/api/v1/entries/programs.php @@ -22,6 +22,9 @@ class programsEntry extends Entry $_COOKIE['showClosed'] = $this->param('showClosed', 0); $mergeChildren = $this->param('mergeChildren', 0); + $fields = $this->param('fields', ''); + if(stripos(",{$fields},", ",dropmenu,") !== false) return $this->getDropMenu(); + $program = $this->loadController('program', 'browse'); $program->browse($this->param('status', 'all'), $this->param('order', 'order_asc')); @@ -65,7 +68,7 @@ class programsEntry extends Entry $result[] = $program; } } - return $this->send(200, array('programs' => $result)); + return $this->send(200, array('programs' => array_values($result))); } if(isset($data->status) and $data->status == 'fail') { @@ -74,4 +77,38 @@ class programsEntry extends Entry return $this->sendError(400, 'error'); } + + /** + * Get drop menu. + * + * @access public + * @return void + */ + public function getDropMenu() + { + + $programs = $this->dao->select('id,name,parent,path,grade,`order`')->from(TABLE_PROJECT) + ->where('deleted')->eq('0') + ->andWhere('type')->eq('program') + ->andWhere('id')->in($this->app->user->view->programs) + ->beginIF(empty($_COOKIE['showClosed']))->andWhere('status')->ne('closed')->fi() + ->orderBy('grade desc, `order`') + ->fetchAll('id'); + + $dropMenu = array(); + foreach($programs as $programID => $program) + { + if(empty($program->parent)) + { + $dropMenu[] = $program; + } + elseif(isset($programs[$program->parent])) + { + if(!isset($programs[$program->parent]->children)) $programs[$program->parent]->children = array(); + $programs[$program->parent]->children[] = $program; + } + } + + $this->send(200, $dropMenu); + } }