Example #1
0
 public function lenderInviteViaEmail($lender, $email, $subject, $custom_message)
 {
     $lender_invite = new Invite();
     $lender_invite->setLender($lender);
     $lender_invite->setEmail($email);
     $lender_invite->isInvited(true);
     $success = $lender_invite->save();
     if ($success) {
         $this->lenderMailer->sendLenderInvite($lender, $lender_invite, $subject, $custom_message);
     }
     return $lender_invite;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Invite();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Invite'])) {
         $model->attributes = $_POST['Invite'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
 public function actionInvite()
 {
     $model = new Invite();
     if (Yii::app()->request->isPostRequest) {
         $params = Yii::app()->request->getParam('Invite');
         $model->setAttributes($params);
         $model->setAttribute('index.twigstatus', 0);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Ваше заявка отправлена, спасибо!');
             $model->unsetAttributes();
         }
     }
     $this->render('invite', ['model' => $model]);
 }
Example #4
0
 public function Join($block = 0)
 {
     Auth::RequireLogin(true);
     if (!$this->auth->isLogged()) {
         $this->json->error("You need to be logged in.");
     }
     $this->Block = new Game_Block($block);
     // Make sure the game exists
     if (!$this->Block->exists()) {
         $this->json->error("Block could not be found.");
     }
     // Make sure the game is not in the past
     if ($this->Block->time != 0 && $this->Block->time < time()) {
         $this->json->error("This block is already in the past.");
     }
     $this->Account = new Account(Auth::Get("id"));
     if (!$this->Account->exists()) {
         $this->json->error("Your account could not be loaded.");
     }
     $this->Related_Account = $this->Block->account->where("id", Auth::Get("id"))->include_join_fields()->get();
     if ($this->Related_Account->exists() && $this->Related_Account->join_active) {
         $this->json->error("You are already playing this block.");
     }
     // Get the Fixture
     $this->Fixture = $this->Block->fixture->get();
     // Make sure the fixture exists
     if (!$this->Fixture->exists()) {
         $this->json->error("Fixture could not be loaded.");
     }
     // Check the limit of this block
     $this->PlayersCount = $this->Block->account->include_join_fields()->where(array("active" => 1))->count();
     if ($this->PlayersCount >= (int) $this->Fixture->type * 2) {
         $this->json->error("This game is already full!");
     }
     if ($this->Fixture->payp_cost > 0 && (!$this->Related_Account->exists() || $this->Related_Account->join_type == "game")) {
         $this->Account->credits -= $this->Fixture->payp_cost;
         $this->Account->save();
         // Add Payment Record
         $payment = new Payment();
         $payment->account_id = Auth::Get("id");
         $payment->game_block_id = $this->Block->id;
         $payment->amount = $this->Fixture->payp_cost;
         $payment->date = time();
         $payment->type = "game";
         $payment->fixture_id = $this->Fixture->id;
         $payment->paid = 0;
         $payment->status = "active";
         $payment->save();
     }
     // Cancel refund if there is one
     if ($this->Related_Account->exists() && $this->Related_Account->join_type == "block") {
         $this->LastPayment = new Payment();
         $this->LastPayment->where(array("account_id" => Auth::Get("id"), "game_block_id" => $this->Block->id, "amount <" => 0))->order_by("id", "DESC")->limit(1)->get();
         if ($this->LastPayment->exists()) {
             $this->LastPayment->status = "canceled";
             $this->LastPayment->save();
         }
     }
     // Make all invites inactive for this fixture
     $Invite = new Invite();
     $Invite->where(array("email" => Auth::Get("email"), "fixture_id" => $this->Fixture->id, "valid" => 1, "joined" => 0))->limit(1)->get();
     // Check for Invitation
     if ($Invite->exists()) {
         $Invite->joined = 1;
         $Invite->valid = 0;
         $Invite->joined_on = time();
         $Invite->joined_account = Auth::Get("id");
         // If invitation exists, mark it as accepted
         $Invite->save();
     }
     // Relate this player with a manager
     $this->PlayerManager = new Player_Manager();
     $this->PlayerManager->player_id = Auth::Get("id");
     $this->PlayerManager->manager_id = $this->Fixture->owner;
     $this->PlayerManager->save();
     // Relate Account
     $this->Block->save($this->Account);
     $this->Block->set_join_field($this->Account, "active", 1);
     if (!$this->Related_Account->exists()) {
         $this->Block->set_join_field($this->Account, "type", "game");
     }
     // Send success response
     $this->json->success();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $postdata = file_get_contents("php://input");
     //var_dump($postdata);
     $request = json_decode($postdata);
     $model = new Event();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (array_key_exists('host_phone', $request) and array_key_exists('subject', $request) and array_key_exists('planned_time', $request) and array_key_exists('current_time', $request) and array_key_exists('invites', $request)) {
         //POST
         //host_phone
         //subject
         //planned_time
         //current_time
         //invites => "2384238034823,23423423424,42342342343,23432423"
         $user = User::model()->findByAttributes(array('phone_number' => $request->host_phone));
         $model->host_id = $user->id;
         $model->create_time = time();
         $model->planned_time = time() + (intval($request->planned_time) - intval($request->current_time));
         $model->subject = $request->subject;
         $invites = split(',', $request->invites);
         array_push($invites, $request->host_phone);
         //parse the $_POST['invites'] csv
         if ($model->save()) {
             echo $model->id;
             foreach ($invites as $invite) {
                 if (strlen($invite) < 5) {
                     continue;
                 }
                 $user = User::model()->findByAttributes(array('phone_number' => intval($invite)));
                 if (!$user or $user->status == 0) {
                     //twilio
                     if (!$user) {
                         $new_user = new User();
                         $new_user->create_time = time();
                         $new_user->phone_number = $invite;
                         $new_user->status = 0;
                         $new_user->save(false);
                     }
                     //$response = http_get("http://jakemor.com/services/sendSMS", array("number"=>$invite, 'message'=>1, 'key'=>"123"), $info);
                 } else {
                     //send user the message, etc
                     $viter = new Invite();
                     $viter->event_id = $model->id;
                     $viter->create_time = time();
                     $viter->receiver_id = $user->id;
                     $viter->sender_id = $model->host_id;
                     $viter->status = 0;
                     $viter->save(false);
                 }
             }
         } else {
             var_dump($model->errors);
         }
     } else {
         echo "did not receive parameters";
     }
 }
Example #6
0
 public function actionAjax()
 {
     //this function does one of three things depending on payload
     //would be better in hindsight to send an "action" command
     //if we want to save the query
     if (isset($_POST['save'])) {
         //if id is set, there we are updating, else it's a new query
         if (isset($_POST['query_id']) && (int) $_POST['query_id']) {
             //we are updating
             $Query = Query::model()->findByPk($_POST['query_id']);
         } else {
             $Query = new Query();
             $Query->created = date("Y-m-d H:i:s");
         }
         // Is this an invite query?
         $Query->invite = isset($_POST['invite']) ? 1 : 0;
         $Query->user_id = Yii::app()->user->id;
         $Query->name = $_POST['Query']['name'];
         $Query->description = $_POST['Query']['description'];
         $Query->JSON = $this->getQueryJSON();
         if ($Query->save()) {
             if (!$_POST['query_id']) {
                 // Creating a Query or an Invite?
                 if ($Query->invite) {
                     // Create a campaign to go with this Query - it has to have one
                     $Campaign = new Campaign();
                     $Campaign->name = $Query->name;
                     $Campaign->description = $Query->description;
                     $Campaign->query_id = $Query->id;
                     $Campaign->status = Campaign::STATUS_NOT_RUN;
                     $Campaign->processing = 0;
                     if ($Campaign->save()) {
                         $errorOccured = false;
                         // Everything is saved ok. Now run the query and get all the contacts
                         $queryResults = $Query->runInviteContactQuery();
                         // loop array and add each one to invite table
                         foreach ($queryResults['rows'] as $contact) {
                             // Create a new Invite model
                             $Invite = new Invite();
                             $Invite->contact_warehouse_id = $contact['contact_warehouse_id'];
                             $Invite->store2contact_id = $contact['store2contact_id'];
                             $Invite->store_id = $contact['store_id'];
                             $Invite->organisation_id = $contact['origin_organisation_id'];
                             $Invite->hash = sha1($contact['contact_warehouse_id'] . $contact['store2contact_id'] . $contact['origin_organisation_id'] . microtime(true) . SHASALT);
                             $Invite->date = date('Y-m-d H:i:s');
                             $Invite->query_id = $Campaign->query_id;
                             $Invite->campaign_id = $Campaign->id;
                             $Invite->status = Invite::STATUS_UNSENT;
                             $Invite->processing = 0;
                             if (!$Invite->save()) {
                                 $errorOccured = true;
                                 $errors = print_r($Invite->errors, true);
                                 Yii::log('Error saving Invite model: ' . $errors, 'error');
                             } else {
                             }
                             unset($Invite);
                         }
                         if ($errorOccured) {
                             mail('*****@*****.**', 'Website Error', 'Invite attempted Invite model could not be saved. See Application logs.');
                         }
                         $Query->num_contacts = sizeof($queryResults['rows']);
                         $Query->save(true, array('num_contacts'));
                         // new. set flash then return request to redirect.
                         Yii::app()->user->setFlash('success', 'The new invite has been created successfully.');
                         $array = array('success' => true, 'redirect' => $this->createUrl('invite/index'));
                     } else {
                         throw new CHttpException('500', 'Error saving campaign');
                     }
                 } else {
                     // new. set flash then return request to redirect.
                     //Run query to get count to save.
                     $queryResults = $Query->runCampaignCountQuery();
                     $Query->num_contacts = $queryResults['count'];
                     $Query->save(true, array('num_contacts'));
                     Yii::app()->user->setFlash('success', 'The new query has been created successfully.');
                     $array = array('success' => true, 'redirect' => $this->createUrl('query/update', array('id' => $Query->id)));
                 }
             } else {
                 $queryResults = $Query->runCampaignCountQuery();
                 $Query->num_contacts = $queryResults['count'];
                 $Query->save(true, array('num_contacts'));
                 $array = array("success" => true, 'id' => $Query->id, 'resultsTotal' => number_format($queryResults['count']));
             }
         } else {
             $array = array("errors" => $Query->getErrors());
         }
         header('Content-Type: application/json');
         print CJSON::encode($array);
     } else {
         if (isset($_POST['new-row'])) {
             $rowNumber = time();
             $Question = QueryQuestion::model()->findByPk($_POST['new']['query_choice']);
             $QueryQuestions = QueryQuestion::model()->findAll(array('order' => 'type,id'));
             header('Content-Type: application/json');
             print json_encode(array('html' => $this->renderPartial('_row', array('Question' => $Question, 'QueryQuestions' => $QueryQuestions, 'and_choice' => $_POST['new']['and_choice'], 'bool_choice' => $_POST['new']['bool_choice'], 'query_choice' => $_POST['new']['query_choice'], 'query_number' => $_POST['new']['query_number'], 'query_option' => $_POST['new']['query_option'], 'rowNumber' => $rowNumber), true)));
         } else {
             if (isset($_POST['render'])) {
                 //just render the question options
                 //get the query question with that id
                 $Question = QueryQuestion::model()->findByPk($_POST['id']);
                 //render partial
                 $this->renderPartial('_options', array('Question' => $Question, 'rowNumber' => $_POST['rowNumber']));
             } elseif (isset($_POST['results'])) {
                 if ($_POST['query_id']) {
                     $Query = Query::model()->findByPk($_POST['query_id']);
                     if (is_null($Query)) {
                         throw new CHttpException(404, 'Not found');
                     }
                     $Query->JSON = $this->getQueryJSON();
                 } else {
                     $Query = new Query();
                     $Query->JSON = $this->getQueryJSON();
                 }
                 if (isset($_POST['invite'])) {
                     $queryResults = $Query->runInviteCountQuery();
                 } else {
                     $queryResults = $Query->runCampaignCountQuery();
                 }
                 header('Content-Type: application/json');
                 $queryResults['results'] = number_format($queryResults['count']);
                 unset($queryResults['rows']);
                 // Don't need rows on query page, just extra HTTP traffic
                 print json_encode($queryResults);
             } else {
                 throw new CHttpException(404, 'The requested page does not exist.');
             }
         }
     }
 }