Exemplo n.º 1
0
 public function doSaveMedia($v)
 {
     if ($v == null) {
         $image = $this->getImagePath();
         if ($this->isNew) {
             $content = file_get_contents(sfConfig::get('sf_root_dir') . '/public_html' . $image);
             $size = getimagesize(sfConfig::get('sf_root_dir') . '/public_html' . $image);
         } else {
             return $this->getObject()->getImagesId();
         }
     } else {
         $content = file_get_contents($v->getTempName());
         $size = getimagesize($v->getTempName());
     }
     $hash = md5($content);
     $criteria = new Criteria();
     $criteria->add(ImagesPeer::CONTENT_HASH, $hash);
     $obj = ImagesPeer::doSelectOne($criteria);
     try {
         if (empty($obj)) {
             $obj = new Images();
             $obj->setNameDownloadedFile($v->getOriginalName())->setNameFileForPage($v->getOriginalName())->setTypeImg($v->getType())->setHeight($size[2])->setWidth($size[1])->setContentHash($hash . '.jpg')->setContent(base64_encode($content))->setCreatedAt(date("Y-m-d H:i"))->setUpdatedAt(date("Y-m-d H:i"))->save();
         }
     } catch (Exception $e) {
         echo "stdfdfdfdfrt";
         die;
     }
     $criteria = new Criteria();
     $criteria->add(ImagesPeer::CONTENT_HASH, $obj->getContentHash());
     $obj = ImagesPeer::doSelectOne($criteria);
     return $obj->getId();
 }
Exemplo n.º 2
0
 public function executeResize(sfWebRequest $request)
 {
     $hash = $request->getParameter('hash');
     $width = $request->getParameter('x');
     $height = $request->getParameter('y');
     $criteria = new Criteria();
     $criteria->add(ImagesPeer::CONTENT_HASH, $hash);
     $obj = ImagesPeer::doSelectOne($criteria);
     $content = base64_decode($obj->getContent());
     $src = sfConfig::get('sf_root_dir') . '/public_html/uploads/' . $hash;
     file_put_contents($src, $content);
     $quality = 100;
     $rgb = 0xffffff;
     if (!file_exists($src)) {
         return false;
     }
     $size = getimagesize($src);
     if ($size === false) {
         return false;
     }
     $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
     $icfunc = "imagecreatefrom" . $format;
     if (!function_exists($icfunc)) {
         return false;
     }
     $x_ratio = $width / $size[0];
     $y_ratio = $height / $size[1];
     $ratio = min($x_ratio, $y_ratio);
     $use_x_ratio = $x_ratio == $ratio;
     $new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
     $new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
     $new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
     $new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
     $isrc = $icfunc($src);
     $idest = imagecreatetruecolor($width, $height);
     imagefill($idest, 0, 0, $rgb);
     imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
     $dir = sfConfig::get('sf_root_dir') . '/public_html/uploads/' . $width . '/' . $height . '/';
     imagejpeg($idest, $dir . $hash, $quality);
     imagedestroy($isrc);
     imagedestroy($idest);
     return $this->renderText(file_get_contents($dir . $hash));
 }
Exemplo n.º 3
0
 /**
  * Selects a collection of Reviews objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of Reviews objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     ReviewsPeer::addSelectColumns($criteria);
     $startcol2 = ReviewsPeer::NUM_COLUMNS - ReviewsPeer::NUM_LAZY_LOAD_COLUMNS;
     ImagesPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (ImagesPeer::NUM_COLUMNS - ImagesPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(ReviewsPeer::IMAGES_ID, ImagesPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseReviewsPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = ReviewsPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = ReviewsPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = ReviewsPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             ReviewsPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Images rows
         $key2 = ImagesPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ImagesPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = ImagesPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ImagesPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (Reviews) to the collection in $obj2 (Images)
             $obj2->addReviews($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 4
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ImagesPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setUrl($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setText($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setAdviceId($arr[$keys[3]]);
     }
 }
Exemplo n.º 5
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ImagesPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setNameFileForPage($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setNameDownloadedFile($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setTypeImg($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setWidth($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setHeight($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setContent($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setContentHash($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setCreatedAt($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setUpdatedAt($arr[$keys[9]]);
     }
 }
Exemplo n.º 6
0
 /**
  * Get the associated Images object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Images The associated Images object.
  * @throws     PropelException
  */
 public function getImages(PropelPDO $con = null)
 {
     if ($this->aImages === null && $this->images_id !== null) {
         $this->aImages = ImagesPeer::retrieveByPk($this->images_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aImages->addColors($this);
         		 */
     }
     return $this->aImages;
 }
Exemplo n.º 7
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(ImagesPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(ImagesPeer::DATABASE_NAME);
         $criteria->add(ImagesPeer::ID, $pks, Criteria::IN);
         $objs = ImagesPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 8
0
 /**
  * Returns the number of related Images objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Images objects.
  * @throws     PropelException
  */
 public function countImagess(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(AdvicePeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collImagess === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(ImagesPeer::ADVICE_ID, $this->id);
             $count = ImagesPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(ImagesPeer::ADVICE_ID, $this->id);
             if (!isset($this->lastImagesCriteria) || !$this->lastImagesCriteria->equals($criteria)) {
                 $count = ImagesPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collImagess);
             }
         } else {
             $count = count($this->collImagess);
         }
     }
     return $count;
 }
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = AdvicePeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related Tags objects
         $criteria = new Criteria(TagsPeer::DATABASE_NAME);
         $criteria->add(TagsPeer::ADVICE_ID, $obj->getId());
         $affectedRows += TagsPeer::doDelete($criteria, $con);
         // delete related Images objects
         $criteria = new Criteria(ImagesPeer::DATABASE_NAME);
         $criteria->add(ImagesPeer::ADVICE_ID, $obj->getId());
         $affectedRows += ImagesPeer::doDelete($criteria, $con);
         // delete related Comments objects
         $criteria = new Criteria(CommentsPeer::DATABASE_NAME);
         $criteria->add(CommentsPeer::ADVICE_ID, $obj->getId());
         $affectedRows += CommentsPeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
Exemplo n.º 10
0
 public function doSaveMedia($v)
 {
     //var_dump($v);die;
     $content = file_get_contents($v['tmp_name']);
     $hash = md5($content);
     $size = getimagesize($v['tmp_name']);
     $criteria = new Criteria();
     $criteria->add(ImagesPeer::CONTENT_HASH, $hash);
     $obj = ImagesPeer::doSelectOne($criteria);
     try {
         if (empty($obj)) {
             $obj = new Images();
             $obj->setNameDownloadedFile($v['name'])->setTypeImg($v['type'])->setHeight($size[2])->setWidth($size[1])->setContentHash($hash . '.jpg')->setContent(base64_encode($content))->setCreatedAt(date("Y-m-d H:i"))->setUpdatedAt(date("Y-m-d H:i"))->save();
         }
     } catch (Exception $e) {
         echo "stdfdfdfdfrt";
         die;
     }
     $criteria = new Criteria();
     $criteria->add(ImagesPeer::CONTENT_HASH, $obj->getContentHash());
     $obj = ImagesPeer::doSelectOne($criteria);
     // var_dump($obj->getId());die;
     return $obj->getId();
 }