Exemplo n.º 1
0
<div class="entity_profile_image">
<div onmouseover="showImageEdit();" onmouseout="hideImageEdit();" style="position: relative;">
  <a id="entity_profile_image_edit" href="<?php 
echo url_for(EntityTable::getInternalUrl($entity, 'uploadImage'));
?>
" style="position: absolute; top: 0; right: 0; display: none; height: 16px; width: 16px;">
    <div style="background-color: #fff;">
      <?php 
echo image_tag('system/edit-pencil.png');
?>
    </div>
  </a>
<?php 
$image = EntityTable::getProfileImageById($entity['id']);
if ($image) {
    ?>
	<?php 
    echo link_to(image_tag(ImageTable::getPath($image, 'profile'), array('alt' => '')), EntityTable::getInternalUrl($entity, 'images'));
    ?>
  <?php 
    slot('share_image', ImageTable::getPath($image, 'profile'));
} else {
    ?>
  <?php 
    $file = $entity['primary_ext'] == 'Person' ? 'anon.png' : 'anons.png';
    ?>
	<?php 
    echo link_to(image_tag('system' . DIRECTORY_SEPARATOR . $file, array('alt' => 'Upload Image')), EntityTable::getInternalUrl($entity, 'uploadImage'));
}
?>
Exemplo n.º 2
0
 public function executeUploadImage($request)
 {
     $this->checkEntity($request);
     $params = $request->getParameter('image');
     $this->upload_form = new ImageUploadForm();
     $this->has_image = EntityTable::hasProfileImage($this->entity);
     if ($request->isMethod('post')) {
         $db = Doctrine_Manager::connection();
         $this->upload_form->bind($params, $request->getFiles('image'));
         if ($this->upload_form->isValid()) {
             try {
                 $db->beginTransaction();
                 $files = $request->getFiles('image');
                 //set filename and path based on upload type
                 if (isset($files['file']['size']) && $files['file']['size']) {
                     $path = $request->getFilePath('image');
                     $path = $path['file'];
                     $originalFilename = $request->getFileName('image');
                     $originalFilename = $originalFilename['file'];
                 } else {
                     $path = $params['url'];
                     $pathParts = explode('?', basename($path));
                     $originalFilename = $pathParts[0];
                 }
                 //if image files can't be created, assume remote url was bad
                 if (!($filename = ImageTable::createFiles($path, $originalFilename))) {
                     $validatorSchema = $this->upload_form->getValidatorSchema();
                     $this->upload_form->getErrorSchema()->addError(new sfValidatorError($validatorSchema['url'], 'invalid'));
                     return sfView::SUCCESS;
                 }
                 //create image
                 $image = new Image();
                 $image->entity_id = $this->entity['id'];
                 $image->filename = $filename;
                 $image->title = $params['title'];
                 $image->caption = $params['caption'];
                 $image->url = $params['url'];
                 if (!$this->has_image) {
                     $image->is_featured = true;
                 } elseif (isset($params['is_featured'])) {
                     $db = Doctrine_Manager::connection();
                     $sql = 'UPDATE image SET is_featured = 0 WHERE entity_id = ?';
                     $stmt = $db->execute($sql, array($this->entity['id']));
                     $image->is_featured = true;
                 } else {
                     $image->is_featured = 0;
                 }
                 $image->is_free = isset($params['is_free']) ? true : null;
                 $image->save();
                 //if featured, unfeature any other images
                 if (isset($params['featured']) && ($profileImage = EntityTable::getProfileImageById($entity))) {
                     $profileImage->is_featured = false;
                     $profileImage->save();
                 }
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
             }
             $this->clearCache($this->entity);
             $this->redirect($image->url ? EntityTable::getInternalUrl($this->entity, 'images') : 'entity/image?id=' . $image->id);
         }
     }
 }