query( "INSERT INTO course (parent_id, label) VALUES (:parent, :label)", [ ':parent' => Registry::get('REQUEST')->POST['parent_id'], ':label' => Registry::get('REQUEST')->POST['label'] ] )->lastInsertID(); $cache = self::update_courses_cache(); // update category caches return $cache['breadcrumbs']; // return } /** update course * --- * @param void (get data from POST) */ public static function update_course() { Registry::use('database')->query( "UPDATE course SET parent_id = :parent, label = :label WHERE id = :id", [ ':id' => Registry::get('REQUEST')->POST['id'], ':parent' => Registry::get('REQUEST')->POST['parent_id'], ':label' => Registry::get('REQUEST')->POST['label'] ] ); $cache = self::update_courses_cache(); return $cache['breadcrumbs']; } /** update courses cache * --- -- -- - - - * Shall run if anything changes to courses * * @param void * @return (array): the two course caches */ public static function update_courses_cache() { $tree = proxy( // cache-get categories [\app\models\cms\Course_model::class, 'category_tree'], [], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE ); $breadcrumbs = proxy( // cache-get breadcrumbs [\app\models\cms\Course_model::class, 'breadcrumbs'], [$tree], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE ); return [ 'tree' => $tree, 'breadcrumbs' => $breadcrumbs ]; } }