public function getWithImages($id = null) { $fileService = new FileService(); if ($id == null) { $filesQuery = $fileService->get(); $itemsQuery = $this->get(); $files = new Plinq($filesQuery); $items = new Plinq($itemsQuery); $result = $items->Select(function ($k, $v) use($files) { $v->images = $files->Where(function ($k2, $v2) use($v) { return $v->id == $v2->itemId; })->ToArray(); return $v; })->ToArray(); return $result; } else { $item = $this->get($id); $files = $fileService->getByItem($id); $item->images = $files; return $item; } }
function getCrmModel() { $config = array('hostname' => "pdb10.runhosting.com", 'username' => "998905_myblog", 'password' => "1234", 'database' => "998905_myblog"); $db = new OBJ_mysql($config); $customers = $db->query("SELECT * FROM crm_company WHERE deleted != 1")->fetchAll(); $deals = $db->query("SELECT * FROM crm_deals WHERE deleted != 1")->fetchAll(); $tasks = $db->query("SELECT * FROM crm_tasks WHERE deleted != 1")->fetchAll(); $people = $db->query("SELECT * FROM crm_people WHERE deleted != 1")->fetchAll(); foreach ($customers as $customer) { $pPeople = new Plinq($people); $pTasks = new Plinq($tasks); $pDeals = new Plinq($deals); $customer->people = $pPeople->Where(function ($k, $v) use($customer) { return $v->company_id == $customer->company_id; })->ToArray(); $customer->deals = $pDeals->Where(function ($k, $v) use($customer) { return $v->deal_company == $customer->company_id; })->ToArray(); $customer->tasks = $pTasks->Where(function ($k, $v) use($customer) { return $v->task_company == $customer->company_id; })->ToArray(); } return $customers; }
//require_once 'php/Mail.php'; require_once 'php/JsonResponse.php'; require_once 'php/ItemService.php'; require_once 'php/FileService.php'; require_once 'php/Plinq.php'; //require_once 'php/contact.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->config(array('debug' => true)); $app->get('/(:state)', function ($state = null) use($app) { $itemService = new ItemService(); $items = $itemService->getWithImages(); $itemsrev = array_reverse($items); $html1 = ""; $html2 = ""; $pitems = new Plinq($itemsrev); $items1 = $pitems->Where(function ($key, $value) { return $key % 2 != 0; })->ToArray(); $items2 = $pitems->Where(function ($key, $value) { return $key % 2 == 0; })->ToArray(); foreach ($items1 as $item) { $html1 .= $app->view()->fetch("item.php", ["model" => $item]); } foreach ($items2 as $item) { $html2 .= $app->view()->fetch("item.php", ["model" => $item]); } $app->render('template.php', array('view' => "home.php", 'state' => $state, 'items1' => $html1, 'items2' => $html2)); }); $app->post('/add/', function () use($app) {