Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from cordoval/more-work-on-lib
Browse files Browse the repository at this point in the history
typos and improvements
  • Loading branch information
stephpy committed Aug 27, 2014
2 parents 0ee882b + 5e0b512 commit 725944b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ matrix:
allow_failures:
- php: hhvm

install: composer install
install: composer install -n

script:
- bin/atoum -d tests/units
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ At this moment, only one driver is **redis**, use `Symfony2` and `Bundle <https:
Description
-----------

A timeline is a collection of action which can be represented by:
A timeline is a collection of actions which can be represented by:

- **Subject**
- **Verb**
Expand All @@ -22,22 +22,22 @@ Example:
+--------------+---------+--------------------------------------------------------------------+
| Subject | Verb | Complements |
+==============+=========+====================================================================+
| Chuck Norris | Own | the world (directComplement), with Vic Mc Key (indirectComplement) |
| Chuck Norris | own | the world (directComplement), with Vic Mc Key (indirectComplement) |
+--------------+---------+--------------------------------------------------------------------+
| Sheldon | say | Bazinga (directComplement) |
+--------------+---------+--------------------------------------------------------------------+

There is two types of action list to retrieve:
There are two types of action lists to retrieve:

Timeline
~~~~~~~~

Wall of a subject with all its actions + all actions of its **spreads**, see `spread.rst <https://github.com/stephpy/timeline/tree/master/doc/spread.rst>`_
Stream of actions where the subject is involved + all actions of its **spreads**, see `spread.rst <https://github.com/stephpy/timeline/tree/master/doc/spread.rst>`_

SubjectAction
~~~~~~~~~~~~~

All actions of the subject.
All actions the subject performed.

Context
~~~~~~~
Expand All @@ -46,7 +46,7 @@ Imagine Chuck Norris has 233 friends and follow 20 companies.

If we have one context, like facebook, his wall will return each action performed by his friends and companies.

You can too use **Contexts** to filter timelines, for example, we can have 3 contexts:
You can also use **Contexts** to filter timelines, for example, we can have 3 contexts:

- GLOBAL: actions of his friends and companies
- FRIEND: actions of his friends
Expand Down
16 changes: 8 additions & 8 deletions example/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
// Push an action

$actionManager = $c['action_manager'];
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');
$bruceLee = $actionManager->findOrCreateComponent('User', 'BruceLee');
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');
$bruceLee = $actionManager->findOrCreateComponent('User', 'BruceLee');

$action = $actionManager->create($chuck, 'kick', array('directComplement' => $bruceLee));
$actionManager->updateAction($action);

// Pull a timeline of a subject

$actionManager = $c['action_manager'];
$actionManager = $c['action_manager'];
$timelineManager = $c['timeline_manager'];
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');

$timeline = $timelineManager->getTimeline($chuck);
$timeline = $timelineManager->getTimeline($chuck);

print sprintf("---- Timeline Results = (%s) -----\n", count($timeline));

foreach ($timeline as $action) {
$subject = $action->getSubject();
$subject = $action->getSubject();
$directComplement = $action->getComponent('directComplement');
//.....
}

// Pull actions of a subject

$actionManager = $c['action_manager'];
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');
$chuck = $actionManager->findOrCreateComponent('User', 'Chuck');

$actions = $actionManager->getSubjectActions($chuck);
$actions = $actionManager->getSubjectActions($chuck);

print sprintf("---- Actions Results = (%s) -----\n", count($actions));

Expand Down
1 change: 1 addition & 0 deletions src/Driver/AbstractActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function create($subject, $verb, array $components = array())
* @param ActionInterface $action action
* @param string $type type
* @param mixed $component component
* @throws \Exception
*/
public function addComponent($action, $type, $component)
{
Expand Down
19 changes: 10 additions & 9 deletions src/Driver/QueryBuilder/Criteria/Asserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Asserter implements CriteriaInterface
CONST ASSERTER_NOT_LIKE = 'NOT LIKE';
CONST ASSERTER_LOWER_THAN = '<';
CONST ASSERTER_LOWER_THAN_EQUAL = '<=';
CONST ASSERTER_GREATHER_THAN = '>';
CONST ASSERTER_GREATHER_THAN_EQUAL = '>=';
CONST ASSERTER_GREATER_THAN = '>';
CONST ASSERTER_GREATER_THAN_EQUAL = '>=';

/**
* @var string
Expand Down Expand Up @@ -109,27 +109,27 @@ public function lte($value)
}

/**
* greather than
* greater than
*
* @param mixed $value value
*
* @return return DateTimeAsserter
* @return Asserter
*/
public function gt($value)
{
return $this->create(self::ASSERTER_GREATHER_THAN, $this->transform($value));
return $this->create(self::ASSERTER_GREATER_THAN, $this->transform($value));
}

/**
* greather than equal
* greater than equal
*
* @param mixed $value value
*
* @return return DateTimeAsserter
* @return Asserter
*/
public function gte($value)
{
return $this->create(self::ASSERTER_GREATHER_THAN_EQUAL, $this->transform($value));
return $this->create(self::ASSERTER_GREATER_THAN_EQUAL, $this->transform($value));
}


Expand Down Expand Up @@ -170,7 +170,8 @@ public function fromArray(array $data)
list ($field, $operator, $value) = $data['value'];

return $this->field($field)
->create($operator, $value);
->create($operator, $value)
;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/QueryBuilder/Criteria/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Operator implements CriteriaInterface
protected $type;

/**
* @var array<CriteriaInterface>
* @var CriteriaInterface[]
*/
protected $criterias = array();

Expand Down Expand Up @@ -77,7 +77,7 @@ public function getType()
}

/**
* @return array<CriteriaInterface>
* @return CriteriaInterface[]
*/
public function getCriterias()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Driver/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function createNewOperator($type, array $args)
return $this->factory
->createOperator()
->setType($type)
->setCriterias($args);
->setCriterias($args)
;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Driver/QueryBuilder/QueryBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function createOperator()
*/
public function createOperatorFromArray(array $data)
{
return $this->createOperator()
->fromArray($data, $this)
;
return $this->createOperator()->fromArray($data, $this);
}

/**
Expand All @@ -86,8 +84,6 @@ public function createAsserter()
*/
public function createAsserterFromArray(array $data)
{
return $this->createAsserter()
->fromArray($data)
;
return $this->createAsserter()->fromArray($data);
}
}
11 changes: 8 additions & 3 deletions src/Driver/Redis/Pager/AbstractPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public function findActionsForIds(array $ids)

$datas = $this->client->hmget($this->getActionKey(), $ids);

return array_values(array_map(function($v) {
return unserialize($v);
}, $datas));
return array_values(
array_map(
function($v) {
return unserialize($v);
},
$datas
)
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Redis/Pager/KnpSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function items(ItemsEvent $event)

$target = $event->target;
$offset = $event->getOffset();
$limit = $event->getLimit() - 1;
$limit = $event->getLimit() - 1;

$ids = $this->client->zRevRange($target->key, $offset, ($offset + $limit));
$ids = $this->client->zRevRange($target->key, $offset, ($offset + $limit));

$event->count = $this->client->zCard($target->key);
$event->items = $this->actionManager->findActionsForIds($ids);
Expand Down
8 changes: 4 additions & 4 deletions src/Driver/Redis/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function paginate($target, $page = 1, $limit = 10, $options = array())
}

$offset = ($page - 1) * $limit;
$limit = $limit - 1; // due to redis
$limit = $limit - 1; // due to redis

$ids = $this->client->zRevRange($target->key, $offset, ($offset + $limit));
$ids = $this->client->zRevRange($target->key, $offset, ($offset + $limit));

$this->page = $page;
$this->items = $this->findActionsForIds($ids);
$this->page = $page;
$this->items = $this->findActionsForIds($ids);
$this->nbResults = $this->client->zCard($target->key);
$this->lastPage = intval(ceil($this->nbResults / ($limit + 1)));

Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Redis/QueryExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function fetch($query, $page = 1, $maxPerPage = 10)
}

$offset = ($page - 1) * $maxPerPage;
$maxPerPage = $maxPerPage - 1; // due to redis
$maxPerPage = $maxPerPage - 1; // due to redis

$ids = $this->client->zRevRange($query->key, $offset, ($offset + $maxPerPage));
$ids = $this->client->zRevRange($query->key, $offset, ($offset + $maxPerPage));

return $this->findActionsForIds($ids);
}
Expand Down

0 comments on commit 725944b

Please sign in to comment.