本文整理汇总了PHP中c2cTools::Modules2Type方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::Modules2Type方法的具体用法?PHP c2cTools::Modules2Type怎么用?PHP c2cTools::Modules2Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cTools
的用法示例。
在下文中一共展示了c2cTools::Modules2Type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeAddAssociation
/**
* Executes "associate current document with document" action
* associated document can only be : articles, summits, books, huts, outings, routes, sites, users
* ... restricted in security.yml to logged people
*/
public function executeAddAssociation()
{
$user = $this->getUser();
$user_id = $user->getId();
$is_moderator = $user->hasCredential(sfConfig::get('app_credentials_moderator'));
//
// Get parameters and check that association is allowed
//
// if session is time-over
if (!$user_id) {
return $this->ajax_feedback('Session is over. Please login again.');
}
if (!$this->hasRequestParameter('document_id') || !$this->hasRequestParameter('main_id') || !$this->hasRequestParameter('document_module')) {
return $this->ajax_feedback('Operation not allowed');
}
$main_module = $this->getRequestParameter('module');
$main_id = $this->getRequestParameter('main_id');
$linked_module = $this->getRequestParameter('document_module');
$linked_id = $this->getRequestParameter('document_id');
$icon = $this->getRequestParameter('icon', '');
$div = $this->getRequestParameter('div', false);
if ($linked_id == $main_id) {
return $this->ajax_feedback('A document can not be linked to itself');
}
switch ($linked_module) {
case 'summits':
$fields = array('id', 'is_protected', 'summit_type');
break;
case 'routes':
$fields = array('id', 'is_protected', 'duration');
break;
case 'huts':
$fields = array('id', 'is_protected', 'shelter_type');
break;
case 'articles':
$fields = array('id', 'is_protected', 'article_type');
break;
case 'images':
$fields = array('id', 'is_protected', 'image_type');
break;
case 'documents':
$fields = array('id', 'is_protected', 'module');
break;
// FIXME prevent such case?
// FIXME prevent such case?
default:
$fields = array('id', 'is_protected');
break;
}
$linked_document = Document::find(c2cTools::module2model($linked_module), $linked_id, $fields);
$linked_module = $linked_module != 'documents' ? $linked_module : $linked_document->get('module');
if (!$linked_document) {
return $this->ajax_feedback('Linked document does not exist');
}
$type_modules = c2cTools::Modules2Type($main_module, $linked_module);
if (empty($type_modules)) {
return $this->ajax_feedback('Wrong association type');
}
list($type, $swap, $main_module_new, $linked_module_new, $strict) = $type_modules;
switch ($main_module) {
case 'summits':
$fields = array('id', 'is_protected', 'summit_type');
break;
case 'routes':
$fields = array('id', 'is_protected', 'duration');
break;
case 'huts':
$fields = array('id', 'is_protected', 'shelter_type');
break;
case 'articles':
$fields = array('id', 'is_protected', 'article_type');
break;
case 'images':
$fields = array('id', 'is_protected', 'image_type');
break;
case 'documents':
$fields = array('id', 'is_protected', 'module');
break;
// FIXME prevent such case?
// FIXME prevent such case?
default:
$fields = array('id', 'is_protected');
break;
}
$main_document = Document::find(c2cTools::module2model($main_module), $main_id, $fields);
if (!$main_document) {
return $this->ajax_feedback('Main document does not exist');
}
if ($swap) {
$main_document_new = $linked_document;
$main_id_new = $linked_id;
$linked_document_new = $main_document;
$linked_id_new = $main_id;
} else {
$main_document_new = $main_document;
//.........这里部分代码省略.........