public function getSearchFieldsAndValues($format, $domain) { $fields = array(); $fields['formats'] = array("text", "image", "video"); if (is_null($format)) { $domains = Entity::distinct('domain')->get(); $usersInvolvedInEntities = array_flatten(Entity::distinct('user_id')->get()->toArray()); } else { $domains = Entity::where('format', $format)->distinct('domain')->get(); $usersInvolvedInEntities = array_flatten(Entity::where('format', $format)->distinct('user_id')->get()->toArray()); if ($key = array_search($format, $fields['formats'])) { $value = $fields['formats'][$key]; unset($fields['formats'][$key]); array_unshift($fields['formats'], $value); } } if (is_null($domain)) { $documentTypes = Entity::where('format', $format)->distinct('documentType')->get(); } else { $documentTypes = Entity::where('format', $format)->where('domain', $domain)->distinct('documentType')->get(); $usersInvolvedInEntities = array_flatten(Entity::where('format', $format)->where('domain', $domain)->distinct('user_id')->get()->toArray()); } foreach ($usersInvolvedInEntities as $key => $user_id) { $fields['userAgents'][$key] = User::find($user_id); } $fields['domains'] = array_flatten($domains->toArray()); $fields['documentTypes'] = array_flatten($documentTypes->toArray()); return $fields; }
public function getWorkerunitdata($action = null) { if (is_null($action)) { $entities = Entity::where('documentType', 'csvresult')->where('title', 'like', '%workerunit%')->get(); if (count($entities) > 0) { return View::make('preprocess.csvresult.pages.workerunitdata', compact('entities')); } return Redirect::to('files/upload')->with('flashNotice', 'You have not uploaded any "csvresult" documents yet'); } elseif ($action == "preview") { if ($URI = Input::get('URI')) { if ($entity = $this->repository->find($URI)) { if ($entity->documentType == "csvresult") { return $document = $this->csvresultMapper->processWorkerunitData($entity, true); } } } } elseif ($action == "process") { if ($URI = Input::get('URI')) { if ($entity = $this->repository->find($URI)) { if ($entity->documentType == "csvresult") { return $document = $this->csvresultMapper->processWorkerunitData($entity); } } } } }
public function getProcess() { if ($URI = Input::get('URI')) { if ($entity = $this->repository->find($URI)) { if ($entity->documentType != "fullvideo") { continue; } $videoPreprocessing = $this->fullvideoStructurer->process($entity); $status_processing = $this->fullvideoStructurer->store($entity, $videoPreprocessing); if (isset($status_processing["keyframes"])) { if (!isset($status_processing["keyframes"]['error'])) { //update the parent Entity::where('_id', '=', $entity->_id)->update(array('keyframes.count' => $status_processing["keyframes"]['success']["noEntitiesCreated"])); } echo "<pre>"; } if (isset($status_processing["segments"])) { if (!isset($status_processing["segments"]['error'])) { //update the parent Entity::where('_id', '=', $entity->_id)->update(array('segments.count' => $status_processing["segments"]['success']["noEntitiesCreated"])); } echo "<pre>"; } if (isset($status_processing["keyframes"]['success']) && isset($status_processing["segments"]['success'])) { return Redirect::back()->with('flashSuccess', 'Your video has been pre-processed in keyframes and video segments'); } else { return Redirect::back()->with('flashError', 'An error occurred while the video was being pre-processed in keyframes and video segments'); } } } else { return Redirect::back()->with('flashError', 'No valid URI given: ' . $URI); } }
public function getActions() { // get all uploaded documents // TODO: change to select by actual type $entities = Entity::where('activity_id', 'LIKE', '%fileuploader%')->get(); if (count($entities) > 0) { return View::make('media.preprocess.relex.pages.actions', compact('entities')); } return Redirect::to('media/upload')->with('flashNotice', 'You have not uploaded any documents yet'); }
/** * Execute the console command * * @return void */ public function fire() { // check if the provided user exists $user = User::where('username', '=', $this->option('user'))->first(); if (!isset($user)) { $this->comment("This user don't exist."); return; } // check if the provided amenity exists and delete it $amenity = Entity::where('type', '=', 'amenity')->where('name', '=', $this->argument('name'))->where('user_id', '=', $user->id)->first(); if (isset($amenity)) { $amenity->delete(); $this->info("Amenity '{$amenity->name}' has been deleted."); } else { $this->comment("This amenity do not exist."); } }
/** * Execute the console command. * * @return void */ public function fire() { $user = User::where('username', '=', $this->option('user'))->first(); if (!isset($user)) { $this->comment("This user don't exist."); return; } // get thing's name do { $valid = true; $name = $this->ask("Name : "); if (empty($name)) { $this->comment("Your name is empty"); $valid = false; } if (Entity::where('name', '=', $name)->where('user_id', '=', $user->id)->first() != null) { $this->comment("A thing with this name already exist."); $valid = false; } } while (!$valid); // get thing's type do { $type = $this->ask("Type (i.e. room) : "); if (empty($type)) { $this->comment("Your type is empty"); } } while (empty($type)); // get thing's description do { $description = $this->ask("Description : "); if (empty($description)) { $this->comment("Your description is empty"); } } while (empty($description)); // get thing's opening hours $opening_hours = array(); $this->info("\t{$name} - schedule"); $add = $this->ask("\t\tAdd opening days ? Y/n") == "Y" ? 1 : 0; while ($add) { do { $day = $this->ask("\t\tDay of week : "); if ($day < 1 || $day > 7) { $this->comment("\t\tYour day must be an integer between 1 and 8."); } } while ($day < 1 || $day > 7); do { do { $valid_from = strtotime($this->ask("\t\tValid from (d-m-Y) : ")); if (empty($valid_from)) { $this->comment("\t\tYour date is empty"); } if ($valid_from < time()) { $this->comment("\t\tYour valid from value is before now"); } } while (empty($valid_from) || $valid_from < time()); do { $valid_through = strtotime($this->ask("\t\tValid through (d-m-Y) : ")); if (empty($valid_through)) { $this->comment("\t\tYour date is empty"); } if ($valid_through < time()) { $this->comment("\t\tYour valid through value is before now"); } } while (empty($valid_through) || $valid_through < time()); if ($valid_from > $valid_through) { $this->comment("\t\tYour valid through date is before valid from date."); } } while ($valid_from > $valid_through); $opens = array(); $closes = array(); $this->info("\t\t\t{$name} - schedule [day {$day} - opening hours]"); do { do { $valid = true; $open_close = $this->ask("\t\t\t\tOpening / Closing hour (H:m - H:m) : "); $open_close = explode("-", $open_close); if (count($open_close) < 2) { $this->comment("\t\t\t\tYour opening closing hours are not valid"); $valid = false; } if (!preg_match("/(2[0-3]|[01][0-9]):[0-5][0-9]/", $open_close[0])) { $this->comment("\t\t\t\tYour opening hour is not valid."); $valid = false; } if (!preg_match("/(2[0-3]|[01][0-9]):[0-5][0-9]/", $open_close[1])) { $this->comment("\t\t\t\tYour closing hour is not valid."); $valid = false; } } while (!$valid); array_push($opens, $open_close[0]); array_push($closes, $open_close[1]); $add = $this->ask("\t\t\tAdd opening hours ? Y/n") == "Y" ? 1 : 0; } while ($add); array_push($opening_hours, array('validFrom' => date('c', $valid_from), 'validThrough' => date('c', $valid_through), 'dayOfWeek' => $day, 'opens' => $opens, 'closes' => $closes)); $add = $this->ask("\t\tAdd opening day ? Y/n") == "Y" ? 1 : 0; } //get thing's price rates $this->info("\t{$name} - price rates"); do { $currency = $this->ask("\t\tCurrency (ISO4217 format) : "); if (empty($currency) || !in_array($currency, $this->ISO4217)) { $this->comment("\t\tYour currency value is invalid"); } } while (empty($currency) || !in_array($currency, $this->ISO4217)); $price_rate = array(); $price_rate['currency'] = $currency; $rates = array('hourly', 'daily', 'weekly', 'monthly', 'yearly'); do { do { $rate = $this->ask("\t\tRate (hourly, daily, weekly, monthly, yearly) : "); if (!in_array($rate, $rates)) { $this->comment("\t\tYour rate value is invalid"); } } while (!in_array($rate, $rates)); do { $price = $this->ask("\t\tPrice for {$rate} rate in {$currency} : "); if (empty($price) || $price < 0) { $this->comment("\t\tYour price value is invalid"); } } while (empty($price) || $price < 0); $price_rate[$rate] = $price; $add = $this->ask("\t\tAdd another price rate ? Y/n : ") == "Y" ? 1 : 0; } while ($add); //get thing's location $this->info("\t{$name} - location"); do { $building_name = $this->ask("\t\tBuilding name : "); if (empty($building_name)) { $this->comment("\t\tYour building name value is invalid"); } } while (empty($building_name)); do { $floor = $this->ask("\t\tFloor : "); if (empty($floor)) { $this->comment("\t\tYour floor value is invalid"); } } while (empty($floor)); $this->info("\t\t\t{$name} - location [map]"); do { $img = $this->ask("\t\t\tMap image URL : "); if (empty($img) || !filter_var($img, FILTER_VALIDATE_URL)) { $this->comment("\t\t\tYour map image URL is invalid"); } } while (empty($img) || !filter_var($img, FILTER_VALIDATE_URL)); do { $reference = $this->ask("\t\t\tMap reference : "); if (empty($reference)) { $this->comment("\t\t\tYour map reference is invalid"); } } while (empty($reference)); // get thing's contact and support vcard URLs do { $contact = $this->ask("Contact vcard URL : "); if (empty($contact) || !filter_var($contact, FILTER_VALIDATE_URL)) { $this->comment("Your contact vcard URL is invalid"); } } while (empty($contact) || !filter_var($contact, FILTER_VALIDATE_URL)); do { $support = $this->ask("Support vcard URL : "); if (empty($support) || !filter_var($support, FILTER_VALIDATE_URL)) { $this->comment("Your support vcard URL is invalid"); } } while (empty($support) || !filter_var($support, FILTER_VALIDATE_URL)); //get thing's amenities and fill properties $this->info("\t{$name} amenities"); $amenities = Entity::where('type', '=', 'amenity')->where('user_id', '=', $user->id)->get(); $add = $this->ask("\t\tAdd amenities ? Y/n") == "Y" ? 1 : 0; $_amenities = array(); while ($add) { do { $this->info("\t\tAvailable amenities : "); foreach ($amenities as $amenity) { $this->info("\t\t\t[{$amenity->id}] {$amenity->name}"); } $id = $this->ask("\t\tAmenity id : "); $present = false; foreach ($amenities as $amenity) { if ($amenity->id == $id) { $present = true; } } if (empty($id) || !$present) { $this->comment("\t\tYour amenity id is invalid"); } } while (empty($id) || !$present); foreach ($amenities as $amenity) { if ($amenity->id == $id) { $this->info("\t\t\t{$amenity->name} properties"); $schema = json_decode($amenity->body); foreach ($schema->properties as $property_name => $property) { do { $value = $this->ask("\t\t\t\t{$property_name} ({$property->description}) : "); if (empty($value)) { $this->comment("\t\t\t\tYour {$property_name} value is invalid."); } } while (empty($value)); array_push($_amenities, array(Config::get('app.url') . $user->username . '/amenities/' . $property_name => $value)); } } } $add = $this->ask("\t\tAdd another amenity ? Y/n") == "Y" ? 1 : 0; } //create thing and save it in database $thing = new Entity(); $thing->name = $name; $thing->type = $type; $thing->user_id = $user->id; // create thing's body $body = array(); $body['name'] = $name; $body['type'] = $type; $body['description'] = $description; $body['opening_hours'] = $opening_hours; $body['price'] = $price_rate; $body['location'] = array(); $body['location']['building_name'] = $building_name; $body['location']['floor'] = $floor; $body['location']['map'] = array(); $body['location']['map']['img'] = $img; $body['location']['map']['reference'] = $reference; $body['contact'] = $contact; $body['support'] = $support; $body['amenities'] = $_amenities; $thing->body = json_encode($body); $thing->save(); $this->info("Thing successfully saved"); }
private function setMailFlag($mailUids, $flag, $value = false) { foreach ($mailUids as $mailUid) { $mailEntity = Entity::where('uid', '=', $mailUid)->first(); if ($mailEntity) { switch ($flag) { case "\\Seen": $mailEntity->seen = $value; break; case "\\Sent": $mailEntity->sent = $value; break; case "\\Flagged": $mailEntity->flagged = $value; break; case "\\Deleted": $mailEntity->deleted = $value; break; } $mailEntity->save(); } } }
/** * Execute the console command. * * @return void */ public function fire() { $user = User::where('username', '=', $this->option('user'))->first(); if (!isset($user)) { $this->comment("This user don't exist."); return; } //get things available for reservation and display them $things = Entity::where('type', '!=', 'amenity')->where('user_id', '=', $user->id)->get(); if (!count($things)) { $this->comment("There is nothing to be reserved."); return; } foreach ($things as $thing) { $this->info("{$thing->name} [{$thing->id}]"); } do { $present = false; // ask user which thing he wants to book $thing_id = $this->ask("Thing id : "); if (empty($thing_id)) { $this->comment("Your thing id is invalid"); } else { for ($i = 0; $i < count($things); $i++) { if ($things[$i]->id == $thing_id) { $present = true; $thing = $things[$i]; } } if (!$present) { $this->comment("Your thing id is invalid"); } } } while (empty($thing_id) || !$present); // get reservation's subject do { $subject = $this->ask("Subject : "); if (empty($subject)) { $this->comment("Your subject is invalid"); } } while (empty($subject)); // get reservation's comment do { $comment = $this->ask("Comment : "); if (empty($comment)) { $this->comment("Your comment is invalid."); } } while (empty($comment)); //get reservation's timing do { $available = 1; do { $valid = true; $from = strtotime($this->ask("From (d-m-Y H:m) : ")); if (empty($from)) { $valid = false; $this->comment("Your value is empty."); } if ($from < time()) { $valid = false; $this->comment("Your reservation can't start before now."); } } while (!$valid); do { $valid = true; $to = strtotime($this->ask("To (d-m-Y H:m) : ")); if (empty($to)) { $valid = false; $this->comment("Your value is empty."); } if ($to < $from) { $valid = false; $this->comment("Your reservation can't end before it start."); } $thing_body = json_decode($thing->body); } while (!$valid); if (!$this->isAvailable($thing_body->opening_hours, array('from' => $from, 'to' => $to))) { $available = 0; $this->comment('The thing is not available at that time'); } } while (!$available); //TODO(qkaiser) : verify if room is available // get reservation's announcement $announce = explode(",", $this->ask("Announce (names separated by a comma) : ")); // create reservation object and save it to database $reservation = new Reservation(); $reservation->user_id = $user->id; $reservation->entity_id = $thing_id; $reservation->subject = $subject; $reservation->comment = $comment; $reservation->from = $from; $reservation->to = $to; if (!count($announce[0])) { $announce = array(); } $reservation->announce = json_encode($announce); $reservation->save(); $this->info("Reservation successfully saved"); return; }
public function listRecords($parameters, $noEntries, &$listOfRecords) { $curlRequest = new SVRequest(); $url = $this->url . "verb=ListRecords"; if (isset($parameters)) { if (!array_key_exists("metadataPrefix", $parameters)) { if (!array_key_exists("resumptionToken", $parameters)) { throw new Exception("Request must contain -metadataPrefix- parameter!"); } else { foreach ($parameters as $param => $value) { $url .= "&" . $param . "=" . $value; } } } else { foreach ($parameters as $param => $value) { $url .= "&" . $param . "=" . $value; } } } else { throw new Exception('Request parameters missing!'); } $entities = Entity::where('documentType', 'tv-news-broadcasts')->lists("title"); while ($noEntries > 0) { //throw new Exception($noEntries); $result = $curlRequest->curlRequest($url, "POST", null); $xml = simplexml_load_string($result["result"]); if ($xml === false) { die('Error parsing XML'); } else { $xmlNode = $xml->ListRecords; if (isset($xmlNode)) { foreach ($xmlNode->record as $rNode) { if (strpos((string) $rNode->metadata->children('oai_oi', 1)->oi->children('oi', 1)->type, "Moving Image") !== false) { if ($noEntries > 0) { if (!in_array((string) $rNode->header->identifier, $entities)) { array_push($listOfRecords, (string) $rNode->header->identifier); array_push($entities, (string) $rNode->header->identifier); // dd($entities); $noEntries--; } else { continue; } } else { break; } } } } if (isset($xml->ListRecords->resumptionToken)) { if ($noEntries > 0) { if (!array_key_exists("resumptionToken", $parameters)) { $parameters["resumptionToken"] = (string) $xml->ListRecords->resumptionToken; unset($parameters["metadataPrefix"]); $this->listRecords($parameters, $noEntries, $listOfRecords); } else { $replacement = array("resumptionToken" => (string) $xml->ListRecords->resumptionToken); $parameters = array_replace($parameters, $replacement); $this->listRecords($parameters, $noEntries, $listOfRecords); } } } } } // dd($listOfRecords); // return $listOfRecords; }
public static function createJobCache() { \Session::flash('rawArray', 1); $db = \DB::getMongoDB(); $db = $db->temp; $result = Entity::where('type', 'job')->with('hasConfiguration')->get()->toArray(); if (count($result) > 0) { try { Temp::where('type', 'job')->forceDelete(); $db->batchInsert($result, array('continueOnError' => true)); } catch (Exception $e) { // ContinueOnError will still throw an exception on duplication, even though it continues, so we just move on. } } \Session::forget('rawArray'); }
<?php // Get a list of titles and template types which are already in the database // and put them to dropdown $aTitles = array(null => '---'); $aTypes = array(null => '---'); $_format = unserialize(Session::get('batch'))->format; $batchUnits = unserialize(Session::get('batch'))->parents; $batchUnitContent = Entity::where("_id", $batchUnits[0])->get()->first(); $unitAttributes = array(); $c = array_change_key_case(array_dot($batchUnitContent['content']), CASE_LOWER); foreach ($c as $key => $val) { $key = strtolower(str_replace('.', '_', $key)); $unitAttributes[$key] = $key; } // dd($unitAttributes); $_aTitles = Entity::where("type", "jobconf")->where("format", $_format)->distinct("content.title")->get(); $_aTitles = array_flatten($_aTitles->toArray()); foreach ($_aTitles as $key => $value) { $pos = strpos($value, '[['); if ($pos > 0) { $t = trim(substr($value, 0, $pos)); if (!array_key_exists($t, $aTitles)) { $aTitles[$t] = $t; } } } $_aTypes = Template::distinct('type')->get(); $_aTypes = array_flatten($_aTypes->toArray()); foreach ($_aTypes as $key => $value) { if (!isset($aTypes[$value])) { $aTypes[$value] = $value;
/** * Create a new reservation for a authenticated user. * @param $clustername : cluster's name from url. * */ public function updateReservation(Cluster $cluster, $id) { if (!strcmp($cluster->clustername, Auth::user()->clustername) || Auth::user()->isAdmin()) { $content = Request::instance()->getContent(); if (empty($content)) { return $this->_sendErrorMessage(400, "Payload.Null", "Received payload is empty."); } if (Input::json() == null) { return $this->_sendErrorMessage(400, "Payload.Invalid", "Received payload is invalid."); } $thing_uri = Input::json()->get('thing'); $thing_name = explode('/', $thing_uri); $thing_name = $thing_name[count($thing_name) - 1]; $thing_uri = str_replace($thing_name, '', $thing_uri); Input::json()->set('thing', $thing_uri); $reservation_validator = Validator::make(Input::json()->all(), array('thing' => 'required|url', 'type' => 'required', 'time' => 'required|time', 'subject' => 'required', 'announce' => 'required', 'customer' => 'required|customer')); if (!$reservation_validator->fails()) { $entity_name = explode('/', Input::json()->get('thing')); $entity_name = $entity_name[count($entity_name) - 1]; $entity = Entity::where('name', '=', $entity_name)->where('type', '=', Input::json()->get('type'))->where('user_id', '=', $cluster->user->id)->first(); if (!isset($entity)) { return $this->_sendErrorMessage(404, "Thing.NotFound", "Thing not found."); } else { $reservation = Reservation::find($id); if ($reservation->exists) { $time = Input::json()->get('time'); if ($this->isAvailable(json_decode($entity->body)->opening_hours, $time)) { //timestamps are UTC so we convert dates to UTC timezone $from = new DateTime($time['from']); $to = new DateTime($time['to']); $from->setTimezone(new DateTimeZone('UTC')); $to->setTimezone(new DateTimeZone('UTC')); $reservation = Reservation::activatedOrBlocking()->where('user_id', '=', $cluster->user->id)->where('entity_id', '=', $entity->id)->where('from', '<', $to)->where('to', '>', $from)->first(); if (!empty($reservation)) { return $this->_sendErrorMessage(404, "Thing.AlreadyReserved", "The thing is already reserved at that time."); } else { $reservation->from = $from->getTimestamp(); $reservation->to = $to->getTimestamp(); $reservation->subject = Input::json()->get('subject'); $reservation->comment = Input::json()->get('comment'); $reservation->announce = json_encode(Input::json()->get('announce')); $reservation->customer = json_encode(Input::json()->get('customer')); $reservation->entity_id = $entity->id; $reservation->user_id = $cluster->user->id; return $reservation->save(); } } else { return $this->_sendErrorMessage(404, "Thing.Unavailable", "The thing is unavailable at that time."); } } } } else { return $this->_sendValidationErrorMessage($reservation_validator); } } else { return $this->_sendErrorMessage(403, "WriteAccessForbiden", "You can't make reservations on behalf of another user."); } }
/** * Execute the console command * * @return void */ public function fire() { $allowed_types = array('array', 'boolean', 'integer', 'number', 'null', 'object', 'string'); $user = User::where('username', '=', $this->option('user'))->first(); if (!isset($user)) { $this->comment("This user don't exist."); return; } do { // get amenity's name do { $name = $this->ask("Amenity name : "); if (empty($name)) { $this->comment("Your amenity name is empty."); } } while (empty($name)); // check if an amenity with this name and user already exist $amenity = Entity::where('type', '=', 'amenity')->where('name', '=', $name)->first(); if (isset($amenity)) { $this->comment("An amenity with this name already exists, please choose another one."); } } while (isset($amenity)); // get amenity's title do { $title = $this->ask("Amenity title : "); if (empty($title)) { $this->comment("Your amenity title is empty."); } } while (empty($title)); // get amenity's description do { $description = $this->ask("Amenity description : "); if (empty($description)) { $this->comment("Your amenity description is empty."); } } while (empty($description)); $amenity = new Entity(); $amenity->user_id = $user->id; $amenity->type = "amenity"; $amenity->name = $name; $json_schema = array(); $json_schema['$schema'] = "http://json-schema.org/draft-04/schema#"; $json_schema['title'] = $title; $json_schema['description'] = $description; $json_schema['type'] = 'object'; $json_schema['properties'] = array(); $i = 0; $this->info("\n\n{$amenity->name} properties."); do { $this->comment("\n# Property {$i}"); // get property name do { $name = $this->ask("\tProperty name : "); if (in_array($name, array_keys($json_schema['properties']))) { $this->comment("A property with this name already exist."); } if (empty($name)) { $this->comment("Your property name is empty."); } } while (in_array($name, array_keys($json_schema['properties'])) || empty($name)); // get property description do { $description = $this->ask("\tProperty description : "); if (empty($description)) { $this->comment("Your property description is empty."); } } while (empty($description)); // set property name and description $json_schema['properties'][$name] = array(); $json_schema['properties'][$name]['description'] = $description; // get property type and verify if it is a valid json-schema core type do { $type = $this->ask("\tProperty type (array, boolean, integer, number, null, object, string) : "); if (!in_array($type, $allowed_types)) { $this->comment("The property type you provided is not valid. Valid types are 'array', 'boolean', 'integer', 'number', 'null', 'object', 'string'."); } } while (!in_array($type, $allowed_types)); // set property type $json_schema['properties'][$name]['type'] = $type; $stop = $this->ask("\nDo you want to add another property ? [Y]/n") == "Y" ? 0 : 1; $i++; } while (!$stop); $amenity->body = json_encode($json_schema); $amenity->save(); $this->info("Amenity '{$amenity->name}' has been saved."); return; }
public function getUnitsrelex() { $count = 0; foreach (\Workerunit::where('type', 'RelEx')->get() as $ann) { set_time_limit(30); if (!isset($ann->content)) { echo "{$ann->_id} no content\r\n"; echo "--------------------------------\r\n"; continue; } if (!empty($ann->unit_id)) { echo "{$ann->_id} has unitid\r\n"; continue; } //dd($ann->question); //$xml = simplexml_load_string($ann->question); //$url = (string) $xml->ExternalURL; $xml = simplexml_load_string($ann->question); //$html = $ann->question;// $html = (string) $xml->HTMLContent; //dd($html); $dom = HtmlDomParser::str_get_html($html); $sentence = rtrim($dom->find('span[class=senval]', 0)->innertext, '.'); $term1 = $dom->find('span[style=color:#0000CD;]', 1)->innertext; $term2 = $dom->find('span[style=color:#0000CD;]', 2)->innertext; /* $sentence = "Poisson regression analysis which included data for multiple measurements of Tme/[TE] over the first year of life and adjusted for age-at-test and maternal smoking during [PREGNANCY] also demonstrated a greater decrease in Tme/Te in female infants who subsequently develop an LRI (P = 0.08"; $term1 = "[PREGNANCY]"; $term2 = "[TE]";*/ $unit = Entity::where('content.terms.first.formatted', $term1)->where('content.terms.second.formatted', $term2)->where('content.sentence.formatted', $sentence)->first(); /* if(!$unit){ $hi = 0; $units = Entity::where('content.terms.first.formatted', $term1) ->where('content.terms.second.formatted', $term2) ->get(); foreach($units as $punit){ try{ $pct = similar_text($sentence, $punit->content['sentence']['formatted']); } catch (ErrorException $e) { echo "\r\n\r\n\r\n\r\n{$punit->_id}\r\n\r\n\r\n\r\n"; $pct = similar_text(strtolower($sentence), strtolower($punit->content['sentence']['text'])); } if($pct>$hi) { $hi=$pct; $unit = $punit; } } } */ if ($unit) { echo "\r\n\\YY {$sentence}\r\n"; echo "== " . $unit->content['sentence']['formatted']; echo "\r\n{$ann->_id}->{$unit->_id}\r\n"; $ann->unit_id = $unit->_id; $ann->save(); } else { echo "\r\nNO {$ann->_id}\r\n{$term1}--{$term2}--{$sentence}\r\n"; //echo $punit->content['sentence']['formatted']; //echo "\r\n{$ann->unit_id}----------------\r\n"; echo "----------------------------------------"; continue; } } }
/** * Delete an amenity. * @param $clustername : cluster's name from the url * @param $name : the name of the amenity to be deleted * */ public function deleteAmenity(Cluster $cluster, $name) { if (!strcmp($cluster->clustername, Auth::user()->clustername) || Auth::user()->isAdmin()) { $amenity = Entity::where('user_id', '=', $cluster->user->id)->where('type', '=', 'amenity')->where('name', '=', $name); if ($amenity->first() != null) { if ($amenity->delete()) { return Response::json(array('success' => true, 'message' => 'Amenity successfully deleted')); } else { return $this->_sendErrorMessage(500, "Amenity.Unknown", "An error occured while deleting the amenity."); } } else { return $this->_sendErrorMessage(404, "Amenity.NotFound", "Amenity not found."); } } else { return $this->_sendErrorMessage(403, "DeleteAccessForbiden", "You can't delete amenities from another user."); } }
public static function getDistinctValuesForField($field, $conditions = array()) { $distinctFields = Entity::where(function ($query) use($conditions) { foreach ($conditions as $conditionKey => $conditionValue) { $query->where($conditionKey, '=', $conditionValue); } })->distinct($field)->get(); // })->distinct($field)->remember(60, 'text_' . md5(serialize($field)))->get(); $fieldValues = array(); foreach ($distinctFields as $distinctField) { array_push($fieldValues, $distinctField[0]); } if (count($fieldValues) > 0) { sort($fieldValues); return $fieldValues; } return false; }
public function postLoadt() { $jc_id = Session::get('jobconf_id_t'); $j_id = Session::get('job_id_t'); $jc = Entity::where("_id", $jc_id)->first(); $j = Entity::where("_id", $j_id)->first(); $jcco = $jc['content']; $jcco['type'] = Input::get('templateType'); if ($jcco['type'] == Null) { return Redirect::back()->with('flashError', "form not filled in (type)."); } // get a selected, newest jcbase $maxi = Template::where("type", $jcco['type'])->max('version'); $jcbase = Template::where("type", $jcco['type'])->where('version', $maxi)->first(); if (!isset($jcbase)) { Session::flash('flashError', "template not found: " . $jcco['type']); return Redirect::to("jobs2/submit"); } if (!isset($jcbase['cml'])) { Session::flash('flashError', "No template details in this template"); return Redirect::to("jobs2/submit"); } $jcco['cml'] = $jcbase['cml']; if (isset($jcbase['css'])) { $jcco['css'] = $jcbase['css']; } if (isset($jcbase['instructions'])) { $jcco['instructions'] = $jcbase['instructions']; } if (isset($jcbase['js'])) { $jcco['js'] = $jcbase['js']; } $jcco['template_id'] = $jcbase['_id']; $pos = strpos($jcco['title'], '[['); $title = substr($jcco['title'], 0, $pos); $rest = substr($jcco['title'], strpos($jcco['title'], '(entity/')); $jcco['title'] = $title . "[[" . $jcco['type'] . $rest; $jc['content'] = $jcco; //$j['type'] = $jcco['type']; $j['type'] = "job"; $jc->save(); $j->save(); $platform = App::make('cf2'); //upadte $platform->cfUpdate($j['platformJobId'], $jc); $successmessage = "Job loaded."; Session::flash('flashSuccess', $successmessage); return Redirect::to("jobs"); }
/** * Create worker unit */ public function process($signal, $payload, $settings) { //return "blabla"; // increase memory usage to support larger files with up to 10k judgments ini_set('memory_limit', '256M'); set_time_limit(0); $this->status = ['notice' => [], 'success' => [], 'error' => []]; try { if (!empty($payload)) { if ($signal == "new_units") { $settings['units'] = []; $retUnits = json_decode($payload, true); //return $retUnits; // Create activity $activity = $this->createActivity(); if ($settings['documentType'] == "") { $settings['documentType'] = "diveunit"; } if ($settings["batch_description"] == "") { $settings["batch_description"] = "Batch imported from DIVE dashboard"; } foreach ($retUnits as $unitContent) { $hashing = array(); $hashing["project"] = $settings["project"]; $hashing["documentType"] = $settings["documentType"]; $hashing["content"] = $unitContent; $hash = md5(serialize($hashing)); $searchForUnit = \Entity::where("hash", $hash)->first(); if ($searchForUnit != NULL) { //$units[$searchForUnit["_id"]] = $searchForUnit; array_push($settings['units'], $searchForUnit["_id"]); } else { $unit = new Unit(); $unit->project = $settings['project']; $unit->activity_id = $activity->_id; $unit->documentType = $settings['documentType']; $unit->type = "unit"; $unit->parents = []; $unit->content = $unitContent; $unit->hash = $hash; $unit->source = "divedashboard"; //return $unit; $unit->save(); $units[$unit->_id] = $unit; array_push($settings['units'], $unit->_id); // dd($settings['units']); } } // Create Batch $hashBatch = array(); $hashBatch["project"] = $settings["project"]; $hashBatch["batch_description"] = $settings["batch_description"]; $hashBatch["content"] = $settings["units"]; $settings['batch_title'] = "Imported batch from Dive dashboard"; $searchForBatch = \Entity::where("hash", md5(serialize($hashBatch)))->first(); if ($searchForBatch != NULL) { array_push($this->status['notice'], "Batch already exists " . $searchForBatch['_id'] . ""); } else { $batch = Batch::store($settings, $activity); } array_push($this->status['success'], "Successfully imported " . $settings['documentType'] . ""); array_push($this->status['success'], "Logged activities as " . $activity->_id . ""); return $this->status; } else { array_push($this->status['error'], "Unknown request from DIVE dashboard -- " . $signal . ""); return $this->status; } } else { array_push($this->status['error'], "The content of the units is empty -- " . $payload . ""); return $this->status; } } catch (Exception $e) { $activity->forceDelete(); foreach ($this->units as $unit) { if (!$unit->exists()) { $unit->forceDelete(); } } return $e; } }
public function anyTest() { try { if (!($data = Input::get('data'))) { if (!($data = \Request::getContent())) { return false; } } if (empty($data)) { return false; } $data = json_decode($data, true); $data['softwareAgent_id'] = strtolower($data['softwareAgent_id']); try { $this->createPostSoftwareAgent($data); } catch (Exception $e) { return serialize([$e->getMessage()]); } try { $activity = new Activity(); $activity->softwareAgent_id = $data['softwareAgent_id']; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $activity->forceDelete(); return serialize([$e->getMessage()]); } $entity = new Entity(); $entity->format = 'image'; $entity->domain = $data['domain']; $entity->tags = $data['tags']; $entity->documentType = $data['documentType']; $entity->softwareAgent_configuration = $data['softwareAgent_configuration']; if (isset($data['parents'])) { $entity->parents = $data['parents']; } $entity->content = $data['content']; if (isset($data['threshold'])) { $entity->threshold = $data['threshold']; } if (isset($data['relevantFeatures'])) { $entity->recognizedFeatures = $data['relevantFeatures']; } if (isset($data['hash'])) { $entity->hash = $data['hash']; } else { $entity->hash = md5(serialize($data['content'])); } $entity->activity_id = $activity->_id; if (Entity::where('hash', $entity->hash)->first()) { //dd('asdasd'); } else { $entity->save(); } return Response::json($entity); } catch (Exception $e) { dd($e->getMessage()); } }
public function getLastDocumentInc() { $lastMongoURIUsed = Entity::where('format', 'text')->where('domain', 'medical')->where("documentType", 'relex-structured-sentence')->get(array("_id")); if (count($lastMongoURIUsed) > 0) { $lastMongoURIUsed = $lastMongoURIUsed->sortBy(function ($entity) { return $entity->_id; }, SORT_NATURAL)->toArray(); if (end($lastMongoURIUsed)) { $lastMongoIDUsed = explode("/", end($lastMongoURIUsed)['_id']); $inc = end($lastMongoIDUsed) + 1; } } else { $inc = 0; } unset($lastMongoURIUsed); return $inc; }
public function findByRouteName($route_name) { $entity = \Entity::where('route_name', $route_name)->with('attributes')->first(); return $entity; }