示例#1
0
 /**
  * Creates new challenge for given charity and redirects user to payment
  * 
  * @todo read & validate form values
  */
 function new_challenge($charity_id)
 {
     $charity = Charity::find_by_id($charity_id);
     if (!$charity) {
         throw new PageNotFoundException();
     }
     // FIXME: check for duplicates
     $challenge = new Challenge();
     $challenge->charity_id = $charity->id;
     $challenge->user_id = $this->logged_in_user()->id;
     $challenge->base_donation_pence = 1000;
     $challenge->matching_percentage = 10;
     $challenge->matching_upper_limit_pence = 5000;
     $challenge->save();
     return $this->do_prepay_challenge($challenge);
 }
 /**
  * Store a newly created resource in storage.
  * POST /challenges
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::only(array('title', 'description', 'team'));
     $validator = Validator::make($input, array('title' => 'required|min:4', 'description' => "required", 'team' => "required|min:3"));
     if ($validator->fails()) {
         return Redirect::route('backend.challenges.create')->withErrors($validator->messages());
     }
     $challenge = new Challenge();
     $challenge->title = $input['title'];
     $challenge->description = $input['description'];
     $challenge->team = $input['team'];
     $challenge->user_id = $this->currentUser->id;
     if ($challenge->save()) {
         return Redirect::route('backend.challenges.show', array($challenge->id));
     }
     return Redirect::route('backend.challenges.create')->withErrors(array("Something went wrong."));
 }
示例#3
0
 /**
  * Add a new challenge from $path.
  * The path parameter is the place where the challenge was unzipped. The method will mv the challenge in
  * the /challenges folder and install it in the database.
  * @param FilePath $path the filesystem path where the challenge is located usually some temp directory
  * @throws \GuzzleHttp\Exception\XmlParseException if the challenge .xml config file is not found
  * @return void
  */
 public static function addNew(FilePath $path)
 {
     $challengeName = explode(DIRECTORY_SEPARATOR, $path);
     $challengeName = array_pop($challengeName);
     $challengeConfig = Utils::replaceXMLHeader(readfile($path . DIRECTORY_SEPARATOR . $challengeName . ".xml"));
     $xml = simplexml_load_string($challengeConfig);
     if (false === $xml) {
         throw new \GuzzleHttp\Exception\XmlParseException('Challenge xml is invalid');
     }
     $title = $xml[CHALLENGE_XML_TITLE_TAG];
     $author = $xml[CHALLENGE_XML_AUTHOR_TAG];
     $category = $xml[CHALLENGE_XML_CATEGORY_TAG];
     $description = $xml[CHALLENGE_XML_DESCRIPTION_TAG];
     $challenge = new Challenge();
     $challenge->title = $title;
     $challenge->author = $author;
     $challenge->category = $category;
     $challenge->description = $description;
     Utils::recurse_copy($path, CHALLENGE_DIR . $challengeName);
     $challenge->save();
     /*Todo: initialize containers/vagrant boxes*/
 }
示例#4
0
 public function actionSendChallenge()
 {
     if (isset($_POST['idUser'], $_POST['private'], $_POST['comment']) && (isset($_POST['idTruth']) || isset($_POST['idDare'])) && Friend::areFriendsOrFriendRequest($_POST['idUser'], Yii::app()->user->getId(), 1) == 1) {
         $type = isset($_POST['idTruth']) ? "idTruth" : "idDare";
         $id = isset($_POST['idTruth']) ? $_POST['idTruth'] : $_POST['idDare'];
         //If the challenge is public and it already exists
         if ($_POST['private'] == 'false' && Challenge::model()->exists("idUserTo = :idUserTo AND {$type} = :id", array(':idUserTo' => $_POST['idUser'], ':id' => $id))) {
             echo 'ALREADY_EXISTS';
             return;
         }
         $challenge = new Challenge();
         $challenge->idUserFrom = Yii::app()->user->getId();
         $challenge->idUserTo = $_POST['idUser'];
         $challenge->{$type} = $id;
         $challenge->createDate = date('Y-m-d, H:i:s');
         $challenge->private = $_POST['private'] == 'true' ? 1 : 0;
         $challenge->comment = $_POST['comment'];
         if ($challenge->save()) {
             echo "SUCCESS";
         }
     }
 }