Ejemplo n.º 1
0
 public static function getMainImage($parentId, $className)
 {
     if ($parentId) {
         $c = new Criteria();
         $c->add(MediaPeer::CLASS_NAME, $className);
         $c->add(MediaPeer::IS_MAIN, 1);
         $c->add(MediaPeer::PARENT_ID, $parentId);
         $c->add(MediaPeer::TYPE, self::IMAGE);
         return MediaPeer::doSelectOne($c);
     } else {
         return null;
     }
 }
Ejemplo n.º 2
0
 public function executeUploadBanners()
 {
     $this->setLayout("backend");
     $c = new Criteria();
     $c->add(PrefPeer::LABEL, "newsletter");
     $info = PrefPeer::doSelectOne($c);
     if (!$info) {
         $info = new Pref();
         $info->setLabel("newsletter");
         $info->save();
     }
     if ($this->getRequestParameter('submitted')) {
         $request = $this->getRequest();
         try {
             $request->setParameter('parent', $info->getId());
             if ($request->getFileName('banner1')) {
                 $request->setParameter('id', $this->getRequestParameter('banner1Id'));
                 $request->setParameter('attrLabel', 'newsletter468x60');
                 $media = Media::upload('banner1', "upload/newsletter", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
                 if ($media && $media->IsImage()) {
                     $media->resizeImage(null, 60, 468);
                     $media->resizeImage("thumbs", 30, 231);
                 }
             }
             if (!$media) {
                 $media = Document::getDocumentInstance($this->getRequestParameter('banner1Id'));
             }
             if ($media) {
                 $media->setDescription($this->getRequestParameter('banner1Url'));
                 $media->save();
             }
             if ($request->getFileName('banner2')) {
                 $request->setParameter('id', $this->getRequestParameter('banner2Id'));
                 $request->setParameter('attrLabel', 'newsletter160x600');
                 $media2 = Media::upload('banner2', "upload/newsletter", array("image/gif", "image/png", "image/jpeg", "image/pjpeg", "image/x-png"));
                 if ($media2 && $media2->IsImage()) {
                     $media2->resizeImage(null, 600, 160);
                     $media2->resizeImage("thumbs", 125, 40);
                 }
             }
             if (!$media2) {
                 $media2 = Document::getDocumentInstance($this->getRequestParameter('banner2Id'));
             }
             if ($media2) {
                 $media2->setDescription($this->getRequestParameter('banner2Url'));
                 $media2->save();
             }
             $infoVal = $this->getRequestParameter('info');
             if (!$infoVal) {
                 $infoVal = null;
             }
             $info->setContent($infoVal);
             $info->save();
         } catch (Exception $e) {
             $this->message = UtilsHelper::Localize("media.backend." . $e->getMessage());
         }
     }
     $c = new Criteria();
     $c->add(PrefPeer::LABEL, "newsletter");
     $this->info = PrefPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(MediaPeer::LABEL, "newsletter468x60");
     $this->banner1 = MediaPeer::doSelectOne($c);
     $c = new Criteria();
     $c->add(MediaPeer::LABEL, "newsletter160x600");
     $this->banner2 = MediaPeer::doSelectOne($c);
 }
Ejemplo n.º 3
0
 /**
  * Test the toArray() method with new lazyLoad param.
  * @link       http://propel.phpdb.org/trac/ticket/527
  */
 public function testToArrayLazyLoad()
 {
     $c = new Criteria();
     $c->add(MediaPeer::COVER_IMAGE, null, Criteria::NOT_EQUAL);
     $c->add(MediaPeer::EXCERPT, null, Criteria::NOT_EQUAL);
     $m = MediaPeer::doSelectOne($c);
     if ($m === null) {
         $this->fail("Test requires at least one media row w/ cover_image and excerpt NOT NULL");
     }
     $arr1 = $m->toArray(BasePeer::TYPE_COLNAME);
     $this->assertNotNull($arr1[MediaPeer::COVER_IMAGE]);
     $this->assertType('resource', $arr1[MediaPeer::COVER_IMAGE]);
     $arr2 = $m->toArray(BasePeer::TYPE_COLNAME, false);
     $this->assertNull($arr2[MediaPeer::COVER_IMAGE]);
     $this->assertNull($arr2[MediaPeer::EXCERPT]);
     $diffKeys = array_keys(array_diff($arr1, $arr2));
     $expectedDiff = array(MediaPeer::COVER_IMAGE, MediaPeer::EXCERPT);
     $this->assertEquals($expectedDiff, $diffKeys);
 }