示例#1
0
文件: Page.class.php 项目: Gula/magic
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     parent::save($conn);
     // generamos thumbnails
     $file = sfConfig::get('sf_upload_dir') . '/pictures/' . $this->getPicture();
     if (is_file($file)) {
         $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141), array('w' => 60, 'h' => 60));
         $size = getimagesize($file);
         $img = new sfImage($file, $size['mime']);
         if (!is_dir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'))) {
             mkdir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'), 0777);
         }
         foreach ($dims as $dim) {
             $img->thumbnail($dim['w'], $dim['h']);
             $img->setQuality(90);
             $img->saveAs(sfConfig::get('sf_upload_dir') . '/' . $this->get('id') . '/img_' . $this->get('id') . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
         }
     }
 }
示例#2
0
文件: Page.php 项目: kotow/work
 public function save($con = null, $parent = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         parent::save($con);
         // create relationship
         if (!$parent && !Document::getParentOf($this->getId())) {
             $parent = Rootfolder::getRootfolder($this);
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         Document::cacheObj($this, get_class($this));
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }