function writeToJson($userID) { $result = Dao::fetchData($userID); //This will read result row by row $branchIndex = 0; $index = 1; $i = 0; $counter = 0; while ($row = mysqli_fetch_assoc($result)) { $counter++; $i++; if ($counter <= 240) { $branch[$branchIndex][] = $row['question_id']; } if ($i == $index) { $branchIndex++; $i = 0; if ($branchIndex == 16) { $branchIndex = 0; } } if ($counter == 16 || $counter == 48 || $counter == 112) { $index = $index * 2; $i = 0; } //question_id as key $question_id = $row['question_id']; $question[$question_id]['question'] = $row['question']; $question[$question_id]['title'] = $row['title']; $question[$question_id]['image_id'] = $row['image_id']; $question[$question_id]['answers'] = $row['answers']; $question[$question_id]['score'] = $row['score']; $question[$question_id]['parent'] = $row['parent']; $question[$question_id]['concept_name'] = $row['concept_name']; } //echo $counter; //print_r($branch); //print_r($question); $data['branch'] = $branch; $data['question'] = $question; $json_string = json_encode($data); $file = 'file.json'; file_put_contents($file, $json_string); //return $data }
//definição das constantes da aplicação define('APP_ROOT_PATH', __DIR__); define('APP_CONFIG_PATH', __DIR__ . '/../config'); define('APP_VIEW_PATH', __DIR__ . '/../src/view'); //inclusão do autoload do composer require_once APP_ROOT_PATH . '/../vendor/autoload.php'; use Symfony\Component\Yaml\Parser; $app = new Silex\Application(); $yaml = new Parser(); //configura as rotas da aplicação $routing = $yaml->parse(file_get_contents(APP_CONFIG_PATH . '/routing.yml')); if (isset($routing['routings'])) { foreach ($routing['routings'] as $routing) { $method = isset($routing['method']) ? $routing['method'] : 'get'; $app->{$method}($routing['url'], $routing['class']); } } //seta as configurações da aplicação $config = $yaml->parse(file_get_contents(APP_CONFIG_PATH . '/config.yml')); if (isset($config['app'])) { $app['debug'] = isset($config['app']['debug']) ? $config['app']['debug'] : false; } //configura conexao com o banco $app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $config['database'])); //configuração do twig $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => APP_VIEW_PATH)); //atribui a app ao dao e bo \bo\Bo::setApp($app); \dao\Dao::setApp($app); $app->run();