/**
  * Populate static properties for this table module.
  *
  * @return void
  */
 protected function _setup()
 {
     // get the database adapter
     if (!$this->_db) {
         $this->_db = $this->_getDefaultAdapter();
     }
     if (!$this->_db instanceof Zend_Db_Adapter_Abstract) {
         throw new Zend_Db_Table_Exception('db object does not implement Zend_Db_Adapter_Abstract');
     }
     // get the table name
     if (!$this->_name) {
         $this->_name = self::$_inflector->underscore(get_class($this));
     }
     // get the table columns
     if (!$this->_cols) {
         $tmp = array_keys($this->_db->describeTable($this->_name));
         foreach ($tmp as $native) {
             $this->_cols[$native] = self::$_inflector->camelize($native);
         }
     }
     // primary key
     if (!$this->_primary) {
         // none specified
         $table = $this->_name;
         throw new Zend_Db_Table_Exception("primary key not specified for table '{$table}'");
     } elseif (!array_key_exists($this->_primary, $this->_cols)) {
         // wrong name
         $key = $this->_primary;
         $table = $this->_name;
         throw new Zend_Db_Table_Exception("primary key '{$key}' not in columns for table '{$table}'");
     }
 }
Esempio n. 2
0
 /**
  * the constructor
  *
  */
 public function __construct(array $_options = array())
 {
     $imapConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::IMAP);
     // merge _config and dbmail imap
     $this->_config = array_merge($imapConfig['dbmail'], $this->_config);
     // set domain from imap config
     $this->_config['domain'] = !empty($imapConfig['domain']) ? $imapConfig['domain'] : null;
     // _tablename = "dbmail_users"
     $this->_userTable = $this->_config['prefix'] . $this->_config['userTable'];
     // connect to DB
     $this->_getDb($this->_config);
     $columns = $this->_db->describeTable('dbmail_users');
     if (array_key_exists('tine20_userid', $columns) && array_key_exists('tine20_clientid', $columns)) {
         $this->_hasTine20Userid = true;
         $this->_propertyMapping['emailUserId'] = 'tine20_userid';
         $this->_propertyMapping['emailGID'] = 'tine20_clientid';
     }
     $this->_clientId = Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId();
     $this->_config['emailGID'] = Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId();
 }
Esempio n. 3
0
 /**
  *
  * Public service for grouping treatment
  * @param Zend_Db_Adapter $adapter
  * @param string $tablePrefix
  * @param Zend_Db_Select $select
  */
 public static function traitGroup($adapter, $tablePrefix, Zend_Db_Select $select)
 {
     $group = $select->getPart(Zend_Db_Select::GROUP);
     //if (empty($group)) return;
     $order = $select->getPart(Zend_Db_Select::ORDER);
     $columns = $select->getPart(Zend_Db_Select::COLUMNS);
     try {
         //$column is an array where 0 is table, 1 is field and 2 is alias
         foreach ($columns as $column) {
             $field = implode('.', $column);
             if (!in_array($field, $group)) {
                 // replaces * by each name of column
                 if ($column[1] == '*') {
                     $tableFields = $adapter->describeTable($tablePrefix . $column[0]);
                     foreach ($tableFields as $columnName => $schema) {
                         // adds columns into group by clause (table.field)
                         // checks if field has a function (that must be an aggregation)
                         $element = "{$column[0]}.{$columnName}";
                         if (!in_array($element, $group) && !preg_match('/\\(.*\\)/', $element)) {
                             $group[] = $element;
                         }
                     }
                 } else {
                     // adds column into group by clause (table.field)
                     $element = "{$column[0]}.{$column[1]}";
                     if (!preg_match('/\\(.*\\)/', $element)) {
                         $group[] = $element;
                     } else {
                         if (substr($column[1], 0, 10) == "(CASE WHEN") {
                             $group[] = $column[1];
                         }
                     }
                 }
             }
         }
         foreach ($order as $column) {
             $field = $column[0];
             if (preg_match('/.*\\..*/', $field) && !in_array($field, $group)) {
                 // adds column into group by clause (table.field)
                 $group[] = $field;
             }
         }
         $select->reset(Zend_Db_Select::GROUP);
         $select->group($group);
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Exception: ' . $e->getMessage() . ' Trace: ' . $e->getTraceAsString());
     }
     return $select;
 }