/**
  * Load and merge registry keys by userid and a path.
  * The user keys will get merged with the default keys (userid = 0).
  */
 public function loadByPath($userid, $path)
 {
     $repository = $this->getEntityManager()->getRepository('RegistryBundle:Registry');
     /*
     select * from
     (select * from registry
     where userid = 0
     and concat(registrykey, "/", name) not in (select concat(registrykey, "/", name) from registry where userid = 2)
     union
     select * from registry
     where userid = 2) x
     where x.registrykey like 'App/Test/J%'
     */
     $stmt = $this->getEntityManager()->getConnection()->prepare('SELECT r.* FROM
         (
             SELECT * FROM registry r1
             WHERE r1.userid = 0
             AND CONCAT(r1.registrykey, "/", r1.name) NOT IN (
                 SELECT CONCAT(r2.registrykey, "/", r2.name) FROM registry r2 WHERE r2.userid = :userid
             )
             UNION
             SELECT * FROM registry r3
             WHERE r3.userid = :userid
         ) r
         WHERE r.registrykey LIKE :path');
     $params = array('userid' => $userid, 'path' => $path);
     $stmt->execute($params);
     $result = array();
     while ($row = $stmt->fetch()) {
         $r = new Registry();
         $r->LoadByArray($row);
         $result[] = $r;
     }
     return $result;
 }
示例#2
0
 /**
  * Read a set of registry keys and return them as array.
  * 
  * @param integer $userid
  * @param string  $path
  * @return array
  */
 public function getRegistryItems($userid, $path)
 {
     $entities = array();
     if ($this->isModeRedis()) {
         // redis load
         $array = $this->redis->hGetAll($this->redis_prefix . (string) $userid);
         // filter the result array
         foreach (array_keys($array) as $key) {
             if (preg_match('/^' . $path . '/', $key)) {
                 // $key = key; key:name:type
                 // $value = $array[$key]; value
                 // explode key by redis_key_name_delimiter to get key:name:type
                 $s = explode($this->redis_key_name_delimiter, $key);
                 if (count($s) != 3) {
                     throw new \Exception('Redis key format is not correct! (key' . $this->redis_key_name_delimiter . 'name' . $this->redis_key_name_delimiter . 'name)');
                 }
                 $entity = new RegKey();
                 $entity->loadByValues(0, $userid, $s[0], $s[1], $s[2], $array[$key]);
                 $entities[] = $entity;
             }
         }
         // cleanup
         unset($array);
     } else {
         if ($this->isModeDoctrine()) {
             // doctrine load
             $entities = $this->registry->loadByPath($userid, $path);
         }
     }
     return $entities;
 }