/**
  * @todo
  * @param string $capabilities
  * @param string $sub
  */
 public function get($section = NULL)
 {
     $capabilities = array();
     if (is_null($section) || $section == 'configuration') {
         $configuration = array('precision' => View\View::PRECISION, 'database' => Util\Configuration::read('db.driver'), 'debug' => Util\Configuration::read('debug'), 'devmode' => Util\Configuration::read('devmode'));
         $capabilities['configuration'] = $configuration;
     }
     if (is_null($section) || $section == 'formats') {
         $capabilities['formats'] = array_keys(\Volkszaehler\Router::$viewMapping);
     }
     if (is_null($section) || $section == 'contexts') {
         $capabilities['contexts'] = array_keys(\Volkszaehler\Router::$controllerMapping);
     }
     if (is_null($section) || $section == 'definitions') {
         if (!is_null($section)) {
             // only caching when we doesn't request dynamic informations
             $this->view->setCaching('expires', time() + 2 * 7 * 24 * 60 * 60);
             // cache for 2 weeks
         }
         $capabilities['definitions']['entities'] = Definition\EntityDefinition::get();
         $capabilities['definitions']['properties'] = Definition\PropertyDefinition::get();
     }
     if (count($capabilities) == 0) {
         throw new \Exception('Invalid capability identifier: \'' . $section . '\'');
     }
     return array('capabilities' => $capabilities);
 }
 /**
  * @todo
  * @param string $capabilities
  * @param string $sub
  */
 public function get($section = NULL)
 {
     $capabilities = array();
     if (is_null($section) || $section == 'configuration') {
         $configuration = array('precision' => View\View::PRECISION, 'database' => Util\Configuration::read('db.driver'), 'debug' => Util\Configuration::read('debug'), 'devmode' => Util\Configuration::read('devmode'));
         if ($commit = Util\Debug::getCurrentCommit()) {
             $configuration['commit'] = $commit;
         }
         $capabilities['configuration'] = $configuration;
     }
     // db statistics - only if specifically requested
     if ($section == 'database') {
         $conn = $this->em->getConnection();
         // get DBAL connection from EntityManager
         // estimate InnoDB tables to avoid performance penalty
         $rows = $conn->fetchAssoc('EXPLAIN SELECT COUNT(id) FROM data USE INDEX (PRIMARY)');
         if (isset($rows['rows'])) {
             $rows = $rows['rows'];
         } else {
             // get correct values for MyISAM
             $rows = $conn->fetchColumn('SELECT COUNT(1) FROM data');
         }
         // database disc space consumption
         $sql = 'SELECT SUM(data_length + index_length) ' . 'FROM information_schema.tables ' . 'WHERE table_schema = ?';
         $size = $conn->fetchColumn($sql, array(Util\Configuration::read('db.dbname')));
         $aggregation = Util\Configuration::read('aggregation');
         $database = array('data_rows' => $rows, 'data_size' => $size, 'aggregation_enabled' => $aggregation ? 1 : 0);
         // aggregation table size
         if ($aggregation) {
             $agg_rows = $conn->fetchColumn('SELECT COUNT(1) FROM aggregate');
             $database['aggregation_rows'] = $agg_rows;
             $database['aggregation_ratio'] = $agg_rows ? $rows / $agg_rows : 0;
         }
         $capabilities['database'] = $database;
     }
     if (is_null($section) || $section == 'formats') {
         $capabilities['formats'] = array_keys(Router::$viewMapping);
     }
     if (is_null($section) || $section == 'contexts') {
         $capabilities['contexts'] = array_keys(Router::$controllerMapping);
     }
     if (is_null($section) || $section == 'definitions') {
         // unresolved artifact from Symfony migration
         // if (!is_null($section)) { // only caching when we don't request dynamic informations
         // 	$this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks
         // }
         $capabilities['definitions']['entities'] = Definition\EntityDefinition::get();
         $capabilities['definitions']['properties'] = Definition\PropertyDefinition::get();
     }
     if (count($capabilities) == 0) {
         throw new \Exception('Invalid capability identifier: \'' . $section . '\'');
     }
     return array('capabilities' => $capabilities);
 }
Пример #3
0
 public function getDefinition()
 {
     return Definition\PropertyDefinition::get($this->key);
 }
    /**
     * Filter entites by properties
     *
     * @todo improve performance
     * @param array of property => value filters
     * @return array of entities
     */
    public function filter(array $properties)
    {
        $dql = 'SELECT a, p
			FROM Volkszaehler\\Model\\Entity a
			LEFT JOIN a.properties p';
        $i = 0;
        $sqlWhere = array();
        $sqlParams = array();
        foreach ($properties as $key => $value) {
            switch (Definition\PropertyDefinition::get($key)->getType()) {
                case 'string':
                case 'text':
                case 'multiple':
                    $value = "'" . $value . "'";
                    break;
                case 'boolean':
                    $value = (int) $value;
            }
            $sqlWhere[] = 'EXISTS (SELECT p' . $i . ' FROM \\Volkszaehler\\Model\\Property p' . $i . ' WHERE p' . $i . '.key = :key' . $i . ' AND p' . $i . '.value = :value' . $i . ' AND p' . $i . '.entity = a)';
            $sqlParams += array('key' . $i => $key, 'value' . $i => $value);
            $i++;
        }
        if (count($sqlWhere) > 0) {
            $dql .= ' WHERE ' . implode(' AND ', $sqlWhere);
        }
        $q = $this->em->createQuery($dql);
        return $q->execute($sqlParams);
    }
    /**
     * Filter entites by properties
     *
     * @todo improve performance
     * @param array of property => value filters
     * @return array of entities
     */
    public function filter(array $properties)
    {
        $dql = 'SELECT e, p
			FROM Volkszaehler\\Model\\Entity e
			LEFT JOIN e.properties p';
        $i = 0;
        $sqlWhere = array();
        $sqlParams = array();
        foreach ($properties as $key => $value) {
            if (Definition\PropertyDefinition::get($key)->getType() == 'boolean') {
                $value = (int) $value;
            }
            $sqlWhere[] = 'EXISTS (SELECT p' . $i . ' FROM \\Volkszaehler\\Model\\Property p' . $i . ' WHERE p' . $i . '.key = :key' . $i . ' AND p' . $i . '.value = :value' . $i . ' AND p' . $i . '.entity = e)';
            $sqlParams += array('key' . $i => $key, 'value' . $i => $value);
            $i++;
        }
        if (count($sqlWhere) > 0) {
            $dql .= ' WHERE ' . implode(' AND ', $sqlWhere);
        }
        $q = $this->em->createQuery($dql);
        return $q->execute($sqlParams);
    }
 /**
  * @param string $section select specific sub section for output
  */
 public function get($section = NULL)
 {
     $capabilities = array();
     if (is_null($section) || $section == 'configuration') {
         $configuration = array('precision' => View\View::PRECISION, 'database' => Util\Configuration::read('db.driver'), 'debug' => Util\Configuration::read('debug'), 'devmode' => Util\Configuration::read('devmode'));
         if ($commit = Util\Debug::getCurrentCommit()) {
             $configuration['commit'] = $commit;
         }
         $capabilities['configuration'] = $configuration;
     }
     // db statistics - only if specifically requested
     if ($section == 'database') {
         $conn = $this->em->getConnection();
         // get DBAL connection from EntityManager
         // estimate InnoDB tables to avoid performance penalty
         $rows = $this->sqlCount($conn, 'data');
         $size = $this->dbSize($conn, 'data');
         $aggregation = Util\Configuration::read('aggregation');
         $database = array('data_rows' => $rows, 'data_size' => $size, 'aggregation_enabled' => $aggregation ? 1 : 0);
         // aggregation table size
         if ($aggregation) {
             $agg_rows = $this->sqlCount($conn, 'aggregate');
             $agg_size = $this->dbSize($conn, 'aggregate');
             $database['aggregation_rows'] = $agg_rows;
             $database['aggregation_size'] = $agg_size;
             $database['aggregation_ratio'] = $agg_rows ? $rows / $agg_rows : 0;
         }
         $capabilities['database'] = $database;
     }
     if (is_null($section) || $section == 'formats') {
         $capabilities['formats'] = array_keys(Router::$viewMapping);
     }
     if (is_null($section) || $section == 'contexts') {
         $capabilities['contexts'] = array_keys(Router::$controllerMapping);
     }
     if (is_null($section) || $section == 'definitions') {
         // unresolved artifact from Symfony migration
         if (!is_null($section)) {
             // only caching when we don't request dynamic informations
             $this->view->setCaching('expires', time() + 2 * 7 * 24 * 60 * 60);
             // cache for 2 weeks
         }
         $capabilities['definitions']['entities'] = Definition\EntityDefinition::get();
         $capabilities['definitions']['properties'] = Definition\PropertyDefinition::get();
     }
     if (count($capabilities) == 0) {
         throw new \Exception('Invalid capability identifier: \'' . $section . '\'');
     }
     return array('capabilities' => $capabilities);
 }