Esempio n. 1
0
 public function testThatItParsesAssociationsWithName()
 {
     $association = new Association('[Member]-Posts-[Comment]');
     $this->assertEquals('Posts', $association->getName());
     $this->assertEquals('Member', $association->getFrom());
     $this->assertEquals('Comment', $association->getTo());
 }
Esempio n. 2
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     parent::executeView();
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         $user = $this->getUser();
         $prefered_cultures = $user->getCulturesForDocuments();
         $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
         if (count($associated_parkings)) {
             $associated_parkings = Association::createHierarchyWithBestName($associated_parkings, $prefered_cultures, array('type' => 'pp'));
             $associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
         }
         $this->associated_parkings = $associated_parkings;
         $related_portals = array();
         Portal::getLocalPortals($related_portals, $this->associated_areas);
         $this->related_portals = $related_portals;
         $product_type_list = sfConfig::get('mod_products_types_list');
         $product_type_index_list = $this->document->get('product_type');
         $product_type_name_list = array();
         foreach ($product_type_index_list as $product_type_index) {
             $product_type_name_list[] = $this->__($product_type_list[$product_type_index]);
         }
         $product_types = implode(', ', $product_type_name_list);
         $doc_name = $this->document->get('name');
         $title = $doc_name;
         if ($this->document->isArchive()) {
             $version = $this->getRequestParameter('version');
             $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         }
         $title .= ' :: ' . $product_types;
         $this->setPageTitle($title);
         $description = array($product_types . ' :: ' . $doc_name, $this->getAreasList());
         $this->getResponse()->addMeta('description', implode(' - ', $description));
     }
 }
Esempio n. 3
0
 function __construct(&$source, $dest, $options = null)
 {
     parent::__construct($source, $dest, $options);
     if (!isset($options['foreign_key'])) {
         $this->foreign_key = ActiveRecordInflector::foreign_key($this->dest_class);
     }
 }
Esempio n. 4
0
 public function initContent()
 {
     $this->association = Association::getAssociationById($this->idAssociation);
     $this->context->smarty->assign(array('association' => $this->association[0]));
     //pass data to template file
     $this->setTemplate(_PS_THEME_DIR_ . 'association.tpl');
     //call parent initcontent - this is for loading the site's default header, footer, left and right columns
     parent::initContent();
 }
 public function executeForm_fields_image_type()
 {
     // who has the right to change the license:
     // * only moderators have all right
     //  - but they can switch to copyright license only if the image is associated to a book
     // * the creator can switch from personal to collaborative
     // * other users cannot
     $creator = $this->document->getCreator();
     $image_type = $this->document->get('image_type');
     // check if the image is already associated to a book (required to decide whether "copyright" is allowed or not)
     $id = $this->document['id'];
     $associations = Association::findAllAssociations($id, 'bi');
     $this->hide_image_type_edit = !$this->moderator && $image_type != 2 || !$this->moderator && $this->getContext()->getUser()->getId() != $creator['id'];
     // allow copyright license only for images associated to books, and only to moderators
     $this->allow_copyright = $this->moderator && (count($associations) > 0 || $image_type == 3);
 }
 function get($assoc_type)
 {
     assert('$assoc_type == "HMAC-SHA1"');
     // $handle = sprintf( '{%s}%d/%d',  $assoc_type, localtime(), $this->count );
     $path = tempnam($this->store_dir, $assoc_type . '_');
     $handle = basename($path);
     $this->count += 1;
     $secret = oidUtil::random_string(20, null);
     $assoc = Association::from_expires_in($handle, $secret, $this->lifespan);
     $fh = fopen($path, 'w');
     if ($fh) {
         fwrite($fh, base64_encode(@serialize($assoc)));
         fclose($fh);
     }
     return $assoc;
 }
Esempio n. 7
0
 /**
  * @param string $string The string to parse
  */
 public function __construct($string)
 {
     $string = preg_replace(self::COMMENT_PATTERN, '', $string);
     preg_match_all('/' . ClassObject::PATTERN . '/i', $string, $classMatches, PREG_SET_ORDER);
     foreach ($classMatches as $classMatch) {
         $name = $classMatch[ClassObject::PATTERN_NAME_GROUP];
         $class = $this->getClass($name);
         if ($class === null) {
             $this->classes[] = new ClassObject($classMatch[0]);
         } else {
             $this->replaceClass($name, new ClassObject($classMatch[0], $class));
         }
     }
     preg_match_all(Association::getPattern(), $string, $associationMatches, PREG_SET_ORDER);
     foreach ($associationMatches as $associationMatch) {
         $this->associations[] = new Association($associationMatch[0]);
     }
 }
Esempio n. 8
0
function showUmlImage($json)
{
    $title = "View As UML Image";
    $icon = "png.png";
    ?>
  <html>
  <head>
    <title> <?php 
    echo $title;
    ?>
 </title>
    <link rel="shortcut icon" href=<?php 
    echo $icon;
    ?>
 type="image/x-icon" />
  </head>
  </html>
  <?php 
    header("Content-type: image/png");
    require_once "canvas.php";
    $canvas = new Canvas(950, 350);
    $diagram = $canvas->createDiagram();
    $classIds = array();
    foreach ($json->umpleClasses as $umpleClass) {
        $umplePosition = $umpleClass->position;
        $classEntity = new ClassEntity($umpleClass->name, new Position($umplePosition->x, $umplePosition->y, $umplePosition->width, $umplePosition->height));
        $classIds[$umpleClass->id] = $classEntity;
        $classEntity->draw($diagram);
    }
    foreach ($json->umpleAssociations as $umpleAssociation) {
        $classEntity1 = $classIds[$umpleAssociation->classOneId];
        $classEntity2 = $classIds[$umpleAssociation->classTwoId];
        $mult1 = new MultiplicityEnd($classEntity1);
        $mult2 = new MultiplicityEnd($classEntity2);
        $association = new Association($mult1, $mult2);
        $c1Position = $classEntity1->getPosition();
        $c1Offset = $umpleAssociation->offsetOnePosition;
        $c2Position = $classEntity2->getPosition();
        $c2Offset = $umpleAssociation->offsetTwoPosition;
        $p1 = new Point($c1Position->getX() + $c1Offset->x, $c1Position->getY() + $c1Offset->y);
        $p2 = new Point($c2Position->getX() + $c2Offset->x, $c2Position->getY() + $c2Offset->y);
        $association->addConnector($p1);
        $association->addConnector($p2);
        $association->draw($diagram);
    }
    ImagePng($diagram);
    ImageDestroy($diagram);
}
Esempio n. 9
0
 public function fetch_associations($args)
 {
     $where_list = array();
     if (isset($args['role_id'])) {
         $id_list = implode(",", $args['role_id']);
         $where_list[] = "association_role_id in ({$id_list})";
     }
     if (isset($args['group_id'])) {
         $id_list = implode(",", $args['group_id']);
         $where_list[] = "association_group_id in ({$id_list})";
     }
     if (isset($args['type'])) {
         $where_list[] = "association_type=" . intval($args['type']);
     }
     if (empty($where_list)) {
         return;
     }
     // Blog Filter
     if ($sql = $this->include_exclude_blogs($args)) {
         $where_list[] = 'association_blog_id  ' . $sql;
     }
     require_once 'class.mt_association.php';
     $assoc = new Association();
     $where = implode(' and ', $where_list);
     $result = $assoc->Find($where);
     if (!$result) {
         return array();
     }
     return $result;
 }
Esempio n. 10
0
 function ConsumerAssociation($server_url, $handle, $secret, $issued, $lifetime)
 {
     parent::Association($handle, $secret, $issued, $lifetime);
     $this->server_url = $server_url;
 }
Esempio n. 11
0
 /**
  * Executes delete action
  * Checks if there are some associated routes with only this summit.
  * If not, then call the parent default delete action. 
  * If yes, calls error and redirect
  */
 public function executeDelete()
 {
     $referer = $this->getRequest()->getReferer();
     if ($id = $this->getRequestParameter('id')) {
         // Get all associated documents
         $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'));
         if ($associated_docs) {
             // Initialise the list of routes only associated to this summit
             $single_summit_route_list = array();
             // Check if any associated doc is a route
             foreach ($associated_docs as $doc) {
                 if ($doc['module'] == 'routes') {
                     // if we found an associated route, check if it is associated to several summits
                     $route_associated_docs = Association::findAllAssociatedDocs($doc['id'], array('id', 'module'));
                     if ($route_associated_docs) {
                         // Check if any associated doc to the route is a summit different from the one we want to delete
                         $multiple_summit = False;
                         foreach ($route_associated_docs as $route_associated_doc) {
                             // There's an associated summit which is different from the one we want to delete
                             if ($route_associated_doc['module'] == 'summits' && $route_associated_doc['id'] != $id) {
                                 $multiple_summit = True;
                                 break;
                             }
                         }
                         if (!$multiple_summit) {
                             // this route has only one summit: the one we want to delete
                             $single_summit_route_list[] = $doc['id'];
                         }
                     } else {
                         // shouldn't reach here, as the route we found should at least be associated to the summit that should (or not) be deleted
                         $this->setErrorAndRedirect('Document could not be deleted', $referer);
                     }
                 }
             }
             if (!empty($single_summit_route_list)) {
                 // If we found an associated route which has only one summit, we do not delete the summit
                 $this->setErrorAndRedirect('Document could not be deleted because there would be orphean routes%1%', $referer, array('%1%' => '<li><ul>' . implode('</ul><ul>', $single_summit_route_list) . '</ul></li>'));
             }
         }
         // If we reach here, then either there were no associated docs, or none of them was a route.
         parent::executeDelete();
     } else {
         $this->setErrorAndRedirect('Could not understand your request', $referer);
     }
 }
Esempio n. 12
0
 public function testPreUpdate()
 {
     $association = new Association();
     $association->preUpdate();
     $this->assertInstanceOf('DateTime', $association->getUpdatedAt());
 }
Esempio n. 13
0
function import_new_geometry()
{
    global $conn, $comment, $is_map, $is_new_document, $culture, $name, $map_editor, $map_scale, $map_code, $keepassociations, $region_type, $newgeomtext, $no_oldgeom, $document_id, $a_type, $fullwipe, $oldgeom, $newgeom, $prgmsg;
    info("Importing the new geometry...\n");
    try {
        $conn->beginTransaction();
        $history_metadata = new HistoryMetadata();
        $history_metadata->setComment(isset($comment) ? $comment : ($is_new_document ? 'Imported new ' . ($is_map ? 'map' : 'area') : 'Updated geometry'));
        $history_metadata->set('is_minor', false);
        $history_metadata->set('user_id', 2);
        // C2C user
        $history_metadata->save();
        if ($is_new_document) {
            $doc = $is_map ? new Map() : new Area();
            $doc->setCulture($culture);
            $doc->set('name', $name);
            if ($is_map) {
                $doc->set('editor', $map_editor);
                $doc->set('scale', $map_scale);
                $doc->set('code', $map_code);
            } else {
                $doc->set('area_type', $region_type);
            }
        } else {
            $doc = Document::find($is_map ? 'Map' : 'Area', $document_id);
            $name = $doc->get('name');
            if (!$is_map) {
                $region_type = $doc->get('area_type');
            }
        }
        $doc->set('geom_wkt', $newgeomtext);
        $doc->save();
        info("Geometry uploaded.\n");
        if ($keepassociations) {
            exit;
        }
        if ($is_new_document) {
            $document_id = $doc->get('id');
        }
        // $conn->commit();
        // $conn->beginTransaction();
        if ($is_map) {
            $a_type = 'dm';
        } else {
            switch ($region_type) {
                case 1:
                    // range
                    $a_type = 'dr';
                    break;
                case 2:
                    // country
                    $a_type = 'dc';
                    break;
                case 3:
                    // dept
                    $a_type = 'dd';
                    break;
            }
        }
        // Some explanation for the following queries:
        // - && operator is used to limit docs to the one whose bouding boxes overlap (it uses spatial index)
        // - ST_Within and ST_Intersects are used to work on the actual geometries
        // - ST_Within apears to be faster, so we use it for 'points' (like summits, huts etc), but we have
        //   to use ST_Intersects for 'geometries' (like outings, maps etc)
        // - we only use a buffer of 200m for areas (because of boundaries imprecision), but not for maps
        // - areas are not linked together
        // - maps are not linked to outings, users, and other maps
        // if it is a new document, we create geoassociations for the whole geometry
        // but if its an updated one, we only create geoassociations for the part of the
        // new geometry that does not intersect with the old one
        if ($is_new_document || $no_oldgeom || $fullwipe) {
            // retrieve geom from the database
            $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $geomqueryb = '(SELECT buffer(geom, 200) FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
            $queryparam = array($document_id, $document_id);
        } else {
            $queryparam = array();
            $creategeom = $conn->standaloneQuery("SELECT ST_Difference('{$newgeom}', '{$oldgeom}')")->fetchAll();
            $creategeomb = $conn->standaloneQuery("SELECT ST_Difference(buffer('{$newgeom}', 200), buffer('{$oldgeom}', 200))")->fetchAll();
            $creategeom = $creategeom[0]['st_difference'];
            $creategeomb = $creategeomb[0]['st_difference'];
            $geomquery = "'{$creategeom}'";
            $geomqueryb = "'{$creategeomb}'";
        }
        // for maps, we don't use buffer at all
        if ($is_map) {
            $geomqueryb = $geomquery;
        }
        $queries = array();
        // point geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Within(geom, {$geomqueryb}) " . "AND module IN('summits', 'huts', 'sites', 'parkings', 'products', 'portals', 'images'" . ($is_map ? '' : ", 'users'") . ')', $queryparam);
        // multipoint geometry
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomqueryb} " . "AND ST_Intersects(geom, {$geomqueryb}) AND module" . ($is_map ? "='routes'" : " IN('routes', 'outings')"), $queryparam);
        // for maps areas associations, we always compute 'full wipe', without buffer
        $geomquery = '(SELECT geom FROM ' . ($is_map ? 'maps' : 'areas') . ' WHERE id=?)';
        $queries[] = array("SELECT id, module FROM documents WHERE geom && {$geomquery} " . "AND ST_Intersects(geom, {$geomquery}) AND module='" . ($is_map ? 'areas' : 'maps') . "'", array($document_id, $document_id));
        $results_a = array();
        foreach ($queries as $query) {
            $results_a[] = $conn->standaloneQuery($query[0], $query[1])->fetchAll();
        }
        $results = array();
        foreach ($results_a as $results_set) {
            foreach ($results_set as $d) {
                $results[] = $d;
            }
        }
        $prgmsg = "Create new associations...";
        info($prgmsg);
        $tot = count($results);
        foreach ($results as $i => $d) {
            progression($i, $tot);
            // Apparently in some cases, we ar trying to create associations that
            // already exist, so we check first
            if (!GeoAssociation::find($document_id, $d['id'], null, false)) {
                $a = new GeoAssociation();
                $created[$d['module']] = isset($created[$d['module']]) ? $created[$d['module']] + 1 : 1;
                // for map - area geoassociations, links must not be dm but dr, dc, dd...
                if ($is_map && $d['module'] === 'areas') {
                    $area = Document::find('Area', $d['id']);
                    switch ($area->get('area_type')) {
                        case 1:
                            // range
                            $t_a_type = 'dr';
                            break;
                        case 2:
                            // country
                            $t_a_type = 'dc';
                            break;
                        case 3:
                            // dept
                            $t_a_type = 'dd';
                            break;
                    }
                    $a->doSaveWithValues($document_id, $d['id'], $t_a_type);
                } else {
                    $a->doSaveWithValues($d['id'], $document_id, $a_type);
                }
            }
            // inherited docs: we add geoassociations for the 'inherited docs' from sites, routes and summits
            // but not if they already have a geometry (gps track)
            switch ($d['module']) {
                case 'sites':
                case 'routes':
                    if ($is_map) {
                        break;
                    }
                    // we do not link maps to outings
                    $associated_outings = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), $d['module'] === 'routes' ? 'ro' : 'to');
                    if (count($associated_outings)) {
                        foreach ($associated_outings as $outing) {
                            if (!$outing['geom_wkt'] && GeoAssociation::find($outing['id'], $document_id, $a_type) === false) {
                                // we create geoassociation (if it already existed, it has been deleted before in the script)
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($outing['id'], $document_id, $a_type);
                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                            }
                        }
                    }
                    break;
                case 'summits':
                    // if summit is of type raid, we should not try to update its routes and outings summit_type=5
                    $summit = Document::find('Summit', $d['id']);
                    if ($summit->get('summit_type') == 5) {
                        break;
                    }
                    $associated_routes = Association::findAllAssociatedDocs($d['id'], array('id', 'geom_wkt'), 'sr');
                    if (count($associated_routes)) {
                        foreach ($associated_routes as $route) {
                            $i = $route['id'];
                            if (!$route['geom_wkt'] && GeoAssociation::find($i, $document_id, $a_type) === false) {
                                $a = new GeoAssociation();
                                $a->doSaveWithValues($i, $document_id, $a_type);
                                $created['routes'] = isset($created['routes']) ? $created['routes'] + 1 : 1;
                                if (!$is_map) {
                                    $associated_outings = Association::findAllAssociatedDocs($i, array('id', 'geom_wkt'), 'ro');
                                    if (count($associated_outings)) {
                                        foreach ($associated_outings as $outing) {
                                            $j = $outing['id'];
                                            if (!$outing['geom_wkt'] && GeoAssociation::find($j, $document_id, $a_type) === false) {
                                                $a = new GeoAssociation();
                                                $a->doSaveWithValues($j, $document_id, $a_type);
                                                $created['outings'] = isset($created['outings']) ? $created['outings'] + 1 : 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }
        info("\n");
        $conn->commit();
        if (isset($created)) {
            associations_result($created);
        }
        if ($is_new_document) {
            info('Added new ' . ($is_map ? 'map' : 'area') . " {$name} ({$document_id})\n");
        } else {
            info('Updated ' . ($is_map ? 'map' : 'area') . " ({$document_id})\n");
        }
    } catch (Exception $e) {
        $conn->rollback();
        throw $e;
    }
}
Esempio n. 14
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. 15
0
 public function executeManageimages()
 {
     if (!$this->getUser()->isConnected()) {
         $referer = $this->getRequest()->getReferer();
         $this->setErrorAndRedirect('You need to login to access this page', $referer);
     }
     $user_id = $this->getUser()->getId();
     // logged user id
     $this->pager = new c2cDoctrinePager('Image', c2cTools::mobileVersion() ? sfConfig::get('app_list_mobile_maxline_number') : sfConfig::get('app_list_maxline_number'));
     $q = $this->pager->getQuery();
     $q->select('i.id, i.filename, i.image_type, ii.name, ii.culture')->from('Image i')->leftJoin('i.associations a ON i.id = a.linked_id')->leftJoin('i.ImageI18n ii')->leftJoin('i.versions v')->leftJoin('v.history_metadata hm');
     $where = 'i.image_type = 2 AND v.version = 1 AND hm.user_id = ?';
     $document_type = $this->getRequestParameter('dtyp');
     if (!empty($document_type)) {
         if ($document_type <= 1) {
             $types = array('ai', 'mi', 'bi', 'hi', 'pi', 'ri', 'ti', 'si');
         } else {
             $types = array('oi', 'ui');
         }
         $where .= " AND a.type IN ( '" . implode("', '", $types) . "' )";
     } else {
         $document_type = $this->getRequestParameter('ctyp');
         if (!empty($document_type)) {
             $q->leftJoin('a.Article c');
             if ($document_type <= 1) {
                 $document_type = 1;
             } else {
                 $document_type = 2;
             }
             $where .= " AND a.type = 'ci' AND c.article_type = {$document_type}";
         }
     }
     $q->where($where, array($user_id));
     $q->orderBy('i.id DESC');
     $page = $this->getRequestParameter('page', 1);
     $this->pager->setPage($page);
     $this->pager->init();
     $this->page = $page;
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // images management
         $switch = $this->getRequestParameter('switch');
         $lang = $this->getUser()->getCulture();
         if (empty($switch)) {
             return $this->setNoticeAndRedirect('No image has been edited', "/users/manageimages?module=users&page={$page}");
         }
         $conn = sfDoctrine::Connection();
         $conn->beginTransaction();
         $history_metadata = new HistoryMetadata();
         $history_metadata->setComment('Switch to collaborative license');
         $history_metadata->set('is_minor', true);
         $history_metadata->set('user_id', $user_id);
         $history_metadata->save();
         foreach ($switch as $image_id) {
             // verify id corresponds to an image created by the user
             $img = Doctrine_Query::create()->select('i.id')->from('Image i')->leftJoin('i.versions v')->leftJoin('v.history_metadata hm')->where('v.version = 1 AND hm.user_id = ? AND i.id = ?', array($user_id, $image_id))->execute();
             if (empty($img)) {
                 $conn->rollback();
                 return $this->setNoticeAndRedirect('You do not have the right to change the license of theses images', "/users/manageimages?module=users&page={$page}");
             }
             $db_doc = Document::find('Image', $image_id);
             $db_doc->set('image_type', 1);
             $db_doc->save();
             // clear cache
             $this->clearCache('images', $image_id, false, 'view');
             $associated_docs = Association::findAllAssociatedDocs($image_id, array('id', 'module'));
             foreach ($associated_docs as $doc) {
                 // clear their view cache
                 $this->clearCache($doc['module'], $doc['id'], false, 'view');
             }
         }
         // apply modifications if everything went fine
         $conn->commit();
         return $this->setNoticeAndRedirect('Your images have been successfully updated', "/users/manageimages?module=users&page={$page}");
     } else {
         // display form
         $this->setPageTitle($this->__('User image management'));
     }
 }
 public function test_scenario3()
 {
     $data = array(array('filename' => 'data/tiny_mushrooms.csv', 'item_list' => array('Edible'), 'json_rule' => '{"rule_id":"000007","confidence":0.79279,"leverage":0.07885,"lhs":[0],"lhs_cover":[0.888,222],"p_value":2.08358e-17,"rhs":[11],"rhs_cover":[0.704,176],"lift":1.12613,"support":[0.704,176]}', 'seach_strategy' => 'lhs_cover'));
     foreach ($data as $item) {
         print "\nSuccessfully creating local association object\n";
         print "Given I create a data source uploading a " . $item["filename"] . " file\n";
         $source = self::$api->create_source($item["filename"], $options = array('project' => self::$project->resource));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
         $this->assertEquals(1, $source->object->status->code);
         print "And I wait until the source is ready\n";
         $resource = self::$api->_check_resource($source->resource, null, 20000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create dataset with local source\n";
         $dataset = self::$api->create_dataset($source->resource);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
         $this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
         print "And I wait until the dataset is ready\n";
         $resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create an association with search strategy <" . $item["seach_strategy"] . "> from a dataset";
         $association = self::$api->create_association($dataset->resource, array('name' => 'new association', 'search_strategy' => $item['seach_strategy']));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $association->code);
         print "And I wait until the association is ready\n";
         $resource = self::$api->_check_resource($association->resource, null, 10000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print $association->resource . "\n";
         $association = self::$api->get_association($association->resource);
         print "And I create a local association\n";
         $local_association = new Association($association);
         print "When I get the rules for " . json_encode($item["item_list"]) . "\n";
         $association_rules = $local_association->get_rules(null, null, null, null, $item["item_list"]);
         print "Then the first rule is <" . $item["json_rule"] . ">\n";
         $this->assertEquals($association_rules[0]->to_json(), $item["json_rule"]);
     }
 }
Esempio n. 17
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. 18
0
 function __construct(&$source, $dest, $options = null)
 {
     parent::__construct($source, $dest, $options);
     $this->foreign_key = ActiveRecordInflector::foreign_key($this->source_class);
 }
Esempio n. 19
0
 public function executeInsertimagetag()
 {
     $user = $this->getUser();
     $prefered_cultures = $user->getCulturesForDocuments();
     $module = $this->getRequestParameter('mod');
     $id = $this->getRequestParameter('id');
     $associated_docs = Association::findAllWithBestName($id, $prefered_cultures);
     $associated_images = Document::fetchAdditionalFieldsFor(array_filter($associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type'));
     $doc = Document::find(c2cTools::module2model($module), $id);
     if (empty($doc)) {
         $this->setNotFoundAndRedirect();
     }
     if (c2cTools::is_collaborative_document($doc)) {
         // for collaborative content, keep only collaborative images
         $associated_images = array_filter($associated_images, array('c2cTools', 'is_collaborative_document'));
     }
     $this->document_id = $id;
     $this->div = $this->getRequestParameter('div');
     $this->associated_images = $associated_images;
 }
Esempio n. 20
0
     if (empty($tag[1]) || !empty($image_ids[$tag[1]])) {
         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();
Esempio n. 21
0
 /**
  * Overriddes the one in parent class 
  * this is because we sometimes have to do things when centroid coordinates have moved.
  */
 protected function refreshGeoAssociations($id)
 {
     c2cTools::log("Entering refreshGeoAssociations for outings linked with route {$id}");
     $associated_outings = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'ro');
     if (count($associated_outings)) {
         $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main');
         // we create new associations :
         //  (and delete old associations before creating the new ones)
         //  (and do not create outings-maps associations)
         foreach ($associated_outings as $outing) {
             $i = $outing['id'];
             if (!$outing['geom_wkt']) {
                 // replicate geoassoces from doc $id to outing $i and delete previous ones
                 // (because there might be geoassociations created by this same process)
                 // and we do not replicate map associations to outings
                 $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, false);
                 c2cTools::log("created {$nb_created} geo associations for outing N° {$i}");
                 $this->clearCache('outings', $i, false, 'view');
             }
         }
     }
 }
Esempio n. 22
0
function display_class(Class_Prog $class, TableCreator $table_creator)
{
    $txt = "";
    if (!$class->library) {
        $id = $class->full_name();
        $name = $class->full_name(" :: ");
        $txt .= $table_creator->anchor($id, '') . "\n";
        $txt .= $table_creator->title(4, $name, $class->name);
        $txt .= $table_creator->begin_desc_list();
        $txt .= $table_creator->desc_list_item('Descrizione', $class->description);
        if (strlen(trim($class->usage)) > 0) {
            $txt .= $table_creator->desc_list_item('Utilizzo', $class->usage);
        }
        $class->with('children', 'parents');
        if (count($class->parents)) {
            $inh_txt = '';
            $inh_txt .= "\\vspace{-7mm}\n";
            $inh_txt .= $table_creator->begin_list();
            foreach ($class->parents as $par) {
                if (!$par->library) {
                    $inh_txt .= $table_creator->list_item($table_creator->link($par->full_name(), $par->full_name(" :: ")));
                } else {
                    $inh_txt .= $table_creator->list_item($par->full_name());
                }
            }
            $inh_txt .= $table_creator->end_list();
            $txt .= $table_creator->desc_list_item('Classi ereditate', $inh_txt);
        }
        if (count($class->children)) {
            $inh_txt = '';
            $inh_txt .= "\\vspace{-7mm}\n";
            $inh_txt .= $table_creator->begin_list();
            foreach ($class->children as $par) {
                $inh_txt .= $table_creator->list_item($table_creator->link($par->full_name(), $par->full_name(" :: ")));
            }
            $inh_txt .= $table_creator->end_list();
            $txt .= $table_creator->desc_list_item('Classi figlie', $inh_txt);
        }
        $ass = Association::model()->findAll('class_from = :idc or class_to = :idc', array(':idc' => $class->id_class));
        if (count($ass)) {
            $rel = '';
            $rel .= "\\vspace{-7mm}\n";
            $rel .= $table_creator->begin_desc_list();
            foreach ($ass as $ss) {
                if ($ss->class_to != $class->id_class) {
                    $par = $ss->with('classTo')->classTo;
                    $ass_dir = "uscente";
                } else {
                    if ($ss->class_from != $class->id_class) {
                        $par = $ss->with('classFrom')->classFrom;
                        $ass_dir = "entrante";
                    } else {
                        continue;
                    }
                }
                $ss->with('attribute');
                if (!$par->library) {
                    $acn = $par->full_name();
                    if (strlen($acn) > 60) {
                        $acn = substr($acn, strlen($acn) - 60);
                        $acn = "..." . substr($acn, strpos($acn, "::") + 2);
                    }
                    $ass_name = $table_creator->link($par->full_name(), $acn);
                } else {
                    $ass_name = $par->full_name();
                }
                $ass_txt = "Relazione {$ass_dir}, " . lcfirst($ss->attribute->description);
                $rel .= $table_creator->desc_list_item($ass_name, $ass_txt);
            }
            $rel .= $table_creator->end_desc_list();
            $txt .= $table_creator->desc_list_item('Relazioni con altre classi', $rel);
        }
    }
    $txt .= $table_creator->end_desc_list();
    $txt .= "\n\\vspace{0.5cm}\n";
    return $txt;
}
Esempio n. 23
0
 /**
  * Destructor.
  */
 public function __destruct()
 {
     parent::__destruct();
 }
Esempio n. 24
0
     }
     if ($max_ele > 0) {
         $item->addChild('geom', "{$lon},{$lat}");
         $item->addChild('elevation', $max_ele);
     } else {
         // could not find any geolocalized route to link
         // => we go to the next step : find highest associated summits to these routes
         $coords = Route::findHighestAssociatedSummitCoords($associated_routes);
         if ($coords['ele'] > 0) {
             if (strlen($coords['lon']) && strlen($coords['lat'])) {
                 $item->addChild('geom', $coords['lon'] . ',' . $coords['lat']);
             }
             $item->addChild('elevation', $coords['ele']);
         }
     }
 } elseif ($associated_sites = Association::findAllAssociatedDocs($id, $fields = array('id', 'lon', 'lat', 'elevation'), 'to')) {
     // find highest site
     $max_ele = 0;
     foreach ($associated_sites as $site) {
         if (($ele = $site['elevation']) && $ele > $max_ele && ($lon = $site['lon']) && ($lat = $site['lat'])) {
             $highest_site = $site;
             $max_ele = $site['elevation'];
         }
     }
     if ($max_ele > 0) {
         $item->addChild('geom', "{$lon},{$lat}");
         $item->addChild('elevation', $max_ele);
     }
 }
 $item->addChild('date', $object->get('date'));
 $item->addChild('lang', $lang);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
// needed for doctrine connection to work
sfContext::getInstance();
// Next Step : retrieve highest summits associated (in fact there should always be only one) with routes, and transfer summit geoassociations to route.
// WARNING: set correct id limits
// WARNING 2: routes must be consecutive.
$id = 44918;
$id_max = 57877;
while ($id <= $id_max) {
    echo "Computing associations for route {$id} ... \n";
    // if associations with areas for current doc already existed, delete them
    //$deleted = GeoAssociation::deleteAllFor($id, array('dr', 'dc', 'dd', 'dm'));
    //if ($deleted) echo "Deleted $deleted already existing geoassociations. \n";
    // get all associated regions (3+maps) with this summit:
    //$summit_id is the id of associated summit with route $id
    $associated_docs = Association::findAllAssociatedDocs($id, array('id', 'module'), 'sr');
    // summit-route
    foreach ($associated_docs as $doc) {
        if ($doc['module'] == 'summits') {
            $summit_id = $doc['id'];
        }
    }
    $associations = GeoAssociation::findAllAssociations($summit_id, array('dr', 'dc', 'dd', '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'));
        echo "Created association with " . $ea->get('linked_id') . " \n";
        unset($a);
    }
    $id++;
Esempio n. 26
0
     * Returns a hashcode for this association.
     * The hashcode of an this association
     * is just the hashcode of the key.
     *
     * @return integer A hashcode for this association.
     */
    public function getHashCode()
    {
        return $this->key->getHashCode();
    }
    //}>d
    /**
     * Main program.
     *
     * @param array $args Command-line arguments.
     * @return integer Zero on success; non-zero on failure.
     */
    public static function main($args)
    {
        printf("Association main program.\n");
        $status = 0;
        $a1 = new Association(box(1), NULL);
        printf("%s\n", str($a1));
        $a2 = new Association(box(2), box(4));
        printf("%s\n", str($a2));
        return $status;
    }
}
if (realpath($argv[0]) == realpath(__FILE__)) {
    exit(Association::main(array_slice($argv, 1)));
}
Esempio n. 27
0
 /**
  * Association constructor.
  *
  * @param string $record  referenced object
  * @param string $localId  localId column name
  * @param string $foreignId  paramId column name
  */
 public function __construct($record, $localId, $foreignId)
 {
     parent::__construct(self::BELONGS_TO, NULL, $localId, $foreignId);
     $this->belongsToRecord = $record;
 }
Esempio n. 28
0
 /**
  * filter for people who have the right to edit current document (linked people for outings, original editor for articles ....)
  * overrides the one in parent class.
  */
 protected function filterAuthorizedPeople($id)
 {
     // we know here that document $id exists and that its model is the current one (Outing).
     // we must guess the associated people and restrain edit rights to these people + moderator.
     $user = $this->getUser();
     $a = Association::find($user->getId(), $id, 'uo');
     if (!$a && !$user->hasCredential('moderator')) {
         $referer = $this->getRequest()->getReferer();
         $this->setErrorAndRedirect('You do not have the rights to edit this outing', $referer);
     }
 }
Esempio n. 29
0
 /**
  * @param ProductInterface $product
  * @param AssociationType $type
  */
 public function __construct(ProductInterface $product, AssociationType $type)
 {
     parent::__construct($type);
     $this->product = $product;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAssocCreate($attribute)
 {
     $model = new Association();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $attribute = $this->loadAttribute($attribute);
     $model->id_attribute = $attribute->id_attribute;
     $model->class_from = $attribute->id_class;
     if (isset($_POST['Association'])) {
         $model->attributes = $_POST['Association'];
         if ($model->save()) {
             $this->redirect(array('attributeview', 'id' => $attribute->id_attribute));
         }
     }
     $this->render('attribute/association/create', array('model' => $model, 'attribute' => $attribute));
 }