コード例 #1
0
ファイル: member.php プロジェクト: uzura8/flockbird
 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;
 }
コード例 #2
0
ファイル: albumimage.php プロジェクト: uzura8/flockbird
 public static function save_with_relations($album_id, \Model_Member $member = null, $public_flag = null, $file_path = null, $timeline_type_key = 'album_image', $optional_values = array())
 {
     if (!\Util_Array::array_in_array(array_keys($optional_values), array('name', 'shot_at', 'shot_at_time', 'public_flag'))) {
         throw new \InvalidArgumentException('Parameter optional_values is invalid.');
     }
     if (is_null($public_flag)) {
         $public_flag = isset($optional_values['public_flag']) ? $optional_values['public_flag'] : conf('public_flag.default');
     }
     $album = null;
     if (empty($member)) {
         $album = Model_Album::find($album_id, array('related' => 'member'));
         $member = $album->member;
     }
     $options = \Site_Upload::get_uploader_options($member->id, 'ai', $album_id);
     $uploadhandler = new \Site_Uploader($options);
     $file = $uploadhandler->save($file_path);
     if (!empty($file->error)) {
         throw new \FuelException($file->error);
     }
     $self = new self();
     $self->album_id = $album_id;
     $self->file_name = $file->name;
     $self->public_flag = $public_flag;
     $self->shot_at = self::get_shot_at_for_insert($file->shot_at, isset($optional_values['shot_at_time']) ? $optional_values['shot_at_time'] : null, isset($optional_values['shot_at']) ? $optional_values['shot_at'] : null);
     $self->save();
     // カバー写真の更新
     if ($timeline_type_key == 'album_image_profile') {
         if (!$album) {
             $album = Model_Album::find($album_id);
         }
         $album->cover_album_image_id = $self->id;
         $album->save();
     }
     // timeline 投稿
     if (\Module::loaded('timeline')) {
         switch ($timeline_type_key) {
             case 'album_image_profile':
                 $timeline_foreign_id = $self->id;
                 $timeline_child_foreign_ids = array();
                 break;
             case 'album':
             case 'album_image':
             default:
                 $timeline_foreign_id = $self->album->id;
                 $timeline_child_foreign_ids = array($self->id);
                 break;
         }
         \Timeline\Site_Model::save_timeline($member->id, $public_flag, $timeline_type_key, $timeline_foreign_id, $self->updated_at, null, null, $timeline_child_foreign_ids);
     }
     return array($self, $file);
 }