Example #1
0
 public static function save_profile_image(Model_Member $member, $file_path = null)
 {
     if (conf('upload.types.img.types.m.save_as_album_image')) {
         $album_id = \Album\Model_Album::get_id_for_foreign_table($member->id, 'member');
         list($album_image, $file) = \Album\Model_AlbumImage::save_with_relations($album_id, $member, conf('public_flag.maxRange'), $file_path, 'album_image_profile');
         $member->file_name = $album_image->file_name;
         $member->save();
     } else {
         if ($member->file_name) {
             Model_File::delete_with_timeline($member->file_name);
         }
         $options = Site_Upload::get_uploader_options($member->id);
         $uploadhandler = new Site_Uploader($options);
         $file = $uploadhandler->save($file_path);
         if (!empty($file->error)) {
             throw new FuelException($file->error);
         }
         $member->file_name = $file->name;
         $member->save();
         // timeline 投稿
         if (is_enabled('timeline')) {
             \Timeline\Site_Model::save_timeline($member->id, conf('public_flag.maxRange'), 'profile_image', $file->id, $member->updated_at);
         }
     }
     return $file;
 }
Example #2
0
 /**
  * Mmeber_Profile_Image unset
  * 
  * @access  public
  * @return  Response
  */
 public function action_unset()
 {
     Util_security::check_csrf();
     try {
         DB::start_transaction();
         if (!conf('upload.types.img.types.m.save_as_album_image')) {
             Model_File::delete_with_timeline($this->u->file_name);
         }
         $this->u->file_name = null;
         $this->u->save();
         DB::commit_transaction();
         Session::set_flash('message', term('profile', 'site.picture') . 'を削除しました。');
     } catch (Database_Exception $e) {
         if (DB::in_transaction()) {
             DB::rollback_transaction();
         }
         Session::set_flash('error', Site_Controller::get_error_message($e, true));
     } catch (FuelException $e) {
         if (DB::in_transaction()) {
             DB::rollback_transaction();
         }
         Session::set_flash('error', $e->getMessage());
     }
     Response::redirect('member/profile/image');
 }