本文整理汇总了PHP中c2cTools::Model2Module方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::Model2Module方法的具体用法?PHP c2cTools::Model2Module怎么用?PHP c2cTools::Model2Module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cTools
的用法示例。
在下文中一共展示了c2cTools::Model2Module方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeSuggest
public function executeSuggest()
{
sfLoader::loadHelpers(array('General', 'Url'));
$model = $this->hasRequestParameter('module_id') ? c2cTools::module2model(sfConfig::get('app_modules_list')[$this->getRequestParameter('module_id')]) : $this->model_class;
if (!in_array($model, array('Hut', 'Image', 'Parking', 'Product', 'Site', 'Summit', 'User'))) {
return $this->setErrorAndRedirect('Invalid request');
}
$exclude = $this->hasRequestParameter('exclude') ? array_map('intval', explode(',', $this->getRequestParameter('exclude'))) : null;
if ($model == 'User') {
// get user id
$userid = intval($this->getRequestParameter('id'));
if ($userid <= 0) {
return $this->setErrorAndRedirect('Invalid request');
}
$items = Language::getTheBest(User::getFriends($userid, $exclude), $model);
} else {
// get lat, lon and excluded values
$lon = floatval($this->getRequestParameter('lon'));
$lat = floatval($this->getRequestParameter('lat'));
if (!$lon || !$lat) {
return $this->setErrorAndRedirect('Invalid request');
}
$items = Language::getTheBest(Document::getNearest($lon, $lat, $model, $exclude), $model);
}
$output = [];
foreach ($items as $item) {
$routing_rule = $model == 'User' ? '@document_by_id_lang' : '@document_by_id_lang_slug';
array_push($output, array('id' => $item['id'], 'name' => $item[$model . 'I18n'][0]['name'], 'url' => url_for($routing_rule . '?module=' . c2cTools::Model2Module($model) . '&id=' . $item['id'] . '&lang=' . $item[$model . 'I18n'][0]['culture'] . '&slug=' . make_slug($item[$model . 'I18n'][0]['name']))));
}
return $this->renderText(json_encode($output));
}
示例2: doMerge
protected function doMerge($from_id, $document_from, $to_id, $document_to)
{
// fetch associated documents before doing the merging as associations will be transferred
$associations = Association::findAllAssociations($from_id);
parent::doMerge($from_id, $document_from, $to_id, $document_to);
// search documents in which from is inserted, and replace the insertion with to
foreach ($associations as $a) {
$check_id = $a['main_id'] == $from_id ? $a['linked_id'] : ($check_id = $a['main_id']);
$check_model = c2cTools::Letter2Model(substr($a['type'], 0, 1));
$check_module = c2cTools::Model2Module($check_model);
$check_doc = Document::find($check_model, $check_id);
$fields = sfConfig::get('mod_images_bbcode_fields_' . $check_module);
// clear linked doc cache
$this->clearCache($check_module, $check_id);
$languages = $check_doc->getLanguages();
foreach ($languages as $language) {
$modified = false;
$conn = sfDoctrine::Connection();
$conn->beginTransaction();
$check_doc->setCulture($language);
foreach ($fields as $field) {
$text = $check_doc[$field];
$edited = preg_replace('#(\\[img=\\s*)' . $from_id . '([\\w\\s]*\\].*?\\[/img\\])\\n?#is', '${1}' . $to_id . '${2}', $text);
$edited = preg_replace('#(\\[img=\\s*)' . $from_id . '([\\w\\s]*\\/\\])\\n?#is', '${1}' . $to_id . '${2}', $edited);
if ($edited != $text) {
$modified = true;
$check_doc->set($field, $edited);
}
}
if ($modified) {
$history_metadata = new HistoryMetadata();
$history_metadata->setComment('Updated image tags');
$history_metadata->set('is_minor', true);
$history_metadata->set('user_id', sfConfig::get('app_moderator_user_id'));
$history_metadata->save();
c2cTools::log('After merge of image ' . $from_id . ' into ' . $to_id . ': update image tag for ' . strtolower($check_model) . ' ' . $check_id . ' (' . $language . ')');
$check_doc->save();
$conn->commit();
} else {
$conn->rollback();
}
}
}
// clear images lists and whatsnew cache
$this->clearCache('images', 0, true);
}