Beispiel #1
0
 public function testUpdate()
 {
     $faker = TestCase::faker();
     $user = TestCase::getFixture('users.user_1');
     // Events
     Subbly::events()->listen($this->getService()->name() . ':updating', function ($model) use($user) {
         $this->assertEquals($user->id, $model->id);
         Subbly::events()->forget($this->getService()->name() . ':updating');
     });
     Subbly::events()->listen($this->getService()->name() . ':updated', function ($model) use($user) {
         $this->assertEquals($user->id, $model->id);
         Subbly::events()->forget($this->getService()->name() . ':updated');
     });
     $user->firstname = $faker->firstname;
     $user->lastname = $faker->lastname;
     $returnedUser = $this->getService()->update($user);
     $this->assertInstanceOf('Subbly\\Model\\User', $user);
     $this->assertInstanceOf('Subbly\\Model\\User', $returnedUser);
     $this->assertEquals($user->id, $returnedUser->id);
 }
 /**
  * Perform file(s) upload to the server.
  *
  * @route POST /api/v1/uploader
  * @authentication required
  */
 public function store()
 {
     // TODO: to clean
     if (!Input::hasFile('file')) {
         return $this->jsonErrorResponse('"file" is required.');
     }
     Subbly::events()->fire('subbly.upload:creating', array());
     $file = Input::file('file');
     $file_type = Input::get('file_type', 'product_image');
     $destination = app_upload($file_type);
     $publicPath = public_upload($file_type);
     $filename = sprintf('%s.%s', uniqid(), $file->getClientOriginalExtension());
     $inputFile = Input::all();
     unset($inputFile['file']);
     $fileData = array('file' => array_merge($inputFile, array('filename' => $filename, 'file_path' => sprintf('%s/%s', $publicPath, $filename))));
     $uploadSuccess = $file->move($destination, $filename);
     if ($uploadSuccess) {
         Subbly::events()->fire('subbly.upload:created', $fileData);
     } else {
         Subbly::events()->fire('subbly.upload:error', $fileData);
     }
     return $this->jsonResponse($fileData, array('status' => array('code' => 201, 'message' => 'Upload done')));
 }
Beispiel #3
0
 /**
  * Fire an event.
  *
  * @param string  $eventName Name of the event
  * @param array   $vars      Event vars
  * @param boolean $halt
  *
  * @return array|null
  *
  * @api
  */
 protected function fireEvent($eventName, array $vars = array(), $halt = true)
 {
     $method = $halt ? 'until' : 'fire';
     $eventName = sprintf('%s:%s', $this->name(), $eventName);
     return Subbly::events()->{$method}($eventName, $vars);
 }
Beispiel #4
0
// Orders
Subbly::events()->listen('subbly.orders:created', function ($order) {
    // delete all orders stats
});
// Attach file to model on upload
Subbly::events()->listen('subbly.upload:created', function ($file) {
    if ($file['file_type'] == 'product_image') {
        if (isset($file['sku']) && $file['sku'] !== 'false') {
            $product = Subbly::api('subbly.product')->find($file['sku']);
            $productImage = Subbly::api('subbly.product_image')->create(array('filename' => $file['filename'], 'product_id' => $file['sku']), $product);
        }
    }
});
// Attach file to model on upload
// Attach categories to products on create
Subbly::events()->listen('subbly.product:created', function ($product) {
    $doneSomething = false;
    if (Input::has('product_image')) {
        $files = Input::get('product_image');
        foreach ($files as $file) {
            $productImage = Subbly::api('subbly.product_image')->create(array('filename' => $file, 'product_id' => $product->sku), $product);
        }
        $doneSomething = true;
    }
    if (Input::has('product_category')) {
        Subbly::api('subbly.product_category')->create(Input::get('product_category'), $product);
        $doneSomething = true;
    }
    // reload product with new values
    // if( $doneSomething )
    // {