public function getCollectionImages()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $id = Input::has('id') ? Input::get('id') : 0;
     $collection = Collection::with('images')->find($id);
     if ($collection) {
         $collection = $collection->toArray();
         if (!empty($collection['images'])) {
             foreach ($collection['images'] as $key => $image) {
                 if ($image['ratio'] > 1) {
                     $width = 150;
                     $height = $width / $image['ratio'];
                 } else {
                     $height = 150;
                     $width = $height * $image['ratio'];
                 }
                 $collection['images'][$key] = ['id' => $image['id'], 'name' => $image['name'], 'short_name' => $image['short_name'], 'description' => $image['description'], 'path' => URL . '/pic/thumb/' . $image['short_name'] . '-' . $image['id'] . '.jpg', 'width' => $width, 'height' => $height, 'ratio' => $image['ratio'], 'main' => $image['pivot']['type'] == 'main' ? 1 : 0];
             }
         }
         return $collection;
     }
     return [];
 }
Example #2
0
 public function test3_Appending()
 {
     $collection = new Collection(new Yaml());
     $collection_of_values = new Collection(new Yaml());
     # appending
     static::$collection->append('part1.item2', ['name' => 'Janice']);
     $this->assertEquals('Janice', static::$collection->get('part1.item2.name'));
     static::$collection->forget('part1');
     static::$collection->append('part1', ['item2' => ['name' => 'Janice']]);
     static::$collection->with('with', 'with test');
     $this->assertEquals('with test', static::$collection->get('with'));
     $this->assertTrue(static::$collection->count() === 2);
     static::$collection->forget('with');
     $this->assertTrue(static::$collection->count() === 1);
     # setup
     $test_array = ['merge_with' => ['merge' => 'this']];
     $collection_of_values->with($test_array);
     # test with an array
     $collection->merge($test_array);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with a collection as a value object
     $collection->merge($collection_of_values);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     $collection->forget('merge_with');
     # test with value object
     $value_object = new \stdClass();
     $value_object->merge_with = $test_array['merge_with'];
     $collection->merge($value_object);
     $this->assertEquals($collection->get('merge_with.merge'), 'this');
     # test with flat array
     $collection->merge(Util::array_from_str('merge with'));
     $this->assertEquals($collection->get('merge'), NULL);
     $this->assertEquals($collection->get('with'), NULL);
     $this->setExpectedException('InvalidArgumentException', "Cannot append an already existing key: 'part1'");
     static::$collection->append('part1', ['item2' => ['name' => 'Mary']]);
 }
 public function index($collectionId)
 {
     try {
         $collection = Collection::with('images')->findOrFail($collectionId);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return App::abort(404);
     }
     $collection = $collection->toArray();
     if (!empty($collection['images'])) {
         foreach ($collection['images'] as $key => $image) {
             $height = 175;
             $width = $height * $image['ratio'];
             $collection['images'][$key] = ['id' => $image['id'], 'name' => $image['name'], 'short_name' => $image['short_name'], 'description' => $image['description'], 'path' => URL . '/pic/with-logo/' . $image['short_name'] . '-' . $image['id'] . '.jpg', 'width' => $width, 'height' => $height];
         }
     }
     $this->layout->content = View::make('frontend.collections.index')->with(['collection' => $collection]);
 }