/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { $db = $_backend->getAdapter(); // prepare value $value = $this->_value ? 1 : 0; if ($value) { // nothing to do -> show all contacts! if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Query all account contacts.'); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Only query visible and enabled account contacts.'); } if (Tinebase_Core::getUser() instanceof Tinebase_Model_FullUser) { $where = '/* is no user */ ' . Tinebase_Backend_Sql_Command::getIfIsNull($db, $db->quoteIdentifier('accounts.id'), 'true', 'false') . ' OR /* is user */ (' . Tinebase_Backend_Sql_Command::getIfIsNull($db, $db->quoteIdentifier('accounts.id'), 'false', 'true') . ' AND ' . $db->quoteInto($db->quoteIdentifier('accounts.status') . ' = ?', 'enabled') . " AND " . '(' . $db->quoteInto($db->quoteIdentifier('accounts.visibility') . ' = ?', 'displayed') . ' OR ' . $db->quoteInto($db->quoteIdentifier('accounts.id') . ' = ?', Tinebase_Core::getUser()->getId()) . ')' . ")"; } else { $where = '/* is no user */ ' . Tinebase_Backend_Sql_Command::getIfIsNull($db, $db->quoteIdentifier('accounts.id'), 'true', 'false') . ' OR /* is user */ (' . Tinebase_Backend_Sql_Command::getIfIsNull($db, $db->quoteIdentifier('accounts.id'), 'false', 'true') . ' AND ' . $db->quoteInto($db->quoteIdentifier('accounts.status') . ' = ?', 'enabled') . " AND " . $db->quoteInto($db->quoteIdentifier('accounts.visibility') . ' = ?', 'displayed') . ")"; } $_select->where($where); $select = $_select instanceof Zend_Db_Select ? $_select : $_select->getSelect(); $select = Tinebase_Backend_Sql_Abstract::traitGroup($db, $_backend->getTablePrefix(), $select); $_select instanceof Zend_Db_Select ? $_select = $select : $_select->setSelect($select); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' contacts query ' . $_select->assemble()); } } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { $correlationName = Tinebase_Record_Abstract::generateUID(30); $db = $_backend->getAdapter(); $_select->joinLeft(array($correlationName => $db->table_prefix . 'adb_list_m_role'), $db->quoteIdentifier($correlationName . '.contact_id') . ' = ' . $db->quoteIdentifier('addressbook.id'), array()); $_select->where($db->quoteIdentifier($correlationName . '.list_role_id') . ' IN (?)', (array) $this->_value); }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if ($this->_value === self::VALUE_NOTSET) { return; } $action = $this->_opSqlMap[$this->_operator]; $db = $_backend->getAdapter(); // prepare value $value = $this->_value ? 1 : 0; if (!empty($this->_options['fields'])) { foreach ((array) $this->_options['fields'] as $fieldName) { $quotedField = $db->quoteIdentifier(strpos($fieldName, '.') === false ? $_backend->getTableName() . '.' . $fieldName : $fieldName); if ($value) { $_select->where($quotedField . $action['sqlop'], $value); } else { $_select->orwhere($quotedField . $action['sqlop'], $value); } } } else { if (!empty($this->_options['leftOperand'])) { $_select->where($this->_options['leftOperand'] . $action['sqlop'], $value); } else { $_select->where($this->_getQuotedFieldName($_backend) . $action['sqlop'], $value); } } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend * @throws Tinebase_Exception_NotFound */ public function appendFilterSql2($_select, $_backend) { $this->_options['ignoreAcl'] = TRUE; $this->_resolve(); $quotedDisplayContainerIdentifier = $_backend->getAdapter()->quoteIdentifier('attendee.displaycontainer_id'); $_select->where($quotedDisplayContainerIdentifier . ' IN (?)', empty($this->_containerIds) ? " " : $this->_containerIds); }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if (empty($this->_value)) { $_select->where('1=1/* empty query */'); return; } $db = Tinebase_Core::getDb(); switch ($this->_operator) { case 'contains': case 'equals': case 'startswith': $queries = explode(' ', $this->_value); foreach ($queries as $query) { $whereParts = array(); foreach ($this->_options['fields'] as $qField) { // if field has . in name, then we already have tablename if (strpos($qField, '.') !== FALSE) { $whereParts[] = Tinebase_Backend_Sql_Command::factory($db)->prepareForILike(Tinebase_Backend_Sql_Command::factory($db)->getUnaccent($db->quoteIdentifier($qField))) . ' ' . Tinebase_Backend_Sql_Command::factory($db)->getLike() . Tinebase_Backend_Sql_Command::factory($db)->prepareForILike(Tinebase_Backend_Sql_Command::factory($db)->getUnaccent('(?)')); } else { $whereParts[] = Tinebase_Backend_Sql_Command::factory($db)->prepareForILike(Tinebase_Backend_Sql_Command::factory($db)->getUnaccent($db->quoteIdentifier($_backend->getTableName() . '.' . $qField))) . ' ' . Tinebase_Backend_Sql_Command::factory($db)->getLike() . Tinebase_Backend_Sql_Command::factory($db)->prepareForILike(Tinebase_Backend_Sql_Command::factory($db)->getUnaccent('(?)')); } } $whereClause = ''; if (!empty($whereParts)) { $whereClause = implode(' OR ', $whereParts); } if (!empty($whereClause)) { if ($this->_operator == 'equals') { $_select->where($db->quoteInto($whereClause, trim($query))); } else { if ($this->_operator == 'startswith') { $_select->where($db->quoteInto($whereClause, trim($query) . '%')); } else { $_select->where($db->quoteInto($whereClause, '%' . trim($query) . '%')); } } } } break; case 'in': foreach ($this->_options['fields'] as $qField) { // if field has . in name, then we allready have tablename if (strpos($qField, '.') !== FALSE) { $whereParts[] = $db->quoteInto($db->quoteIdentifier($qField) . ' IN (?)', (array) $this->_value); } else { $whereParts[] = $db->quoteInto($db->quoteIdentifier($_backend->getTableName() . '.' . $qField) . ' IN (?)', (array) $this->_value); } } if (!empty($whereParts)) { $whereClause = implode(' OR ', $whereParts); } if (!empty($whereClause)) { $_select->where($whereClause); } break; default: throw new Tinebase_Exception_InvalidArgument('Operator not defined: ' . $this->_operator); } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if ($this->_value === 'all') { $_select->where('1=1'); return; } $gs = new Tinebase_Backend_Sql_Filter_GroupSelect($_select); $adapter = $_backend->getAdapter(); $isExcept = strpos($this->_operator, 'Except') !== false; $sign = $isExcept ? '<>' : '='; //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') value: ' . print_r($this->_value, true)); foreach ($this->_value as $attenderValue) { if (in_array($attenderValue['user_type'], array(Calendar_Model_Attender::USERTYPE_USER, Calendar_Model_Attender::USERTYPE_GROUPMEMBER))) { // @todo user_id might contain filter in the future -> get userids from adressbook controller with contact filter // transform CURRENTCONTACT $attenderValue['user_id'] = $attenderValue['user_id'] == Addressbook_Model_Contact::CURRENTCONTACT ? Tinebase_Core::getUser()->contact_id : $attenderValue['user_id']; $attendee = array(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $attenderValue['user_id'])); if (!$isExcept) { $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $attenderValue['user_id']); } } else { if ($attenderValue['user_type'] == self::USERTYPE_MEMBEROF) { // resolve group members $group = Tinebase_Group::getInstance()->getGroupById($attenderValue['user_id']); $attendee = array(); // fetch list only if list_id is not NULL, otherwise we get back an empty list object if (!empty($group->list_id)) { $contactList = Addressbook_Controller_List::getInstance()->get($group->list_id); foreach ($contactList->members as $member) { $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $member); if (!$isExcept) { $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $member); } } } } else { $attendee = array($attenderValue); } } foreach ($attendee as $attender) { $gs->orWhere(($isExcept ? '' : $adapter->quoteInto($adapter->quoteIdentifier('attendee.user_type') . ' = ?', $attender['user_type']) . ' AND ') . $adapter->quoteInto($adapter->quoteIdentifier('attendee.user_id') . ' ' . $sign . ' ?', $attender['user_id'])); } } if (substr($this->_operator, 0, 3) === 'not') { // join attendee to be excluded as a new column. records having this column NULL don't have the attendee $dname = 'attendee-not-' . Tinebase_Record_Abstract::generateUID(5); $_select->joinLeft(array($dname => $_backend->getTablePrefix() . 'cal_attendee'), $adapter->quoteIdentifier($dname . '.cal_event_id') . ' = ' . $adapter->quoteIdentifier($_backend->getTableName() . '.id') . ' AND ' . $gs->getSQL(), array($dname => $_backend->getDbCommand()->getAggregate($dname . '.id'))); $_select->having($_backend->getDbCommand()->getAggregate($dname . '.id') . ' IS NULL'); } else { if ($isExcept) { $dname = 'attendee-hasSome-' . Tinebase_Record_Abstract::generateUID(5); $_select->joinLeft(array($dname => $_backend->getTablePrefix() . 'cal_attendee'), $adapter->quoteIdentifier($dname . '.cal_event_id') . ' = ' . $adapter->quoteIdentifier($_backend->getTableName() . '.id') . ' AND ' . $gs->getSQL(), array($dname => $_backend->getDbCommand()->getAggregate($dname . '.id'))); $_select->having($_backend->getDbCommand()->getAggregate($dname . '.id') . ' IS NOT NULL'); } else { $gs->appendWhere(Zend_Db_Select::SQL_OR); } } }
/** * append grants acl filter * * @param Zend_Db_Select $select * @param Tinebase_Backend_Sql_Abstract $backend * @param Tinebase_Model_User $user */ protected function _appendGrantsFilter($select, $backend, $user) { $db = $backend->getAdapter(); $select->join(array($this->_aclTableName => SQL_TABLE_PREFIX . $this->_aclTableName), "{$db->quoteIdentifier($this->_aclTableName . '.record_id')} = {$db->quoteIdentifier($backend->getTableName() . '.id')}", array()); Tinebase_Container::addGrantsSql($select, $user, $this->_requiredGrants, $this->_aclTableName); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' $select after appending grants sql: ' . $select); } }
/** * get field type from schema * * @param Tinebase_Backend_Sql_Abstract $backend */ protected function _getFieldType($backend) { $schema = $backend->getSchema(); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' schema: ' . print_r($schema, TRUE)); } $type = isset($schema[$this->_field]) || array_key_exists($this->_field, $schema) ? $schema[$this->_field]['DATA_TYPE'] : NULL; return $type; }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend * @throws Tinebase_Exception_NotFound */ public function appendFilterSql($_select, $_backend) { $this->_options['ignoreAcl'] = TRUE; $this->_resolve(); $quotedDisplayContainerIdentifier = $_backend->getAdapter()->quoteIdentifier('attendee.displaycontainer_id'); $where = empty($this->_containerIds) ? Tinebase_Backend_Sql_Command::getFalseValue($_backend->getAdapter()) : $_select->getAdapter()->quoteInto($this->_getQuotedFieldName($_backend) . ' IN (?)', $this->_containerIds); $orWhere = empty($this->_containerIds) ? Tinebase_Backend_Sql_Command::getFalseValue($_backend->getAdapter()) : $_select->getAdapter()->quoteInto($quotedDisplayContainerIdentifier . ' IN (?)', $this->_containerIds); $_select->where($where); $_select->orWhere($orWhere); }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend * @throws Tinebase_Exception_NotFound */ public function appendFilterSql($_select, $_backend) { $db = $_backend->getAdapter(); $correlationName = Tinebase_Record_Abstract::generateUID() . $this->_value . 'owner'; $_select->joinLeft(array($correlationName => SQL_TABLE_PREFIX . 'container_acl'), $db->quoteIdentifier("{$correlationName}.container_id") . " = container.id", array()); // only personal containers have an owner! $_select->where("{$db->quoteIdentifier('container.type')} = ?", Tinebase_Model_Container::TYPE_PERSONAL); // assure admin grant $_select->where($db->quoteIdentifier("{$correlationName}.account_id") . " = " . $db->quote($this->_value) . ' AND ' . $db->quoteIdentifier("{$correlationName}.account_grant") . " = ?", Tinebase_Model_Grants::GRANT_ADMIN); }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { $db = $_backend->getAdapter(); // prepare value $value = $this->_value ? 1 : 0; if ($value) { // nothing to filter } else { $_select->where($db->quoteIdentifier($_backend->getTableName() . '.is_open') . ' = 1'); } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . 'Adding Relation filter: ' . $_backend->getModelName() . ' <-> ' . $this->_options['related_model']); } $this->_resolveForeignIds(); $ownIds = $this->_getOwnIds($_backend->getModelName()); $idField = array_key_exists('idProperty', $this->_options) ? $this->_options['idProperty'] : 'id'; $db = $_backend->getAdapter(); $qField = $db->quoteIdentifier($_backend->getTableName() . '.' . $idField); $_select->where($db->quoteInto("{$qField} IN (?)", empty($ownIds) ? ' ' : $ownIds)); }
/** * appends custom filters to a given select object * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend * @return void * * @todo replace custom filter! */ public function appendFilterSql($_select, $_backend) { $this->_appendAclSqlFilter($_select); $db = $_backend->getAdapter(); foreach ($this->_customData as $customData) { $value = $customData['value']; if ($customData['field'] == 'is_cleared') { $_select->joinLeft(array('ta' => $db->table_prefix . 'timetracker_timeaccount'), $db->quoteIdentifier('ta.id') . ' = ' . $db->quoteIdentifier('timetracker_timesheet.timeaccount_id'), array()); $opStatus = $value ? '=' : '<>'; $op = $value ? ' OR ' : ' AND '; $_select->where($db->quoteInto($customData['field'] . ' = ?', $value) . $op . $db->quoteInto('ta.status' . $opStatus . ' ? ', 'billed')); } } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . 'Adding Path filter for: ' . $_backend->getModelName()); } $this->_resolvePathIds(); $idField = isset($this->_options['idProperty']) || array_key_exists('idProperty', $this->_options) ? $this->_options['idProperty'] : 'id'; $db = $_backend->getAdapter(); $qField = $db->quoteIdentifier($_backend->getTableName() . '.' . $idField); if (empty($this->_pathRecordIds)) { $_select->where('1=0'); } else { $_select->where($db->quoteInto("{$qField} IN (?)", $this->_pathRecordIds)); } }
/** * converts record into raw data for adapter * * @param Tinebase_Record_Interface $_record * @return array */ protected function _recordToRawData(Tinebase_Record_Interface $_record) { $result = parent::_recordToRawData($_record); // context is joined from the asterisk_context table and can not be set here unset($result['context']); return $result; }
/** * appends custom filters to a given select object * - add user phone ids to filter * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend * @return void */ public function appendFilterSql($_select, $_backend) { $accountIdFilter = $this->_findFilter('account_id'); if ($accountIdFilter !== NULL) { $db = Tinebase_Core::getDb(); $backend = new Voipmanager_Backend_Snom_Phone(); $_validPhoneIds = $backend->getValidPhoneIds($accountIdFilter->getValue()); if (empty($_validPhoneIds)) { $_select->where('1=0'); } else { $_select->where($db->quoteInto($db->quoteIdentifier($_backend->getTableName() . '.id') . ' IN (?)', $_validPhoneIds)); } // remove filter $this->_removeFilter('account_id'); } }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { $select = parent::_getSelect($_cols, $_getDeleted); $select->joinLeft($this->_tablePrefix . 'bill_debitor', $this->_db->quoteIdentifier($this->_tablePrefix . 'bill_debitor.id') . ' = ' . $this->_db->quoteIdentifier($this->_tableName . '.debitor_id'), array()); $select->joinLeft($this->_tablePrefix . 'addressbook', $this->_db->quoteIdentifier($this->_tablePrefix . 'bill_debitor.contact_id') . ' = ' . $this->_db->quoteIdentifier($this->_tablePrefix . 'addressbook.id'), array()); return $select; }
/** * get grants for records * * @param Tinebase_Record_RecordSet $records */ public function getGrantsForRecords(Tinebase_Record_RecordSet $records) { $recordIds = $records->getArrayOfIds(); if (empty($recordIds)) { return; } $select = $this->_getAclSelectByRecordIds($recordIds)->group(array('record_id', 'account_type', 'account_id')); Tinebase_Backend_Sql_Abstract::traitGroup($select); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $select); } $stmt = $this->_db->query($select); $grantsData = $stmt->fetchAll(Zend_Db::FETCH_ASSOC); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' grantsData: ' . print_r($grantsData, true)); } foreach ($grantsData as $grantData) { $givenGrants = explode(',', $grantData['account_grants']); foreach ($givenGrants as $grant) { $grantData[$grant] = TRUE; } $recordGrant = new $this->_modelName($grantData, true); unset($recordGrant->account_grant); $record = $records->getById($recordGrant->record_id); if (!$record->grants instanceof Tinebase_Record_RecordSet) { $record->grants = new Tinebase_Record_RecordSet($this->_modelName); } $record->grants->addRecord($recordGrant); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Records with grants: ' . print_r($records->toArray(), true)); } }
public function get($id, $_getDeleted = FALSE, $getDependent = false) { $record = parent::get($id, $_getDeleted); if ($getDependent) { $this->appendDependentRecords($record); } return $record; }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { if ($this->_accountId === '0') { // get anyones preferences $field = $_backend->getAdapter()->quoteIdentifier($_backend->getTableName() . '.account_type'); $_select->where(Tinebase_Core::getDb()->quoteInto($field . '= ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE)); } else { $conditions = array(array('condition' => Tinebase_Model_Filter_FilterGroup::CONDITION_AND, 'filters' => array(array('field' => 'account_id', 'operator' => 'equals', 'value' => $this->_accountId), array('field' => 'account_type', 'operator' => 'equals', 'value' => $this->_accountType))), array('field' => 'account_type', 'operator' => 'equals', 'value' => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE)); // add groups if accountType is user if ($this->_accountType === Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) { $groups = Tinebase_Group::getInstance()->getGroupMemberships($this->_accountId); $conditions[] = array('condition' => Tinebase_Model_Filter_FilterGroup::CONDITION_AND, 'filters' => array(array('field' => 'account_id', 'operator' => 'in', 'value' => $groups), array('field' => 'account_type', 'operator' => 'equals', 'value' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP))); } $filter = new Tinebase_Model_PreferenceFilter($conditions, Tinebase_Model_Filter_FilterGroup::CONDITION_OR); Tinebase_Backend_Sql_Filter_FilterGroup::appendFilters($_select, $filter, $_backend); } }
/** * appends sql to given select statement * * @param Tinebase_Backend_Sql_Filter_GroupSelect $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { $db = $_backend->getAdapter(); $value = $this->_value ? 1 : 0; if ($value) { // nothing to do -> show all lists! if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Query all lists.'); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Only query visible lists.'); } $_select->join(array('groupvisibility' => $db->table_prefix . 'groups'), $db->quoteIdentifier('groupvisibility.list_id') . ' = ' . $db->quoteIdentifier('addressbook_lists.id'), array()); $_select->where($db->quoteIdentifier('groupvisibility.visibility') . ' = ?', 'displayed'); } }
public function get($id, $_getDeleted = FALSE, $regular = true) { $record = parent::get($id, $_getDeleted); if (!$regular) { return $this->loadOrderPosition($record); } return $record; }
/** * the constructor * * allowed options: * - modelName * - tableName * - tablePrefix * - modlogActive * * @param Zend_Db_Adapter_Abstract $_db (optional) * @param array $_options (optional) * @throws Tinebase_Exception_Backend_Database */ public function __construct($_dbAdapter = NULL, $_options = array()) { parent::__construct($_dbAdapter, $_options); $this->_additionalSearchCountCols = array('is_billable_combined' => null, 'duration' => 'duration', 'duration_billable' => null); $this->_foreignTables['is_billable_combined']['select'] = array('is_billable_combined' => new Zend_Db_Expr('(' . $this->_db->quoteIdentifier('timetracker_timesheet.is_billable') . '*' . $this->_db->quoteIdentifier('timetracker_timeaccount.is_billable') . ')')); $this->_foreignTables['is_cleared_combined']['select'] = array('is_cleared_combined' => new Zend_Db_Expr('(CASE WHEN ' . $this->_db->quoteIdentifier('timetracker_timesheet.is_cleared') . " = '1' OR " . $this->_db->quoteIdentifier('timetracker_timeaccount.status') . " = 'billed' THEN 1 ELSE 0 END)")); $this->_foreignTables['duration_billable']['select'] = array('duration_billable' => new Zend_Db_Expr('(' . $this->_db->quoteIdentifier('duration') . '*' . $this->_db->quoteIdentifier('timetracker_timesheet.is_billable') . '*' . $this->_db->quoteIdentifier('timetracker_timeaccount.is_billable') . ')')); }
/** * converts record into raw data for adapter * * @param Tinebase_Record_Interface $_record * @return array */ protected function _recordToRawData(Tinebase_Record_Interface $_record) { $result = parent::_recordToRawData($_record); // stored in foreign key unset($result['members']); unset($result['group_id']); return $result; }
/** * the constructor * * @param Zend_Db_Adapter_Abstract $_db (optional) * @param array $_options (optional) */ public function __construct($_dbAdapter = NULL, $_options = array()) { parent::__construct($_dbAdapter, $_options); // set default adapter $config = Tinebase_Core::getConfig(); $adapter = $config->{Tinebase_Auth_CredentialCache_Adapter_Config::CONFIG_KEY} ? 'Config' : 'Cookie'; $this->setCacheAdapter($adapter); }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { $select = parent::_getSelect($_cols, $_getDeleted); // return probableTurnover (turnover * probability) if ($_cols == '*' || array_key_exists('probableTurnover', (array) $_cols)) { $select->columns(array('probableTurnover' => '(' . $this->_db->quoteIdentifier($this->_tableName . '.turnover') . '*' . $this->_db->quoteIdentifier($this->_tableName . '.probability') . '*0.01)')); } return $select; }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { $select = parent::_getSelect($_cols, $_getDeleted); $select->joinLeft(array('op' => $this->_tablePrefix . 'bill_order_position'), $this->_db->quoteIdentifier('op.id') . ' = ' . $this->_db->quoteIdentifier($this->_tableName . '.order_position_id'), array()); $select->joinLeft(array('sa' => $this->_tablePrefix . 'bill_article'), $this->_db->quoteIdentifier('op.article_id') . ' = ' . $this->_db->quoteIdentifier('sa.id'), array()); $select->joinLeft(array('order' => $this->_tablePrefix . 'bill_order'), $this->_db->quoteIdentifier('order.id') . ' = ' . $this->_db->quoteIdentifier('op.order_id'), array()); $select->joinLeft(array('receipt' => $this->_tablePrefix . 'bill_receipt'), $this->_db->quoteIdentifier('receipt.id') . ' = ' . $this->_db->quoteIdentifier($this->_tableName . '.receipt_id'), array()); $select->columns(array('article_id' => 'sa.id', 'unit_id' => 'sa.article_unit_id', 'article_nr' => 'sa.article_nr', 'article_group_id' => 'sa.article_group_id', 'article_series_id' => 'sa.article_series_id', 'article_ext_nr' => 'sa.article_ext_nr', 'name' => 'sa.name', 'description' => 'sa.description', 'price_netto' => 'op.price_netto', 'price_brutto' => 'op.price_brutto', 'min_price_netto' => 'MIN(op.price_netto)', 'min_price_brutto' => 'MIN(op.price_brutto)', 'max_price_netto' => 'MAX(op.price_netto)', 'max_price_brutto' => 'MAX(op.price_brutto)', 'amount' => 'SUM(op.amount)', 'total_netto' => 'SUM(op.total_netto)', 'total_brutto' => 'SUM(op.total_brutto)', 'total1_netto' => 'SUM(op.total1_netto)', 'total1_brutto' => 'SUM(op.total1_brutto)', 'total2_netto' => 'SUM(op.total2_netto)', 'total2_brutto' => 'SUM(op.total2_brutto)', 'date1' => 'MIN(receipt.invoice_date)', 'date2' => 'MAX(receipt.invoice_date)')); $select->group(array('sa.id')); return $select; }
/** * Creates new entry * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_Database * @throws Tinebase_Exception */ public function create(Tinebase_Record_Interface $_record) { try { $newEntry = parent::create($_record); Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . 'Successfully added new schedule task on database system.'); return $newEntry; } catch (Tinebase_Exception_Backend_Database $ex) { Tinebase_Core::getLogger()->error(__METHOD__ . '::' . __LINE__ . 'Database insertion fails at backend unit: ' . print_r($ex, true)); return $ex->getMessage(); } }
/** * converts record into raw data for adapter * * @param Tinebase_Record_Abstract $_record * @return array */ protected function _recordToRawData($_record) { // special handling, convert to UNIX timestamp if (isset($_record['regseconds']) && $_record['regseconds'] instanceof DateTime) { $_record['regseconds'] = $_record['regseconds']->getTimestamp(); } $result = parent::_recordToRawData($_record); // context is joined from the asterisk_context table and can not be set here unset($result['context']); return $result; }
/** * returns columns to fetch in first query and if an id/value pair is requested * * @param array|string $_cols * @param Tinebase_Model_Filter_FilterGroup $_filter * @param Tinebase_Model_Pagination $_pagination * @return array */ protected function _getColumnsToFetch($_cols, Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL) { $result = parent::_getColumnsToFetch($_cols, $_filter, $_pagination); // sanitize sorting fields $foreignTableSortFields = array('size' => 'tree_filerevisions', 'creation_time' => 'tree_fileobjects', 'created_by' => 'tree_fileobjects', 'last_modified_time' => 'tree_fileobjects', 'last_modified_by' => 'tree_fileobjects', 'type' => 'tree_fileobjects', 'contenttype' => 'tree_fileobjects', 'revision' => 'tree_fileobjects'); foreach ($foreignTableSortFields as $field => $table) { if (isset($result[0][$field])) { $result[0][$field] = $table . '.' . $field; } } return $result; }