public function walkWalkableObject(Walkable $object) { $this->walkable = $object; foreach ($object->getWalkables() as $field => $value) { $this->walkField($field, $value); } }
/** * Loads routes matching a Walk or WalkInstance. * * Only one Type_Planned route will be returned. If possible, this will be for the Walkable passed in. * Otherwise, a route planned for the base Walk or the most recently-uploaded route for any instance is used. * All Type_Logged routes for any matching Walkable will be returned. * * @param Walkable $w Walk or WalkInstance to find routes for * @param boolean $allowRelated If true, routes for related instances and the walk itself will be found - if $w is a Walk, that Walk and all instances are returned. If $w is a WalkInstance that instance and the parent Walk are returned. * @param int $type Type of route to fetch - see Route::Type_Planned and Route::Type_Logged * @param int $limit Limit the number of routes to find. Default is no limit (0) * @return Array Array of routes for this Walk or WalkInstance */ public static function loadForWalkable(Walkable $w, $allowRelated = false, $type = null, $limit = 0) { $db =& JFactory::getDBO(); $query = $db->getQuery(true); $query->select("routeid, type"); $query->from("routes"); // What walks/instances are allowed? if ($w instanceof Walk) { $qryWalkID = array("walkid = " . $w->id); if ($allowRelated) { foreach ($w->getInstances() as $wi) { $qryWalkID[] = "walkinstanceid = " . $wi->id; } } $query->where("(" . implode(" OR ", $qryWalkID) . ")"); $query->order("walkid IS NOT NULL"); // Put the Walk first } else { $qryWalkInstance = array("walkinstanceid = " . $w->id); if ($allowRelated) { $qryWalkInstance[] = "walkid = " . $w->walkid; } $query->where("(" . implode(" OR ", $qryWalkInstance) . ")"); $query->order("walkinstanceid IS NOT NULL"); // Put the WalkInstance first } if (isset($type)) { $query->where("type = " . (int) $type); } $query->order("uploadeddatetime DESC"); // Most recent first if (!empty($limit)) { $query->setLimit($limit, 0); } $db->setQuery($query); $db->query(); $routes = array(); $dbArr = $db->loadAssocList("routeid"); $foundPlanned = false; if (!empty($dbArr)) { foreach ($dbArr as $row) { // Only want the first planned route that comes out if ($row['type'] == 10) { if ($foundPlanned) { continue; } $foundPlanned = true; } $routes[] = self::loadSingle($row['routeid'], $w); } } return $routes; }