本文整理汇总了PHP中Media::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::getId方法的具体用法?PHP Media::getId怎么用?PHP Media::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::getId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: transform
/**
* Transforms an object (media) to a string (id).
*
* @param Media|null $media
*
* @return string
*/
public function transform($media)
{
if (null === $media || !$media instanceof \Apoutchika\MediaBundle\Model\MediaInterface) {
return '';
}
return $media->getId();
}
示例3: getImage
function getImage($img)
{
try {
if (strpos($img, 'http://') !== false) {
$original_url = $img;
$pos = strrpos($img, ".");
$ext = substr($img, $pos + 1);
$media = new Media();
$media->save();
$fileName = $media->getId() . "." . $ext;
$basePath = sfConfig::get('sf_web_dir') . "/media/upload/";
file_put_contents($basePath . $fileName, file_get_contents($img));
$mime = explode(";", Media::mime_content_type($basePath . $fileName));
$mime = $mime[0];
$media->setFilename($fileName);
$media->setFiletype($mime);
$media->setFiledirpath($basePath);
$media->save(null, $o);
chmod($basePath . $fileName, 0777);
$media->resizeImage(null, 450);
$media->resizeImage(1, 150);
} elseif (base64_decode($img)) {
$ext = "jpg";
$media = new Media();
$media->save();
$fileName = $media->getId() . "." . $ext;
$basePath = sfConfig::get('sf_web_dir') . "/media/upload/";
file_put_contents($basePath . $fileName, base64_decode($img));
$mime = explode(";", Media::mime_content_type($basePath . $fileName));
$mime = $mime[0];
$media->setFilename($fileName);
$media->setFiletype($mime);
$media->setFiledirpath($basePath);
$media->save(null, $o);
chmod($basePath . $fileName, 0777);
$media->resizeImage(null, 450);
$media->resizeImage(1, 150);
}
} catch (Exception $e) {
$media->delete();
FileHelper::Log("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]");
echo_cms("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]");
}
}
示例4: testScenarioUsingQuery
public function testScenarioUsingQuery()
{
// Add publisher records
// ---------------------
try {
$scholastic = new Publisher();
$scholastic->setName("Scholastic");
// do not save, will do later to test cascade
$morrow = new Publisher();
$morrow->setName("William Morrow");
$morrow->save();
$morrow_id = $morrow->getId();
$penguin = new Publisher();
$penguin->setName("Penguin");
$penguin->save();
$penguin_id = $penguin->getId();
$vintage = new Publisher();
$vintage->setName("Vintage");
$vintage->save();
$vintage_id = $vintage->getId();
$this->assertTrue(true, 'Save Publisher records');
} catch (Exception $e) {
$this->fail('Save publisher records');
}
// Add author records
// ------------------
try {
$rowling = new Author();
$rowling->setFirstName("J.K.");
$rowling->setLastName("Rowling");
// do not save, will do later to test cascade
$stephenson = new Author();
$stephenson->setFirstName("Neal");
$stephenson->setLastName("Stephenson");
$stephenson->save();
$stephenson_id = $stephenson->getId();
$byron = new Author();
$byron->setFirstName("George");
$byron->setLastName("Byron");
$byron->save();
$byron_id = $byron->getId();
$grass = new Author();
$grass->setFirstName("Gunter");
$grass->setLastName("Grass");
$grass->save();
$grass_id = $grass->getId();
$this->assertTrue(true, 'Save Author records');
} catch (Exception $e) {
$this->fail('Save Author records');
}
// Add book records
// ----------------
try {
$phoenix = new Book();
$phoenix->setTitle("Harry Potter and the Order of the Phoenix");
$phoenix->setISBN("043935806X");
$phoenix->setAuthor($rowling);
$phoenix->setPublisher($scholastic);
$phoenix->save();
$phoenix_id = $phoenix->getId();
$this->assertFalse($rowling->isNew(), 'saving book also saves related author');
$this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher');
$qs = new Book();
$qs->setISBN("0380977427");
$qs->setTitle("Quicksilver");
$qs->setAuthor($stephenson);
$qs->setPublisher($morrow);
$qs->save();
$qs_id = $qs->getId();
$dj = new Book();
$dj->setISBN("0140422161");
$dj->setTitle("Don Juan");
$dj->setAuthor($byron);
$dj->setPublisher($penguin);
$dj->save();
$dj_id = $qs->getId();
$td = new Book();
$td->setISBN("067972575X");
$td->setTitle("The Tin Drum");
$td->setAuthor($grass);
$td->setPublisher($vintage);
$td->save();
$td_id = $td->getId();
$this->assertTrue(true, 'Save Book records');
} catch (Exception $e) {
$this->fail('Save Author records');
}
// Add review records
// ------------------
try {
$r1 = new Review();
$r1->setBook($phoenix);
$r1->setReviewedBy("Washington Post");
$r1->setRecommended(true);
$r1->setReviewDate(time());
$r1->save();
$r1_id = $r1->getId();
$r2 = new Review();
$r2->setBook($phoenix);
$r2->setReviewedBy("New York Times");
//.........这里部分代码省略.........
示例5: die
die("Error test date/time: " . $e->__toString());
}
// Handle BLOB/CLOB Columns
// ------------------------
try {
print "\nTesting the BLOB/CLOB columns\n";
print "-------------------------------\n\n";
$blob_path = dirname(__FILE__) . '/etc/lob/tin_drum.gif';
$blob2_path = dirname(__FILE__) . '/etc/lob/propel.gif';
$clob_path = dirname(__FILE__) . '/etc/lob/tin_drum.txt';
$m1 = new Media();
$m1->setBook($phoenix);
$m1->setCoverImage(file_get_contents($blob_path));
$m1->setExcerpt(file_get_contents($clob_path));
$m1->save();
$m1_id = $m1->getId();
print "Added Media collection [id = {$m1_id}].\n";
print "Looking for just-created mediat by PK (={$m1_id}) .... ";
try {
$m1_lookup = MediaPeer::retrieveByPk($m1_id);
} catch (Exception $e) {
print "ERROR!\n";
die("Error retrieving media by pk: " . $e->__toString());
}
if ($m1_lookup) {
print "FOUND!\n";
} else {
print "NOT FOUND :(\n";
die("Couldn't find just-created media item: media_id = {$m1_id}");
}
print "Making sure BLOB was correctly updated: ";
示例6: testLobSetting_WriteMode
public function testLobSetting_WriteMode()
{
$blob_path = $this->getLobFile('tin_drum.gif');
$blob2_path = $this->getLobFile('propel.gif');
$clob_path = $this->getLobFile('tin_drum.txt');
$book = BookPeer::doSelectOne(new Criteria());
$m1 = new Media();
$m1->setBook($book);
$m1->setCoverImage(file_get_contents($blob_path));
$m1->setExcerpt(file_get_contents($clob_path));
$m1->save();
MediaPeer::clearInstancePool();
// make sure we have the latest from the db:
$m2 = MediaPeer::retrieveByPK($m1->getId());
// now attempt to assign a temporary stream, opened in 'w' mode, to the db
$stream = fopen("php://memory", 'w');
fwrite($stream, file_get_contents($blob2_path));
$m2->setCoverImage($stream);
$m2->save();
fclose($stream);
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w' mode");
$stream2 = fopen("php://memory", 'w+');
fwrite($stream2, file_get_contents($blob_path));
rewind($stream2);
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($stream2)), "Expecting setup to be correct");
$m2->setCoverImage($stream2);
$m2->save();
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w+' mode");
}
示例7: upload
public static function upload($fieldName, $to = "upload", $accept = array())
{
$request = sfContext::getInstance()->getRequest();
if (strpos($fieldName, '/') === false) {
$fileName = $request->getFileName($fieldName);
$filePath = $request->getFilePath($fieldName);
$error = $request->getFileValue($fieldName, "error");
$real_file = false;
} else {
$fileName = $fieldName;
$filePath = $fieldName;
$error = 0;
$real_file = true;
}
$fileType = self::mime_content_type($filePath);
$fileTypes = explode(";", $fileType);
$fileType = array_shift($fileTypes);
if ($error = $request->getFileValue($fieldName, "error")) {
switch ($error) {
case 1:
$errorMsg = "UPLOAD_ERR_INI_SIZE";
break;
case 2:
$errorMsg = "UPLOAD_ERR_FORM_SIZE";
break;
case 3:
$errorMsg = "UPLOAD_ERR_PARTIAL";
break;
case 4:
$errorMsg = "UPLOAD_ERR_NO_FILE";
break;
case 5:
$errorMsg = "UPLOAD_ERR_NO_TMP_DIR";
break;
case 6:
$errorMsg = "UPLOAD_ERR_CANT_WRITE";
break;
}
}
if (!empty($accept)) {
if (!empty($fileName) && !in_array($fileType, $accept)) {
throw new Exception("UPLOAD_ERR_WRONG_FILE_TYPE");
}
}
if ($request->getParameter('parent')) {
$parent = Document::getDocumentInstance($request->getParameter('parent'));
} else {
$parent = Rootfolder::getRootfolderByModule('media');
}
$len = strlen(DIRECTORY_SEPARATOR);
if (substr($to, -$len, $len) != DIRECTORY_SEPARATOR) {
$to = $to . DIRECTORY_SEPARATOR;
}
//TODO
$toPath = '/Applications/MAMP/trademark/httpdocs/media/upload/';
//self::getMediaPath().$to;//
$dirs = explode(DIRECTORY_SEPARATOR, $toPath);
$thumbDir = '';
foreach ($dirs as $dir) {
$thumbDir .= $dir . DIRECTORY_SEPARATOR;
try {
if (!is_dir($thumbDir)) {
mkdir($thumbDir, 0777, true);
}
} catch (Exception $e) {
throw new Exception("UPLOAD_ERR_CANT_CREATE_DIR");
}
}
if (!$request->getParameter('id')) {
if ($error) {
throw new Exception($errorMsg);
}
$media = new Media();
$media->save(null, $parent, false);
} else {
if ($error && $error != 4 && !empty($fileName)) {
throw new Exception($errorMsg);
}
$media = Document::getDocumentInstance($request->getParameter('id'));
if (!$media || get_class($media) != "Media") {
$media = new Media();
$media->save(null, $parent, false);
} elseif ($error != 4) {
if (file_exists($file = $media->getServerAbsoluteUrl())) {
@unlink($file);
}
if (file_exists($thumb = $media->getServerAbsoluteThumbUrl())) {
@unlink($thumb);
}
}
}
$ext = $media->getExtention($fileName);
$extLen = strlen($ext);
$saveFileName = $media->getId() . "." . $ext;
if ($real_file) {
@copy($fileName, $toPath . $saveFileName);
@chmod($toPath . $saveFileName, 0777);
@copy($fileName, $toPath . 'thumbs' . DIRECTORY_SEPARATOR . $saveFileName);
@chmod($toPath . 'thumbs' . DIRECTORY_SEPARATOR . $saveFileName, 0777);
} else {
//.........这里部分代码省略.........
示例8: addInstanceToPool
/**
* Adds an object to the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doSelect*()
* methods in your stub classes -- you may need to explicitly add objects
* to the cache in order to ensure that the same objects are always returned by doSelect*()
* and retrieveByPK*() calls.
*
* @param Media $value A Media object.
* @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
*/
public static function addInstanceToPool(Media $obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if ($key === null) {
$key = (string) $obj->getId();
}
// if key === null
self::$instances[$key] = $obj;
}
}