Creates a form to delete a Plan entity.

@param Plan $plan The Plan entity

@return \Symfony\Component\Form\Form The form
439344
private function createDeleteForm(Plan $plan)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('ecommerce_plan_delete', array('id' => $plan->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
1266050
public function deleteAction($layoutId)
    {
        $em = $this->get('doctrine.orm.entity_manager');
        $layout = $em->find('LexikMailerBundle:Layout', $layoutId);

        if (!$layout) {
            throw $this->createNotFoundException(sprintf('No layout found for id "%d".', $layoutId));
        }

        $em->remove($layout);
        $em->flush();

        return $this->redirect($this->generateUrl('lexik_mailer.layout_list'));
    }
611166
private function createDeleteForm(Located $located)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('ecommerce_located_delete', array('id' => $located->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
911755
public function cancelPaymentPlan($param)
    {
        $param['method'] = CheckoutApi_Client_Adapter_Constant::API_DELETE;
        $this->flushState();
        $uri = $this->getUriRecurringPayments().'/plans';
        $hasError = false;
        $isPlanIdValid = CheckoutApi_Client_Validation_GW3::isPlanIdValid($param);
        if(!$isPlanIdValid ) {
            $hasError = true;
            $this->throwException('Please provide a valid plan id',array('param'=>$param));
        }else {

            $uri = "$uri/{$param['planId']}";
        }

        return $this->request( $uri ,$param,!$hasError);
    }
993171
public static function delete_template($id, $deleteplans = true) {
        $params = self::validate_parameters(self::delete_template_parameters(), array(
            'id' => $id,
            'deleteplans' => $deleteplans,
        ));

        $template = api::read_template($params['id']);
        self::validate_context($template->get_context());

        return api::delete_template($params['id'], $params['deleteplans']);
    }
1044409
protected static function archive_user_competencies_in_plan($plan) {

        // Check if the plan was already completed.
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            throw new coding_exception('The plan is already completed.');
        }

        $competencies = $plan->get_competencies();
        $usercompetencies = user_competency::get_multiple($plan->get('userid'), $competencies);

        $i = 0;
        foreach ($competencies as $competency) {
            $found = false;

            foreach ($usercompetencies as $uckey => $uc) {
                if ($uc->get('competencyid') == $competency->get('id')) {
                    $found = true;

                    $ucprecord = $uc->to_record();
                    $ucprecord->planid = $plan->get('id');
                    $ucprecord->sortorder = $i;
                    unset($ucprecord->id);
                    unset($ucprecord->status);
                    unset($ucprecord->reviewerid);

                    $usercompetencyplan = new user_competency_plan(0, $ucprecord);
                    $usercompetencyplan->create();

                    unset($usercompetencies[$uckey]);
                    break;
                }
            }

            // If the user competency doesn't exist, we create a new relation in user_competency_plan.
            if (!$found) {
                $usercompetencyplan = user_competency_plan::create_relation($plan->get('userid'), $competency->get('id'),
                        $plan->get('id'));
                $usercompetencyplan->set('sortorder', $i);
                $usercompetencyplan->create();
            }
            $i++;
        }
    }
846372
private function createCreateForm(Collection $entity)
    {
        $form = $this->createForm($this->get('amulen.classification.form.collection'), $entity, array(
            'action' => $this->generateUrl('admin_collection_create'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }
778287
public function editAction($id)
        {

            /** @var RemoteApp $oRemoteApp */
            $oRemoteApp = RemoteAppQuery::create()->findOneById($id);

            if (count($oRemoteApp) === 0) {
                throw $this->createNotFoundException('Unable to find RemoteApp entity.');
            }

            $editForm   = $this->createEditForm($oRemoteApp);
            $deleteForm = $this->createDeleteForm($id);

            return $this->render('SlashworksAppBundle:RemoteApp:edit.html.twig', array(
                'entity'      => $oRemoteApp,
                'edit_form'   => $editForm->createView(),
                'delete_form' => $deleteForm->createView(),
            ));
        }
373285
private function getPlan(string $name): Plan
    {
        if (empty($this->plans[$name])) {
            throw new Exception\DomainException(
                sprintf(
                    'Invalid plan "%s" specified.',
                    $name
                )
            );
        }

        return new Plan($name, $this->plans[$name], $this->stepInterface);
    }
139415
protected function _delete_form()
    {

        if (version_compare(phpversion(), '5.5', '<')) {
            return $this->container
                ->get('templating.helper.form')
                ->widget(
                    $this->container->get('form.factory')->createBuilder('form', array('id' => '@id'), array())
                        ->add('id', 'hidden')
                        ->getForm()
                        ->createView()
                );
        }
        else {
            return $this->container
                ->get('templating.helper.form')
                ->widget(
                    $this->container->get('form.factory')->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', array('id' => '@id'), array())
                        ->add('id', 'Symfony\Component\Form\Extension\Core\Type\HiddenType')
                        ->getForm()
                        ->createView()
                );
        }
    }
1140947
public static function delete_plan($id) {
        global $DB;
        static::require_enabled();

        $plan = new plan($id);

        if (!$plan->can_manage()) {
            $context = context_user::instance($plan->get('userid'));
            throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
        }

        // Wrap the suppression in a DB transaction.
        $transaction = $DB->start_delegated_transaction();

        // Delete plan competencies.
        $plancomps = plan_competency::get_records(array('planid' => $plan->get('id')));
        foreach ($plancomps as $plancomp) {
            $plancomp->delete();
        }

        // Delete archive user competencies if the status of the plan is complete.
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            self::remove_archived_user_competencies_in_plan($plan);
        }
        $event = \core\event\competency_plan_deleted::create_from_plan($plan);
        $success = $plan->delete();

        $transaction->allow_commit();

        // Trigger deleted event.
        $event->trigger();

        return $success;
    }
318890
protected static function remove_archived_user_competencies_in_plan($plan) {
        $competencies = $plan->get_competencies();
        $usercompetenciesplan = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), $competencies);

        foreach ($usercompetenciesplan as $ucpkey => $ucp) {
            $ucp->delete();
        }
    }
1154475
public static function unlink_plan_from_template($planorid) {
        global $DB;
        static::require_enabled();

        $plan = $planorid;
        if (!is_object($planorid)) {
            $plan = new plan($planorid);
        }

        // The user must be allowed to manage the plans of the user, nothing about the template.
        if (!$plan->can_manage()) {
            throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
        }

        // Only plan with status DRAFT or ACTIVE can be unliked..
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            throw new coding_exception('Only draft or active plan can be unliked from a template');
        }

        // Early exit, it's already done...
        if (!$plan->is_based_on_template()) {
            return true;
        }

        // Fetch the template.
        $template = new template($plan->get('templateid'));

        // Now, proceed by copying all competencies to the plan, then update the plan.
        $transaction = $DB->start_delegated_transaction();
        $competencies = template_competency::list_competencies($template->get('id'), false);
        $i = 0;
        foreach ($competencies as $competency) {
            $record = (object) array(
                'planid' => $plan->get('id'),
                'competencyid' => $competency->get('id'),
                'sortorder' => $i++
            );
            $pc = new plan_competency(null, $record);
            $pc->create();
        }
        $plan->set('origtemplateid', $template->get('id'));
        $plan->set('templateid', null);
        $success = $plan->update();
        $transaction->allow_commit();

        // Trigger unlinked event.
        \core\event\competency_plan_unlinked::create_from_plan($plan)->trigger();

        return $success;
    }
907744
public function changePlan($plan)
    {
        if (is_numeric($plan)) {
            $plan = App::make(PlanInterface::class)->find($plan);
        }

        // If plans doesn't have the same billing frequency (e.g., interval
        // and interval_count) we will update the billing dates starting
        // today... and sice we are basically creating a new billing cycle,
        // the usage data will be cleared.
        if (is_null($this->plan) or $this->plan->interval !== $plan->interval or
                $this->plan->interval_count !== $plan->interval_count) {
            // Set period
            $this->setNewPeriod($plan->interval, $plan->interval_count);

            // Clear usage data
            $usageManager = new SubscriptionUsageManager($this);
            $usageManager->clear();
        }

        // Attach new plan to subscription
        $this->plan_id = $plan->id;

        return $this;
    }
899264
public static function delete_plan($id) {
        $params = self::validate_parameters(self::delete_plan_parameters(), array(
            'id' => $id,
        ));

        $plan = api::read_plan($params['id']);
        self::validate_context($plan->get_context());

        return external_api::clean_returnvalue(self::delete_plan_returns(), api::delete_plan($params['id']));
    }
243913
public function swap($plan)
    {
        if ($this->onGracePeriod() && $this->braintree_plan === $plan) {
            return $this->resume();
        }

        if (! $this->active()) {
            return $this->owner->newSubscription($this->name, $plan)
                                ->skipTrial()->create();
        }

        $plan = BraintreeService::findPlan($plan);

        if ($this->wouldChangeBillingFrequency($plan) && $this->prorate) {
            return $this->swapAcrossFrequencies($plan);
        }

        $subscription = $this->asBraintreeSubscription();

        $response = BraintreeSubscription::update($subscription->id, [
            'planId' => $plan->id,
            'price' => number_format($plan->price * (1 + ($this->owner->taxPercentage() / 100)), 2, '.', ''),
            'neverExpires' => true,
            'numberOfBillingCycles' => null,
            'options' => [
                'prorateCharges' => $this->prorate,
            ],
        ]);

        if ($response->success) {
            $this->fill([
                'braintree_plan' => $plan->id,
                'ends_at' => null,
            ])->save();
        } else {
            throw new Exception('Braintree failed to swap plans: '.$response->message);
        }

        return $this;
    }
1157326
public function create($subscription, $plan, array $parameters = [])
    {
        $parameters = array_merge($parameters, compact('plan', 'subscription'));

        return $this->_post('subscription_items', $parameters);
    }