/** * ajaxでメディアを表示する画面 */ public function ajax_media_load() { Config::set('DEBUG', 0); // デバッグ設定を変更 $request = Request::getInstance(); $files_model = Model::load('Files'); $blog_id = $this->getBlogId(); // 検索条件 $where = 'blog_id=?'; $params = array($blog_id); if ($request->get('keyword')) { $where .= ' AND name like ?'; $params[] = '%' . $request->get('keyword') . '%'; } $options = array('where' => $where, 'params' => $params, 'limit' => Config::get('PAGE.FILE.LIMIT', App::getPageLimit('FILE_AJAX')), 'page' => $request->get('page', 0, Request::VALID_UNSIGNED_INT), 'order' => 'id DESC'); $files = $files_model->find('all', $options); $paging = $files_model->getPaging($options); $this->set('files', $files); $this->set('paging', $paging); $this->layout = 'ajax.html'; }
/** * 新規作成 */ public function upload() { $request = Request::getInstance(); $files_model = Model::load('Files'); $blog_id = $this->getBlogId(); Session::set('sig', App::genRandomString()); // 初期表示時 if ($request->file('file')) { // 新規登録処理 $errors = array(); $errors['file'] = $files_model->insertValidate($request->file('file'), $request->get('file'), $data_file); if (empty($errors['file'])) { $data_file['blog_id'] = $blog_id; $tmp_name = $data_file['tmp_name']; unset($data_file['tmp_name']); if ($id = $files_model->insert($data_file)) { // ファイルの移動 $data_file['id'] = $id; $move_file_path = App::getUserFilePath($data_file, true); App::mkdir($move_file_path); move_uploaded_file($tmp_name, $move_file_path); $this->setInfoMessage(__('I have completed the upload of files')); $this->redirect(array('action' => 'upload')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); return; } // PCの場合はajaxでファイル情報を取得するので以下の処理は不要 if (App::isPC()) { return; } // 検索条件 $where = 'blog_id=?'; $params = array($blog_id); if ($keyword = $request->get('keyword')) { $keyword = Model::escape_wildcard($keyword); $keyword = "%{$keyword}%"; $where .= ' AND name LIKE ?'; $params = array_merge($params, array($keyword)); } // 並び順 $order = 'created_at DESC, id DESC'; switch ($request->get('order')) { default: case 'created_at_desc': break; case 'created_at_asc': $order = 'created_at ASC, id ASC'; break; case 'name_desc': $order = 'name DESC, id DESC'; break; case 'name_asc': $order = 'name ASC, id ASC'; break; } $options = array('where' => $where, 'params' => $params, 'limit' => $request->get('limit', App::getPageLimit('FILE'), Request::VALID_POSITIVE_INT), 'page' => $request->get('page', 0, Request::VALID_UNSIGNED_INT), 'order' => $order); $files = $files_model->find('all', $options); $paging = $files_model->getPaging($options); $this->set('files', $files); $this->set('paging', $paging); }