public function grants() { $fh = fopen("../resources/grants.csv", "r"); $grants = 0; $currentPost = false; $currentName = false; while ($data = fgetcsv($fh)) { $grants++; list($post, $groupName, $desc, $y2011, $y2010, $change) = $data; /** * What post to file this udner */ if (is_numeric($post)) { $currentPost = (double) $post; $currentName = $groupName; // Store grant group $grantGroup = GrantGroup::create(); $grantGroup->save(array('post' => $currentPost, 'desc' => $groupName)); } /** * Assert we are under a post before starting to store */ if ($currentPost) { /** * Place in previously mentioned group */ $grant = Grant::create(); $grant->save(array('post' => $currentPost, 'name' => $currentName, 'group' => $grantGroup->_id, 'desc' => $desc, 'y2011' => (int) ($y2011 / 1000), 'y2010' => (int) ($y2010 / 1000), 'change' => (int) ($change / 1000))); } } return compact('grants'); }
public function byGroup($id = false) { $id = $id ?: $this->request->query['id']; if ($id) { $grants = Grant::find('all', array('conditions' => array('group' => new MongoId($id)), 'limit' => 100)); return compact('grants'); } }