当前位置: 首页>>代码示例>>PHP>>正文


PHP c2cTools::Type2Modules方法代码示例

本文整理汇总了PHP中c2cTools::Type2Modules方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::Type2Modules方法的具体用法?PHP c2cTools::Type2Modules怎么用?PHP c2cTools::Type2Modules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在c2cTools的用法示例。


在下文中一共展示了c2cTools::Type2Modules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addAssociatedDocuments

 public static function addAssociatedDocuments(&$docs, $type, $is_main, $data_fields = array(), $i18n_fields = array())
 {
     if (count($docs) == 0 || empty($data_fields) && empty($i18n_fields)) {
         return array();
     }
     $modules = c2cTools::Type2Modules($type);
     $main_module = $modules['main'];
     $linked_module = $modules['linked'];
     if (empty($main_module) || empty($linked_module)) {
         return array();
     }
     $doc_ids = array();
     foreach (array_keys($docs) as $key) {
         $id = $docs[$key]['id'];
         $doc_ids[] = $id;
         $docs[$id] = $docs[$key];
         unset($docs[$key]);
     }
     // retrieve associations
     if ($main_module == $linked_module) {
         $associations = Association::countAll($doc_ids, $type);
         $module = $main_module;
     } elseif ($is_main) {
         $associations = Association::countAllLinked($doc_ids, $type);
         $module = $linked_module;
     } else {
         $associations = Association::countAllMain($doc_ids, $type);
         $module = $main_module;
     }
     if (count($associations) == 0) {
         return array();
     }
     $linked_ids = array();
     foreach ($associations as $assoc) {
         if ($is_main) {
             $doc_id = $assoc['main_id'];
             $linked_id = $assoc['linked_id'];
         } else {
             $doc_id = $assoc['linked_id'];
             $linked_id = $assoc['main_id'];
         }
         $linked_ids[] = $linked_id;
         if (isset($docs[$doc_id]['linked_docs'])) {
             $docs[$doc_id]['linked_docs'] = array_merge($docs[$doc_id]['linked_docs'], array($linked_id));
         } else {
             $docs[$doc_id]['linked_docs'] = array($linked_id);
         }
     }
     $linked_ids = array_unique($linked_ids);
     $conditions = array();
     foreach ($linked_ids as $id) {
         $conditions[] = '?';
     }
     // retrieve info on the linked docs (name etc)
     $model = c2cTools::module2model($module);
     $q = Doctrine_Query::create()->from("{$model} m")->where('m.id IN ( ' . implode(', ', $conditions) . ' )', $linked_ids);
     if (!in_array('id', $data_fields)) {
         $data_fields[] = 'id';
     }
     $q->addSelect('m.' . implode(', m.', $data_fields));
     $has_name = false;
     if (!empty($i18n_fields)) {
         if (in_array('name', $i18n_fields)) {
             if (!in_array('search_name', $i18n_fields)) {
                 $i18n_fields[] = 'search_name';
                 $i18n_fields[] = 'culture';
             }
             $has_name = true;
         }
         $q->addSelect('mi.' . implode(', mi.', $i18n_fields))->leftJoin('m.' . $model . 'I18n mi');
     }
     $linked_docs_info = $q->execute(array(), Doctrine::FETCH_ARRAY);
     if ($has_name) {
         $user_prefered_langs = sfContext::getInstance()->getUser()->getCulturesForDocuments();
         $linked_docs_info = Language::getTheBest($linked_docs_info, $model);
     }
     // add linked docs info into $docs
     foreach ($docs as $doc_id => $doc) {
         if (isset($doc['linked_docs'])) {
             foreach ($doc['linked_docs'] as $key => $linked_doc_id) {
                 $docs[$doc_id]['linked_docs'][$key] = $linked_docs_info[$linked_doc_id];
             }
         }
     }
 }
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:85,代码来源:BaseDocument.class.php


注:本文中的c2cTools::Type2Modules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。