/**
  * Render the image browser widget
  *
  * @param string $name
  * @param mixed $value
  * @param array $attributes
  * @param array $errors
  * @return string Widget HTML
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Partial'));
     $object = $this->getOption('object');
     $per_page = sfConfig::get('app_sf_image_pool_chooser_per_page', 24);
     $tag = $object->getTagRestriction();
     if ($tag) {
         $tag = implode(',', $tag);
     }
     // Because we use this for image upload
     $vars = array('pager' => sfImagePoolImageTable::getInstance()->getPager($per_page, 1, $object), 'name' => $name, 'object' => $object, 'per_page' => $per_page, 'images' => $object->getPoolImages(), 'multiple' => (bool) $object->allowSelectMultiple(), 'tag' => $tag);
     return get_partial('sfImagePoolAdmin/widget', $vars);
 }
 /**
  * Method for setting images but from ids only.
  *
  * @param $object
  * @param array $image_ids
  */
 public function setImageIds($image_ids = array(), Doctrine_Record $object = null)
 {
     $object = is_null($object) ? $this->getInvoker() : $object;
     if (empty($image_ids)) {
         return $object->getPoolImages()->clear();
     }
     $images = sfImagePoolImageTable::getInstance()->getByIds($image_ids);
     $this->setImages($images, $object);
 }
Ejemplo n.º 3
0
 /**
  * AJAX powered pagination
  *
  * @return void
  * @author Ben Lancaster
  * @author Jo Carter <*****@*****.**>
  **/
 public function executeChooser(sfWebRequest $request)
 {
     sfConfig::set('sf_web_debug', false);
     // Is there a potential taggable object to restrict by?
     $class = $request->hasParameter('class') ? $request->getParameter('class') : null;
     $class_id = $request->hasParameter('class_id') ? $request->getParameter('class_id') : null;
     if ($class && $class_id) {
         $object = Doctrine_Core::getTable($class)->findOneById($class_id);
     } else {
         $object = null;
     }
     // Or a tag set? Added for MooEditable
     $tag = $request->hasParameter('tag') ? $request->getParameter('tag') : null;
     $per_page = sfConfig::get('app_sf_image_pool_chooser_per_page', 24);
     $pager = sfImagePoolImageTable::getInstance()->getPager($per_page, $request->getParameter('page', 1), $object, $tag);
     $vars = array('paginationId' => 'pagination', 'kind' => 'image-chooser', 'pager' => $pager, 'object' => $object, 'tag' => $tag, 'multiple' => $request->getParameter('multiple', false) === 'true');
     return $this->renderPartial('sfImagePoolAdmin/chooser_pagination', $vars);
 }
    $image->filename = 'test.png';
    $image->mime_type = 'image/png';
    $image->save();
    $t->isa_ok($image, 'sfImagePoolImage', 'Image created');
    $thumbnail_options = array('width' => 300, 'height' => 300, 'scale' => false);
    // Create cache
    $cache = sfImagePoolCache::getInstance($image, $adapter_options, $thumbnail_options);
    $t->isa_ok($cache, 'sfImagePoolRackspaceCloudFilesCache', 'Cache class created');
    $container = $cache->getContainer();
    $t->is($container->name, $adapter_options['options']['container'], 'Container created or already exists');
    // copy test file in place
    copy($_test_dir . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'test.png', $cache->getDestination());
    $url = $cache->commit(false);
    $imageCrop = sfImagePoolCropTable::getInstance()->findCrop($image, $thumbnail_options['width'], $thumbnail_options['height'], !$thumbnail_options['scale'], $cache::CROP_IDENTIFIER);
    $t->isa_ok($imageCrop, 'sfImagePoolCrop', 'Crop created');
    $objectName = $cache->getCloudName();
    $object = $container->get_object($objectName);
    $t->isa_ok($object, 'CF_Object', 'Image created on Rackspace cloud');
    $image->delete();
    $image = sfImagePoolImageTable::getInstance()->findOneByFilename('test.png');
    $t->is($image, false, 'Image deleted from database');
    try {
        $object2 = $container->get_object($objectName);
        $t->fail('Object not deleted from cloud');
    } catch (NoSuchObjectException $e) {
        $t->pass('Object deleted from cloud');
    }
} else {
    $t->fail('Please ensure you have set up your Rackspace cache options - use the rackspace:initialise task to accomplish this or see the README');
    $t->skip('Skipping tests', 6);
}