예제 #1
0
파일: Comment.php 프로젝트: shevron/stoa
 public function save()
 {
     if ($this->_data['created_at'] === null) {
         $this->_data['created_at'] = $_SERVER['REQUEST_TIME'];
     }
     return parent::save();
 }
예제 #2
0
파일: Post.php 프로젝트: shevron/stoa
 public function save()
 {
     $this->_data['normalized_title'] = self::_normalizeTitle($this->_data['title']);
     if ($this->_data['created_at'] === null) {
         $this->_data['created_at'] = $_SERVER['REQUEST_TIME'];
     }
     return parent::save();
 }
예제 #3
0
파일: Tag.php 프로젝트: shevron/stoa
 /**
  * Get an array of all tags related to the specified tag, with relativity ranking
  * 
  * The relativity ranking designates how many posts include both tags
  * 
  * @param  string $tag
  * @return array
  */
 public static function getRelatedTags($tag)
 {
     $return = array();
     $params = array('group' => true, 'startkey' => array($tag), 'endkey' => array($tag, array()));
     $tags = Geves_Model_Object::getDb()->view('tag', 'related', $params);
     foreach ($tags as $value) {
         $key = $tags->currentKey();
         $return[$key[1]] = $value;
     }
     return $return;
 }
예제 #4
0
파일: Bootstrap.php 프로젝트: shevron/stoa
 protected function _initDb()
 {
     $dbConfig = $this->_options['couchdb'];
     Geves_Model_Object::setDbConfig($dbConfig);
     if ($dbConfig['validate']) {
         // Make sure the DB exists
         try {
             $db = Sopha_Db::createDb($dbConfig['dbname'], $dbConfig['hostname'], $dbConfig['port']);
         } catch (Sopha_Db_Exception $ex) {
             if ($ex->getCode() != 412) {
                 throw $ex;
             }
             $db = Geves_Model_Object::getDb();
         }
         // Load design documents and create them
         $views = (require APPLICATION_PATH . '/configs/couchdb-views.php');
         if (!is_array($views)) {
             throw new ErrorException("Unable to configure database views: \$views is not properly defined");
         }
         foreach ($views as $view => $viewData) {
             try {
                 $db->create($viewData, array('_design', $view));
             } catch (Sopha_Db_Exception $ex) {
                 if ($ex->getCode() == 409) {
                     // document already exists
                     if ($dbConfig['replaceViews']) {
                         $view = $db->retrieve(array('_design', $view));
                         $view->fromArray($viewData);
                         $db->update($view);
                     }
                 } else {
                     throw $ex;
                 }
             }
         }
     }
 }
예제 #5
0
파일: Object.php 프로젝트: shevron/stoa
 /**
  * Set the DB configuration and create the DB connection adapter
  * 
  * @param  array | Zend_Config $config
  */
 public static function setDbConfig($config)
 {
     if ($config instanceof Zend_Config) {
         $config = $config->toArray();
     }
     if (!isset($config['dbname'])) {
         throw new Geves_Model_Exception("No DB name was set, unable to init Sopha_Db");
     }
     $hostname = isset($config['hostname']) ? $config['hostname'] : null;
     $port = isset($config['port']) ? $config['port'] : null;
     self::$_couch = new Sopha_Db($config['dbname'], $hostname, $port);
 }