示例#1
0
 public function executeCurrentVersion(dmWebRequest $request)
 {
     if ($branch = $request->getParameter('branch')) {
         $version = dmDb::pdo('SELECT v.number FROM version v INNER JOIN branch b ON v.branch_id = b.id AND b.number = ? WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(str_replace(array('_', '-'), '.', $branch), true))->fetchColumn();
     } else {
         $version = dmDb::pdo('SELECT v.number FROM version v WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(true))->fetchColumn();
     }
     return $this->renderText($version);
 }
示例#2
0
 protected function preTransform($text)
 {
     $text = parent::preTransform($text);
     if (strpos($text, '[/code]')) {
         $text = preg_replace_callback('#\\[code\\s?(\\w*)\\]((?:\\n|.)*)\\n\\[/code\\]#uU', array($this, 'formatCode'), $text);
     }
     if (strpos($text, '%latest_diem_version%')) {
         $version = dmDb::pdo('SELECT v.number FROM version v INNER JOIN branch b ON v.branch_id = b.id AND b.number = ? WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array('5.0', true))->fetchColumn();
         $text = str_replace('%latest_diem_version%', $version, $text);
     }
     if (strpos($text, '%latest_diem_download_url%')) {
         $version = dmDb::query('Version v')->innerJoin('v.Branch b')->where('b.number = ?', '5.0')->andWhere('v.is_active = ?', true)->orderBy('v.position ASC')->fetchOne();
         $text = str_replace('%latest_diem_download_url%', $this->helper->link($version->downloadUrl)->getAbsoluteHref(), $text);
     }
     return $text;
 }
示例#3
0
 public function removeOldLocks()
 {
     dmDb::pdo(sprintf('DELETE FROM %s WHERE time < ?', $this->getTableName()), array($_SERVER['REQUEST_TIME'] - 10 * sfConfig::get('dm_locks_timeout', 10)));
 }
 public function getData($tableName)
 {
     return dmDb::pdo('SELECT * FROM ' . $tableName, array(), $this->conn)->fetchAll(Doctrine::FETCH_ASSOC);
 }
示例#5
0
    protected function getParentSlugs($module)
    {
        if ($module->hasListPage()) {
            $parentPageModuleKey = $module->getKey();
            $parentPageActionKey = 'list';
        } elseif ($parentModule = $module->getNearestAncestorWithPage()) {
            $parentPageModuleKey = $parentModule->getKey();
            $parentPageActionKey = 'show';
        } else {
            throw new dmException(sprintf('can not identify parent module for %s module', $module));
        }
        $parentSlugResults = dmDb::pdo('SELECT t.id, t.slug
FROM dm_page p, dm_page_translation t
WHERE p.module = ? AND p.action = ? AND p.id = t.id AND t.lang = ?', array($parentPageModuleKey, $parentPageActionKey, $this->culture))->fetchAll(PDO::FETCH_NUM);
        $parentSlugs = array();
        foreach ($parentSlugResults as $psr) {
            $parentSlugs[$psr[0]] = $psr[1];
        }
        unset($parentSlugsResult);
        return $parentSlugs;
    }
示例#6
0
 protected function getAvailableIdsByLocalAlias(dmDoctrineTable $refTable)
 {
     $availableIds = array();
     foreach ($refTable->getRelationHolder()->getLocals() as $relationAlias => $relation) {
         $tmp = dmDb::pdo('SELECT t.id FROM ' . $relation->getTable()->getTableName() . ' t')->fetchAll(PDO::FETCH_NUM);
         if (empty($tmp)) {
             throw new dmRecordException();
         }
         foreach ($tmp as $t) {
             $availableIds[$relationAlias][$t[0]] = $t[0];
         }
     }
     return $availableIds;
 }
示例#7
0
 protected function getParentRecordIds(dmProjectModule $module, dmProjectModule $parentModule)
 {
     /*
      * if parent is local relation for module,
      * we can prepare parent records
      */
     if ($module->hasLocal($parentModule)) {
         $local = $module->getTable()->getRelationHolder()->getLocalByClass($parentModule->getModel())->getLocal();
         $query = sprintf('SELECT r.id, r.%s FROM %s r WHERE EXISTS (SELECT page.id FROM dm_page page WHERE page.module = ? AND page.action = ? AND page.record_id = r.%s)', $local, $module->getTable()->getTableName(), $local);
         $_parentRecordIds = dmDb::pdo($query, array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM);
         $parentRecordIds = array();
         foreach ($_parentRecordIds as $_parentRecordId) {
             $parentRecordIds[$_parentRecordId[0]] = $_parentRecordId[1];
         }
     } elseif ($module->hasAssociation($parentModule)) {
         $association = $module->getTable()->getRelationHolder()->getAssociationByClass($parentModule->getModel());
         $query = sprintf('SELECT association.%s, association.%s FROM %s association WHERE EXISTS (SELECT page.id FROM dm_page page WHERE page.module = ? AND page.action = ? AND page.record_id = association.%s) GROUP BY association.%s', $association->getForeign(), $association->getLocal(), $association->getAssociationTable()->getTableName(), $association->getForeign(), $association->getLocal());
         $_parentRecordIds = dmDb::pdo($query, array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM);
         $parentRecordIds = array();
         foreach ($_parentRecordIds as $value) {
             $parentRecordIds[$value[1]] = $value[0];
         }
     } else {
         $parentRecordIds = false;
     }
     return $parentRecordIds;
 }
示例#8
0
 public static function load($useCache = true)
 {
     if (!self::$culture) {
         if (class_exists('dmContext', false) && dmContext::hasInstance() && ($user = dmContext::getInstance()->getUser())) {
             self::$culture = $user->getCulture();
         } else {
             self::$culture = sfConfig::get('sf_default_culture');
         }
     }
     try {
         if (self::$culture == sfConfig::get('sf_default_culture')) {
             $results = dmDb::pdo('SELECT s.name, t.value, t.lang FROM dm_setting s LEFT JOIN dm_setting_translation t ON t.id=s.id AND t.lang = ?', array(self::$culture))->fetchAll(PDO::FETCH_NUM);
         } else {
             $results = dmDb::pdo('SELECT s.name, t.value, t.lang FROM dm_setting s LEFT JOIN dm_setting_translation t ON t.id=s.id AND t.lang IN (?, ?)', array(self::$culture, sfConfig::get('sf_default_culture')))->fetchAll(PDO::FETCH_NUM);
         }
     } catch (PDOException $e) {
         $results = array();
     } catch (Doctrine_Connection_Exception $e) {
         $results = array();
     }
     self::$config = array();
     foreach ($results as $result) {
         if (!isset(self::$config[$result[0]]) || isset(self::$config[$result[0]]) && $result[2] == self::$culture) {
             self::$config[$result[0]] = $result[1];
         }
     }
     unset($results);
     self::$loaded = true;
 }
示例#9
0
 public static function load($useCache = true)
 {
     if ($useCache && file_exists(self::getCacheFileName())) {
         require_once self::getCacheFileName();
     } else {
         if (sfConfig::has('dm_i18n_cultures')) {
             $cultures = sfConfig::get('dm_i18n_cultures');
         } else {
             $tmp = sfYaml::load(file_get_contents(dmOs::join(sfConfig::get('sf_config_dir'), 'dm/config.yml')));
             $cultures = $tmp['all']['i18n']['cultures'];
         }
         $results = dmDb::pdo(sprintf('SELECT s.name, s.type, t.value, t.default_value, t.lang FROM dm_setting s LEFT JOIN dm_setting_translation t ON t.id=s.id AND t.lang IN (\'%s\')', implode('\', \'', $cultures)))->fetchAll(PDO::FETCH_NUM);
         $config = array();
         foreach ($results as $result) {
             $value = $result[2] != '' ? $result[2] : $result[3];
             switch ($result[1]) {
                 case 'boolean':
                     if ($value == '1') {
                         $value = true;
                     } else {
                         $value = false;
                     }
                     break;
                 case 'number':
                     $value = floatval($value);
                     break;
                 case 'integer':
                     $value = intval($value);
                     break;
             }
             // sfConfig::set(sprintf('dm_dmConfig_cache_%s_%s', $result[4], $result[0]), $value);
             // $config[sprintf('dm_dmConfig_cache_%s_%s', $result[4], $result[0])] = $value;
             $config[$result[0]][$result[4]] = $value;
         }
         unset($results);
         self::toMemory($config, $cultures);
         self::dump();
     }
     self::$loaded = true;
 }
示例#10
0
 /**
  * Checks if a particular catalogue+variant exists in the database.
  *
  * @param string $variant catalogue+variant
  * @return boolean true if the catalogue+variant is in the database, false otherwise.
  */
 public function isValidSource($variant)
 {
     $result = dmDb::pdo('SELECT EXISTS(SELECT 1 FROM ' . $this->catalogueTable . ' WHERE name = ?)', array($variant))->fetch(PDO::FETCH_NUM);
     return $result[0];
 }