本文整理汇总了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];
}
}
}
}