Exemplo n.º 1
0
 /**
  * @param	Organization $organization The organization object to add.
  */
 protected function doAddOrganization($organization)
 {
     $organizationProduct = new OrganizationProduct();
     $organizationProduct->setOrganization($organization);
     $this->addOrganizationProduct($organizationProduct);
 }
Exemplo n.º 2
0
        } else {
            return error('unknown-product', 'Product not found');
        }
    });
});
$app->post('/products/:id/organizations', function ($id) use($app) {
    if_is_admin(function () use($app, $id) {
        $product = ProductQuery::create()->findPk($id);
        if ($product) {
            $data = json_decode($app->request()->getBody(), true);
            $res = array();
            foreach ($data as $newRelation) {
                $org = OrganizationQuery::create()->findPk($newRelation['id']);
                if ($org) {
                    $op = new OrganizationProduct();
                    $op->setOrganization($org);
                    if ($newRelation['expires']) {
                        $op->setExpires($newRelation['expires']);
                    }
                    $product->addOrganizationProduct($op);
                }
                $res[] = $op;
            }
            try {
                $product->save();
                ok($res);
            } catch (Exception $e) {
                error('io-error', $e->getMessage());
            }
        } else {
            return error('unknown-product', 'Product not found');
Exemplo n.º 3
0
 /**
  * @param	OrganizationProduct $organizationProduct The organizationProduct object to add.
  */
 protected function doAddOrganizationProduct($organizationProduct)
 {
     $this->collOrganizationProducts[] = $organizationProduct;
     $organizationProduct->setOrganization($this);
 }