Example #1
0
 /**
  * get export object for given filter and format
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string|array $_options format (as string) or export definition id (array)
  * @param Tinebase_Controller_Record_Interface $_controller (optional)
  * @param array $_additionalOptions (optional)
  * @return Tinebase_Export_Abstract
  * @throws Tinebase_Exception_NotFound
  */
 public static function factory($_filter, $_options, $_controller = NULL, $_additionalOptions = array())
 {
     if (!is_array($_options)) {
         $_options = array('format' => $_options);
     }
     if (array_key_exists('definitionId', $_options)) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->get($_options['definitionId']);
         $exportClass = $definition->plugin;
         // export plugin needs the definition id
         $_additionalOptions = array_merge($_additionalOptions, $_options);
     } else {
         if (array_key_exists('format', $_options) && !empty($_options['format'])) {
             $appName = $_filter->getApplicationName();
             $model = $_filter->getModelName();
             $exportClass = $appName . '_Export_' . ucfirst(strtolower($_options['format']));
             if (!@class_exists($exportClass)) {
                 // check for model specific export class
                 list($a, $b, $modelPart) = explode('_', $model);
                 $exportClass = $exportClass . '_' . $modelPart;
                 if (!@class_exists($exportClass)) {
                     throw new Tinebase_Exception_NotFound('No ' . $_options['format'] . ' export class found for ' . $appName . ' / ' . $model);
                 }
             }
         } else {
             throw new Tinebase_Exception_InvalidArgument('Export definition ID or format required in options');
         }
     }
     if (preg_match('/pdf/i', $exportClass)) {
         // legacy
         $result = new $exportClass($_additionalOptions);
     } else {
         $result = new $exportClass($_filter, $_controller, $_additionalOptions);
     }
     return $result;
 }
 /**
  * get export object for given filter and format
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string|array $_options format (as string) or export definition id (array)
  * @param Tinebase_Controller_Record_Interface $_controller (optional)
  * @param array $_additionalOptions (optional)
  * @return Tinebase_Export_Abstract
  * @throws Tinebase_Exception_NotFound
  */
 public static function factory($_filter, $_options, $_controller = NULL, $_additionalOptions = array())
 {
     if (!is_array($_options)) {
         $_options = array('format' => $_options);
     }
     // always merge options? this needs to be refactored!
     $_additionalOptions = array_merge($_additionalOptions, $_options);
     if (isset($_options['definitionId']) || array_key_exists('definitionId', $_options)) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->get($_options['definitionId']);
         $exportClass = $definition->plugin;
     } else {
         if ((isset($_options['format']) || array_key_exists('format', $_options)) && !empty($_options['format'])) {
             $appName = $_filter->getApplicationName();
             $model = $_filter->getModelName();
             $exportClass = $appName . '_Export_' . ucfirst(strtolower($_options['format']));
             // start output buffering to catch errors, append them to log and exception
             ob_start();
             if (!class_exists($exportClass)) {
                 $ob = ob_get_length() > 0 ? ob_get_clean() : '';
                 // check for model specific export class
                 list($a, $b, $modelPart) = explode('_', $model);
                 $exportClass2 = $exportClass . '_' . $modelPart;
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                     Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Could not find class ' . $exportClass . ' trying ' . $exportClass2 . '. Output Buffer: ' . PHP_EOL . $ob, Zend_Log::NOTICE);
                 }
                 if (!class_exists($exportClass2)) {
                     $ob = ob_get_length() > 0 ? ob_get_clean() : NULL;
                     ob_end_flush();
                     throw new Tinebase_Exception_NotFound('No ' . $_options['format'] . ' export class found for ' . $appName . ' / ' . $model . '. ClassName: ' . $exportClass2 . ($ob ? 'Output: ' . $ob : ''));
                 } else {
                     $exportClass = $exportClass2;
                 }
             }
             ob_end_flush();
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Export options: ' . print_r($_options, TRUE));
             }
             throw new Tinebase_Exception_InvalidArgument('Export definition ID or format required in options');
         }
     }
     if (preg_match('/pdf/i', $exportClass)) {
         // legacy
         $result = new $exportClass($_additionalOptions);
     } else {
         $result = new $exportClass($_filter, $_controller, $_additionalOptions);
     }
     return $result;
 }
Example #3
0
 /**
  * Searches tags according to foreign filter
  * -> returns the count of tag occurrences in the result set
  *
  * @param  Tinebase_Model_Filter_FilterGroup $_filter
  * @return Tinebase_Record_RecordSet  Set of Tinebase_Model_Tag
  */
 public function searchTagsByForeignFilter($_filter)
 {
     $controller = Tinebase_Core::getApplicationInstance($_filter->getApplicationName(), $_filter->getModelName());
     $recordIds = $controller->search($_filter, NULL, FALSE, TRUE);
     if (!empty($recordIds)) {
         $app = Tinebase_Application::getInstance()->getApplicationByName($_filter->getApplicationName());
         $select = $this->_getSelect($recordIds, $app->getId());
         Tinebase_Model_TagRight::applyAclSql($select);
         $tags = $this->_db->fetchAll($select);
         $tagData = $this->_getDistinctTagsAndComputeOccurrence($tags);
     } else {
         $tagData = array();
     }
     return new Tinebase_Record_RecordSet('Tinebase_Model_Tag', $tagData);
 }
 /**
  * Removes containers where current user has no access to
  *
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string $_action get|update
  */
 public function checkFilterACL(Tinebase_Model_Filter_FilterGroup $_filter, $_action = 'get')
 {
     if (!$this->_doContainerACLChecks) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Container ACL disabled for ' . $_filter->getModelName() . '.');
         }
         return TRUE;
     }
     $aclFilters = $_filter->getAclFilters();
     if (!$aclFilters) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Force a standard containerFilter (specialNode = all) as ACL filter.');
         }
         $containerFilter = $_filter->createFilter('container_id', 'specialNode', 'all', array('applicationName' => $_filter->getApplicationName()));
         $_filter->addFilter($containerFilter);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Setting filter grants for action ' . $_action);
     }
     switch ($_action) {
         case 'get':
             $_filter->setRequiredGrants(array(Tinebase_Model_Grants::GRANT_READ, Tinebase_Model_Grants::GRANT_ADMIN));
             break;
         case 'update':
             $_filter->setRequiredGrants(array(Tinebase_Model_Grants::GRANT_EDIT, Tinebase_Model_Grants::GRANT_ADMIN));
             break;
         case 'export':
             $_filter->setRequiredGrants(array(Tinebase_Model_Grants::GRANT_EXPORT, Tinebase_Model_Grants::GRANT_ADMIN));
             break;
         case 'sync':
             $_filter->setRequiredGrants(array(Tinebase_Model_Grants::GRANT_SYNC, Tinebase_Model_Grants::GRANT_ADMIN));
             break;
         default:
             throw new Tinebase_Exception_UnexpectedValue('Unknown action: ' . $_action);
     }
 }