Beispiel #1
0
 public function update_public_flag_with_relations($public_flag)
 {
     $this->public_flag = $public_flag;
     if (!$this->is_changed('public_flag')) {
         return;
     }
     $this->save();
     // album_image の public_flag の更新
     if ($this->is_published && is_enabled('album') && ($album_images = Model_NoteAlbumImage::get_album_image4note_id($this->id))) {
         foreach ($album_images as $album_image) {
             $album_image->update_public_flag($public_flag, true);
         }
     }
 }
Beispiel #2
0
 /**
  * Note edit
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit($id = null)
 {
     $note = Model_Note::check_authority($id, $this->u->id);
     $val = self::get_validation_object($note, true);
     $album_images = array();
     if (is_enabled('album')) {
         $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'note');
         $album_images = Model_NoteAlbumImage::get_album_image4note_id($note->id);
     }
     $files = is_enabled('album') ? \Site_Upload::get_file_objects($album_images, $album_id, false, $this->u->id) : array();
     $file_tmps = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $moved_files = array();
         try {
             if (is_enabled('album')) {
                 $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total);
             }
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             \DB::start_transaction();
             list($is_changed, $is_published, $moved_files) = $note->save_with_relations($this->u->id, $post, $file_tmps, $album_images, $files);
             \DB::commit_transaction();
             // thumbnail 作成 & tmp_file thumbnail 削除
             \Site_FileTmp::make_and_remove_thumbnails($moved_files, 'note');
             $message = sprintf('%sを%sしました。', term('note'), $is_published ? term('form.publish') : term('form.edit'));
             \Session::set_flash('message', $message);
             \Response::redirect('note/detail/' . $note->id);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             if ($moved_files) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_files);
             }
             $file_tmps = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id);
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $files = array_merge($files, $file_tmps);
     $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('note'), term('form.do_edit')), array('/note/' . $id => $note->title), $note->member, 'note');
     $this->template->post_header = \View::forge('_parts/form_header');
     $this->template->post_footer = \View::forge('_parts/form_footer');
     $this->template->content = \View::forge('_parts/form', array('val' => $val, 'note' => $note, 'is_edit' => true, 'files' => $files));
 }