public function registerEvents(Events $events)
 {
     parent::registerEvents($events);
     $key = 'events';
     $events->addCallbackListener($events::HYDRATE_BEFORE, function (EventArguments $args) use($key) {
         $data = json_decode($args->data[$key], TRUE);
         $events = [];
         foreach ($data as $row) {
             $event = new $row['_class']();
             unset($row['_class']);
             foreach ($row as $prop => $val) {
                 $event->{$prop} = $val;
             }
             $events[] = $event;
         }
         $args->data[$key] = $events;
     });
     $events->addCallbackListener($events::SERIALIZE_BEFORE, function (EventArguments $args) use($key) {
         $args->values[$key] = json_encode($args->values[$key] ?: []);
     });
 }
Ejemplo n.º 2
0
 public function createManyToManyMapper($param, IRepository $targetRepository, $targetParam)
 {
     /** @var DibiManyToManyMapper $mtm */
     $mtm = parent::createManyToManyMapper($param, $targetRepository, $targetParam);
     if ($targetRepository instanceof SubjectsRepository) {
         $mtm->table = 'editors_x_subjects';
         $mtm->parentParam = 'user_id';
         $mtm->childParam = 'subject_id';
     } else {
         if ($targetRepository instanceof SchemasRepository) {
             $mtm->table = 'editors_x_schemas';
             $mtm->parentParam = 'user_id';
             $mtm->childParam = 'schema_id';
         } else {
             if ($targetRepository instanceof BlocksRepository) {
                 $mtm->table = 'editors_x_blocks';
                 $mtm->parentParam = 'user_id';
                 $mtm->childParam = 'block_id';
             }
         }
     }
     return $mtm;
 }
 public function findAll()
 {
     return parent::findAll()->orderBy('position', 'ASC');
 }