public function edit()
 {
     $user = User::findOrFail(Auth::user()->id);
     $entity = Entity::where('user_id', Auth::user()->id)->firstOrFail();
     $about = About::where('user_id', Auth::user()->id)->firstOrFail();
     $contact = Contact::where('user_id', Auth::user()->id)->firstOrFail();
     $home = Home::where('user_id', Auth::user()->id)->firstOrFail();
     $quote = Quote::where('user_id', Auth::user()->id)->get();
     $quote_count = $quote->count();
     $skill = Skill::where('user_id', Auth::user()->id)->get();
     $skill_count = $skill->count();
     $skill_slider = SkillSlider::where('user_id', Auth::user()->id)->get();
     $skill_slider_count = $skill_slider->count();
     $portfolio_piece = PortfolioPiece::where('user_id', Auth::user()->id)->get();
     $portfolio_piece_count = $portfolio_piece->count();
     return view('edit')->with('user', $user)->with('home', $home)->with('entity', $entity)->with('contact', $contact)->with('about', $about)->with('skill', $skill)->with('skill_count', $skill_count)->with('quote', $quote)->with('quote_count', $quote_count)->with('skill_slider', $skill_slider)->with('skill_slider_count', $skill_slider_count)->with('portfolio_piece', $portfolio_piece)->with('portfolio_piece_count', $portfolio_piece_count);
 }
Esempio n. 2
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $entityName = $this->request->input('entityName');
     $entityWebsite = $this->request->input('entityWebsite');
     $found = Entity::where('title', $entityName)->get();
     $num = count($found);
     if ($num >= 1) {
         $resp['code'] = 0;
         $resp['message'] = "We're sorry but that entity has already been submitted.";
     } elseif ($num === 0) {
         $new_entity = new Entity();
         $new_entity->title = $entityName;
         $new_entity->website = $entityWebsite;
         $new_entity->save();
         if (count(Entity::where('title', $entityName)->get() === 1)) {
             $resp['code'] = 1;
             $resp['message'] = "Enity successfully submitted.";
         }
     }
     return $resp;
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::transaction(function () {
         DataValue::where('fk_ent_id', 341)->update(array('fk_ent_id' => 355));
         Entity::where('id', 341)->delete();
         $charts = Chart::all();
         foreach ($charts as $chart) {
             $config = json_decode($chart->config);
             $countries = $config->{'selected-countries'};
             if (empty($countries)) {
                 continue;
             }
             foreach ($countries as $country) {
                 if ($country->id == "341") {
                     echo "Updating chart config for " . $chart->id . "\n";
                     $country->id = "355";
                     $country->name = "World";
                 }
             }
             $chart->config = json_encode($config);
             $chart->save();
         }
     });
 }
 public function updateSocialMedia()
 {
     $user = User::find(Auth::user()->id);
     $entity = Entity::where('user_id', Auth::user()->id)->firstOrFail();
     if (isset($user) && $entity != NULL) {
         if (Input::get('facebook') != '') {
             $entity->facebook = Input::get('facebook');
         }
         if (Input::get('instagram') != '') {
             $entity->instagram = Input::get('instagram');
         }
         if (Input::get('linkedin') != '') {
             $entity->linkedin = Input::get('linkedin');
         }
         if (Input::get('twitter') != '') {
             $entity->twitter = Input::get('twitter');
         }
         if (Input::get('github') != '') {
             $entity->github = Input::get('github');
         }
         if (Input::get('behance') != '') {
             $entity->behance = Input::get('behance');
         }
         if (Input::get('dribble') != '') {
             $entity->dribble = Input::get('dribble');
         }
         if (Input::get('extra_1') != '') {
             $entity->extra_1 = Input::get('extra_1');
         }
         if (Input::get('extra_2') != '') {
             $entity->extra_1 = Input::get('extra_2');
         }
         $entity->save();
         return redirect('home')->with('status', 'success');
     } else {
         return 'An error has occured';
     }
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     //set_time_limit( 600 );
     //ini_set('memory_limit', '256M');
     //bump up limits
     set_time_limit(600);
     ini_set('memory_limit', '256M');
     return;
     //will we be checking entities
     $entityCheck = $this->validate_entities == 'on' ? false : true;
     //create new file
     $inputFileData = ['raw_data' => $this->data, 'fk_user_id' => $this->userId];
     $inputFile = InputFile::create($inputFileData);
     $inputFileDataId = $inputFile->id;
     $multivariantDataset = $this->multivariant_dataset;
     $variables = $this->variables;
     if (!empty($variables)) {
         $entityData = [];
         //creating new datasource, if there is some
         $sourceName = $this->source_name;
         if (!empty($sourceName)) {
             $datasourceData = ['name' => $this->source_name, 'link' => $this->source_link, 'description' => $this->source_description];
             $datasource = Datasource::create($datasourceData);
         } else {
             //fake datasoure
             $datasource = new \stdClass();
             $datasource->id = null;
         }
         //create new dataset or pick existing one
         $datasetName = $this->new_dataset_name;
         $datasetData = ['name' => $datasetName, 'fk_dst_cat_id' => $this->category_id, 'fk_dst_subcat_id' => $this->subcategory_id, 'description' => $this->new_dataset_description, 'fk_dsr_id' => $datasource->id];
         $dataset = Dataset::create($datasetData);
         $datasetId = $dataset->id;
         //process possible tags
         $tagsInput = $this->new_dataset_tags;
         if (!empty($tagsInput)) {
             $tagsArr = explode(',', $tagsInput);
             foreach ($tagsArr as $tag) {
                 $tag = DatasetTag::create(['name' => $tag]);
                 $tagId = $tag->id;
                 $datasetTagLink = LinkDatasetsTags::create(['fk_dst_id' => $datasetId, 'fk_dst_tags_id' => $tagId]);
             }
         }
         //store inserted variables, for case of rolling back
         $inserted_variables = array();
         foreach ($variables as $variableJsonString) {
             //convert back single out to actual single quote
             //$variableJsonString = str_replace( "'", "‘", $variableJsonString );
             //setting json_decode second param to false, to try to save memory
             $variableObj = json_decode($variableJsonString, false);
             $variableData = ['name' => $variableObj->name, 'fk_var_type_id' => $this->variable_type, 'fk_dst_id' => $datasetId, 'unit' => $variableObj->unit, 'description' => $variableObj->description, 'fk_dsr_id' => $datasource->id];
             //update of existing variable or new variable
             if (!isset($variableObj->id)) {
                 //new variable
                 $variable = Variable::create($variableData);
             } else {
                 //update variable
                 $variable = Variable::find($variableObj->id);
                 $variable->fill($variableData);
                 $variable->save();
             }
             $variableId = $variable->id;
             $inserted_variables[] = $variable;
             $variableValues = $variableObj->values;
             foreach ($variableValues as $countryValue) {
                 $entityData = ['name' => $countryValue->key, 'fk_ent_t_id' => 5, 'validated' => 0];
                 if ($entityCheck) {
                     //entity validation (only if not multivariant dataset)
                     //find corresponding iso code
                     $entityIsoName = EntityIsoName::match($entityData['name'])->first();
                     if (!$entityIsoName) {
                         //!haven't found corresponding country, throw an error!
                         //rollback everything first
                         foreach ($inserted_variables as $inserted_var) {
                             $inserted_var->data()->delete();
                             $inserted_var->delete();
                         }
                         //is new dataset
                         if ($this->new_dataset === '1') {
                             $dataset = Dataset::find($datasetId);
                             //delete itself
                             $dataset->delete();
                         }
                         \Log::error('Error non-existing entity in dataset.');
                         \Log::error($entityData['name']);
                         return redirect()->route('import')->with('message', 'Error non-existing entity in dataset.')->with('message-class', 'error');
                     }
                     //enter standardized info
                     $entityData['name'] = $entityIsoName->name;
                     $entityData['code'] = $entityIsoName->code;
                     $entityData['validated'] = 1;
                 }
                 //find try finding entity in db
                 if (isset($entityIsoName)) {
                     $entity = Entity::where('code', $entityIsoName->code)->first();
                 } else {
                     //not standardized data
                     $entity = Entity::where('code', $entityData['name'])->orWhere('name', $entityData['name'])->first();
                 }
                 if (!$entity) {
                     //entity haven't found in database, so insert it
                     $entity = Entity::create($entityData);
                 }
                 //check to override validation if stored in db not validated and now is validate
                 if ($entity->validated == 0 && $entityData['validated'] === 1) {
                     $entity->validated = 1;
                     $entity->save();
                 }
                 $entityId = $entity->id;
                 $countryValues = $countryValue->values;
                 //prepare vars for mass insert
                 $times = [];
                 $values = [];
                 //TODO - get latest time for base timeId
                 $lastTime = Time::orderBy('id', 'desc')->first();
                 $timeId = !empty($lastTime) ? $lastTime->id : 0;
                 foreach ($countryValues as $value) {
                     if ($this->hasValue($value->x) && $this->hasValue($value->y)) {
                         $timeId++;
                         //create time
                         $timeObj = $value->x;
                         $timeValue = ['startDate' => isset($timeObj->sd) ? $timeObj->sd : "", 'endDate' => isset($timeObj->ed) ? $timeObj->ed : "", 'date' => isset($timeObj->d) ? $timeObj->d : "", 'label' => isset($timeObj->l) ? $timeObj->l : ""];
                         //convert timedomain
                         $fk_ttype_id = 1;
                         if (!empty($timeObj->td)) {
                             $ttQuery = TimeType::query();
                             $fk_ttype_id = $ttQuery->whereRaw('LOWER(`name`) like ?', [$timeObj->td])->first()->id;
                         }
                         $timeValue['fk_ttype_id'] = $fk_ttype_id;
                         //using mass insert instead
                         //$time = Time::create( $timeValue );
                         //$timeId = $time->id;
                         $times[] = $timeValue;
                         //create value
                         $dataValueData = ['value' => $value->y, 'fk_time_id' => $timeId, 'fk_input_files_id' => $inputFileDataId, 'fk_var_id' => $variableId, 'fk_ent_id' => $entityId, 'fk_dsr_id' => $datasource->id];
                         //using mass insert instead
                         //$dataValue = DataValue::create( $dataValueData );
                         $values[] = $dataValueData;
                     }
                 }
                 //mass insertion
                 Time::insert($times);
                 DataValue::insert($values);
             }
         }
     }
 }
 public function entity(Request $request)
 {
     try {
         $name = $request->get('name');
         $entityCheck = $request->has('entityCheck') ? $request->get('entityCheck') : false;
         $inputFileDataId = $request->has('inputFileId') ? $request->get('inputFileId') : '';
         $datasourceId = $request->has('datasourceId') ? $request->get('datasourceId') : '';
         $variableId = $request->has('variableId') ? $request->get('variableId') : '';
         $entityData = ['name' => $name, 'fk_ent_t_id' => 5, 'validated' => 0];
         if ($entityCheck) {
             //entity validation (only if not multivariant dataset)
             //find corresponding iso code
             $entityIsoName = EntityIsoName::match($entityData['name'])->first();
             if (!$entityIsoName) {
                 return redirect()->route('import')->with('message', 'Error non-existing entity in dataset.')->with('message-class', 'error');
             }
             //enter standardized info
             $entityData['name'] = $entityIsoName->name;
             $entityData['code'] = $entityIsoName->code;
             $entityData['validated'] = 1;
         }
         //find try finding entity in db
         if (isset($entityIsoName)) {
             $entity = Entity::where('code', $entityIsoName->code)->first();
         } else {
             //not standardized data
             $entity = Entity::where('code', $entityData['name'])->orWhere('name', $entityData['name'])->first();
         }
         if (!$entity) {
             //entity haven't found in database, so insert it
             $entity = Entity::create($entityData);
         }
         //check to override validation if stored in db not validated and now is validate
         if ($entity->validated == 0 && $entityData['validated'] === 1) {
             $entity->validated = 1;
             $entity->save();
         }
         $entityId = $entity->id;
         $countryValues = $request->get("values");
         //$countryValue->values;
         //prepare vars for mass insert
         $times = [];
         $values = [];
         //TODO - get latest time for base timeId
         $lastTime = Time::orderBy('id', 'desc')->first();
         $timeId = !empty($lastTime) ? $lastTime->id : 0;
         foreach ($countryValues as $value) {
             if (isset($value['x']) && isset($value['y']) && $this->hasValue($value['x']) && $this->hasValue($value['y'])) {
                 $timeId++;
                 //create time
                 $timeObj = $value['x'];
                 $timeValue = ['startDate' => isset($timeObj['sd']) ? $timeObj['sd'] : "", 'endDate' => isset($timeObj['ed']) ? $timeObj['ed'] : "", 'date' => isset($timeObj['d']) ? $timeObj['d'] : "", 'label' => isset($timeObj['l']) ? $timeObj['l'] : ""];
                 //convert timedomain
                 $fk_ttype_id = 1;
                 if (!empty($timeObj['td'])) {
                     $ttQuery = TimeType::query();
                     $fk_ttype_id = $ttQuery->whereRaw('LOWER(`name`) like ?', [$timeObj['td']])->first()->id;
                 }
                 $timeValue['fk_ttype_id'] = $fk_ttype_id;
                 //using mass insert instead
                 //$time = Time::create( $timeValue );
                 //$timeId = $time->id;
                 $times[] = $timeValue;
                 //create value
                 $dataValueData = ['value' => $value['y'], 'fk_time_id' => $timeId, 'fk_input_files_id' => $inputFileDataId, 'fk_var_id' => $variableId, 'fk_ent_id' => $entityId, 'fk_dsr_id' => $datasourceId];
                 //using mass insert instead
                 //$dataValue = DataValue::create( $dataValueData );
                 $values[] = $dataValueData;
             }
         }
         //mass insertion
         Time::insert($times);
         DataValue::insert($values);
         return ['success' => true];
     } catch (Exception $e) {
         return ['success' => false];
     }
 }