Пример #1
0
 public function updateActivity($memberId, $body, $options = array())
 {
     $object = new ActivityData();
     $object->setMemberId($memberId);
     $object->setBody($body);
     if (isset($options['public_flag'])) {
         $publicFlagKeys = array_keys($this->getPublicFlags(false));
         if (!in_array($options['public_flag'], $publicFlagKeys)) {
             throw new LogicException('Invalid public flag');
         }
         $object->setPublicFlag($options['public_flag']);
     }
     if (isset($options['in_reply_to_activity_id'])) {
         $object->setInReplyToActivityId($options['in_reply_to_activity_id']);
     }
     if (isset($options['is_pc']) && !$options['is_pc']) {
         $object->setIsPc(false);
     }
     if (isset($options['is_mobile']) && !$options['is_mobile']) {
         $object->setIsMobile(false);
     }
     if (isset($options['uri'])) {
         $object->setUri($options['uri']);
     }
     if (isset($options['source'])) {
         $object->setSource($options['source']);
         if (isset($options['source_uri'])) {
             $object->setSourceUri($options['source_uri']);
         }
     }
     $activityImages = array();
     if (isset($options['images'])) {
         if (!is_array($options['images'])) {
             $options['images'] = array($options['images']);
         }
         foreach ($options['images'] as $image) {
             $activityImage = new ActivityImage();
             if (isset($image['file_id'])) {
                 $activityImage->setFileId($image['file_id']);
             } elseif (isset($image['uri']) && isset($image['mime_type'])) {
                 $activityImage->setUri($image['uri']);
                 $activityImage->setMimeType($image['mime_type']);
             } else {
                 throw new LogicException('Invalid image data');
             }
             $activityImages[] = $activityImage;
         }
     }
     if (isset($options['foreign_table']) && isset($options['foreign_id'])) {
         $object->setForeignTable($options['foreign_table']);
         $object->setForeignId($options['foreign_id']);
     }
     $object->save();
     foreach ($activityImages as $activityImage) {
         $activityImage->setActivityData($object);
         $activityImage->save();
     }
     return $object;
 }
 public function createActivityImageByFileInfoAndActivityId(array $fileInfo, $activityId)
 {
     $file = new File();
     $file->setOriginalFilename(basename($fileInfo['name']));
     $file->setType($fileInfo['type']);
     $fileFormat = $file->getImageFormat();
     if (is_null($fileFormat) || '' == $fileFormat) {
         $fileFormat = pathinfo($fileInfo['name'], PATHINFO_EXTENSION);
     }
     $fileBaseName = md5(time()) . '_' . $fileFormat;
     $filename = 'ac_' . $fileInfo['member_id'] . '_' . $fileBaseName;
     $file->setName($filename);
     $file->setFilesize($fileInfo['size']);
     $bin = new FileBin();
     $bin->setBin($fileInfo['binary']);
     $file->setFileBin($bin);
     $file->save();
     $activityImage = new ActivityImage();
     $activityImage->setActivityDataId($activityId);
     $activityImage->setFileId($file->getId());
     $activityImage->setUri($this->getActivityImageUriByfileInfoAndFilename($fileInfo, $filename));
     $activityImage->setMimeType($file->type);
     $activityImage->save();
     $this->createUploadImageFileByFileInfoAndSaveFileName($fileInfo, $filename);
     return $activityImage;
 }
Пример #3
0
 public function createActivityImageByFileInfoAndActivity(sfValidatedFile $fileInfo, ActivityData $activity)
 {
     $file = new File();
     $file->setFromValidatedFile($fileInfo);
     $file->name = 'ac_' . $activity->member_id . '_' . $file->name;
     $file->save();
     $activityImage = new ActivityImage();
     $activityImage->setActivityData($activity);
     $activityImage->setFileId($file->getId());
     $activityImage->setMimeType($file->type);
     $activityImage->save();
     return $activityImage;
 }