Beispiel #1
0
 public function updateSettings(Sprint $sprint)
 {
     foreach (Input::only('sprint_start', 'sprint_end', 'title', 'ignore_estimates') as $key => $value) {
         $sprint->{$key} = $value;
     }
     $validation = $sprint->validate();
     if ($validation->fails()) {
         Flash::error(implode(' ', $validation->messages()->all()));
     } elseif ($sprint->save()) {
         Flash::success('The sprint settings have been updated');
     } else {
         Flash::error('The sprint settings could not be updated. Please try again');
     }
     return Redirect::back();
 }
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new Sprint;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Sprint']))
		{
			$model->attributes=$_POST['Sprint'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->sprint_id));
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}
Beispiel #3
0
 /**
  * @Given a sprint :sprint exists for the :project project
  */
 public function aSprintExistsForTheProject($sprintTitle, $projectTitle)
 {
     Auth::login(User::where('username', $this->params['phabricator_username'])->first());
     // this is a bit ugly.
     $project = Project::firstOrCreate(['title' => $projectTitle]);
     $phabricatorProject = $this->getOrCreatePhabricatorProjectFromTitle($sprintTitle);
     $existingSprint = Sprint::where('phid', $phabricatorProject['phid'])->first();
     if ($existingSprint !== null && !$existingSprint->delete()) {
         throw new Exception('Could not delete the existing sprint.');
     }
     $newSprint = new Sprint(['title' => $sprintTitle, 'project_id' => $project->id, 'sprint_start' => '2014-12-01', 'sprint_end' => '2014-12-14', 'phabricator_id' => $phabricatorProject['id'], 'phid' => $phabricatorProject['phid']]);
     if (!$phabricatorProject || !$newSprint->save()) {
         throw new Exception('There was a problem creating the sprint.' . $newSprint->getPhabricatorError());
     }
     $this->phabricatorProjectID = $existingSprint ? $existingSprint->phabricator_id : $newSprint->phabricator_id;
 }
 public function addAction()
 {
     //var_dump(Input::all());
     if (Input::server("REQUEST_METHOD") == "POST") {
         try {
             $action = "insert";
             $id = Input::get('id');
             //$school = Input::get('school');
             $course = Input::get('course');
             $name = Input::get('name');
             $description = Input::get('description');
             $fluency = Input::get('fluency');
             $publish = Input::get('publish');
             $cards_id = Input::get('card_ids');
             $f_text = Input::get('f_text');
             $f_cardtype = Input::get('cardtype');
             $f_text_option = Input::get('f_text_option');
             $f_sound = Input::get('f_sound');
             $f_image = Input::get('f_image');
             if (isset($id) && !empty($id)) {
                 $sprint = Sprint::find($id);
                 $action = "update";
                 $cards = DB::table('cards')->where('sprint', $id)->get();
                 foreach ($cards as $card) {
                     $flag = false;
                     for ($i = 0; $i < sizeof($cards_id); $i++) {
                         if ($card->id == $cards_id[$i]) {
                             $flag = true;
                         }
                     }
                     if (!$flag) {
                         DB::table('cards')->where('id', $card->id)->delete();
                     }
                 }
             } else {
                 $sprint = new Sprint();
             }
             //$sprint->school = $school;
             $sprint->course = $course;
             $sprint->name = $name;
             $sprint->description = $description;
             $sprint->fluency_rate = $fluency;
             $sprint->published = $publish;
             $sprint->save();
             if ($action == "insert") {
                 $sprint_id = DB::getPdo()->lastInsertId();
             } else {
                 $sprint_id = $id;
             }
             $cards = "";
             for ($i = 0; $i < count($f_text); $i++) {
                 $idx = $i + 1;
                 $card_type = $f_cardtype[$i];
                 $cardid = $cards_id[$i];
                 if ($action == "update" && $cardid > 0) {
                     $card = Card::find($cardid);
                 } else {
                     $card = new Card();
                 }
                 $card->sprint = $sprint_id;
                 $card->card_type = $card_type;
                 $card->f_text = $f_text[$i];
                 if (!empty($f_text_option[$i])) {
                     $card->f_text_option = $f_text_option[$i];
                 } else {
                     $card->f_text_option = 0;
                 }
                 if (!empty($f_sound[$i])) {
                     $f_sound_path = "";
                     $f_sound_file = "";
                     if ($f_sound[$i] == "none") {
                         $card->f_sound_option = 0;
                     } else {
                         $card->f_sound_option = 1;
                         $f_sound_pos = strripos($f_sound[$i], "/");
                         $f_sound_path = substr($f_sound[$i], 0, $f_sound_pos + 1);
                         $f_sound_file = substr($f_sound[$i], $f_sound_pos + 1);
                     }
                     $card->f_sound = $f_sound_file;
                     $card->f_sound_path = $f_sound_path;
                 } else {
                     if ($f_sound[$i] == "none") {
                         $card->f_sound_option = 0;
                     } else {
                         $card->f_sound_option = 1;
                     }
                     $card->f_sound = "";
                     $card->f_sound_path = "";
                 }
                 if (!empty($f_image[$i])) {
                     $f_image_file = "";
                     $f_image_path = "";
                     if ($f_image[$i] == "none") {
                         $card->f_image_option = 0;
                     } else {
                         $card->f_image_option = 0;
                         $f_image_pos = strripos($f_image[$i], "/");
                         $f_image_path = substr($f_image[$i], 0, $f_image_pos + 1);
                         $f_image_file = substr($f_image[$i], $f_image_pos + 1);
                     }
                     $card->f_image = $f_image_file;
                     $card->f_image_path = $f_image_path;
                 } else {
                     if ($f_image[$i] == "none") {
                         $card->f_image_option = 0;
                     } else {
                         $card->f_image_option = 1;
                     }
                     $card->f_image = "";
                     $card->f_image_path = "";
                 }
                 if (is_array(Input::get('b_text-' . $idx))) {
                     $b_value = Input::get('b_text-' . $idx);
                     $b_text_options = Input::get('b_text_option-' . $idx);
                     $b_sounds = Input::get('b_sound-' . $idx);
                     $b_images = Input::get('b_image-' . $idx);
                     $subcard_id = Input::get('subcard_id-' . $idx);
                     if ($card_type == 'singlecard') {
                         $card->b_text = $b_value[0];
                         if (!empty($b_text_options[0])) {
                             $card->b_text_option = $b_text_options[0];
                         } else {
                             $card->b_text_option = 0;
                         }
                         if (!empty($b_sounds[0])) {
                             $b_sound_file = "";
                             $b_sound_path = "";
                             if ($b_sounds[0] == "none") {
                                 $card->b_sound_option = 0;
                             } else {
                                 $card->b_sound_option = 1;
                                 $b_sound_pos = strripos($b_sounds[0], "/");
                                 $b_sound_path = substr($b_sounds[0], 0, $b_sound_pos + 1);
                                 $b_sound_file = substr($b_sounds[0], $b_sound_pos + 1);
                             }
                             $card->b_sound = $b_sound_file;
                             $card->b_sound_path = $b_sound_path;
                         } else {
                             if ($b_sounds[0] == "none") {
                                 $card->b_sound_option = 0;
                             } else {
                                 $card->b_sound_option = 1;
                             }
                             $card->b_sound = "";
                             $card->b_sound_path = "";
                         }
                         if (!empty($b_images[0])) {
                             $b_image_file = "";
                             $b_image_path = "";
                             if ($b_images[0] == "none") {
                                 $card->b_image_option = 0;
                             } else {
                                 $card->b_image_option = 1;
                                 $b_image_pos = strripos($b_images[0], "/");
                                 $b_image_path = substr($b_images[0], 0, $b_image_pos + 1);
                                 $b_image_file = substr($b_images[0], $b_image_pos + 1);
                             }
                             $card->b_image = $b_image_file;
                             $card->b_image_path = $b_image_path;
                         } else {
                             if ($b_images[0] == "none") {
                                 $card->b_image_option = 0;
                             } else {
                                 $card->b_image_option = 1;
                             }
                             $card->b_image = "";
                             $card->b_image_path = "";
                         }
                         $card->save();
                         if ($action == "update" && $cardid > 0) {
                             $card_id = $cardid;
                         } else {
                             $card_id = DB::getPdo()->lastInsertId();
                         }
                         $cards .= $card_id;
                         $cards .= ",";
                     } else {
                         $card->b_text = "";
                         $card->b_sound = "";
                         $card->b_sound_path = "";
                         $card->b_image = "";
                         $card->b_image_path = "";
                         $card->save();
                         if ($action == "update" && $cardid > 0) {
                             $card_id = $cardid;
                         } else {
                             $card_id = DB::getPdo()->lastInsertId();
                         }
                         $cards .= $card_id;
                         $cards .= ",";
                         for ($j = 0; $j < count($b_value); $j++) {
                             $subcardid = $subcard_id[$j];
                             $answer = 0;
                             $key = $j + 1;
                             if ($card_type == 'radiocard') {
                                 $b_radios = Input::get('option-' . $idx);
                                 if ($key == $b_radios[0]) {
                                     $answer = 1;
                                 }
                             } else {
                                 if ($card_type == 'checkcard') {
                                     $b_checks = Input::get('check-' . $idx);
                                     for ($k = 0; $k < count($b_checks); $k++) {
                                         if ($key == $b_checks[$k]) {
                                             $answer = 1;
                                             break;
                                         }
                                     }
                                 }
                             }
                             if ($action == "update" && $subcardid > 0) {
                                 $subcard = SubCard::find($subcardid);
                             } else {
                                 $subcard = new SubCard();
                             }
                             $subcard->cards = $card_id;
                             $subcard->answer = $b_value[$j];
                             if (!empty($b_text_options[$j])) {
                                 $subcard->b_text_option = $b_text_options[$j];
                             } else {
                                 $subcard->b_text_option = 0;
                             }
                             if (!empty($b_sounds[$j])) {
                                 $b_sound_file = "";
                                 $b_sound_path = "";
                                 if ($b_sounds[$j] == "none") {
                                     $subcard->b_sound_option = 0;
                                 } else {
                                     $subcard->b_sound_option = 1;
                                     $b_sound_pos = strripos($b_sounds[$j], "/");
                                     $b_sound_path = substr($b_sounds[$j], 0, $b_sound_pos + 1);
                                     $b_sound_file = substr($b_sounds[$j], $b_sound_pos + 1);
                                 }
                                 $subcard->b_sound = $b_sound_file;
                                 $subcard->b_sound_path = $b_sound_path;
                             } else {
                                 if ($b_sounds[$j] == "none") {
                                     $subcard->b_sound_option = 0;
                                 } else {
                                     $subcard->b_sound_option = 1;
                                 }
                                 $subcard->b_sound = "";
                                 $subcard->b_sound_path = "";
                             }
                             if (!empty($b_images[$j])) {
                                 $b_image_file = "";
                                 $b_image_path = "";
                                 if ($b_images[$j] == "none") {
                                     $subcard->b_image_option = 0;
                                 } else {
                                     $subcard->b_image_option = 1;
                                     $b_image_pos = strripos($b_images[$j], "/");
                                     $b_image_path = substr($b_images[$j], 0, $b_image_pos + 1);
                                     $b_image_file = substr($b_images[$j], $b_image_pos + 1);
                                 }
                                 $subcard->b_image = $b_image_file;
                                 $subcard->b_image_path = $b_image_path;
                             } else {
                                 if ($b_images[$j] == "none") {
                                     $subcard->b_image_option = 0;
                                 } else {
                                     $subcard->b_image_option = 1;
                                 }
                                 $subcard->b_image = "";
                                 $subcard->b_image_path = "";
                             }
                             $subcard->correctanswer = $answer;
                             $subcard->save();
                         }
                     }
                 }
             }
             $cards = substr($cards, 0, strlen($cards) - 1);
             $sprint = Sprint::find($sprint_id);
             if ($cards == "") {
                 $sprint->cards = "";
             } else {
                 $sprint->cards = $cards;
             }
             $sprint->save();
             if (strcmp(strtolower(Auth::user()->permission), "teacher") == 0) {
                 return Redirect::route('teacher/sprints');
             } else {
                 if (strcmp(strtolower(Auth::user()->permission), "administrator") == 0) {
                     return Redirect::route('admin/sprints');
                 }
             }
         } catch (Exception $ex) {
             echo $ex;
             Session::flash('status_error', '');
         }
     }
 }
Beispiel #5
0
 /**
  * @Given a sprint :sprint exists for the :project project
  */
 public function aSprintExistsForTheProject($sprintTitle, $projectTitle)
 {
     Auth::login(User::where('username', $this->params['phabricator_username'])->first());
     // this is a bit ugly.
     $project = Project::firstOrCreate(['title' => $projectTitle]);
     $existingSprint = Sprint::where('title', $sprintTitle)->first();
     if (!$existingSprint) {
         $newSprint = new Sprint(['title' => $sprintTitle, 'project_id' => $project->id, 'sprint_start' => '2014-12-01', 'sprint_end' => '2014-12-14']);
         if (!$newSprint->save()) {
             throw new Exception('There was a problem creating the sprint.' . $newSprint->getPhabricatorError());
         }
     }
 }