function action() { $category = new Category(); $kdgs = new Kdgs(); $album = new Album(); $story_url = new StoryUrl(); $category_list = $category->get_list("`res_name`='kdgs' and `s_id`='0'"); foreach ($category_list as $k => $v) { $page = 1; while (true) { $album_list = $kdgs->get_children_category_album_list($v['s_p_id'], $page); if (!$album_list) { break; } foreach ($album_list as $k2 => $v2) { $exists = $album->check_exists("`link_url` = '{$v2['url']}'"); if ($exists) { continue; } $album_id = $album->insert(array('title' => $v2['title'], 'min_age' => $v2['min_age'], 'max_age' => $v2['max_age'], 'intro' => '', 's_cover' => $v2['cover'], 'link_url' => $v2['url'], 'add_time' => date('Y-m-d H:i:s'))); $story_url->insert(array('res_name' => 'album', 'res_id' => $album_id, 'field_name' => 'cover', 'source_url' => $v2['cover'], 'source_file_name' => ltrim(strrchr($v2['cover'], '/'), '/'), 'add_time' => date('Y-m-d H:i:s'))); } $page++; } } }
public function postCreate() { if (Auth::guest()) { return Redirect::secure('user/login'); } // do not use layout for this $this->layout = null; // add to db Input::get('isPrivate') == 1 ? $isPrivate = 1 : ($isPrivate = 0); Album::insert(array('user_id' => Input::get('userId'), 'categories_id' => Input::get('category'), 'name' => strip_tags(Purifier::clean(Input::get('name'))), 'isPrivate' => $isPrivate)); // redirect to albums return Redirect::secure('user/albums'); }
/** * Create new Album * * Also updates Category modification time * * @param int $categoryId */ public function create($categoryId) { $category = $this->getCategoryFinder()->findOneBy('id', $categoryId); if ($this->slim->request->isGet()) { $this->slim->render('album/create.html.twig', ['category' => $category, 'sessionUser' => $this->getSessionUser()]); } elseif ($this->slim->request->isPost()) { $name = $_POST['name']; $newAlbum = new Album($this->slim->db); $newAlbum->setCategoryId($category->getId()); $newAlbum->setName($name); $newAlbum->insert(); $category->update(); $this->slim->flash('success', 'Album created'); $this->slim->redirect('/categories/' . $categoryId . '/albums'); } }