Esempio n. 1
0
 /**
  * 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;
         $main_id_new = $main_id;
         $linked_document_new = $linked_document;
         $linked_id_new = $linked_id;
     }
     if ($linked_module_new == 'articles') {
         if (!$is_moderator) {
             if ($linked_document_new->get('article_type') == 2 && !Association::find($user_id, $linked_id_new, 'uc')) {
                 return $this->ajax_feedback('You do not have the right to link a document to a personal article');
             }
             if ($main_module_new == 'articles') {
                 if ($main_document_new->get('article_type') == 2 && !Association::find($user_id, $main_id_new, 'uc')) {
                     return $this->ajax_feedback('You do not have the right to link a document to a personal article');
                 }
             }
             if ($main_module_new == 'outings' && !Association::find($user_id, $main_id_new, 'uo')) {
                 return $this->ajax_feedback('You do not have the right to link an article to another user outing');
             }
         }
         if ($linked_document_new->get('article_type') != 2 && $type == 'uc') {
             return $this->ajax_feedback('An user can not be linked to a collaborative article');
         }
     }
     if ($linked_module_new == 'images') {
         if ($main_document_new->get('is_protected') && !$is_moderator) {
             return $this->ajax_feedback('Document is
             protected');
         }
         if (!$is_moderator) {
             if ($main_module_new == 'users' && $main_id_new != $user_id) {
                 return $this->ajax_feedback('You do not have the right to link an image to another user profile');
             }
             if ($main_module_new == 'outings' && !Association::find($user_id, $main_id_new, 'uo')) {
                 return $this->ajax_feedback('You do not have the right to link an image to another user outing');
             }
             if ($main_module_new == 'articles' && $main_document_new->get('article_type') == 2 && !Association::find($user_id, $main_id_new, 'uc')) {
                 return $this->ajax_feedback('You do not have the right to link an image to a personal article');
             }
             if ($main_module_new == 'images' && $main_document_new->get('image_type') == 2 && $document->getCreatorId() != $user_id) {
                 return $this->ajax_feedback('You do not have the right to link an image to a personal image');
             }
         }
     }
     if ($linked_module_new == 'outings') {
         if (!$is_moderator) {
             if ($main_module_new == 'users' && !Association::find($user_id, $linked_id_new, 'uo')) {
                 return $this->ajax_feedback('You do not have the right to link an user to another user outing');
             }
             if ($main_module_new == 'routes' && !Association::find($user_id, $linked_id_new, 'uo')) {
                 return $this->ajax_feedback('You do not have the right to link a route to another user outing');
             }
             if ($main_module_new == 'sites' && !Association::find($user_id, $linked_id_new, 'uo')) {
                 return $this->ajax_feedback('You do not have the right to link a site to another user outing');
             }
         }
     }
     if ($linked_module_new == 'xreports') {
         if (!$is_moderator) {
             if ($main_module_new == 'users' && !Association::find($user_id, $linked_id_new, 'ux')) {
                 return $this->ajax_feedback('You do not have the right to link an user to another user xreport');
             }
             if ($main_module_new == 'outings' && !Association::find($user_id, $linked_id_new, 'ux')) {
                 return $this->ajax_feedback('You do not have the right to link an outing to another user xreport');
             }
             if ($main_module_new == 'routes' && !Association::find($user_id, $linked_id_new, 'ux')) {
                 return $this->ajax_feedback('You do not have the right to link a route to another user xreport');
             }
             if ($main_module_new == 'sites' && !Association::find($user_id, $linked_id_new, 'ux')) {
                 return $this->ajax_feedback('You do not have the right to link a site to another user xreport');
             }
         }
     }
     if ($linked_module_new == 'huts') {
         if ($main_module_new == 'summits') {
             $associations = Association::findAllAssociations($linked_id_new, 'sh');
             if (count($associations)) {
                 return $this->ajax_feedback('This hut is already linked to a summit');
             }
         }
         if ($main_module_new == 'parkings') {
             $associations_pp = Association::findAllAssociations($main_id_new, 'pp');
             $associations_ph = Association::findAllAssociations($linked_id_new, 'ph');
             foreach ($associations_pp as $a_pp) {
                 foreach ($associations_ph as $a_ph) {
                     if ($a_pp['main_id'] == $a_ph['main_id'] || $a_pp['linked_id'] == $a_ph['main_id']) {
                         return $this->ajax_feedback('A parking can not be linked to a hut if a main/sub parking is already linked to it');
                     }
                 }
             }
         }
     }
     if ($linked_module_new == 'routes') {
         if ($main_module_new == 'summits' && $main_document_new->get('summit_type') == 5 && $linked_document_new->get('duration') <= 2) {
             return $this->ajax_feedback('A raid summit can not be linked to a stage route');
         }
         if ($main_module_new == 'huts' && ($main_document_new->get('shelter_type') == 5 || $main_document_new->get('shelter_type') == 6)) {
             return $this->ajax_feedback('A gite can not be linked to a route');
         }
         if ($main_module_new == 'parkings') {
             $associations_pp = Association::findAllAssociations($main_id_new, 'pp');
             $associations_pr = Association::findAllAssociations($linked_id_new, 'pr');
             foreach ($associations_pp as $a_pp) {
                 foreach ($associations_pr as $a_pr) {
                     if ($a_pp['main_id'] == $a_pr['main_id'] || $a_pp['linked_id'] == $a_pr['main_id']) {
                         return $this->ajax_feedback('A parking can not be linked to a route if a main/sub parking is already linked to it');
                     }
                 }
             }
         }
     }
     if ($linked_module_new == 'sites') {
         if ($main_module_new == 'sites') {
             if (Association::countAllMain(array($linked_id_new), 'tt')) {
                 return $this->ajax_feedback('A sub site can not be linked to more than one main site');
             }
         }
         if ($main_module_new == 'summits') {
             if (Association::countAllMain(array($linked_id_new), 'st')) {
                 return $this->ajax_feedback('A site can not be linked to more than one summit');
             }
             if (Association::countAllMain(array($linked_id_new), 'tt')) {
                 return $this->ajax_feedback('A summit can not be linked to a sub site');
             }
         }
         if ($main_module_new == 'parkings') {
             $associations_pp = Association::findAllAssociations($main_id_new, 'pp');
             $associations_pt = Association::findAllAssociations($linked_id_new, 'pt');
             foreach ($associations_pp as $a_pp) {
                 foreach ($associations_pt as $a_pt) {
                     if ($a_pp['main_id'] == $a_pt['main_id'] || $a_pp['linked_id'] == $a_pt['main_id']) {
                         return $this->ajax_feedback('A parking can not be linked to a site if a main/sub parking is already linked to it');
                     }
                 }
             }
         }
     }
     if ($linked_module_new == 'summits') {
         if ($main_module_new == 'summits') {
             if ($main_document_new->get('summit_type') == 5 || $linked_document_new->get('summit_type') == 5) {
                 return $this->ajax_feedback('A raid summit can not be linked to a real summit');
             }
             if (Association::countAllMain(array($linked_id_new), 'ss')) {
                 return $this->ajax_feedback('A sub summit can not be linked to more than one main summit');
             }
         }
     }
     if ($linked_module_new == 'parkings') {
         if ($main_module_new == 'parkings') {
             if (Association::countAllMain(array($linked_id_new), 'pp')) {
                 // return $this->ajax_feedback('A sub parking can not be linked to more than one main parking');
             }
         }
     }
     if (Association::find($main_id_new, $linked_id_new, $type, false)) {
         return $this->ajax_feedback('The document is already linked to the current document');
     }
     if ($linked_module_new == 'outings' && $main_module_new == 'users' && $linked_id != $user_id) {
         // send an email to warn the new user associated
         $email_recipient = UserPrivateData::find($linked_id)->getEmail();
         $email_subject = $this->__('You have been associated to an outing');
         $server = $_SERVER['SERVER_NAME'];
         $outing_link = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . "://{$server}/outings/{$main_id}";
         $htmlBody = $this->__('You have been associated to outing %1% details', array('%1%' => '<a href="' . $outing_link . '">' . $outing_link . '</a>'));
         $mail = new sfMail();
         $mail->setCharset('utf-8');
         // definition of the required parameters
         $mail->setSender(sfConfig::get('app_outgoing_emails_sender'));
         $mail->setFrom(sfConfig::get('app_outgoing_emails_from'));
         $mail->addReplyTo(sfConfig::get('app_outgoing_emails_reply_to'));
         $mail->addAddress($email_recipient);
         $mail->setSubject($email_subject);
         $mail->setContentType('text/html');
         $mail->setBody($htmlBody);
         $mail->setAltBody(strip_tags($htmlBody));
         // send the email
         $mail->send();
     }
     // Perform association
     $a = new Association();
     $status = $a->doSaveWithValues($main_id_new, $linked_id_new, $type, $user_id);
     if (!$status) {
         return $this->ajax_feedback('Could not perform association');
     }
     // cache clearing for current doc in every lang:
     $this->clearCache($main_module, $main_id, false, 'view');
     $this->clearCache($linked_module, $linked_id, false, 'view');
     // html to return
     sfLoader::loadHelpers(array('Tag', 'Url', 'Asset', 'AutoComplete'));
     $linked_document->setBestName($user->getPreferedLanguageList());
     $bestname = $linked_document->get('name');
     if ($linked_module == 'routes') {
         // in that case, output not only route name but also best summit name whose id has been passed (summit_id)
         $summit = explode(' [', $this->getRequestParameter('summits_name'));
         $bestname = $summit[0] . $this->__('&nbsp;:') . ' ' . $bestname;
     }
     $linked_module_name = $icon ? $icon : $this->__($linked_module);
     $type_id_string = $type . '_' . $linked_id;
     $out = link_to($bestname, "@document_by_id?module={$linked_module}&id={$linked_id}");
     if ($user->hasCredential('moderator')) {
         $out .= c2c_link_to_delete_element($type, $main_id_new, $linked_id_new, !$swap, $strict);
     }
     if ($div) {
         $icon_string = '';
         if ($icon) {
             $icon_string = '<div class="assoc_img picto_' . $icon . '" title="' . ucfirst(__($icon)) . '">' . '<span>' . ucfirst(__($icon)) . __('&nbsp;:') . '</span>' . '</div>';
         }
         $out = '<div class="linked_elt" id="' . $type_id_string . '">' . $icon_string . $out . '</div>';
     } else {
         $out = '<li id="' . $type_id_string . '">' . picto_tag('picto_' . $linked_module, $linked_module_name) . ' ' . $out . '</li>';
     }
     return $this->renderText($out);
 }
Esempio n. 2
0
 protected function endEdit()
 {
     //Test if form is submitted or not
     if ($this->success) {
         // try to perform association with linked_doc (if pertinent)
         $summit_id = $this->getRequestParameter('summit_id');
         $id = $this->document->get('id');
         $user_id = $this->getUser()->getId();
         if ($this->new_document && $summit_id || $summit_id && !Association::find($summit_id, $id, 'sr')) {
             $sr = new Association();
             $sr->doSaveWithValues($summit_id, $id, 'sr', $user_id);
             // main, linked, type
             // clear cache of associated summit ...
             $this->clearCache('summits', $summit_id, false, 'view');
         }
         // here if we have created a new document and if $this->document->get('geom_wkt') is null, then use associated doc geom associations:
         // this allows us to filter on ranges even if no GPX is uploaded
         if ($this->new_document && $summit_id && !$this->document->get('geom_wkt')) {
             // get all associated regions (3+maps) with this summit:
             $associations = GeoAssociation::findAllAssociations($summit_id, array('dr', 'dc', 'dd', 'dv', 'dm'));
             // replicate them with route_id instead of summit_id:
             foreach ($associations as $ea) {
                 $a = new GeoAssociation();
                 $a->doSaveWithValues($id, $ea->get('linked_id'), $ea->get('type'));
             }
         }
         // if we add a route to a summit-hut, link the route to the hut
         $hut_asso = Association::findAllAssociations($summit_id, 'sh');
         if ($this->new_document && $summit_id && count($hut_asso) > 0) {
             // associate hut to summit
             $asso = new Association();
             $hut_id = $hut_asso[0]->get('linked_id');
             $asso->doSaveWithValues($hut_id, $id, 'hr', 2);
             // C2C user
             // clear cache of associated hut ...
             $this->clearCache('huts', $hut_id, false, 'view');
         }
         parent::endEdit();
         // redirect to document view
     } else {
         if ($this->link_with = $this->getRequestParameter('link')) {
             // linked_doc was already retrieved in filterAdditionalParameters
             if ($this->linked_doc) {
                 $this->linked_doc->setBestCulture($this->getUser()->getCulturesForDocuments());
             }
         } else {
             $this->linked_doc = $this->getHighestSummit();
         }
     }
 }
Esempio n. 3
0
 public static function customSave($name, $filename, $associated_doc_id, $user_id, $model, $activities = array(), $categories = array(), $image_type = 1)
 {
     $base_path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR;
     $from = $base_path . sfConfig::get('app_images_temp_directory_name');
     $to = $base_path . sfConfig::get('app_images_directory_name');
     c2cTools::log("linking image {$filename} to {$model} {$associated_doc_id}, with title \"{$name}\", user {$user_id} ");
     // save a new image...
     $image = new Image();
     $image->setCulture(sfContext::getInstance()->getUser()->getCulture());
     $image->set('name', $name);
     $image->set('filename', $filename);
     // get and store image dimensions and size
     $size = getimagesize($from . DIRECTORY_SEPARATOR . $filename);
     if ($size) {
         $image->set('width', $size[0]);
         $image->set('height', $size[1]);
     }
     $image->set('file_size', filesize($from . DIRECTORY_SEPARATOR . $filename));
     // here, read eventual lon, lat, elevation and other interesting fields from exif tag...
     // (nb: always after $image->set('filename', $filename))
     $image->populateWithExifDataFrom($from . DIRECTORY_SEPARATOR . $filename);
     // here, copy activities field from the linked document (if it exists):
     if (!empty($activities)) {
         $image->set('activities', $activities);
     }
     if (!empty($categories)) {
         $image->set('categories', $categories);
     }
     $image->set('image_type', $image_type);
     $image->set('has_svg', Images::hasSVG($filename, $from));
     // then save:
     $image->doSaveWithMetadata($user_id, false, 'Image uploaded');
     c2cTools::log('associating and moving files');
     $image_id = $image->get('id');
     $type = c2cTools::Model2Letter($model) . 'i';
     // associate it
     $a = new Association();
     $a->doSaveWithValues($associated_doc_id, $image_id, $type, $user_id);
     // move to uploaded images directory (move the big, small and all other configured in yaml)
     Images::moveAll($filename, $from, $to);
     return $image_id;
 }
Esempio n. 4
0
 protected function endEdit()
 {
     //Test if form is submitted or not
     if ($this->success) {
         // if this is the first version of the outing (aka creation)
         // set a flash message to encourage to also enhance the corresponding route
         if (is_null($this->document->getVersion())) {
             $this->setNotice('thanks for new outing');
         }
         // try to perform association with linked_doc (if pertinent)
         $associated_id = $this->getRequestParameter('document_id');
         $user_id = $this->getUser()->getId();
         $id = $this->document->get('id');
         if ($this->new_document && $associated_id || $associated_id && !Association::find($associated_id, $id)) {
             // we must get this document's module (site or route ?)
             $associated_doc = Document::find('Document', $associated_id, array('module'));
             if ($associated_doc) {
                 $associated_module = $associated_doc->get('module');
                 $a = new Association();
                 if ($associated_module == 'routes') {
                     $a->doSaveWithValues($associated_id, $id, 'ro', $user_id);
                     // main, linked, type
                     // clear cache of associated route ...
                     $this->clearCache('routes', $associated_id, false, 'view');
                 } elseif ($associated_module == 'sites') {
                     $a->doSaveWithValues($associated_id, $id, 'to', $user_id);
                     // main, linked, type
                     // clear cache of associated site ...
                     $this->clearCache('sites', $associated_id, false, 'view');
                 }
                 // here if we have created a new document and if $this->document->get('geom_wkt') is null, then use associated doc geom associations:
                 // this allows us to filter on ranges even if no GPX is uploaded
                 if ($this->new_document && $associated_id && !$this->document->get('geom_wkt')) {
                     // get all associated regions (only regions, countries, depts, no maps !) with this summit:
                     $associations = GeoAssociation::findAllAssociations($associated_id, array('dr', 'dc', 'dd', 'dv'));
                     // replicate them with outing_id instead of (route_id or site_id):
                     foreach ($associations as $ea) {
                         $areas_id = $ea->get('linked_id');
                         $a = new GeoAssociation();
                         $a->doSaveWithValues($id, $areas_id, $ea->get('type'));
                         // clear cache of associated areas
                         $this->clearCache('areas', $areas_id, false, 'view');
                     }
                 }
             }
         }
         // create also association with current user.
         if ($this->new_document) {
             $uo = new Association();
             $uo->doSaveWithValues($user_id, $id, 'uo', $user_id);
             // main, linked, type
             // clear cache of current user
             $this->clearCache('users', $user_id, false, 'view');
         }
         // create association with MW contest article, if requested
         if ($this->new_document) {
             $mw_contest_associate = $this->getRequestParameter('mw_contest_associate');
             if ($mw_contest_associate) {
                 $mw_article_id = sfConfig::get('app_mw_contest_id');
                 $oc = new Association();
                 $oc->doSaveWithValues($id, $mw_article_id, 'oc', $user_id);
             }
         }
         parent::endEdit();
         // redirect to document view
     }
 }
         continue;
     }
     // get image id corresponding to filename
     $query = Doctrine_Query::create()->select('i.id')->from('Image i')->where('filename = \'' . $tag[1] . "'");
     $image_data = $query->execute()->getFirst();
     if (!empty($image_data)) {
         // does the relation already exists, or should it be created?
         $association = Association::find($doc['id'], $image_data['id'], $association_type, true);
         if (empty($association)) {
             // create association
             if ($DEBUG) {
                 echo '  Create association with image ' . $image_data['id'] . "\n";
             }
             if (!$DRY_RUN) {
                 $asso = new Association();
                 $asso->doSaveWithValues($doc['id'], $image_data['id'], $association_type, $TOPO_MODERATOR_USER_ID);
             }
             $stat_associations_required++;
         }
         $image_ids[$tag[1]] = $image_data['id'];
     } else {
         // no corresponding id, the tag is incorrect and must not be modified. but a warning should be notified
         $stat_docs_with_invalid_references[] = $doc['id'] . ' (' . $doc['culture'] . ' - ' . $doc['name'] . ') http://' . $SERVER_NAME . '/' . strtolower($table) . 's' . '/' . $doc['id'] . '/' . $doc['culture'] . "\n";
     }
 }
 // replace image tags
 $conn = sfDoctrine::Connection();
 $db_doc = Document::find($table, $doc['id']);
 if (!$DRY_RUN) {
     $conn->beginTransaction();
     $history_metadata = new HistoryMetadata();
Esempio n. 6
0
 public function executeAddroute()
 {
     $id = $this->getRequestParameter('document_id');
     // check if a summit is already associated to hut. if not, create it
     $create_summit = Association::countMains($id, 'sh') == 0;
     if ($create_summit) {
         $document = Document::find('Hut', $id, array('elevation', 'geom_wkt'));
         $conn = sfDoctrine::Connection();
         try {
             $conn->beginTransaction();
             // create first version of document, with culture and geometry of hut document
             $hut_elevation = $document['elevation'];
             $hut_lat = $document['lat'];
             $hut_lon = $document['lon'];
             $hut_culture = $document->getCulture();
             $hut_name = $document['name'];
             $history_metadata = new HistoryMetadata();
             $history_metadata->setComment($this->__('Created summit synchronized with hut for access'));
             $history_metadata->set('is_minor', false);
             $history_metadata->set('user_id', 2);
             // C2C user
             $history_metadata->save();
             $summit = new Summit();
             $summit->setCulture($hut_culture);
             $summit->set('name', $hut_name);
             $summit->set('elevation', $hut_elevation);
             $summit->set('summit_type', 100);
             // set summit type to ' hut'
             $summit->set('lat', $hut_lat);
             $summit->set('lon', $hut_lon);
             $summit->save();
             $conn->commit();
             // add others culture versions
             foreach ($document->get('HutI18n') as $i18n) {
                 $culture = $i18n->getCulture();
                 if ($culture != $hut_culture) {
                     $conn->beginTransaction();
                     $hut_name = $i18n->getName();
                     $history_metadata = new HistoryMetadata();
                     $history_metadata->setComment($this->__('Created summit synchronized with hut for access'));
                     $history_metadata->set('is_minor', false);
                     $history_metadata->set('user_id', 2);
                     // C2C user
                     $history_metadata->save();
                     $summit->setCulture($culture);
                     $summit->set('name', $hut_name);
                     $summit->save();
                     $conn->commit();
                 }
             }
         } catch (Exception $e) {
             $conn->rollback();
             return $this->setErrorAndRedirect($this->__('Failed to create synchronized summit'), "routes/edit?link={$summit_id}");
         }
         $summit_id = $summit->get('id');
         // get all associated regions (3+maps) with this hut:
         $associations = GeoAssociation::findAllAssociations($id, array('dr', 'dc', 'dd', 'dv', 'dm'));
         // replicate them with summit_id instead of id:
         foreach ($associations as $ea) {
             $a = new GeoAssociation();
             $a->doSaveWithValues($summit_id, $ea->get('linked_id'), $ea->get('type'));
         }
         // associate hut to summit
         $asso = new Association();
         $asso->doSaveWithValues($summit_id, $id, 'sh', 2);
         // C2C user
     } else {
         $associations = Association::findAllAssociations($id, 'sh');
         $summit_id = $associations[0]->get('main_id');
     }
     $this->clearCache('huts', $id);
     return $this->redirect("routes/edit?link={$summit_id}");
 }
Esempio n. 7
0
 protected function endEdit()
 {
     if ($this->success) {
         // create also association with current user (only if this is a personal article)
         if ($this->new_document && $this->document->get('article_type') == 2) {
             $user_id = $this->getUser()->getId();
             $uc = new Association();
             $uc->doSaveWithValues($user_id, $this->document->get('id'), 'uc', $user_id);
             // main, linked, type
         }
         parent::endEdit();
         // redirect to document view
     }
 }