public function locationsmanageAction() { $request = $this->getRequest(); $action = $request->getPost('action'); $post_id = $request->getPost('post_id'); $ret = array('post_id' => 0); $post = new DatabaseObject_BlogPost($this->db); if ($post->loadForUser($this->identity->user_id, $post_id)) { $ret['post_id'] = $post->getId(); switch ($action) { case 'get': $ret['locations'] = array(); foreach ($post->locations as $location) { $ret['locations'][] = array('location_id' => $location->getId(), 'latitude' => $location->latitude, 'longitude' => $location->longitude, 'description' => $location->description); } break; case 'add': $fp = new FormProcessor_BlogPostLocation($post); if ($fp->process($request)) { $ret['location_id'] = $fp->location->getId(); $ret['latitude'] = $fp->location->latitude; $ret['longitude'] = $fp->location->longitude; $ret['description'] = $fp->location->description; } else { $ret['location_id'] = 0; } break; case 'delete': $location_id = $request->getPost('location_id'); $location = new DatabaseObject_BlogPostLocation($this->db); if ($location->loadForPost($post->getId(), $location_id)) { $ret['location_id'] = $location->getId(); $location->delete(); } break; case 'move': $location_id = $request->getPost('location_id'); $location = new DatabaseObject_BlogPostLocation($this->db); if ($location->loadForPost($post->getId(), $location_id)) { $location->longitude = $request->getPost('longitude'); $location->latitude = $request->getPost('latitude'); $location->save(); $ret['location_id'] = $location->getId(); $ret['latitude'] = $location->latitude; $ret['longitude'] = $location->longitude; $ret['description'] = $location->description; } break; } } $this->sendJson($ret); }
public static function GetPosts($db, $options = array()) { $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'p.ts_created'); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = self::_GetBaseQuery($db, $options); $select->from(null, 'p.*'); if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } $select->order($options['order']); $data = $db->fetchAll($select); $posts = self::BuildMultiple($db, __CLASS__, $data); $post_ids = array_keys($posts); if (count($post_ids) == 0) { return array(); } $profiles = Profile::BuildMultiple($db, 'Profile_BlogPost', array('post_id' => $post_ids)); foreach ($posts as $post_id => $post) { if (array_key_exists($post_id, $profiles) && $profiles[$post_id] instanceof Profile_BlogPost) { $posts[$post_id]->profile = $profiles[$post_id]; } else { $posts[$post_id]->profile->setPostId($post_id); } } $options = array('post_id' => $post_ids); $images = DatabaseObject_BlogPostImage::GetImages($db, $options); foreach ($images as $image) { $posts[$image->post_id]->images[$image->getId()] = $image; } $locations = DatabaseObject_BlogPostLocation::GetLocations($db, $options); foreach ($locations as $l) { $posts[$l->post_id]->locations[$l->getId()] = $l; } return $posts; }