Exemplo n.º 1
0
 /**
  *  数据处理
  * @param type $data 数据
  * @return type
  */
 private function dataHandle($data, $text = '')
 {
     if (!$data) {
         return $data;
     }
     import("Input");
     $data = addslashes($data);
     $data = strip_tags($data);
     $data = str_replace(array(" ", "\r\t"), array(""), $data);
     $data = Input::forSearch($data);
     $data = Input::deleteHtmlTags($data);
     $config = F("Search_config");
     if (!$config) {
         $this->search_cache();
         $config = F("Search_config");
     }
     //判断是否启用sphinx全文索引,如果不是,则进行php简易分词处理
     if ((int) $config['sphinxenable'] == 0 && $config['segment']) {
         static $Segment;
         if (!isset($Segment)) {
             import("Segment", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
             $Segment = new Segment();
         }
         $fulltext_data = $Segment->get_keyword($Segment->split_result($data));
         $data = $text . $fulltext_data;
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * @param Segment $segment
  *
  * @return void
  */
 public function add($segment)
 {
     if (!$this->exists(function ($key, Segment $element) use($segment) {
         return $segment->getId() == $element->getId();
     })) {
         parent::add($segment);
     }
 }
Exemplo n.º 3
0
 /**
  * @dataProvider routeProvider
  * @param        Segment $route
  * @param        string  $path
  * @param        integer $offset
  * @param        array   $params
  */
 public function __testAssembling(Segment $route, $path, $offset, array $params = null)
 {
     if ($params === null) {
         // Data which will not match are not tested for assembling.
         return;
     }
     $result = $route->assemble($params);
     if ($offset !== null) {
         $this->assertEquals($offset, strpos($path, $result, $offset));
     } else {
         $this->assertEquals($path, $result);
     }
 }
Exemplo n.º 4
0
 /**
  * Create a new instance and populate its properties with JSON data
  * @param array $jsonData
  * @return \moosend\Models\Campaign
  */
 public static function withJSON(array $jsonData)
 {
     $instance = new self();
     $instance->ID = $jsonData['ID'];
     $instance->Name = $jsonData['Name'];
     $instance->Subject = $jsonData['Subject'];
     $instance->WebLocation = $jsonData['WebLocation'];
     $instance->HTMLContent = $jsonData['HTMLContent'];
     $instance->PlainContent = $jsonData['PlainContent'];
     $instance->Sender = Sender::withJSON($jsonData['Sender']);
     $instance->DeliveredOn = $jsonData['DeliveredOn'];
     $instance->ReplyToEmail = Sender::withJSON($jsonData['ReplyToEmail']);
     $instance->CreatedOn = $jsonData['CreatedOn'];
     $instance->UpdatedOn = $jsonData['UpdatedOn'];
     $instance->ScheduledFor = $jsonData['ScheduledFor'];
     $instance->Timezone = $jsonData['Timezone'];
     $instance->FormatType = $jsonData['FormatType'];
     $instance->ABCampaignData = ABCampaignData::withJSON($jsonData['ABCampaignData']);
     $instance->MailingList = MailingList::withJSON($jsonData['MailingList']);
     $instance->ConfirmationTo = $jsonData['ConfirmationTo'];
     $instance->Status = $jsonData['Status'];
     if (isset($jsonData['Segment'])) {
         $instance->Segment = Segment::withJSON($jsonData['Segment']);
     }
     $instance->IsTransactional = $jsonData['IsTransactional'];
     return $instance;
 }
 /**
  * @param AddSegmentsErrors $errors
  */
 private function isAdNumberValid($errors)
 {
     $adNumber = $this->segment->getAdNumber();
     if (!ValidatorUtility::doesFieldExist($adNumber) || !ValidatorUtility::isInteger($adNumber)) {
         $errors->markAdNumberMissing();
     }
 }
 /**
  * Process a result row.
  * @param array $row
  * @param int $row_num The current row number when processing results.  If there was a result limit, it starts the count from the beginning of the
  * result offset.  Othwerwise, it starts counting form zero.
  * @param DOMNode $contentNode. Default to null. A node to append the result onto
  */
 protected function processResultRow($row, $row_num, $contentNode = null)
 {
     $mapped_row = $this->mapResults($row);
     try {
         $this->odf_row->setVars('++row_num', $row_num + 1, $this->encoding, $this->charset);
     } catch (SegmentException $e) {
         //It's ok if it's not there so don't do anything.
     }
     foreach ($this->header_vars as $key => $val) {
         try {
             $this->odf_row->setVars($key, $val, $this->encoding, $this->charset);
         } catch (SegmentException $e) {
             //It's ok if it's not there so don't do anything.
         }
     }
     $ff = I2CE_FormFactory::instance();
     foreach ($mapped_row as $key => $val) {
         if (array_key_exists($key, $this->image_objs) && ($fieldObj = $this->image_objs[$key])) {
             //need to get $reportform+id and get the formObj.
             list($form, $field) = explode('+', $key, 2);
             $formid = $form . '+id';
             if (!array_key_exists($formid, $mapped_row) || !($formObj = $ff->createContainer($mapped_row[$formid])) instanceof I2CE_Form || !($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
                 I2CE::raiseError("Can't get form/field associated to {$key}" . print_r($mapped_row, true));
                 try {
                     $this->odf_row->setVars($key, '');
                 } catch (SegementException $e) {
                     //It's ok if it's not there so don't do anything.
                 }
                 continue;
             }
             $formObj->populate();
             try {
                 $this->odf_row->setImageFromField($this->full_keys[$key], $fieldObj, $this->extra[$key]);
             } catch (SegmentException $e) {
                 //It's ok if it's not there so don't do anything.
             }
         } else {
             if ($row_num == 0) {
                 try {
                     $this->odf->setVars($key, $val, $this->encoding, $this->charset);
                 } catch (OdfException $e) {
                     //It's ok if it's not there so don't do anything.
                 }
                 try {
                     $this->odf->setStyleVars($key, $val, $this->encoding, $this->charset);
                 } catch (OdfException $e) {
                     //It's ok if it's not there so don't do anything.
                 }
             }
             try {
                 $this->odf_row->setVars($key, $val, $this->encoding, $this->charset);
             } catch (SegmentException $e) {
                 //It's ok if it's not there so don't do anything.
             }
         }
     }
     $this->odf_row->merge();
     return true;
 }
 public function showPage($slug)
 {
     if ($page_translation = \App\PageTranslation::findBySlug($slug)) {
         $page = $page_translation->page;
         if ($page->type != 'blank' && $page->type != 'external' && $page_translation->locale != \App::getLocale()) {
             return redirect('change-locale/' . $page_translation->locale . '/' . $page_translation->slug);
         }
         $array = ['page' => $page, 'i' => NULL, 'dt' => false];
         if ($page->type == 'blank' || $page->type == 'external') {
             return abort(404);
         }
         $slug = $page_translation->slug;
         if ($slug == 'postulacion-a' || $slug == 'postulacion-b') {
             if (!\Auth::check()) {
                 return redirect()->guest('auth/login');
             }
             if (request()->has('postulation_a') && $slug == 'postulacion-a') {
                 if (!\Auth::user()->registry_a()->whereHas('postulation_a', function ($query) {
                     $query->where('id', request()->input('postulation_a'));
                     $query->where('status', 'holding');
                 })->first()) {
                     return redirect('postulaciones')->with(['message_error' => 'No tiene acceso para editar este formulario.']);
                 }
             } else {
                 if (request()->has('postulation_b') && $slug == 'postulacion-b') {
                     if (!\Auth::user()->registry_b()->whereHas('postulation_b', function ($query) {
                         $query->where('id', request()->input('postulation_b'));
                         $query->where('status', 'holding');
                     })->first()) {
                         return redirect('postulaciones')->with(['message_error' => 'No tiene acceso para editar este formulario.']);
                     }
                 } else {
                     return redirect('postulaciones')->with(['message_error' => 'Hubo un error al realizar su consulta.']);
                 }
             }
         }
         foreach ($page->nodes as $node) {
             $array = \Segment::get_node_array($array, $node, $page);
         }
         $array = array_merge($array, \CustomFunc::get_page_array($page));
         if ($page->type == 'customized') {
             if ($page->customized_name == 'home') {
                 $array['social_networks'] = \App\SocialNetwork::get();
             } else {
                 if ($page->customized_name == 'postulaciones') {
                     $array['registry_a'] = \Auth::user()->registry_a;
                     $array['registry_b'] = \Auth::user()->registry_b;
                 }
             }
             return view('content.' . $page->customized_name, $array);
         } else {
             return view('content.page', $array);
         }
     } else {
         return abort(404);
     }
 }
Exemplo n.º 8
0
 function testTimestamps()
 {
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "integer-timestamp", "timestamp" => (int) mktime(0, 0, 0, date('n'), 1, date('Y')))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "string-integer-timestamp", "timestamp" => (string) mktime(0, 0, 0, date('n'), 1, date('Y')))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "iso8630-timestamp", "timestamp" => date(DATE_ATOM, mktime(0, 0, 0, date('n'), 1, date('Y'))))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "iso8601-timestamp", "timestamp" => date(DATE_ATOM, mktime(0, 0, 0, date('n'), 1, date('Y'))))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "strtotime-timestamp", "timestamp" => strtotime('1 week ago'))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "microtime-timestamp", "timestamp" => microtime(true))));
     $this->assertTrue(Segment::track(array("userId" => "user-id", "event" => "invalid-float-timestamp", "timestamp" => (string) mktime(0, 0, 0, date('n'), 1, date('Y')) . '.')));
 }
 public function measurements()
 {
     ////////////////MEASUREMENT HEAD////////////////
     $ids = DB::table('tblMeasurementHeader')->select('strMeasurementID')->orderBy('created_at', 'desc')->orderBy('strMeasurementID', 'desc')->take(1)->get();
     $ID = $ids["0"]->strMeasurementID;
     $categoryNewID = $this->smartCounter($ID);
     $records = MeasurementHead::all();
     $array = array();
     foreach ($records as $record) {
         if (count($array) == 0) {
             $item1 = array();
             $item1[0] = $record->strCategoryName;
             $item1[1] = $record->strSegmentName;
             $item1[2] = [$record->strMeasurementName];
             array_push($array, $item1);
             continue;
         }
         $doesExist = FALSE;
         foreach ($array as $checker) {
             if ($checker[0] == $record->strCategoryName && $checker[1] == $record->strSegmentName) {
                 $doesExist = TRUE;
                 break;
             }
         }
         if (!$doesExist) {
             $itemPush = array();
             $itemPush[0] = $record->strCategoryName;
             $itemPush[1] = $record->strSegmentName;
             $itemPush[2] = [$record->strMeasurementName];
             array_push($array, $itemPush);
             continue;
         }
         for ($i = 0; $i < count($array); $i++) {
             if ($array[$i][0] == $record->strCategoryName && $array[$i][1] == $record->strSegmentName) {
                 array_push($array[$i][2], $record->strMeasurementName);
             }
         }
     }
     $head = DB::table('tblMeasurementHeader AS a')->leftJoin('tblGarmentCategory AS b', 'a.strCategoryName', '=', 'b.strGarmentCategoryID')->leftJoin('tblGarmentSegment AS c', 'a.strSegmentName', '=', 'c.strGarmentSegmentID')->leftJoin('tblMeasurementDetail AS d', 'a.strMeasurementName', '=', 'd.strMeasurementDetailID')->leftJoin('tblReasonMeasurementCategory AS e', 'a.strMeasurementID', '=', 'e.strInactiveHeadID')->select('a.*', 'b.strGarmentCategoryName', 'c.strGarmentSegmentName', 'd.strMeasurementDetailName', 'e.strInactiveHeadID', 'e.strInactiveReason')->orderBy('created_at')->get();
     $category = Category::all();
     $segment = Segment::all();
     $detailList = MeasurementDetail::all();
     $reasonHead = ReasonMeasurementCategory::all();
     ////////////////MEASUREMENT HEAD////////////////
     ////////////////MEASUREMENT DETAILS////////////////
     $ids = DB::table('tblMeasurementDetail')->select('strMeasurementDetailID')->orderBy('created_at', 'desc')->orderBy('strMeasurementDetailID', 'desc')->take(1)->get();
     $ID = $ids["0"]->strMeasurementDetailID;
     $detailNewID = $this->smartCounter($ID);
     $detail = MeasurementDetail::all();
     $reasonDetail = ReasonMeasurementDetail::all();
     $detail = DB::table('tblMeasurementDetail')->leftJoin('tblReasonMeasurementDetail', 'tblMeasurementDetail.strMeasurementDetailID', '=', 'tblReasonMeasurementDetail.strInactiveDetailID')->select('tblMeasurementDetail.*', 'tblReasonMeasurementDetail.strInactiveDetailID', 'tblReasonMeasurementDetail.strInactiveReason')->orderBy('created_at')->get();
     ////////////////MEASUREMENT DETAILS////////////////
     // dito magbabago
     return View::make('measurements')->with('head', $head)->with('detail', $detail)->with('reasonDetail', $reasonDetail)->with('reasonHead', $reasonHead)->with('categoryNewID', $categoryNewID)->with('detailNewID', $detailNewID)->with('category', $category)->with('segment', $segment)->with('detailList', $detailList);
 }
 public function pattern()
 {
     $ids = DB::table('tblDesignPattern')->select('strDesignPatternID')->orderBy('created_at', 'desc')->orderBy('strDesignPatternID', 'desc')->take(1)->get();
     $ID = $ids["0"]->strDesignPatternID;
     $newID = $this->smartCounter($ID);
     $category = Category::all();
     $segment = Segment::all();
     $reason = ReasonDesignPattern::all();
     $pattern = DB::table('tblDesignPattern')->join('tblGarmentCategory', 'tblDesignPattern.strDesignCategory', '=', 'tblGarmentCategory.strGarmentCategoryID')->join('tblGarmentSegment', 'tblDesignPattern.strDesignSegmentName', '=', 'tblGarmentSegment.strGarmentSegmentID')->leftJoin('tblReasonDesignPattern', 'tblDesignPattern.strDesignPatternID', '=', 'tblReasonDesignPattern.strInactivePatternID')->select('tblDesignPattern.*', 'tblGarmentCategory.strGarmentCategoryName', 'tblGarmentSegment.strGarmentSegmentName', 'tblReasonDesignPattern.strInactivePatternID', 'tblReasonDesignPattern.strInactiveReason')->orderBy('strDesignPatternID')->get();
     return View::make('designPattern')->with('newID', $newID)->with('pattern', $pattern)->with('category', $category)->with('reason', $reason)->with('segment', $segment);
 }
Exemplo n.º 11
0
 /**
  * test grabbing a Trail Relationship by segmentType
  **/
 public function testGetValidTrailRelationshipBySegmentType()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("trailRelationship");
     //create a new Trail Relationship and insert it into mySQL
     $trailRelationship = new TrailRelationship($this->segment->getSegmentId(), $this->trail->getTrailId(), $this->VALID_SEGMENTTYPE);
     $trailRelationship->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoTrailRelationship = TrailRelationship::getTrailRelationshipBySegmentType($this->getPDO(), $this->VALID_SEGMENTTYPE);
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("trailRelationship"));
     $this->assertSame($pdoTrailRelationship->getSegmentId(), $this->segment->getSegmentId());
     $this->assertSame($pdoTrailRelationship->getTrailId(), $this->trail->getTrailId());
     $this->assertSame($pdoTrailRelationship->getSegmentType(), $this->VALID_SEGMENTTYPE);
 }
 /**
  * Segment constructor.
  *
  * @param LVM $lvm
  * @param PV $physicalVolume
  * @param LV $logicalVolume
  * @param int $physicalStart
  * @param int $physicalExtentCount
  * @param int $logicalExtentCount
  * @param int $logicalStart
  * @param string $segmentType
  */
 public function __construct(LVM $lvm, PV $physicalVolume, LV $logicalVolume, $physicalStart, $physicalExtentCount, $logicalExtentCount, $logicalStart, $segmentType)
 {
     $this->lvm = $lvm;
     $this->lvm->segments[] = $this;
     $this->physicalVolume = $physicalVolume;
     $this->physicalVolume->physicalExtents[] = $this;
     $this->logicalVolume = $logicalVolume;
     $this->logicalVolume->segments[] = $this;
     $this->physicalStart = $physicalStart;
     $this->physicalExtentCount = $physicalExtentCount;
     $this->logicalExtentCount = $logicalExtentCount;
     $this->logicalStart = $logicalStart;
     $this->segmentType = $segmentType;
     parent::__construct($lvm, $physicalVolume, $logicalVolume, $physicalStart, $physicalExtentCount, $logicalExtentCount, $logicalStart);
 }
Exemplo n.º 13
0
 /**
  * send summary
  */
 public function sendAll()
 {
     // send properties of a certain user
     foreach ($this->properties as $user => $prop) {
         if (\Segment::identify(array('userId' => $user, 'traits' => $prop, 'context' => array('active' => false, 'ip' => 0)))) {
             // remove submitted property
             unset($this->properties[$user]);
         }
     }
     // track events (of a user)
     foreach ($this->events as $idx => $stat) {
         // ordinary action
         if (\Segment::track(array('userId' => $stat['user'], 'event' => $stat['action'], 'properties' => $stat['additional_info'], 'timestamp' => $stat['time']))) {
             // remove submitted event
             // oh yeah this works in php with foreach (do not try at home with a real language)
             unset($this->events[$idx]);
         }
     }
     return count($this->events) + count($this->properties) === 0;
 }
Exemplo n.º 14
0
 /**
  * This setUp function changes the date string to a DateTime object, creates a segment, creates test values for user salt and hash, and then creates user and trail entries to use for testing
  */
 public function setUp()
 {
     parent::setUp();
     // necessary DateTime format to run the test
     $this->VALID_CREATEDATE = DateTime::createFromFormat("Y-m-d H:i:s", $this->VALID_CREATEDATE);
     //create points needed for segment
     $segmentStart = new Point(35.554, 44.546);
     $segmentStop = new Point(35.554, 48.445);
     //create new segment to use for testing
     $this->segment = new Segment(null, $segmentStart, $segmentStop, 7565, 9800);
     $this->segment->insert($this->getPDO());
     //create needed dependencies to ensure user can be created to run unit testing
     $this->salt = bin2hex(openssl_random_pseudo_bytes(32));
     $this->hash = hash_pbkdf2("sha512", "iLoveIllinois", $this->salt, 262144, 128);
     //create a new user to use for testing
     $this->user = new User(null, $this->VALID_BROWSER, $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, "S", "*****@*****.**", $this->hash, "george kephart", $this->salt);
     $this->user->insert($this->getPDO());
     // create a trail to own test
     // Trail(trailId, userId, browser, createDate, ipAddress, submitTrailId, trailAccessibility, trailAmenities, trailConditions,
     $this->trail = new Trail(null, $this->user->getUserId(), "Safari", $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, null, "y", "Picnic area", "Good", "This trail is a beautiful winding trail located in the Sandia Mountains", 3, 1054.53, "la luz trail", 1, "Mostly switchbacks with a few sections of rock fall", "Heavy", "Hiking", "fpfyRTmt6XeE9ehEKZ5LwF");
     $this->trail->insert($this->getPDO());
 }
Exemplo n.º 15
0
 function testAlias()
 {
     $this->assertTrue(Segment::alias(array("previousId" => "previous-id", "userId" => "user-id")));
 }
Exemplo n.º 16
0
/**
    For each segment, the first marker and the second marker of the same segment will have the same lines. We check the line used. If it does not exist in second segment's second marker, then we know that the first marker is a junction point and needs to have a transfer.
    
    @param $path[]<Segment> the list of path segments
    @param $type<String> the type of connection (s2s,dir)
*/
function consolidatePath($path, $type)
{
    $cpath = array();
    $debug = false;
    $path_array = $path->path;
    $count = count($path_array);
    if ($debug) {
        echo "// algorithm2.php:consolidatePath()<br/>";
    }
    // this is a direction path and there is only one or two paths.
    // that means it either goes from loc->station->loc or just loc->loc
    if (($type == "dir" || $type == "dir_alt") && $count <= 2) {
        if ($debug) {
            echo "// end algorithm2.php:consolidatePath()<br/>";
        }
        return "walk";
    }
    //set up the first segment
    $segment = $path_array[0];
    if ($type == "s2s") {
        $i = 1;
    } else {
        $cpath[] = $segment;
        $segment = $path_array[1];
        $i = 2;
    }
    $marker1 = $segment->m1;
    $current_lines = $segment->m1->getOverlapLines($segment->m2);
    $connection = $segment->connection;
    $total_time = $segment->t;
    $segment2 = $path_array[$i];
    // loop through the path, starting at the next segment.
    for (; $i < $count; $i++) {
        // grab the segment
        $segment2 = $path_array[$i];
        if ($debug) {
            echo "[{$i}/{$count}]@" . $segment2->m1->name . "<br/>";
            echo "lines = ";
            foreach ($current_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        if ($connection == "transfer") {
            // we know this segment is a transfer, so they will have to get off the train
            if ($debug) {
                echo "transfer<br/>";
            }
            $lines = $marker1->getOverlapLines($segment2->m1);
            $lines = getCorrectLines($lines, "transfer");
            if ($debug) {
                echo "lines: ";
                foreach ($lines as $line) {
                    echo $line->name . " ";
                }
                echo "<br/>";
            }
            // create the transfer segment
            $new_segment = new Segment($marker1, $segment2->m1, $lines, $total_time, $connection);
            if ($debug) {
                echo "adding segment = " . $new_segment->toString() . "<br/>";
            }
            $cpath[] = $new_segment;
            $segment = $path_array[$i];
            if ($debug) {
                echo "new segment = " . $segment->toString() . "<br/>";
            }
            $marker1 = $segment->m1;
            $current_lines = $marker1->getOverlapLines($segment->m2);
            $connection = $segment->connection;
            $total_time = $segment->t;
            if ($i < $count) {
                // more segments available
                if ($debug) {
                    echo "more segments {$i}/{$count}<br/>";
                }
                continue;
            }
            // we end here with this segment
            if ($debug) {
                echo "ending after transfer<br/>";
            }
            //$current_lines = getCorrectLines($current_lines, $connection);
            //$new_segment = new Segment($segment->m1, $segment->m2, $current_lines, $total_time, $connection);
            //$cpath[] = $new_segment;
            return $cpath;
        }
        // not a transfer
        $segment_lines = array();
        // find out which lines fit the segment
        foreach ($segment2->m1->lines as $line) {
            if ($debug) {
                echo "looking @ line: " . $line->name . "<br/>";
            }
            // check the connections and find which one to go to
            foreach ($line->connections as $line_connection) {
                if ($debug) {
                    echo "looking @ connection: " . $line_connection->id . "<br/>";
                }
                if ($line_connection->id == $segment2->m2->id) {
                    $line_name = $line->name;
                    if ($debug) {
                        echo "adding line {$line_name}<br/>";
                    }
                    $segment_lines["{$line_name}"] = $line;
                    break;
                }
            }
        }
        if ($debug) {
            echo "lines that fit the segment: ";
            foreach ($segment_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        // we found all the lines that go to the marker that is next
        // now compare them to the current lines we have
        $new_lines = linesIntersect($current_lines, $segment_lines);
        if ($debug) {
            echo "lines that intersect the old: ";
            foreach ($new_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        if (count($new_lines) == 0) {
            // no overlapping lines
            // end the old segment and add to the path
            $new_segment = new Segment($marker1, $segment2->m1, $current_lines, $total_time, $connection);
            if ($debug) {
                echo "adding segment = " . $new_segment->toString() . "<br/>";
            }
            $cpath[] = $new_segment;
            // reset our variables for the next segment
            $segment = $segment2;
            $marker1 = $segment2->m1;
            $current_lines = $segment2->m1->getOverlapLines($segment2->m2);
            $connection = $segment2->connection;
            $total_time = $segment2->t;
            continue;
        }
        // we move forward
        if ($debug) {
            echo "# current_lines: " . count($new_lines) . "<br/>";
            foreach ($new_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        $current_lines = $new_lines;
        $connection = $segment2->connection;
        $total_time += $segment2->t;
    }
    // for
    // add the last segment
    if ($marker1->id != $segment2->m2->id) {
        $current_lines = getCorrectLines($current_lines, $connection);
        $new_segment = new Segment($marker1, $segment2->m2, $current_lines, $total_time, $connection);
        $cpath[] = $new_segment;
    }
    return $cpath;
}
Exemplo n.º 17
0
Arquivo: odf.php Projeto: rhertzog/lcs
 /**
  * Rajoute le segment fusionné au document
  *
  * @param Segment $segment
  * @throws OdfException
  * @return odf
  */
 public function mergeSegment(Segment $segment)
 {
     if (! array_key_exists($segment->getName(), $this->segments)) {
         throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?');
     }
     $string = $segment->getName();
     $reg = '@<text:p[^>]*>\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]<\/text:p>@smU';
     $this->contentXml = preg_replace($reg, $segment->getXmlParsed(), $this->contentXml);
     return $this;
 }
Exemplo n.º 18
0
    }
    $payload = json_decode($line, true);
    $dt = new DateTime($payload["timestamp"]);
    $ts = floatval($dt->getTimestamp() . "." . $dt->format("u"));
    $payload["timestamp"] = $ts;
    $type = $payload["type"];
    $ret = call_user_func_array(array("Segment", $type), array($payload));
    if ($ret) {
        $successful++;
    }
    $total++;
    if ($total % 100 === 0) {
        Segment::flush();
    }
}
Segment::flush();
unlink($file);
/**
 * Sent
 */
print "sent {$successful} from {$total} requests successfully";
exit(0);
/**
 * Parse arguments
 */
function parse($argv)
{
    $ret = array();
    for ($i = 0; $i < count($argv); ++$i) {
        $arg = $argv[$i];
        if ('--' != substr($arg, 0, 2)) {
Exemplo n.º 19
0
function processGuitar4svg()
{
    global $guitar, $threshold;
    //test strings ends are on nut and bridge
    //if not dont to partials
    $numStrings = sizeof($guitar['strings']);
    $doPartials = true;
    $parallelFrets = true;
    $nut = new Segment($guitar['strings'][0]->end1(), $guitar['strings'][$numStrings - 1]->end1());
    $bridge = new Segment($guitar['strings'][0]->end2(), $guitar['strings'][$numStrings - 1]->end2());
    $midline = new Segment(new Point(($nut->end2->x + $nut->end1->x) / 2, ($nut->end2->y + $nut->end1->y) / 2), new Point(($bridge->end2->x + $bridge->end1->x) / 2, ($bridge->end2->y + $bridge->end1->y) / 2));
    foreach ($guitar['strings'] as $string) {
        if (!($nut->distanceToPoint($string->end1()) < $threshold) || !($bridge->distanceToPoint($string->end2()) < $threshold)) {
            echo $string->toString(), '<br />';
            echo $nut->distanceToPoint($string->end1()), '<br />';
            echo $bridge->distanceToPoint($string->end2()), '<br />';
            $doPartials = false;
            break;
        }
    }
    $denom = ($bridge->end2->y - $bridge->end1->y) * ($nut->end2->x - $nut->end1->x) - ($bridge->end2->x - $bridge->end1->x) * ($nut->end2->y - $nut->end1->y);
    if ($denom != 0) {
        $parallelFrets = false;
    }
    $intersection = intersect($nut, $bridge);
    $strings = array();
    $tones = sizeof($guitar['scale']['steps']) - 1;
    $totalWidth = array();
    $scale = $guitar['scale']['steps'];
    for ($i = 0; $i < $numStrings; $i++) {
        $base = $guitar['tuning'][$i];
        $frets = array();
        $frets[0]['fret'] = $doPartials ? new Segment($guitar['meta'][$i]->end1, $guitar['meta'][$i + 1]->end1) : new Segment($guitar['strings'][$i]->end1, $guitar['strings'][$i]->end1);
        $frets[0]['intersection'] = $guitar['strings'][$i]->end1;
        for ($j = 1; $j <= $guitar['frets']; $j++) {
            $step = ($base + $j - 1) % $tones + 1;
            //		$step=(($base+$j)%($tones-1))+1;
            //		$step=$step==0?1:$step;
            $ratio = 1 - $scale[$step][1] * $scale[$step - 1][0] / ($scale[$step][0] * $scale[$step - 1][1]);
            $x = $frets[$j - 1]['intersection']->x + $ratio * ($guitar['strings'][$i]->end2->x - $frets[$j - 1]['intersection']->x);
            $y = $frets[$j - 1]['intersection']->y + $ratio * ($guitar['strings'][$i]->end2->y - $frets[$j - 1]['intersection']->y);
            $frets[$j]['intersection'] = new Point($x, $y);
            $temp = new Segment($guitar['strings'][$i]->end1(), $frets[$j]['intersection']);
            $frets[$j]['nutDist'] = $temp->length();
            $frets[$j]['totalRatio'] = $frets[$j]['nutDist'] / $guitar['strings'][$i]->length();
            if ($doPartials) {
                /*			//partials depending on nut bridge intersection (bad)
                				$temp=$parallelFrets?
                					$nut->createParallel($frets[$j]['intersection']):
                					new Segment($intersection,$frets[$j]['intersection']);
                				$frets[$j]['fret']=new Segment(intersect($temp,$guitar['meta'][$i]),
                						intersect($temp,$guitar['meta'][$i+1]));
                				//partials depending on meta lines (questionable)
                				if ($parallelFrets)
                				{
                					$frets[$j]['fret']=$nut->createParallel($frets[$j]['intersection']);
                				}
                				else
                				{
                					$frets[$j]['fret']=new Segment(
                						$guitar['meta'][$i]->pointAt($guitar['meta'][$i]->length()*
                							$frets[$j]['totalRatio']),
                						$guitar['meta'][$i+1]->pointAt($guitar['meta'][$i+1]->length()*
                							$frets[$j]['totalRatio'])
                						);
                				}
                	*/
                //partials depending on outer strings (questionable)
                if ($parallelFrets) {
                    $temp = $nut->createParallel($frets[$j]['intersection']);
                } else {
                    $temp = new Segment($guitar['strings'][0]->pointAt($guitar['strings'][0]->length() * $frets[$j]['totalRatio']), $guitar['strings'][$numStrings - 1]->pointAt($guitar['strings'][$numStrings - 1]->length() * $frets[$j]['totalRatio']));
                }
                $frets[$j]['fret'] = new Segment(intersect($temp, $guitar['meta'][$i]), intersect($temp, $guitar['meta'][$i + 1]));
            } else {
                $frets[$j]['fret'] = new Segment($frets[$j]['intersection'], $frets[$j]['intersection']);
            }
        }
        $strings[] = $frets;
    }
    return array('strings' => $strings, 'midline' => $midline, 'nut' => $nut, 'bridge' => $bridge);
}
Exemplo n.º 20
0
 public function index()
 {
     C('TOKEN_ON', false);
     $seo = seo();
     $this->assign("seo", $seo);
     if (isset($_GET['q'])) {
         G('search');
         //关键字
         $q = Input::forSearch(safe_replace($this->_get("q")));
         $q = htmlspecialchars(strip_tags($q));
         //时间范围
         $time = $this->_get("time");
         //模型
         $mid = (int) $this->_get("modelid");
         //栏目
         $catid = (int) $this->_get("catid");
         //排序
         $order = array("adddate" => "DESC", "searchid" => "DESC");
         //搜索历史记录
         $shistory = cookie("shistory");
         if (!$shistory) {
             $shistory = array();
         }
         $model = F("Model");
         $category = F("Category");
         if (trim($_GET['q']) == '') {
             header('Location: ' . U("Search/Index/index"));
             exit;
         }
         array_unshift($shistory, $q);
         $shistory = array_slice(array_unique($shistory), 0, 10);
         //加入搜索历史
         cookie("shistory", $shistory);
         $where = array();
         //每页显示条数
         $pagesize = $this->config['pagesize'] ? $this->config['pagesize'] : 10;
         //缓存时间
         $cachetime = (int) $this->config['cachetime'];
         //按时间搜索
         if ($time == 'day') {
             //一天
             $search_time = time() - 86400;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'week') {
             //一周
             $search_time = time() - 604800;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'month') {
             //一月
             $search_time = time() - 2592000;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'year') {
             //一年
             $search_time = time() - 31536000;
             $where['adddate'] = array("GT", $search_time);
         } else {
             $search_time = 0;
         }
         //可用数据源
         $this->config['modelid'] = $this->config['modelid'] ? $this->config['modelid'] : array();
         //按模型搜索
         if ($mid && in_array($mid, $this->config['modelid'])) {
             $where['modelid'] = array("EQ", (int) $mid);
         }
         //按栏目搜索
         if ($catid) {
             //不支持多栏目搜索,和父栏目搜索。
             $where['catid'] = array("EQ", (int) $catid);
         }
         //分页模板
         $TP = '共有{recordcount}条信息&nbsp;{pageindex}/{pagecount}&nbsp;{first}{prev}{liststart}{list}{listend}{next}{last}';
         //如果开启sphinx
         if ($this->config['sphinxenable']) {
             import("Sphinxapi", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
             $sphinxhost = $this->config['sphinxhost'];
             $sphinxport = $this->config['sphinxport'];
             $cl = new SphinxClient();
             //设置searchd的主机名和TCP端口
             $cl->SetServer($sphinxhost, $sphinxport);
             //设置连接超时
             $cl->SetConnectTimeout(1);
             //控制搜索结果集的返回格式
             $cl->SetArrayResult(true);
             //设置全文查询的匹配模式 api http://docs.php.net/manual/zh/sphinxclient.setmatchmode.php
             $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
             //设置排名模式 api http://docs.php.net/manual/zh/sphinxclient.setrankingmode.php
             $cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
             //按一种类似SQL的方式将列组合起来,升序或降序排列。用weight是权重排序
             $cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc");
             //设置返回结果集偏移量和数目
             $page = (int) $this->_get(C("VAR_PAGE"));
             $page = $page < 1 ? 1 : $page;
             $offset = $pagesize * ($page - 1);
             $cl->SetLimits($offset, $pagesize, $pagesize > 1000 ? $pagesize : 1000);
             if (in_array($time, array("day", "week", "month", "year"))) {
                 //过滤时间
                 $cl->SetFilterRange('adddate', $search_time, time(), false);
             }
             if ($mid && in_array($mid, $this->config['modelid'])) {
                 //过滤模型
                 $cl->SetFilter('modelid', (int) $mid);
             }
             if ($catid) {
                 //过滤栏目
                 $cl->SetFilter('catid', (int) $catid);
             }
             //执行搜索 api http://docs.php.net/manual/zh/sphinxclient.query.php
             $res = $cl->Query($q, "*");
             //信息总数
             $count = $res['total'];
             //如果结果不为空
             if (!empty($res['matches'])) {
                 $result_sphinx = $res['matches'];
             }
             $result = array();
             //数组重新组合
             foreach ($result_sphinx as $k => $v) {
                 $result[$k] = array("searchid" => $v['id'], "adddate" => $v['attrs']['adddate'], "catid" => $v['attrs']['catid'], "id" => $v['attrs']['id'], "modelid" => $v['attrs']['modelid']);
             }
             $words = array();
             //搜索关键字
             foreach ($res['words'] as $k => $v) {
                 $words[] = $k;
             }
             $page = page($count, $pagesize);
             $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
             $this->assign("Page", $page->show('default'));
         } else {
             import("Segment", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
             $Segment = new Segment();
             //分词结果
             $segment_q = $Segment->get_keyword($Segment->split_result($q));
             $words = explode(" ", $segment_q);
             if (!empty($segment_q)) {
                 $where['_string'] = " MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE) ";
             } else {
                 //这种搜索最不行
                 $where['data'] = array('like', "%{$q}%");
             }
             //查询结果缓存
             if ($cachetime) {
                 //统计
                 $count = M("Search")->cache(true, $cachetime)->where($where)->count();
                 $page = page($count, $pagesize);
                 $result = M("Search")->cache(true, $cachetime)->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select();
             } else {
                 $count = M("Search")->where($where)->count();
                 $page = $this->page($count, $pagesize);
                 $result = M("Search")->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select();
             }
             $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
             $this->assign("Page", $page->show('default'));
         }
         //搜索结果处理
         if ($result && is_array($result)) {
             foreach ($result as $k => $r) {
                 $modelid = $r['modelid'];
                 $id = $r['id'];
                 $tablename = ucwords($model[$modelid]['tablename']);
                 if ($tablename) {
                     $result[$k] = M($tablename)->where(array("id" => $id))->find();
                 }
             }
         }
         //搜索记录
         if (strlen($q) < 17 && strlen($q) > 1 && $result) {
             $res = M("SearchKeyword")->where(array('keyword' => $q))->find();
             if ($res) {
                 //关键词搜索数+1
                 M("SearchKeyword")->where(array('keyword' => $q))->setInc("searchnums");
             } else {
                 //关键词转换为拼音
                 load("@.iconvfunc");
                 $pinyin = gbk_to_pinyin(iconv('utf-8', 'gbk//IGNORE', $q));
                 if (is_array($pinyin)) {
                     $pinyin = implode('', $pinyin);
                 }
                 M("SearchKeyword")->add(array('keyword' => $q, 'searchnums' => 1, 'data' => $segment_q, 'pinyin' => $pinyin));
             }
         }
         //相关搜索功能
         if ($this->config['relationenble']) {
             $map = array();
             //相关搜索
             if (!empty($segment_q)) {
                 $relation_q = str_replace(' ', '%', $segment_q);
             } else {
                 $relation_q = $q;
             }
             $map['_string'] = " MATCH (`data`) AGAINST ('%{$relation_q}%' IN BOOLEAN MODE) ";
             $relation = M("SearchKeyword")->where($map)->select();
             $this->assign("relation", $relation);
         }
         foreach ($this->config['modelid'] as $modelid) {
             $source[$modelid] = array("name" => $model[$modelid]['name'], "modelid" => $modelid);
         }
         //搜索结果
         $this->assign("result", $result);
         //运行时间
         $search_time = G('search', 'end', 6);
         $this->assign("count", $count ? $count : 0);
         $this->assign("search_time", $search_time);
         $this->assign("keyword", $q);
         $this->assign("category", $category);
         $this->assign("source", $source);
         $this->assign("time", $time);
         $this->assign("modelid", $mid);
         $this->assign("shistory", $shistory);
         //分词后的搜索关键字
         $this->assign("words", $words);
         $this->display("search");
     } else {
         $this->display();
     }
 }
Exemplo n.º 21
0
 $terrain = filter_input(INPUT_GET, "terrain", FILTER_SANITIZE_STRING);
 $traffic = filter_input(INPUT_GET, "traffic", FILTER_SANITIZE_STRING);
 $use = filter_input(INPUT_GET, "use", FILTER_SANITIZE_STRING);
 $uuid = filter_input(INPUT_GET, "uuid", FILTER_SANITIZE_STRING);
 // handle all restful calls
 // get some of all trails
 if ($method === "GET") {
     setXsrfCookie("/");
     if (empty($id) === false) {
         $reply->data = Trail::getTrailById($pdo, $id);
         // Grab segments
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $id);
         $points = [];
         foreach ($trailRelationships as $trailRelationship) {
             $points[] = [Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStart()->getY(), Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStart()->getX()];
             $points[] = [Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStop()->getY(), Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId())->getSegmentStop()->getX()];
         }
         // Add segments to reply
         $reply->points = $points;
     } elseif (empty($userId) === false) {
         $reply->data = Trail::getTrailByUserId($pdo, $userId)->toArray();
     } elseif (empty($submitId) === false) {
         $reply->data = Trail::getTrailBySubmitTrailId($pdo, $submitId)->toArray();
     } elseif (empty($amenities) === false) {
         $reply->data = Trail::getTrailByTrailAmenities($pdo, $amenities)->toArray();
     } elseif (empty($condition) === false) {
         $reply->data = Trail::getTrailByTrailCondition($pdo, $condition)->toArray();
     } elseif (empty($description) === false) {
         $reply->data = Trail::getTrailByTrailDescription($pdo, $description)->toArray();
     } elseif (empty($difficulty) === false) {
         $reply->data = Trail::getTrailByTrailDifficulty($pdo, $difficulty)->toArray();
 public function reactGarmentSegment()
 {
     $id = Input::get('reactID');
     $isAdded = FALSE;
     if (!$isAdded) {
         $segment = Segment::find($id);
         $reas = Input::get('reactInactiveSegment');
         $reason = DB::table('tblReasonSegment')->where('strInactiveSegmentID', '=', $reas)->delete();
         $segment->boolIsActive = 1;
         $segment->save();
         return Redirect::to('/utilities/inactiveData?successRec=true');
     } else {
         return Redirect::to('/utilities/inactiveData?successRec=false');
     }
 }
Exemplo n.º 23
0
$category = $_POST['category'];
$canCon = isset($_POST['can_con']);
$newRelease = isset($_POST['new_release']);
$frenchVocalMusic = isset($_POST['french_vocal_music']);
$editSegment = isset($_POST['is_existing_segment']);
$segmentId = $_POST['segment_id'];
if (!isset($episodeId) || $episodeId <= 0) {
    outputErrorResponse("Invalid episode ID");
}
try {
    $db = connectToDatabase();
    $episode = new Episode($db, $episodeId);
    $episodeStartDateTime = $episode->getStartTime();
    $segmentTime = addDateToSegmentStartTime($episodeStartDateTime, $segmentTime);
    $playlistId = $episode->getPlaylistId();
    $segment = new Segment($db, $segmentId);
    $segment->setCategory($category);
    $segment->setPlaylistId($playlistId);
    $segment->setDuration(null);
    $segment->setStartTime($segmentTime);
    switch ($category) {
        case 2:
        case 3:
            $segment->setName($name);
            $segment->setAuthor($author);
            $segment->setAlbum($album);
            $segment->setCategory($category);
            $segment->setIsCanCon($canCon);
            $segment->setIsNewRelease($newRelease);
            $segment->setIsFrenchVocalMusic($frenchVocalMusic);
            $segment->setAdNumber(null);
Exemplo n.º 24
0
/**
    For each segment, the first marker and the second marker of the same segment will have the same lines. We check the line used. If it does not exist in second segment's second marker, then we know that the first marker is a junction point and needs to have a transfer.
    
    @param $path[]<Segment> the list of path segments
    @param $type<String> the type of connection (s2s,dir)
    
    @deprecated
*/
function consolidatePath2($path, $type)
{
    $cpath = array();
    /*
        What are the conditions that determine a transfer?
        1. If the connection type is different (express -> local)
        2. If the train in the next segment is different and the original one is not available
        3. if the connection type is transfer
    */
    // debugging
    $debug = true;
    $path_array = $path->path;
    $count = count($path_array);
    // this is a direction path and there is only one or two paths.
    // that means it either goes from loc->station->loc or just loc->loc
    if ($type == "dir" && $count <= 2) {
        return "walk";
    }
    //set up the first segment
    $segment = $path_array[0];
    if ($type == "s2s") {
        $i = 1;
    } else {
        $cpath[] = $segment;
        $segment = $path_array[1];
        $i = 2;
    }
    $marker1 = $segment->m1;
    $current_lines = $segment->m1->getOverlapLines($segment->m2);
    $connection = $segment->connection;
    $total_time = $segment->t;
    $segment2 = $path_array[$i + 1];
    // loop through the path, starting at the next segment.
    for (; $i < $count; $i++) {
        // grab the segment
        $segment2 = $path_array[$i];
        if ($debug) {
            echo "@" . $segment2->m1->name . "<br/>";
            echo "lines = ";
            foreach ($current_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        if ($connection == "transfer") {
            // we know this segment is a transfer, so they will have to get off the train
            echo "transfer<br/>";
            // end the segment
            $new_segment = new Segment($marker1, $segment2->m1, $current_lines, $total_time, $connection);
            if ($debug) {
                echo "segment = " . $new_segment->toString() . "<br/>";
            }
            $cpath[] = $new_segment;
            // add the transfer segment
            // we need to get the transfer lines
            $lines = $segment2->m1->getOverlapLines($segment2->m2);
            $lines = getCorrectLines($lines, $segment2->connection);
            // create new segment
            $new_segment = new Segment($segment2->m1, $segment2->m2, $lines, $segment2->t, $segment2->connection);
            $cpath[] = $new_segment;
            // increment if we need to
            if ($i < $count) {
                // increment
                $i++;
                $segment = $path_array[$i];
                $marker1 = $segment->m1;
                $current_lines = $segment->m1->getOverlapLines($segment->m2);
                $connection = $segment->connection;
                $total_time = $segment->t;
                if ($i < $count) {
                    // more segments available
                    continue;
                }
                // we end here with this segment
                $new_segment = new Segment($segment->m1, $segment->m2, $current_lines, $total_time, $connection);
                $cpath[] = $new_segment;
                return $cpath;
            }
        } else {
            if ($connection != $segment2->connection) {
                // the connection types are different, but trains can shift from express to local and vice versa.
                if ($debug) {
                    echo "old conn: " . $connection . " | new conn: " . $segment2->connection . "<br/>";
                }
                // do we have the same train available?
                if (sameTrain($current_lines, $segment2)) {
                    // it's the same train, so we just update our lines and continue
                    $current_lines = updateLines($segment, $current_lines);
                    $total_time += $segment2->t;
                    $connection = $segment2->connection;
                    continue;
                }
                // different trains, so we need to transfer
                // end the old segment and add to the path
                $new_segment = new Segment($marker1, $segment2->m1, $current_lines, $total_time, $connection);
                if ($debug) {
                    echo "new_segment = " . $new_segment->toString() . "<br/>";
                }
                $cpath[] = $new_segment;
                // reset our variables for the next segment
                $segment = $segment2;
                $marker1 = $segment2->m1;
                $current_lines = $segment2->m1->getOverlapLines($segment2->m2);
                $connection = $segment2->connection;
                $total_time = $segment2->t;
                continue;
            } else {
                if (!sameTrain($current_lines, $segment2)) {
                    // different trains, so we need to transfer
                    if ($debug) {
                        echo "old lines: ";
                        foreach ($current_lines as $line) {
                            echo $line->name . " ";
                        }
                        echo "<br/>";
                        echo "new line: " . $segment2->lines[0]->name . "<br/>";
                    }
                    // end the old segment and add to the path
                    $new_segment = new Segment($marker1, $segment2->m1, $current_lines, $total_time, $connection);
                    if ($debug) {
                        echo "new_segment = " . $new_segment->toString() . "<br/>";
                    }
                    $cpath[] = $new_segment;
                    // reset our variables for the next segment
                    $segment = $segment2;
                    $marker1 = $segment2->m1;
                    $current_lines = $segment2->m1->getOverlapLines($segment2->m2);
                    $connection = $segment2->connection;
                    $total_time = $segment2->t;
                    continue;
                }
            }
        }
        // otherwise, we keep going and merge the segments
        $current_lines = linesIntersect($current_lines, $segment2->m1->getOverlapLines($segment2->m2));
        if ($debug) {
            echo "# current_lines after intersect: " . count($current_lines) . "<br/>";
            foreach ($current_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        $current_lines = getCorrectLines($current_lines, $connection);
        if ($debug) {
            echo "# current_lines after correction: " . count($current_lines) . "<br/>";
            foreach ($current_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        $connection = $segment2->connection;
        $total_time = $segment2->t;
    }
    // for
    // add the last segment
    $new_segment = new Segment($marker1, $segment2->m2, $current_lines, $total_time, $connection);
    $cpath[] = $new_segment;
    return $cpath;
}
Exemplo n.º 25
0
 /**
  * calculates trail distance using phpgeo composer package.
  **/
 public static function calculateTrailDistance()
 {
     $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
     $trails = Trail::getAllTrails($pdo);
     $testNum = 0;
     foreach ($trails as $trail) {
         $testNum++;
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $trail->getTrailId());
         $track = new Polyline();
         foreach ($trailRelationships as $trailRelationship) {
             $segment = Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId());
             $track->addPoint(new Coordinate($segment->getSegmentStart()->getY(), $segment->getSegmentStart()->getX()));
             $track->addPoint(new Coordinate($segment->getSegmentStop()->getY(), $segment->getSegmentStop()->getX()));
         }
         $trailDistanceM = $track->getLength(new Vincenty());
         $trailDistanceMi = $trailDistanceM / 1609.344;
         $trailDistance = $trailDistanceMi;
         $trail->setTrailDistance($trailDistance);
         $trail->update($pdo);
     }
 }
Exemplo n.º 26
0
 /**
  * Creates a segment instance
  *
  * @param string $marker
  * @param [:int] $data
  */
 public function __construct($marker, $text)
 {
     parent::__construct($marker, null);
     $this->text = $text;
 }
Exemplo n.º 27
0
 /**
  * Add the merged segment to the document
  *
  * @param Segment $segment
  * @throws OdfException
  * @return odf
  */
 public function mergeSegment(Segment $segment)
 {
     if (!array_key_exists($segment->getName(), $this->segments)) {
         throw new OdfException($segment->getName() . 'cannot be parsed, has it been set yet ?');
     }
     $string = $segment->getName();
     // $reg = '@<text:p[^>]*>\[!--\sBEGIN\s' . $string . '\s--\](.*)\[!--.+END\s' . $string . '\s--\]<\/text:p>@smU';
     $reg = '@\\[!--\\sBEGIN\\s' . $string . '\\s--\\](.*)\\[!--.+END\\s' . $string . '\\s--\\]@smU';
     $this->contentXml = preg_replace($reg, $segment->getXmlParsed(), $this->contentXml);
     foreach ($segment->manif_vars as $val) {
         $this->manif_vars[] = $val;
     }
     //copy all segment image names into current array
     return $this;
 }
Exemplo n.º 28
0
                // verify the segment in question exists
                if ($segment === null) {
                    throw new RuntimeException("segment must exist", 404);
                }
                $segment = new Segment($id, $segmentStart, $segmentStop, $requestObject->segmentStartElevation, $requestObject->segmentStopElevation);
                $segment->update($pdo);
                $reply->message = "segment update was successful";
            }
            if ($method === "POST") {
                // form a mini-constructor to assemble a segmentStart and a segmentStop....?????
                $segment = new Segment(null, $segmentStart, $segmentStop, $requestObject->segmentStartElevation, $requestObject->segmentStopElevation);
                $segment->insert($pdo);
                $reply->message = "segment insert was successful";
            }
        } elseif ($method === "DELETE") {
            $segment = Segment::getSegmentBySegmentId($pdo, $id);
            if ($segment === null) {
                throw new RuntimeException("segment must exist", 404);
            }
            $segment->delete($pdo);
            $deletedObject = new stdClass();
            $deletedObject->segmentId = $id;
            $reply->message = "segment was successfully Deleted";
        } else {
            if (empty($method) === false && $method !== "GET") {
                throw new RuntimeException("only active users are allowed to modify entries", 401);
            }
        }
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
Exemplo n.º 29
0
 static function getLangHandler($language)
 {
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $filter_word_like_any = $cparams->get('filter_word_like_any', 0);
     if ($language == 'th-TH' && $filter_word_like_any == 0) {
         $segmenter_path = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'THSplitLib' . DS . 'segment.php';
         if (JFile::exists($segmenter_path)) {
             require_once $segmenter_path;
             // Apply caching to dictionary parsing regardless of cache setting ...
             $handlercache = JFactory::getCache('com_flexicontent_lang_handlers');
             // Get Joomla Cache of '... lang_handlers' Caching Group
             $handlercache->setCaching(1);
             // Force cache ON
             $handlercache->setLifeTime(24 * 3600);
             // Set expire time (hard-code this to 1 day), since it is costly
             $dictionary = $handlercache->call(array('Segment', 'loadDictionary'));
             Segment::setDictionary($dictionary);
             $handler = new Segment();
             return $handler;
         }
     }
     return false;
 }
Exemplo n.º 30
0
 /**
  * Creates a segment instance
  *
  * @param string $marker
  * @param [:var] $data
  */
 public function __construct($marker, $data)
 {
     parent::__construct($marker, NULL);
     $this->data = $data;
 }