示例#1
0
 /**
  * Changes the association order for associations of same type (eg summit-summit)
  * It should only be used for ss, pp and tt associations, but there is probably
  * no real problem if other associations are inverted
  */
 public function executeInvertAssociation()
 {
     $user = $this->getUser();
     $user_id = $user->getId();
     $is_moderator = $user->hasCredential('moderator');
     $type = $this->getRequestParameter('type');
     $main_id = $this->getRequestParameter('main_id');
     $linked_id = $this->getRequestParameter('linked_id');
     // check if session timed out
     if (!$user_id) {
         return $this->setErrorAndRedirect('Session is over. Please login again.', $this->getRequest()->getReferer());
     }
     // only moderators can perform such actions
     if (!$is_moderator) {
         return $this->setErrorAndRedirect('You do not have enough credentials to perform this operation', $this->getRequest()->getReferer());
     }
     // we check that the association type really exists and that the two
     // documents are from the same model
     if (substr($type, 0, 1) != substr($type, -1) || !in_array($type, sfConfig::get('app_associations_types'))) {
         return $this->ajax_feedback('Wrong association type');
     }
     // check that association exists in database
     $models = c2cTools::Type2Models($type);
     $model = $models['main'];
     $module = c2cTools::model2module($model);
     $a = Association::find($main_id, $linked_id, $type);
     // strict search
     if (!$a) {
         return $this->setErrorAndRedirect('Operation not allowed', $this->getRequest()->getReferer());
     }
     // invert association
     $conn = sfDoctrine::Connection();
     try {
         $conn->beginTransaction();
         $a->main_id = $linked_id;
         $a->linked_id = $main_id;
         $a->save();
         $al1 = new AssociationLog();
         $al1->main_id = $main_id;
         $al1->linked_id = $linked_id;
         $al1->type = $type;
         $al1->user_id = $user_id;
         $al1->is_creation = 'false';
         $al1->save();
         $al1 = new AssociationLog();
         $al1->main_id = $linked_id;
         $al1->linked_id = $main_id;
         $al1->type = $type;
         $al1->user_id = $user_id;
         $al1->is_creation = 'true';
         $al1->save();
         $conn->commit();
     } catch (exception $e) {
         $conn->rollback();
         c2cTools::log("executeInvertAssociation() : invertion failed ({$main_id}, {$linked_id}, {$type}, {$user_id}) - rollback");
         return $this->ajax_feedback('Association invertion failed');
     }
     // remove cache and force page reload
     $this->clearCache($module, $main_id, false, 'view');
     $this->clearCache($module, $linked_id, false, 'view');
     return $this->setNoticeAndRedirect('Association inverted', $this->getRequest()->getReferer());
 }
echo __('Linked document');
?>
</th>
            <th><?php 
echo __('Author');
?>
</th>
        </tr>
    </thead>
    <tbody>
    <?php 
$table_list_even_odd = 0;
foreach ($items as $item) {
    $table_class = $table_list_even_odd++ % 2 == 0 ? 'table_list_even' : 'table_list_odd';
    $user_link = '@document_by_id?module=users&id=' . $item['user_private_data']['id'];
    $models = c2cTools::Type2Models($item['type']);
    $main_module = c2cTools::model2module($models['main']);
    $linked_module = c2cTools::model2module($models['linked']);
    $main_item = count($item['mainI18n']) ? $item['mainI18n'][0] : null;
    $linked_item = count($item['linkedI18n']) ? $item['linkedI18n'][0] : null;
    // FIXME: routes slugs
    $main_link = '@document_by_id_lang_slug?module=' . $main_module . '&id=' . $item['main_id'] . '&lang=' . $main_item['culture'] . '&slug=' . make_slug($main_item['name']);
    $linked_link = '@document_by_id_lang_slug?module=' . $linked_module . '&id=' . $item['linked_id'] . '&lang=' . $linked_item['culture'] . '&slug=' . make_slug($linked_item['name']);
    ?>
        <tr class="<?php 
    echo $table_class;
    if ($item['is_creation']) {
        echo ' creation';
    } else {
        echo ' deletion';
    }