本文整理汇总了PHP中Media::setType方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::setType方法的具体用法?PHP Media::setType怎么用?PHP Media::setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::setType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveMedia
public static function saveMedia($file, $parentId, $type, $className, $isMain)
{
if ($file['name']) {
$media = new Media();
$media->setParentId($parentId);
$media->setType($type);
$media->setClassName($className);
$media->setPath($file['name']);
//retrive file extention
$fileNameArr = explode('.', $file['name']);
$fileExt = end($fileNameArr);
$media->setExt($fileExt);
if ($isMain) {
$media->setIsMain(1);
}
$media->save();
//Save file
if ($type == MediaPeer::IMAGE) {
// resize image
$image = new sfThumbnail(800, 800);
$image->loadFile($file['tmp_name']);
//$image->save(sfConfig::get('sf_upload_dir')."/$parentId/".$file['name'], 'image/jpeg');
$image->save(sfConfig::get('sf_upload_dir') . "/" . $media->getId() . "." . $media->getExt());
// create thunmbnail
$imageTh = new sfThumbnail(80, 80);
$imageTh->loadFile($file['tmp_name']);
$imageTh->save(sfConfig::get('sf_upload_dir') . "/th_" . $media->getId() . "." . $media->getExt());
}
}
}
示例2: getMedia
/**
* @param array $data
* @return Media
*/
public function getMedia($data = array())
{
$media = new Media();
$media->setId($data["id"])->setLink($data["link"])->setCaptionText(isset($data["caption"]) && isset($data["caption"]["text"]) ? $data["caption"]["text"] : "");
if ($data["type"] == "image") {
$media->setType(Media::TYPE_IMAGE);
$media->setSource($data["images"]["standard_resolution"]["url"]);
} elseif ($data["type"] == "video") {
$media->setType(Media::TYPE_VIDEO);
$media->setSource($data["videos"]["standard_resolution"]["url"]);
}
$media->setUser($this->getUserInfo($data["user"]));
if (intval($data["comments"]["count"]) > 0) {
foreach ($data["comments"]["data"] as $comment) {
$createdAt = new \DateTime();
$createdAt->setTimestamp(intval($comment["created_time"]));
$commentObj = new Comment();
$commentObj->setId($comment["id"])->setCreatedAt($createdAt)->setText($comment["text"]);
$media->addComment($commentObj);
}
}
return $media;
}
示例3: getPostData
if (isPutMethod()) {
$data = getPostData();
$tripId = '';
if (isset($data['tripId'])) {
$tripId = $data['tripId'];
}
$mediaId = '';
if (isset($data['mediaId'])) {
$mediaId = $data['mediaId'];
}
if ($tripId === '' || $mediaId === '') {
$response = errorResponse(RESPONSE_BAD_REQUEST);
} else {
$object = new Media($tripId, $mediaId);
if (isset($data['type'])) {
$object->setType($data['type']);
}
if (isset($data['caption'])) {
$object->setCaption($data['caption']);
}
if (isset($data['timestamp'])) {
$object->setTimestamp($data['timestamp']);
}
if (isset($data['location'])) {
$object->setLocation($data['location']);
}
if (isset($data['width'])) {
$object->setWidth($data['width']);
}
if (isset($data['height'])) {
$object->setHeight($data['height']);
示例4: testHashOldInstance
/**
* Test #17.
* The findByHash function returns an object populated with previous
* values if a hash for a previous instance is given.
* @depends testUpdate
* @depends testHashGetInstance
*/
public function testHashOldInstance()
{
global $testTripId1, $testMediaId1;
// create the object and save it
$object = new Media($testTripId1, $testMediaId1);
$object->setType('photo');
$object->setCaption('Caption 1');
$object->setTimestamp('2015-09-30 12:03:45');
$object->setLocation('location');
$object->setWidth('900');
$object->setHeight('600');
$object->setDeleted('N');
$this->assertTrue($object->save());
$this->assertEquals(1, $this->countTestRows());
$old_hash = $object->getHash();
// change values and update the object
$object->setType('video');
$object->setCaption('Caption 2');
$object->setTimestamp('2015-10-01 10:01:01');
$object->setLocation('location 2');
$object->setWidth('640');
$object->setHeight('480');
$object->setDeleted('Y');
$this->assertTrue($object->save());
$this->assertEquals(2, $this->countTestRows());
$new_hash = $object->getHash();
// read the object from the database and confirm that the old
// values are returned
$object = Media::findByHash($old_hash);
$this->assertNotNull($object);
$this->assertEquals($testTripId1, $object->getTripId());
$this->assertEquals($testMediaId1, $object->getMediaId());
$this->assertEquals('photo', $object->getType());
$this->assertEquals('Caption 1', $object->getCaption());
$this->assertEquals('2015-09-30 12:03:45', $object->getTimestamp());
$this->assertEquals('location', $object->getLocation());
$this->assertEquals('900', $object->getWidth());
$this->assertEquals('600', $object->getHeight());
$this->assertEquals('N', $object->getDeleted());
$this->assertEquals($old_hash, $object->getHash());
// read the new object from the database and confirm that the new
// values are returned
$object = Media::findByHash($new_hash);
$this->assertNotNull($object);
$this->assertEquals($testTripId1, $object->getTripId());
$this->assertEquals($testMediaId1, $object->getMediaId());
$this->assertEquals('video', $object->getType());
$this->assertEquals('Caption 2', $object->getCaption());
$this->assertEquals('2015-10-01 10:01:01', $object->getTimestamp());
$this->assertEquals('location 2', $object->getLocation());
$this->assertEquals('640', $object->getWidth());
$this->assertEquals('480', $object->getHeight());
$this->assertEquals('Y', $object->getDeleted());
$this->assertEquals($new_hash, $object->getHash());
}
示例5: basename
if (file_exists($imageFileType)) {
echo "Sorry, file already exists.";
$error = 1;
}
// Check file size
if ($sizeArray[$count] > 5000000) {
echo "Sorry, your file is too large.";
$error = 1;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$error = 1;
} else {
// set type of file to add to database
$media->setType("img");
}
if ($error == 0) {
if (move_uploaded_file($tmpNameArray[$count], $uploaddir . basename($nameArray[$count]))) {
$files[] = $uploaddir . $nameArray[$count];
echo $uploaddir;
// create thumb
$image = $uploaddir . basename($nameArray[$count]);
$imageSize = getimagesize($image);
$width = $imageSize[0];
$height = $imageSize[1];
$newSize = ($width + $height) / ($width * ($height / 150));
$newWidth = $width * $newSize;
$newHeight = $height * $newSize;
// finalize thum by checking what file format it is
if ($imageFileType == "jpg" || $imageFileType == "jpeg") {
示例6: testAddMedia
public function testAddMedia()
{
$media = new Media();
$media->setType('audio/mpeg');
$this->object->addMedia($media);
$this->assertAttributeContainsOnly($media, 'medias', $this->object);
}
示例7: testSynchGet
/**
* Test #11. SYNCH get an existent object.
* @depends testDataWipedBeforeTest
* @depends testGetExistent
*/
public function testSynchGet()
{
global $testTripId1;
global $testMediaId1;
global $synchAuthToken;
// Create the object and set attributes
$object = new Media($testTripId1, $testMediaId1);
$object->setType('photo');
$object->setCaption('Caption 1');
$object->setTimestamp('2015-09-30 12:03:45');
$object->setLocation('location');
$object->setWidth('900');
$object->setHeight('600');
$object->setDeleted('Y');
// Save the object and confirm a row is added to the database
$this->assertTrue($object->save());
$this->assertEquals(1, $this->countTestRows());
$data = array('hash' => $object->getHash());
$result = getApi('synchMedia.php', $data, $synchAuthToken);
$this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
$this->assertTrue(isset($result['tripId']));
$this->assertTrue(isset($result['mediaId']));
$this->assertTrue(isset($result['created']));
$this->assertTrue(isset($result['updated']));
$this->assertTrue(isset($result['type']));
$this->assertTrue(isset($result['caption']));
$this->assertTrue(isset($result['timestamp']));
$this->assertTrue(isset($result['location']));
$this->assertTrue(isset($result['width']));
$this->assertTrue(isset($result['height']));
$this->assertTrue(isset($result['deleted']));
$this->assertTrue(isset($result['hash']));
$this->assertEquals($testTripId1, $result['tripId']);
$this->assertEquals($testMediaId1, $result['mediaId']);
$this->assertEquals($object->getCreated(), $result['created']);
$this->assertEquals($object->getUpdated(), $result['updated']);
$this->assertEquals('photo', $result['type']);
$this->assertEquals('Caption 1', $result['caption']);
$this->assertEquals('2015-09-30 12:03:45', $result['timestamp']);
$this->assertEquals('location', $result['location']);
$this->assertEquals('900', $result['width']);
$this->assertEquals('600', $result['height']);
$this->assertEquals('Y', $result['deleted']);
$this->assertEquals($object->getHash(), $result['hash']);
}