Ejemplo n.º 1
0
 /**
  * Observer to change status of a single plan
  * according to all user's responses
  *
  * @param $planId
  * @return mixed
  */
 public function updatePlanStatus($planId)
 {
     if (isset($planId)) {
         $plan = $this->model->find($planId);
         $testers = $plan->testers()->get();
         $results = $this->getTestersTicketsStatus($plan, $testers, 'single');
     } else {
         $plans = $this->model->all();
         foreach ($plans as $plan) {
             $testers = $plan->testers()->get();
             $results[] = $this->getTestersTicketsStatus($plan, $testers);
         }
     }
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Update built plan details
  *
  * @param $planId
  * @param $request
  * @return array|bool
  */
 public function updateBuiltPlan($planId, $request)
 {
     $redirect = false;
     $errorMsg = '';
     // Start transaction
     DB::beginTransaction();
     // Start plan update
     try {
         $plan = $this->model->find($planId);
         $plan->update(['description' => $request->get('description'), 'started_at' => $request->get('started_at'), 'expired_at' => $request->get('expired_at')]);
     } catch (\Exception $e) {
         $errorMsg = $e->getMessage();
         $redirect = true;
     } catch (QueryException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     } catch (ModelNotFoundException $e) {
         $errorMsg = $e->getErrors();
         $redirect = true;
     }
     // Redirect if errors
     if ($redirect) {
         // Rollback
         DB::rollback();
         // Log to system
         Tools::log($errorMsg, $request);
         return false;
     }
     // Commit all changes
     DB::commit();
     $results = ['type' => 'plan', 'status' => 'update', 'plan_id' => $plan->id, 'creator_id' => $plan->creator_id, 'description' => $plan->description];
     return $results;
 }