public function afterSave() { parent::afterSave(); if (count($this->data) == 0) { foreach (Sector::model()->findAll() as $sector) { $data = new Data(); $data->metric_id = $this->id; $data->sector_id = $sector->id; $data->save(); } } }
public static function wizard($step = NULL) { // save the widget $widgetData = array(); $widgetJson = json_encode($widgetData); $widget = new Widget(); $widget->widget_name = 'note widget'; $widget->widget_type = 'note'; $widget->widget_provider = 'note'; $widget->widget_source = $widgetJson; $widget->dashboard_id = Auth::user()->dashboards()->first()->id; $widget->position = '{"size_x":3,"size_y":3,"col":1,"row":1}'; $widget->save(); // save an empty data line $text = new Data(); $text->widget_id = $widget->id; $text->data_object = ''; $text->date = Carbon::now()->toDateString(); $text->save(); return Redirect::route('dashboard.dashboard')->with('success', 'Note widget added.'); }
// 登出 case 'lo': $m = new User(); $m->logout(); break; //注册 //注册 case 'rg': $m = new User(); $m->register(); break; // 保存 // 保存 case 'sv': $m = new Data(); $m->save(); break; // 验证流程图是否存在 // 验证流程图是否存在 case 'cn': $m = new Data(); $m->checkName(); break; // 获取文件列表 // 获取文件列表 case 'fl': $m = new Data(); $m->getFileList(); break; // 获取单个文件内容 // 获取单个文件内容
public function save() { return Data::save($this); }
/** * @param $e */ public function postAddElement($e) { $searchEntry = new Data($e->getTarget()); $searchEntry->save(); }
/** * */ private function GetSEOState($taskID) { $dataProvider = new CActiveDataProvider(SiteUrl::model(), array('pagination' => false)); echo '資料庫共' . $dataProvider->totalItemCount . '筆資料' . "\r\n"; $i = 0; foreach ($dataProvider->getData() as $record) { $site = $record->site; $id = $record->SiteID; // if($i>=5) // { // break; // } //移除前面的http:// (若有的話) $site = preg_replace('#^https?://#', '', $site); $site = preg_replace('#^http?://#', '', $site); //系統延遲 $pagerank = 0; $now = new DateTime(); try { $pagerank = \SEOstats\Services\Google::getPageRank($site); if (!is_numeric($pagerank)) { $pagerank = null; } } catch (Exception $e) { $pagerank = null; } usleep(rand(1000, 3000)); //下面這行是採用Google API提供之資料 //$googleIds = \SEOstats\Services\Google::getSiteindexTotal($site); //下面這行是採用網頁搜尋結果資料 if ($i % 2 == 1) { usleep(rand(500, 1000)); $googleIds = $this->GetGoogleSearch("site:{$site}"); } else { $googleIds = $this->GetGoogleSearch("site:{$site}"); } sleep(3); if (is_null($googleIds)) { //用另外種管道重抓一次 usleep(rand(5000, 10000)); echo '[log]' . $site . "使用重抓索引資料;/r/n"; $googleIds = \SEOstats\Services\Google::getSiteindexTotal($site); } if ($i % 2 == 1) { usleep(rand(500, 1000)); $googleLinks = $this->GetGoogleSearch("link:{$site}"); } else { $googleLinks = $this->GetGoogleSearch("link:{$site}"); } //如果抓不到資料就換個管道 if (is_null($googleLinks)) { //用另外種管道重抓一次 usleep(rand(5000, 10000)); echo '[log]' . $site . "使用API重抓頁面數資料;/r/n"; $googleLinks = \SEOstats\Services\Google::getBacklinksTotal($site); } usleep(rand(1010, 15020)); //echo("[log]".$now->format( 'Y-m-d H:i:s' )."搜尋".$site."有".$googleLinks.'項結果 '."\r\n"); //取得社群分享數據 $seostats = new \SEOstats\SEOstats(); $seostats->setUrl("http://{$site}"); $fb = Social::getFacebookShares(); //print_r($fb); usleep(rand(4000, 10000)); // //設定抓取的檔案類型 // $fileTypeList = array('pdf', 'doc', 'docx', 'ppt', 'pptx', 'ps', 'eps'); $fileCount = array(); $error_statues = 0; foreach ($fileTypeList as $key => $value) { usleep(rand(5000, 10000)); if ($error_statues == 0) { $fileCount[$value] = $this->GetGoogleSearch("site:{$site}" . ' filetype:' . $value); } if (is_null($fileCount[$value])) { $fileCount[$value] = \SEOstats\Services\Google::getSiteFileTypeTotal($site, $value); //表示系統被Google封鎖了。 if (is_null($fileCount[$value])) { $fileCount[$value] = 0; $error_statues++; } } } usleep(rand(4000, 10000)); //取得網站資訊,包含網站一些設定資訊。 $info = $this->get_url_info($site); $model = new Data(); $model->attributes = array('SiteID' => $id, 'GoogleData' => $googleIds, 'google_backlink' => $googleLinks, 'filetime' => $info['filetime'] = !-1 ? date("Y-m-d H:i:s", $info['filetime']) : null, 'robot' => $this->remoteFileExists("{$site}/robots.txt"), 'sitemap' => $this->remoteFileExists("{$site}/sitemap.xml"), 'Time' => $now->format('Y-m-d H:i:s'), 'Facebook' => $fb['total_count'], 'FB_share_count' => $fb['share_count'], 'FB_like_count' => $fb['like_count'], 'FB_comment_count' => $fb['comment_count'], 'FB_commentsbox_count' => $fb['commentsbox_count'], 'FB_click_count' => $fb['click_count'], 'TwitterShares' => Social::getTwitterShares(), 'LinkedInShares' => Social::getLinkedInShares(), 'pdf' => $fileCount['pdf'], 'doc' => $fileCount['doc'], 'docx' => $fileCount['docx'], 'ppt' => $fileCount['ppt'], 'pptx' => $fileCount['pptx'], 'ps' => $fileCount['ps'], 'eps' => $fileCount['eps'], 'YY' => $now->format('Y'), 'MM' => $now->format('m'), 'DD' => $now->format('d'), 'TaskID' => $taskID, 'google_page_rank' => $pagerank); //Yii::app()->end(); if ($model->save()) { $i++; } else { print "網址: {$site} 出現錯誤"; print_r($model->getErrors()); } usleep(rand(100, 400)); // if($i==3) // { // break; // } } echo '執行完畢,共儲存' . $i . '筆資料'; }
protected function syncChildren($thingName, $member, $parent) { if (!isset($parent[$member])) { throw new DumbassDeveloperException($member . " is not a child member of given parent"); } $channel = Channel::Shopify; $children = $parent[$member]; $parentThing = Thing::loadByAltId($parent["id"]); foreach ($children as $child) { $id = $child['id']; $thingChild = null; try { $thingChild = Thing::loadByAltId($id); } catch (InstanceNotFoundException $ex) { //create a thing for the top level product $thingChild = new Thing(); $thingChild->setAltid($id); $thingChild->setName($thingName); $thingChild->setChannel($channel); $thingChild->setThing($parentThing); //set the parent of the child thing $thingChild->save(); } //all data associated to the child $thingData_raw = $thingChild->getData(); //indexed numerically //make array indexed by key $thingDatas = array(); //indexed by key foreach ($thingData_raw as $thingData) { $thingDatas[$thingData->getKey()] = $thingData; } foreach ($child as $key => $value) { //create a new data if not exist in thingData if (!isset($thingDatas[$key])) { $data = new Data(); $data->setKey($key); $data->setValue($value); $data->setThing($thingChild); $data->save(); } else { $dbData = $thingDatas[$key]; if ($dbData->getValue() != $value) { $dbData->setValue($value); $dbData->save(); } } } } }
return false; } $text_open = $app->request->getPost('text_open'); $text_closed = $app->request->getPost('text_closed'); $text_secret_key = $app->request->getPost('text_secret_key'); if (!$text_open || !$text_closed || !$text_secret_key) { $app->response->redirect("?message=empty_fields")->sendHeaders(); return false; } $data['user_id'] = $app->session->get('user_id'); $data['text_open'] = $text_open; $data['text_closed'] = $app->crypt->encryptBase64($text_closed, $text_secret_key); $data['salt'] = Users::generateSalt(); $data['text_secret_key'] = Users::sha1Rounds($app->config->app->static_salt . $text_secret_key . $data['salt']); $d = new Data(); $d->save($data); $app->response->redirect("?message=data_add_success")->sendHeaders(); }); $app->post('/ajax', function () use($app) { if (!$app->request->isAjax()) { $app->response->setStatusCode(404, "Not Found")->sendHeaders(); return false; } if ($app->security->checkToken('token') === false) { $app->response->setStatusCode(501, "Token error")->sendHeaders(); return false; } $action = $app->request->getPost('action'); $data = $app->request->getPost('data'); $filter = new \Phalcon\Filter(); switch ($action) {
public function data_save($id, $key, $value) { $validation = new Phalcon\Validation(); $validation->add('key', new PresenceOf(['message' => 'key is needed'])); $validation->add('key', new StringLength(['max' => 200, 'messageMaximum' => 'The key is too long, we can not save it.'])); $validation->add('value', new PresenceOf(['message' => 'value is needed'])); $validation->add('value', new StringLength(['max' => 200, 'messageMaximum' => 'The value is too long, we can not save it.'])); $messages = $validation->validate(['key' => $key, 'value' => $value]); foreach ($messages as $message) { throw new Exception($message, 102); } $data = $this->findData($id, $key); if ($data == null) { $data = new Data(); $data->user_id = $id; $data->key = $key; } $data->key = $key; $data->value = $value; $data->date = date("y-m-d H:i:s", time()); $success = $data->save(); if ($success) { return 0; } else { foreach ($data->getMessages() as $message) { throw new Exception($message, 100); } } }
public static function getEvents($user, $widget) { switch ($widget->widget_type) { case 'google-spreadsheet-line-cell': Log::info("google-spreadsheet-line-cell - widget_id - " . $widget['id']); $widget_source = json_decode($widget['widget_source'], true); $spreadsheetId = $widget_source['googleSpreadsheetId']; $worksheetName = $widget_source['googleWorksheetName']; # setup Google stuff $client = GooglespreadsheetHelper::setGoogleClient(); $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user); # init service $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); # get spreadsheet $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId); $worksheetFeed = $spreadsheet->getWorksheets(); # get worksheet $worksheet = $worksheetFeed->getByTitle($worksheetName); $listFeed = $worksheet->getListFeed(); # get celldata (first line = header, second line = content) $listArray = array(); $values = array(); foreach ($listFeed->getEntries() as $entry) { $values = $entry->getValues(); break; # break, so we just the first line } $time = time(); $data = new Data(); $data->widget_id = $widget['id']; $data->data_object = json_encode($values); $data->date = date("Y-m-d", $time); $data->timestamp = date('Y-m-d H:i:s', $time); $data->save(); $widget->widget_ready = true; $widget->save(); break; # / case 'google-spreadsheet-line-cell' # / case 'google-spreadsheet-line-cell' case 'google-spreadsheet-line-column': Log::info("google-spreadsheet-line-column - widget_id - " . $widget['id']); $widget_source = json_decode($widget['widget_source'], true); $spreadsheetId = $widget_source['googleSpreadsheetId']; $worksheetName = $widget_source['googleWorksheetName']; # setup Google stuff $client = GooglespreadsheetHelper::setGoogleClient(); $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user); # init service $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); # get spreadsheet $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId); $worksheetFeed = $spreadsheet->getWorksheets(); # get worksheet $worksheet = $worksheetFeed->getByTitle($worksheetName); # get feeddata (first line = header) $listFeed = $worksheet->getListFeed(); foreach ($listFeed->getEntries() as $entry) { $array = $entry->getValues(); $date = array_values($array)[0]; $value = array_values($array)[1]; # format date (from almost everything to Y-m-d) $time = strtotime(trim(str_replace('.', '-', $date), '-')); # have we saved data for this date? $db_data = Data::where('widget_id', '=', $widget['id'])->where('date', '=', date("Y-m-d", $time)); if ($db_data->count() == 0) { # nope, save it $data = new Data(); $data->widget_id = $widget['id']; $data->data_object = json_encode(array("value" => $value)); $data->date = date("Y-m-d", $time); $data->timestamp = date('Y-m-d H:i:s', $time); $data->save(); } else { # yes, update it $db_data->update(['data_object' => json_encode(array("value" => $value))]); } } $widget->widget_ready = true; $widget->save(); break; # / case 'google-spreadsheet-line-column' # / case 'google-spreadsheet-line-column' case 'google-spreadsheet-text-cell': Log::info("google-spreadsheet-text-cell - widget_id - " . $widget['id']); $widget_source = json_decode($widget['widget_source'], true); $spreadsheetId = $widget_source['googleSpreadsheetId']; $worksheetName = $widget_source['googleWorksheetName']; # setup Google stuff $client = GooglespreadsheetHelper::setGoogleClient(); $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user); # init service $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); # get spreadsheet $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId); $worksheetFeed = $spreadsheet->getWorksheets(); # get worksheet $worksheet = $worksheetFeed->getByTitle($worksheetName); # get feeddata (first line = header) $listFeed = $worksheet->getListFeed(); foreach ($listFeed->getEntries() as $entry) { $array = $entry->getValues(); $value = array_values($array)[0]; $time = time(); # have we saved data for this widget? $db_data = Data::where('widget_id', '=', $widget['id']); if ($db_data->count() == 0) { # nope, save it $data = new Data(); $data->widget_id = $widget['id']; $data->data_object = json_encode(array("value" => $value)); $data->date = date("Y-m-d", $time); $data->timestamp = date('Y-m-d H:i:s', $time); $data->save(); } else { # yes, update it $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time)]); } break; # just the first line } $widget->widget_ready = true; $widget->save(); break; # / case 'google-spreadsheet-text-cell' # / case 'google-spreadsheet-text-cell' case 'google-spreadsheet-text-column': Log::info("google-spreadsheet-text-column - widget_id - " . $widget['id']); $widget_source = json_decode($widget['widget_source'], true); $spreadsheetId = $widget_source['googleSpreadsheetId']; $worksheetName = $widget_source['googleWorksheetName']; # setup Google stuff $client = GooglespreadsheetHelper::setGoogleClient(); $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user); # init service $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); # get spreadsheet $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId); $worksheetFeed = $spreadsheet->getWorksheets(); # get worksheet $worksheet = $worksheetFeed->getByTitle($worksheetName); # get feeddata (first line = header) $listFeed = $worksheet->getListFeed(); foreach ($listFeed->getEntries() as $entry) { $array = $entry->getValues(); $value = array_values($array)[0]; $time = time(); # have we saved data for this widget? $db_data = Data::where('widget_id', '=', $widget['id']); if ($db_data->count() == 0) { # nope, save it $data = new Data(); $data->widget_id = $widget['id']; $data->data_object = json_encode(array("value" => $value)); $data->date = date("Y-m-d", $time); $data->timestamp = date('Y-m-d H:i:s', $time); $data->save(); } else { # yes, update it $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time)]); } } $widget->widget_ready = true; $widget->save(); break; # / case 'google-spreadsheet-text-column' # / case 'google-spreadsheet-text-column' case 'google-spreadsheet-text-column-random': Log::info("google-spreadsheet-text-column-random - widget_id - " . $widget['id']); $widget_source = json_decode($widget['widget_source'], true); $spreadsheetId = $widget_source['googleSpreadsheetId']; $worksheetName = $widget_source['googleWorksheetName']; # setup Google stuff $client = GooglespreadsheetHelper::setGoogleClient(); $access_token = GooglespreadsheetHelper::getGoogleAccessToken($client, $user); # init service $serviceRequest = new DefaultServiceRequest($access_token); ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); # get spreadsheet $spreadsheet = $spreadsheetService->getSpreadsheetById($spreadsheetId); $worksheetFeed = $spreadsheet->getWorksheets(); # get worksheet $worksheet = $worksheetFeed->getByTitle($worksheetName); # get feeddata (first line = header) $listFeed = $worksheet->getListFeed(); $key = 0; foreach ($listFeed->getEntries() as $entry) { $array = $entry->getValues(); $value = array_values($array)[0]; $time = time(); # have we saved data for this widget? $db_data = Data::where('widget_id', '=', $widget['id'])->where('data_key', '=', $key); if ($db_data->count() == 0) { # nope, save it $data = new Data(); $data->widget_id = $widget['id']; $data->data_key = $key; $data->data_object = json_encode(array("value" => $value)); $data->date = date("Y-m-d", $time); $data->timestamp = date('Y-m-d H:i:s', $time); $data->save(); $key++; } else { # yes, update it $db_data->update(['data_object' => json_encode(array("value" => $value)), 'date' => date("Y-m-d", $time), 'timestamp' => date('Y-m-d H:i:s', $time), 'data_key' => $key]); } } $widget->widget_ready = true; $widget->save(); break; # / case 'google-spreadsheet-text-column-random' } # / switch ($widget_type) }
} } } $contenu .= '<a class="button" href="?action=game">Retour à l\'accueil</a>'; } else { if ($action == 'generate') { for ($i = 0; $i < 100; $i++) { $matrixCode = Matrix::generateMatrixRandom($listeCartes); $code = Matrix::generateCode(); $code = Matrix::generateCode(); while ($dataFile[$code]) { $code = Matrix::generateCode(); } $dataFile[$code] = $code . ':' . $matrixCode; } Data::save($dataFile); echo 'Sauvegardé dans games.txt'; } } } } } } } } } } } } } }
/** * [saveDataAction description] * @return [type] [description] */ public function saveDataAction() { Input::flash(); $data = Input::all(); $rules = array('dataname' => array('min:3', 'required')); // Build the custom messages array. $messages = array('dataname.min' => 'กรุณาระบุชื่อข้อมูลอย่างนี้อย :min ตัวอักษร.', 'dataname.required' => 'กรุณาระบุชื่อข้อมูล'); // Create a new validator instance. $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { $data_content = trim($data['dataname']); $data_tablename = trim($data['table_name']); $data_obj = new Data(); $rs_check = $data_obj->checkData($data_content); if ($rs_check) { $data_obj->data_name = $data_content; $data_obj->table_name = $data_tablename; $data_obj->save(); return Redirect::to('data')->with('success', 'บันทึกสำเร็จ'); } else { return Redirect::to('data-add')->with('warning', 'มีชื่อข้อมูลอยู่ในระบบแล้ว'); } } else { // $errors = $validator->messages(); return Redirect::to('data-add')->withErrors($validator); } }
function propise_action() { global $_, $conf; switch ($_['action']) { case 'propise_save_sensor': Action::write(function ($_, &$response) { require_once 'Sensor.class.php'; $sensor = new Sensor(); if (empty($_['labelSensor'])) { throw new Exception("Le nom est obligatoire"); } if (empty($_['uidSensor'])) { throw new Exception("L'UID est obligatoire"); } $sensor = !empty($_['id']) ? $sensor->getById($_['id']) : new Sensor(); $sensor->label = $_['labelSensor']; $sensor->location = $_['locationSensor']; $sensor->uid = $_['uidSensor']; $sensor->save(); //Reference device for other plugins $device = new Device(); $device->label = $sensor->label; $device->plugin = 'propise'; $device->type = Device::CAPTOR; $device->location = $sensor->location; $device->icon = 'fa-heartbeat'; $device->setValue('humidity', 0); $device->setValue('temperature', 0); $device->setValue('light', 0); $device->setValue('mouvment', 0); $device->setValue('sound', 0); $device->state = 1; $device->uid = $sensor->id; $device->save(); $response['message'] = 'Sonde enregistrée avec succès'; }, array('propise' => 'c')); break; case 'propise_delete_sensor': Action::write(function ($_, $response) { require_once 'Sensor.class.php'; $sensor = new Sensor(); $sensor->delete(array('id' => $_['id'])); }, array('propise' => 'd')); break; case 'propise_add_data': /*for($i=0;$i<60;$i++){ $_ = array( 'uid'=>'sensor-2', 'humidity'=>rand(0,100), 'temperature'=>rand(0,100), 'light'=>rand(0,100), 'mouvment'=>rand(0,1), 'sound'=>rand(0,1) );*/ require_once 'Sensor.class.php'; require_once 'Data.class.php'; $sensor = new Sensor(); $data = new Data(); $sensor = $sensor->load(array('uid' => $_['uid'])); if ($sensor == null || $sensor->id == 0) { return; } $data->time = time(); //$data->time = strtotime(date('Ymd H:').$i.':00'); $data->humidity = $_['humidity']; $data->temperature = $_['temperature']; $data->light = $_['light']; $data->mouvment = $_['mouvment']; $data->sound = $_['sound']; $data->sensor = $sensor->id; $data->save(); //} break; case 'propise_load_widget': require_once dirname(__FILE__) . '/../dashboard/Widget.class.php'; Action::write(function ($_, &$response) { $widget = new Widget(); $widget = $widget->getById($_['id']); $parameters = $widget->data(); if (empty($parameters['sensor'])) { $content = 'Choisissez une localisation en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget'; } else { global $conf; require_once 'Data.class.php'; require_once 'Sensor.class.php'; $sensor = new Sensor(); $data = new Data(); $sensor = $sensor->getById($parameters['sensor']); $datas = $data->loadAll(array('sensor' => $sensor->id), 'time DESC', 1); $response['title'] = 'Sonde ' . $sensor->label . ' (' . $sensor->uid . ')'; $content = ' <!-- CSS --> <style> .propise_view{ background:#36B3E1; color:#ffffff; margin:0px; padding:10px; width:100%; list-style-type:none; transition:all 0.2s ease-in-out; box-sizing: border-box; } .propise_menu{ margin:0; } .propise_menu li{ cursor: pointer; display: inline-block; font-size: 20px; height: 25px; margin-top: 3px; padding: 5px; text-align: center; transition: all 0.2s ease-in-out 0s; width: 30px; border-top:4px solid #cecece; } color: #cecece; .propise_menu li:hover{ background:#222222; color:#ffffff; } .propise_view li{ display:none; font-family: "Open Sans Light",sans-serif; text-align:center; padding:15px 0; font-weight:300; font-size:60px; } .propise_view li.propise_temperature{ display:block; } .propise_menu li.propise_temperature{ border-color:#36B3E1; } .propise_menu li.propise_humidity{ border-color:#50597B; } .propise_menu li.propise_light{ border-color:#EF4D66; } .propise_menu li.propise_mouvment{ border-color:#FFBF4C; } .propise_menu li.propise_sound{ border-color:#84C400; } .propise_menu li.propise_stats{ border-color:#C1004F; } </style> <!-- HTML --> '; $content .= '<div class="propise_widget"><ul class="propise_view">'; $content .= '<li class="propise_temperature"><i class="fa fa-fire"></i> ' . round($datas[0]->temperature, 1) . '°</li>'; $content .= '<li class="propise_humidity"><i class="fa fa-tint"></i> ' . round($datas[0]->humidity, 1) . '%</li>'; $content .= '<li class="propise_light"><i class="fa fa-sun-o"></i> ' . round($datas[0]->light, 1) . '%</li>'; $content .= '<li class="propise_mouvment"><i class="fa fa-eye' . ($datas[0]->mouvment == 1 ? '' : '-slash') . '"></i></li>'; $content .= '<li class="propise_sound"><i class="fa fa-bell' . ($datas[0]->sound == 1 ? '' : '-slash') . '"></i></li>'; $content .= '</ul><ul class="propise_menu">'; $content .= '<li class="propise_temperature" onclick="propise_menu(this)" data-view="temperature"><i class="fa fa-fire"></i></li>'; $content .= '<li class="propise_humidity" onclick="propise_menu(this)" data-view="humidity"><i class="fa fa-tint"></i></li>'; $content .= '<li class="propise_light" onclick="propise_menu(this)" data-view="light"><i class="fa fa-sun-o"></i></li>'; $content .= '<li class="propise_mouvment" onclick="propise_menu(this)" data-view="mouvment"><i class="fa fa-eye"></i></li>'; $content .= '<li class="propise_sound" onclick="propise_menu(this)" data-view="sound"><i class="fa fa-bell"></i></li>'; $content .= '<li class="propise_stats" onclick="window.open(\'index.php?module=propise\')"><i class="fa fa-line-chart"></i></li>'; $content .= '</ul>'; $content .= '</div>'; $content .= ' <!-- JS --> <script type="text/javascript"> function propise_menu(element){ var container = $(element).closest(".propise_widget"); $(".propise_view li",container).hide(); $(".propise_view").css("background-color",$(element).css("border-top-color")); $(".propise_view li.propise_"+$(element).data("view"),container).fadeIn(); }; </script> '; } $response['content'] = $content; }); break; case 'propise_edit_widget': require_once dirname(__FILE__) . '/../dashboard/Widget.class.php'; require_once dirname(__FILE__) . '/Sensor.class.php'; $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $sensor = new Sensor(); $sensors = $sensor->populate(); $content = '<h3>Choix de la sonde</h3>'; if (count($sensors) == 0) { $content = 'Aucune sonde enregistrée,<a href="setting.php?section=propise">enregistrer une sonde<a>'; } else { $content .= '<select id="sensor">'; foreach ($sensors as $sensor) { $content .= '<option ' . ($sensor->id == $data['sensor'] ? 'selected="selected"' : '') . ' value="' . $sensor->id . '">' . $sensor->label . ' (' . $sensor->uid . ')</option>'; } $content .= '</select>'; } echo $content; break; case 'propise_save_widget': require_once dirname(__FILE__) . '/../dashboard/Widget.class.php'; $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['sensor'] = $_['sensor']; $widget->data($data); $widget->save(); echo $content; break; } }
public function postUpload($unique) { //disable php timeout and db query log DB::disableQueryLog(); set_time_limit(0); $compare = Compare::where('unique', $unique)->first(); if (!$compare || !Session::get('owner')) { return Redirect::to('compare/notfound'); } $file = Input::file('csv'); $data_set = array(); $config = new LexerConfig(); $config->setDelimiter("\t"); $lexer = new Lexer($config); //setup the interpreter $interpreter = new Interpreter(); $interpreter->unstrict(); $interpreter->addObserver(function (array $row) use(&$data_set) { $data_set[] = $row[0]; }); //parse it! $lexer->parse($file, $interpreter); //loop through the data foreach ($data_set as $data_item) { $data = new Data(); $data->compare_id = $unique; $data->owner_id = Session::get('owner'); $data->hash = md5($data_item); $data->save(); } return Redirect::back(); }