/**
  * Update the specified resource in storage.
  *
  * @param  License $license
  * @return Response
  */
 public function update(License $license, Request $request)
 {
     $input = array_except($request->all(), ['_method', '_token']);
     $license->update($input);
     Cache::flush();
     return redirect()->route('licenses.show', $license->id)->with('message', 'License updated.')->with('message-class', 'success');
 }
 public function edit($id)
 {
     $pl_data = \App\PerangkatLunak::find($id);
     $medias = \App\Media::lists('nama_media', 'id');
     $licenses = \App\License::lists('nama_license', 'id');
     $jenises = \App\Jenis::lists('nama_jenis', 'id');
     $companies = \App\Company::lists('nama_company', 'id');
     return view('perangkat_lunak.edit', ['pl_data' => $pl_data, 'medias' => $medias, 'licenses' => $licenses, 'jenises' => $jenises, 'companies' => $companies]);
 }
 public function remove($id)
 {
     $license = License::findOrFail($id);
     $date = new \DateTime();
     //this returns the current date time
     $license->user_id = 0;
     $license->save();
     if ($license->user_id != 0) {
         DB::table('users')->where('id', $license->user_id)->update(array('status' => 'INACTIVE', 'inactive_date' => $date));
     }
     \Session::flash('message', 'You have successfully remove user for this License');
     $company = Company::findOrFail($license->company_id);
     $licenses = License::whereRaw('company_id like ? order by id', array($license->company_id))->paginate(15)->appends(Input::except('page'));
     return view('licenses.list', compact('company', 'licenses'));
 }
 public function dimensions(Request $request)
 {
     set_time_limit(10);
     ini_set('memory_limit', '256M');
     //check we have everything we should have
     if (!Input::has('dimensions')) {
         //we don't have necessary info, bail out
         return ['success' => false];
     }
     //filtering by entities?
     $selectedCountriesIds = Input::get("selectedCountries");
     $selectedCountriesIdsString = !empty($selectedCountriesIds) && count($selectedCountriesIds) > 0 ? implode(",", $selectedCountriesIds) : "";
     //filtering by time?
     $chartTime = Input::get("chartTime");
     if (Input::has('chartId')) {
         //caching - construct key with selected countries as well
         $key = 'chart-dimensions-' . Input::get('chartId') . '-countries-' . $selectedCountriesIdsString;
         //if there's something in cache and not exporting
         if (Cache::has($key) && !Input::has('export') && (Input::has('cache') && Input::get('cache') === "true")) {
             //return Cache::get( $key );
         }
     }
     $data = array();
     //extra array for storing values for export
     $times = array();
     $datasourcesIdsArr = array();
     $dimensionsInput = Input::get('dimensions');
     $dimensions = json_decode($dimensionsInput);
     //isn't it just empty object
     if (empty($dimensions)) {
         return ['success' => false];
     }
     $chartType = Input::get('chartType');
     //there's special setting for linechart
     $isLineChart = $chartType == "1" || $chartType == "4" || $chartType == "5" || $chartType == "6" ? true : false;
     //find out how many variables we have
     $groupByEntity = Input::get('groupByVariables') == 'false' ? true : false;
     //special case for linechart with multiple variables
     $multiVariantByEntity = false;
     if ($groupByEntity && $isLineChart && count($dimensions) > 1) {
         //make sure they're all
         foreach ($dimensions as $dimension) {
             if ($dimension->property !== "y") {
                 $multiVariantByEntity = false;
                 break;
             }
             $multiVariantByEntity = true;
         }
     }
     $timeType = '';
     if ($groupByEntity) {
         $entities = array();
         $dataByEntity = array();
         $dataByEntityTime = array();
     } else {
         $variables = array();
         $dataByVariable = array();
         $dataByVariableTime = array();
     }
     /**
      * 1) get data into variable
      **/
     //store the longest variable, will be used as main one
     $dimensionsByKey = [];
     $minDataLength = false;
     $mainDimId = false;
     $otherDimIds = [];
     //for edge cases for legend, we need to store entityname
     $entityName = "";
     //categorical data
     $categoricalData = array();
     $categoricalData["color"] = array();
     $categoricalData["shape"] = array();
     $categoricalDimensions = array();
     foreach ($dimensions as $dimension) {
         $id = $dimension->variableId;
         //use query builder instead of eloquent
         $variableQuery = DB::table('data_values')->select('data_values.*', 'times.*', 'entities.name as name', 'variables.name as variable_name')->join('entities', 'data_values.fk_ent_id', '=', 'entities.id')->join('variables', 'data_values.fk_var_id', '=', 'variables.id')->join('times', 'data_values.fk_time_id', '=', 'times.id')->where('data_values.fk_var_id', $id);
         //are we filtering based on entity selection?
         if (!empty($selectedCountriesIds) && count($selectedCountriesIds) > 0) {
             $variableQuery->whereIn('data_values.fk_ent_id', $selectedCountriesIds);
         }
         //are we filtering based on time selection?
         if (!empty($chartTime) && count($chartTime) > 1) {
             //exclude categorical properties from time filtering
             if ($dimension->property !== "color" && $dimension->property !== "shape") {
                 $minTime = $chartTime[0];
                 $maxTime = $chartTime[1];
                 $variableQuery->where('times.startDate', '>=', $minTime);
                 //$variableQuery->where( 'times.date', '>=', $minTime );
                 $variableQuery->where('times.endDate', '<=', $maxTime);
                 //$variableQuery->where( 'times.date', '<=', $maxTime );
             }
         }
         $variableData = $variableQuery->get();
         //insert data into existing variable
         $dimension->data = $variableData;
         //is shortes variable? cannot be color/shape variable
         $dataLen = count($variableData);
         if (($dataLen > $minDataLength || !$minDataLength) && ($dimension->property != "color" && $dimension->property != "shape")) {
             $minDataLength = $dataLen;
             $mainDimId = $id;
         }
         //is categorical data
         if ($dimension->property === "color" || $dimension->property === "shape") {
             //store it for later processing
             $categoricalDimensions[] = $dimension;
         }
     }
     /**
      * 2) assign data to entities
      **/
     foreach ($dimensions as $dimension) {
         $id = $dimension->variableId;
         $property = $dimension->property;
         $variableData = $dimension->data;
         //store in array for step 3
         $dimensionsByKey[$id] = $dimension;
         if ($id != $mainDimId) {
             $otherDimIds[] = $id;
         }
         //selectedCountries
         if ($groupByEntity) {
             //group variable data by entities
             //$i = 0;
             $oldEntityId = -1;
             foreach ($variableData as $datum) {
                 //$entityId = $datum->fk_ent_id;
                 $entityId = !$multiVariantByEntity ? $datum->fk_ent_id : $datum->fk_ent_id . "-" . $datum->fk_var_id;
                 //check if new entity and we need to reset cycle
                 if ($oldEntityId != $entityId) {
                     //$i = 0;
                 }
                 $oldEntityId = $entityId;
                 //do we have already object for that entity
                 if (!array_key_exists($entityId, $dataByEntity)) {
                     $key = !$multiVariantByEntity ? $datum->name : $datum->name . " - " . $datum->variable_name;
                     $dataByEntity[$entityId] = array("id" => $entityId, "key" => $key, "entity" => $datum->name, "values" => []);
                 }
                 //is it first property being saved for given property
                 if (!array_key_exists($property, $dataByEntity[$entityId]["values"])) {
                     $dataByEntity[$entityId]["values"][$property] = [];
                 }
                 //store value
                 //AMMEND HERE - store as startYear-endYear?
                 $timeId = $datum->fk_ttype_id !== "6" ? floatval($datum->date) : floatval($datum->startDate) . "-" . floatval($datum->endDate);
                 $dataByEntity[$entityId]["values"][$property][$timeId] = $property != "color" && $property != "shape" && $property != "map" ? floatval($datum->value) : $datum->value;
                 //need to store dimension variablename, dimensions are returned
                 if (!array_key_exists("variableName", $dimension)) {
                     $dimension->variableName = $datum->variable_name;
                 }
                 //if is linechart, store time into x axis
                 /*if( $isLineChart ) {
                 			$dataByEntity[ $entityId ][ "values" ][ $i ][ "x" ] = floatval( $datum->date );
                 		}
                 		$i++;*/
                 //store time type if not stored
                 if (empty($timeType)) {
                     $timeType = TimeType::find($datum->fk_ttype_id)->name;
                 }
                 //store for the need of export
                 if (!array_key_exists($entityId, $dataByEntityTime)) {
                     $dataByEntityTime[$entityId] = [];
                     $entities[$entityId] = $datum->name;
                 }
                 $dataByEntityTime[$entityId][$datum->label] = $datum->value;
                 //AMMEND HERE - store simply as a string?
                 $times[floatval($datum->date)] = true;
                 $datasourcesIdsArr[$datum->fk_dsr_id] = true;
             }
         } else {
             //multivariables
             //get variable names
             $variable = Variable::find($dimension->variableId);
             $key = !empty($variable) && isset($variable->name) ? $variable->name : "";
             //could have display name
             if (!empty($dimension) && !empty($dimension->displayName)) {
                 $key = $dimension->displayName;
             }
             $dataByVariable["id-" . $id] = array("id" => $id, "key" => $key, "values" => []);
             //store variable name to dimension info (useful for stack bar chart)
             $dimensionsByKey[$id]->variableName = $key;
             foreach ($variableData as $datum) {
                 //store entity name for legend purposes
                 $entityName = $datum->name;
                 $dataByVariable["id-" . $id]["values"][] = array("x" => floatval($datum->date), "y" => floatval($datum->value));
                 $times[$datum->label] = true;
                 $datasourcesIdsArr[$datum->fk_dsr_id] = true;
                 //store time type if not stored
                 if (empty($timeType)) {
                     $timeType = TimeType::find($datum->fk_ttype_id)->name;
                 }
                 //store for the need of export
                 if (!array_key_exists($dimension->variableId, $dataByVariableTime)) {
                     $dataByVariableTime[$dimension->variableId] = [];
                     $variables[$dimension->variableId] = $datum->fk_var_id;
                 }
                 $dataByVariableTime[$dimension->variableId][$datum->label] = $datum->value;
             }
         }
     }
     /**
      * 3) prepare array for different chart types
      **/
     //$normalizedData = [];
     $mainDimension = $dimensionsByKey[$mainDimId];
     if ($groupByEntity) {
         $normalizedData = Chart::formatDataForChartType($chartType, $dataByEntity, $dimensionsByKey, $times, false, $mainDimension, $otherDimIds);
     } else {
         //grouping by variable, for linechart, we already have what we need
         if ($chartType !== '1' && $chartType !== '2') {
             $dataByVariable = Chart::formatDataForChartType($chartType, $dataByVariableTime, $dimensionsByKey, $times, true, $mainDimension, $otherDimIds, $entityName);
         }
     }
     if ($chartType == '9999') {
         //if getting dimensions for map, don't need info bellow, just send of the data
         $data = [];
         foreach ($normalizedData as $entityData) {
             $data[] = $entityData;
         }
         $result = ['success' => true, 'data' => $data];
         //TODO - put to cache
         //store into cache - there is no cache
         /*if( !empty( $key ) ) {
         			$minutes = 60*24;
         			Cache::put( $key, $result, $minutes );
         		}*/
         return $result;
     }
     if ($groupByEntity) {
         //convert to array
         foreach ($normalizedData as $entityData) {
             //TODO better check for this?
             if ($entityData['values']) {
                 //here we add any possible categorical data
                 foreach ($categoricalDimensions as $catDimension) {
                     $entityId = $entityData['id'];
                     //is there data for specific property
                     if (array_key_exists('values', $dataByEntity[$entityId]) && array_key_exists($catDimension->property, $dataByEntity[$entityId]['values'])) {
                         //get value - http://stackoverflow.com/questions/1028668/get-first-key-in-a-possibly-associative-array
                         $value = reset($dataByEntity[$entityId]['values'][$catDimension->property]);
                         $catValue = Chart::getValueForCategory($catDimension->property, $categoricalData, $value);
                         //color is assinged to whole entity, shape is assigned to individual data entries
                         if ($catDimension->property === "color") {
                             $entityData[$catDimension->property] = $catValue;
                         } else {
                             if ($catDimension->property === "shape") {
                                 foreach ($entityData["values"] as &$entityValue) {
                                     $entityValue[$catDimension->property] = $catValue;
                                 }
                             }
                         }
                     }
                 }
                 $data[] = $entityData;
             }
         }
     } else {
         //convert to array
         foreach ($dataByVariable as $varData) {
             $data[] = $varData;
         }
     }
     /**
      *	4) fetch all the other necessary data
      **/
     //get all necessary info for datasources
     $datasources = array();
     $prevDimension = "";
     $sourcesByNameDim = array();
     foreach ($dimensions as $dimension) {
         $datasource = new \stdClass();
         //special dimension header for linechart
         $dsr = Variable::getSource($dimension->variableId)->first();
         if ($isLineChart) {
             $dimension = false;
         }
         $currDimension = !empty($dimension) && isset($dimension->name) ? $dimension->name : "undefined";
         $datasource->description = !empty($dsr) ? $this->createSourceDescription($dimension, $dsr, $currDimension === $prevDimension) : '';
         $datasource->name = !empty($dsr) && !empty($dsr->name) ? $dsr->name : '';
         $datasource->link = !empty($dsr) && !empty($dsr->name) ? $dsr->link : '';
         //make sure we don't repeat for the same name and dimension
         $nameDimKey = $currDimension . "-" . $datasource->name;
         if (!isset($sourcesByNameDim[$nameDimKey])) {
             $datasources[] = $datasource;
             $sourcesByNameDim[$nameDimKey] = true;
         }
         //store curr dimension so we don't have to repeat title for next if it's same
         $prevDimension = !empty($dimension) && isset($dimension->name) ? $dimension->name : "";
     }
     /*$datasourcesIds = array_keys( $datasourcesIdsArr );
     		$datasourcesSources = Variable::getSources( $datasourcesIds )->get();//Datasource::findMany( $datasourcesIds );
     		$datasources = array();
     
     		//format datasources info (create generated tables)
     		foreach( $datasourcesSources as $datasourceSource ) {
     			$datasource = new \stdClass();
     			$dimension = $this->findDimensionForVarId( $dimensions, $datasourceSource->var_id );
     			//special dimension header for linechart
     			if( $isLineChart ) {
     				$dimension = false;
     			}
     			$datasource->description = $this->createSourceDescription( $dimension, $datasourceSource );
     			$datasource->name = $datasourceSource->name;
     			$datasource->link = $datasourceSource->link;
     			//$datasource->description = $datasourceSource->description;
     			$datasources[] = $datasource;
     		}*/
     //process data to csv friendly format
     $timeKeys = array_keys($times);
     //sort timeKeys by time
     //AMMEND HERE - what is intervals
     usort($timeKeys, function ($a, $b) {
         if ($a == $b) {
             return 0;
         } else {
             return $a > $b ? 1 : -1;
         }
     });
     //get all the licence information
     $license = License::find(1)->first();
     if ($request->ajax()) {
         $result = ['success' => true, 'data' => $data, 'dimensions' => $dimensions, 'datasources' => $datasources, 'timeType' => $timeType, 'license' => $license];
         //store into cache - there is no cache
         if (!empty($key)) {
             $minutes = 60 * 24;
             Cache::put($key, $result, $minutes);
         }
         return $result;
     } else {
         //export is now happening in front-end
         if (Input::has('export') && Input::get('export') == 'csv') {
             //http://localhost:8888/oxford/our-world-in-data-chart-builder/public/data/dimensions?dimensions=%5B%7B%22variableId%22%3A%221%22%2C%22property%22%3A%22y%22%2C%22name%22%3A%22Y+axis%22%7D%5D
             //return $data;
             //return $this->downloadCsv( $exportData );
         } else {
             //not ajax request, nor csv export, just spit out whatever is in data
             return $data;
         }
     }
 }
 public function save()
 {
     if (Auth::check()) {
         $title = Request::input('title');
         $body = Request::input('body');
         $public = Request::input('public');
         $type = Request::input('type');
         $teams = Request::input('teams');
         $license = Request::input('license');
         $identifier_dict = Request::input('identifier');
         $anchor = Request::input('anchor');
         $entry_id = Request::input('entry_id');
         $user = Auth::user();
         if ($title !== '' && $body !== '' && $type !== '' && !empty($identifier_dict) && $anchor !== '') {
             $db_license = NULL;
             if ($public) {
                 if (isset($_ENV['AUTH_LICENSES']) && $_ENV['AUTH_LICENSES']) {
                     if (empty($license)) {
                         return json_encode(['status' => 'error', 'message' => 'Only paid users can create public annotations']);
                     }
                     $json_license = json_encode($license);
                     $db_license = License::where('license', '=', $json_license)->first();
                     if ($db_license) {
                         if ($db_license->banned_from_public) {
                             if (isset($license['is_beta']) && $license['is_beta']) {
                                 return json_encode(['status' => 'error', 'message' => "Beta users can't make public annotations"]);
                             }
                             return json_encode(['status' => 'error', 'message' => 'You are banned from making public annotations']);
                         }
                     } else {
                         if (isset($license['is_beta']) && $license['is_beta']) {
                             // skip check for beta users
                         } else {
                             if (isset($license['is_app_store']) && $license['is_app_store']) {
                                 if (!DashLicenseUtil::check_itunes_receipt($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             } else {
                                 if (!DashLicenseUtil::check_license($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             }
                         }
                         $db_license = new License();
                         $db_license->license = $json_license;
                         $db_license->save();
                     }
                 }
             }
             $identifier = Identifier::IdentifierFromDictionary($identifier_dict);
             $db_identifier = $identifier->find_in_db();
             if (!$db_identifier) {
                 $identifier->save();
                 $db_identifier = $identifier;
             }
             if ($public && $db_identifier->banned_from_public) {
                 return json_encode(['status' => 'error', 'message' => 'Public annotations are not allowed on this page']);
             }
             $entry = $entry_id ? Entry::where('id', '=', $entry_id)->first() : new Entry();
             if ($entry_id && (!$entry || $entry->user_id != $user->id)) {
                 return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
             }
             $entry->title = $title;
             $entry->body = $body;
             try {
                 $body = MarkdownExtra::defaultTransform($body);
             } catch (\RuntimeException $e) {
                 $message = $e->getMessage();
                 $start = strpos($message, 'no lexer for alias \'');
                 if ($start !== FALSE) {
                     $start += 20;
                     $end = strpos($message, '\'', $start);
                     if ($end !== FALSE) {
                         $lexer = substr($message, $start, $end - $start);
                         return json_encode(['status' => 'error', 'message' => 'Unknown syntax highlighting: ' . $lexer]);
                     }
                 }
                 throw $e;
             }
             $html_safe = new HTML_Safe();
             $html_safe->protocolFiltering = 'black';
             $body = $html_safe->parse($body);
             $body = str_replace('#dashInternal', '#', $body);
             $entry->body_rendered = $body;
             $entry->public = $public;
             $entry->type = $type;
             $entry->anchor = $anchor;
             $entry->user_id = $user->id;
             $entry->identifier_id = $db_identifier->id;
             if ($db_license) {
                 $entry->license_id = $db_license->id;
             }
             if (!$entry_id) {
                 $entry->score = 1;
             }
             $entry->save();
             if (!$entry_id) {
                 $vote = new Vote();
                 $vote->type = 1;
                 $vote->user_id = $user->id;
                 $vote->entry_id = $entry->id;
                 $vote->save();
             }
             $db_teams = $entry->teams();
             $already_assigned = array();
             foreach ($db_teams->get() as $team) {
                 if (!in_arrayi($team->name, $teams)) {
                     $db_teams->detach($team->id);
                 } else {
                     $already_assigned[] = $team->name;
                 }
             }
             foreach ($teams as $team) {
                 if (!in_arrayi($team, $already_assigned)) {
                     $db_team = Team::where('name', '=', $team)->first();
                     if ($db_team && $db_team->users()->where('user_id', '=', $user->id)->first()) {
                         $db_team->entries()->attach($entry->id);
                     }
                 }
             }
             return json_encode(['status' => 'success', 'entry' => $entry]);
         }
         return json_encode(['status' => 'error', 'message' => 'Oops. Unknown error']);
     }
     return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
 }
Пример #6
0
 public function update($id)
 {
     $license = \App\License::find($id);
     $license->update(array('nama_license' => Input::get('nama_license')));
     return redirect('license');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\CreateUserRequest $request, User $user)
 {
     $license = License::whereRaw('company_id = ? and status = "ACTIVE" and user_id = 0', array(Auth::user()->company_id))->first();
     if (!isset($license->id)) {
         \Session::flash('message', 'You have not Licenses');
         return Redirect::action('CompanyUserController@index');
     }
     $password = $request->password;
     $user = new User();
     $request->offsetSet('password', bcrypt($request->password));
     $request->offsetSet('created_by', Auth::user()->id);
     $request->offsetSet('updated_by', Auth::user()->id);
     $request->offsetSet('status', "NEW");
     if ($request->role_id != 2) {
         $request->offsetSet('manager_id', 0);
     }
     if (Auth::user()->role->id == 3) {
         $request->offsetSet('manager_id', Auth::user()->id);
     }
     $user->create($request->all());
     $user = DB::table('users')->where('email', $request->email)->first();
     $userPassword = new UserPassword();
     $userPassword->user_id = $user->id;
     $userPassword->crypt_password = \Crypt::encrypt($password);
     $userPassword->updated_at = new \DateTime();
     $userPassword->created_at = new \DateTime();
     $userPassword->save();
     $goal = parent::assembleGoalSetting();
     $goal->user_id = $user->id;
     $goal->created_by = Auth::user()->id;
     $goal->updated_by = Auth::user()->id;
     $goal->save();
     $license->user_id = $user->id;
     $license->update();
     $contactEmail = $user->email;
     Mail::send('emails.hello', array('first_name' => $user->first_name, 'user_name' => $user->email, 'password' => $password), function ($message) use($contactEmail) {
         $message->from('*****@*****.**', 'Sales Performance Indicator');
         $message->to($contactEmail, 'Sales Performance Indicator')->subject('Welcome to Sales Performance Indicator!');
     });
     \Session::flash('message', 'You have successfully created ' . $user->last_name . ', ' . $user->first_name);
     return Redirect::action('CompanyUserController@index');
 }