static function silentlySendTeamInviteEmail($teamId, $teamName, $playerEmail, $playerId = NULL, $playerName = '')
 {
     // Try to set the players user id if the email exists in the DB
     $foundId = is_null($playerId) ? EmailData::selectUserIdByEmail($playerEmail) : $playerId;
     $userId = !$foundId ? NULL : $foundId;
     $token = self::makeInviteToken();
     $saved = EmailData::insertTeamInvite(array(":token" => $token, ":team_id" => $teamId, ":user_id" => $userId, ":name_first" => NULL, ":name_last" => NULL, ":email" => $playerEmail, ":phone" => NULL, ":created_user_id" => APIAuth::getUserId()));
     if (!$saved) {
         return 'Could not create invite. Check your parameters and try again.';
     }
     if (is_null($userId)) {
         return ApiMailer::sendTeamInviteNewUser($token, $teamName, $playerEmail, $playerName);
     } else {
         return ApiMailer::sendTeamInviteRegisteredUser($token, $teamName, $playerEmail, $playerName);
     }
 }
 static function addAction($app)
 {
     $post = $app->request->post();
     // Validate parameters
     // Must have one or the other, or both 'action' and 'code'
     if (!v::key('action', v::stringType())->validate($post) && !v::key('code', v::stringType())->validate($post)) {
         // Validate input parameters
         return $app->render(400, array('msg' => 'Add action failed. Check your parameters and try again.'));
     }
     // Add the verifed action
     $newAction = array(":action" => v::key('action', v::stringType())->validate($post) ? $app->request->post('action') : '', ":code" => v::key('code', v::stringType())->validate($post) ? $app->request->post('code') : '', ":http_referer" => $app->request->getReferrer(), ":ip_address" => $app->request->getIp(), ":created_user_id" => APIAuth::getUserId());
     $actionId = ActionData::insertAction($newAction);
     if ($actionId) {
         return $app->render(200, array('msg' => 'Action recorded.', 'action' => $actionId));
     } else {
         return $app->render(400, array('msg' => 'Could not add new action.', 'action' => $newAction));
     }
 }
 static function assignRole($app)
 {
     if (!v::key('groupId', v::stringType())->validate($app->request->post()) || !v::key('roleId', v::stringType())->validate($app->request->post())) {
         return $app->render(400, array('msg' => 'Could not assign role from group. Check your parameters and try again.'));
     }
     $data = array(':auth_group_id' => $app->request->post('groupId'), ':auth_role_id' => $app->request->post('roleId'), ":created_user_id" => APIAuth::getUserId());
     if (GroupData::insertRoleAssignment($data)) {
         return $app->render(200, array('msg' => 'Role has been assigned from group.'));
     } else {
         return $app->render(400, array('msg' => 'Could not assign role to group.'));
     }
 }
 static function saveVariablePermissions($app, $variableId)
 {
     if (!v::intVal()->validate($variableId) || !v::key('indestructible')->validate($app->request->post()) || !v::key('locked')->validate($app->request->post())) {
         // Validate input parameters
         return $app->render(400, array('msg' => 'Update failed. Check your parameters and try again.'));
     }
     $savedConfig = ConfigData::getVariableById($variableId);
     if (!$savedConfig) {
         return $app->render(400, array('msg' => 'Variable doesnt seem to exist.'));
     }
     $indestructible = $savedConfig->indestructible;
     // Converting to boolean did not work well,
     // This allows a wider range of true false values
     $indestructible = $app->request->post('indestructible') === 1 || $app->request->post('indestructible') === '1' || $app->request->post('indestructible') === true || $app->request->post('indestructible') === 'true' ? 1 : 0;
     $locked = $savedConfig->locked;
     // Converting to boolean did not work well,
     // This allows a wider range of true false values
     $locked = $app->request->post('locked') === 1 || $app->request->post('locked') === '1' || $app->request->post('locked') === true || $app->request->post('locked') === 'true' ? 1 : 0;
     // If its locked its also indestructible
     $data = array(":id" => $variableId, ":indestructible" => $locked ? 1 : $indestructible, ":locked" => $locked, ":last_updated_by" => APIAuth::getUserId());
     $config = ConfigData::updateVariablePermissions($data);
     if ($config) {
         $config = ConfigData::getVariableById($variableId);
         return $app->render(200, array('variable' => $config));
     } else {
         return $app->render(400, array('msg' => 'Could not update system config variable permissions.'));
     }
 }
 static function initVisibilityElement($app)
 {
     if (!v::key('fieldIdentifier', v::stringType())->validate($app->request->post())) {
         return $app->render(400, array('msg' => 'Could not initialize visibility field. Check your parameters and try again.'));
     }
     if (FieldData::updateVisibilityElementInit(array(':identifier' => $app->request->post('fieldIdentifier'), ":last_updated_by" => APIAuth::getUserId()))) {
         $field = FieldData::getByIdentifier($app->request->post('fieldIdentifier'));
         return $app->render(200, array('msg' => 'The visibility field has been initialized.', 'field' => $field));
     } else {
         return $app->render(400, array('msg' => 'Could not initialize visibility field.'));
     }
 }