Propel2 criterions

Propel2 do not have mysql’s full text search support out of the box.
Of course you can do

$movies = MovieQuery::create()
    -> where('MATCH(Movie.title, Movie.director) AGAINST(? IN BOOLEAN MODE)',
             'big lebowski')
    -> find();

credits to jengeb

This doesn’t looks good for reuse. You can create a Query helper class, but it is still doesn’t looks right.

Here comes the criterions.

Criterions are something like where clauses.

Lets make quick example about in criterion

First we need the ModelCriteria. Basically this is the Query class.

There is this method called `combine`….

Combine several named criterions with a logical operator

So, we need the Criterion.

The easiest way is using the getNewCriterion method

$criterion = $modelCriteria->getNewCriterion(
   'id', // sql field
   12345, // desired value
   '=' // condition name
);

Then we have to add the criterion to the query. This won’t apply the criterion filter!

$modelCriteria->addCond('myCondition', $criterion);

Lets add the criterion to desired filter.

$query->combine(['myCondition']);

This looks too complicated, but actually it is very helpful when you are building something like API.

So, lets back to the full text search. Here is example code of full text search criterion

use Propel\Runtime\ActiveQuery\Criterion\AbstractCriterion;
use Propel\Runtime\ActiveQuery\Criteria;

/**
 * Criterion for MySQL/MariaDB full text search
 *
 * @author po_taka
 */
class FullTextCriterion extends AbstractCriterion
{
    /**
     * Create a new instance.
     *
     * @param Criteria $outer      The outer class (this is an "inner" class).
     * @param string   $column     ignored
     * @param string   $value      The condition to be added to the query string
     * @param string   $comparison SQL MATCH modifier
     */
    public function __construct(Criteria $outer, $column, $value, $comparison = 'IN NATURAL LANGUAGE MODE')
    {
        return parent::__construct($outer, $column, $value, $comparison);
    }

    /**
     * Appends a Prepared Statement representation of the Criterion onto the buffer
     *
     * @param string &$sb    The string that will receive the Prepared Statement
     * @param array  $params A list to which Prepared Statement parameters will be appended
     */
    protected function appendPsForUniqueClauseTo(&$sb, array &$params)
    {
        $field = (null === $this->table) ? $this->column : $this->table . '.' . $this->column;

        $params[] = [
            'table' => $this->realtable,
            'column' => $this->column,
            'value' => $this->value,
        ];

        $sb .= " MATCH (" . $field . ") AGAINST( :p" . count($params) . " " . $this->comparison . ") ";
    }
}

This should be safe against sql injections 🙂 This is the benefit instead of using $query->where('MATCH (my_field) AGAINS "' . $param '")

Example usage

$criterion = new FullTextCriterion(
   $query,
   'my_field',
   'I\'m looking for this text :)'
 );
$modelCriteria->addCond('myCondition', $criterion);
$query->combine(['myCondition']);

I was planing to release some small package for propel2, but I don’t think that anyone will ever use it :/

Posted in php | Comments Off on Propel2 criterions

MTB statistic 2017

MTB statistic 2015

1x RS pike. Yes, I broke the lyrik. I will post more detail later.

3x grips

1x shimano m8000 front brake. The elixir 7 worked fine, I just wanted to move to mineral oil.

~10x inner tubes. Used for ghetto tubeless

1x Kenny full face helmet. I did a lot of bike riding, climbing is via the lift, so width is not a problem. FF protection is ff protection 🙂

1x googles – Smith

1x backpack, Evoc FR. Excellent backpack. The old one have too many fixes.

2x tyres. Maxxis DHR II

1x shoes, Scott FR 10

Posted in mtb | Comments Off on MTB statistic 2017

Booking – free entrance to attractions

Hm, a few weeks ago I decided to go to Rome. I bought flight tickets. A few days before the flight I opened booking.com and searched for hotel. I choosed one of the cheapest – 150 Euro for three nights.

Moments after the reservation I received mail “Angel, you’ve got free entrance to Rome attractions”. I Think to myself “hmmm…some discounts for overprices tours”. Anyway I opened the mail, just to check the attractions. May be I missed some of them in my plans.

And OMG, what the !??!?!? I have free access to so many attraction. And not just me, everyone in my group!

Ohhh, wait… this can’t be true.

I searched over the interned if anyone have used this promotion. I didn’t find and single result.

Just look at these discounts:

I booked room for 150 euro. Entrance for the Catacombs is 60 euros / person. Colosseum  is ~60 euro per person. We were two, we just received 240 euros discounts for 150 euro reservation?!

I keep looked in the internet if this is true. The time passed and we were flying to Rome.

We used the QR code for the first time for airport shuttle bus. We just shown the QR code to the ticket’s girl, she scanned the code and says “ok, all good, you can enter the bus”.

Traveling to the Rimini station I start asking myself – we just saved 12 euro. What if this promotion is one time only? I could save 120 euro from Colosseum tour. Aught!

We decided to try the Hop-on-hop-off bus. Unfortunately they can’t scan the QR code from all stations. The personal told us to get on the bus and show the QR code on the Termini station. I told to myself, aught, what if the code doesn’t work, I will have to pay 44 euro for tickets! We are at the Termini station. Scanning the code…. It works!!! It works! For seconds time.

Then we reserved tour to the Colosseum and the Catacombs. The QR code worked!

I’m writing this post just to confirm – the QR code works for all destinations for the whole group!

There is single time when it didn’t work. As I have noted, we took the bus shuttle from the Airport to the Rome. When we took the bus from Rome to the airport the QR code didn’t worked. The ticket’s guy told us that it is already used. So, probably you can use it only once per attraction. Anyway, we bought tickets – 16 euro. We saved 500+ euros from this QR code.

Posted in Travelling | Comments Off on Booking – free entrance to attractions

Scott FR 10 shoes

Recently I bought Scott FR 10 shoes. They were 15% off, so why not 🙂

Price: ~60 Euro.

Disadvantages: No side protection for ankle.

The sole is stone collector

Pedal pins can’t fit into the hole and grip is lost.

Compared to Exustar BMX Exustar E-SB760 / 750, Scott’s shoes cost almost 50% more money. But Price/Quality ratio is the same. Looks like the sole will have much longer live.

Few rides later …

The picture says it all

I expected more, a lot more. I don’t have to say that I’m disappointment – it is obvious.

Posted in mtb, Review, Sport | Comments Off on Scott FR 10 shoes

Debian Jessie and php7.1

I will explain how to install php7.1 on Debian Jessie using deb.sury.org

Install packages required for third party repositories over https

$ apt-get install apt-transport-https lsb-release ca-certificates wget

Get the repository key

$ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Add the repository

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list

 

Update package list

$ apt-get update

Install php 7.1

$ apt-get install php7.1-cli

You should be able to use php from cli

[email protected]:~# php -v
PHP 7.1.1-1+0~20170120094658.14+jessie~1.gbp69d416 (cli) (built: Jan 20 2017 11:53:59) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
 with Zend OPcache v7.1.1-1+0~20170120094658.14+jessie~1.gbp69d416, Copyright (c) 1999-2017, by Zend Technologies

It is very common that you will need some more packages like xdebug, xml, mysql

apt-get install php7.1-xdebug php7.1-xml php7.1-mysql php7.1-mbstring

This tutorial use info from deb.sury.org

 

Posted in Debian, Linux, php | Comments Off on Debian Jessie and php7.1