Exemple #1
0
 /**
  * @param	Product $product The product object to add.
  */
 protected function doAddProduct($product)
 {
     $userProduct = new UserProduct();
     $userProduct->setProduct($product);
     $this->addUserProduct($userProduct);
 }
Exemple #2
0
            } else {
                error('empty-password', __('The password must not be empty.'));
            }
        } else {
            error('invalid-token', __('The supplied token for password resetting is invalid.'));
        }
    }
});
$app->post('/user/:id/products', function ($id) use($app) {
    if_is_admin(function () use($app, $id) {
        $user = UserQuery::create()->findPk($id);
        if ($user) {
            $data = json_decode($app->request()->getBody(), true);
            foreach ($data as $p_id => $expires) {
                $product = ProductQuery::create()->findPk($p_id);
                if ($product) {
                    $up = new UserProduct();
                    $up->setProduct($product);
                    if ($expires) {
                        $up->setExpires($expires);
                    }
                    $user->addUserProduct($up);
                }
            }
            $user->save();
            ok();
        } else {
            error('user-not-found', 'no user found with that id');
        }
    });
});
 /**
  * @param	UserProduct $userProduct The userProduct object to add.
  */
 protected function doAddUserProduct($userProduct)
 {
     $this->collUserProducts[] = $userProduct;
     $userProduct->setProduct($this);
 }