Skip to content

Commit d90dbcf

Browse files
committed
Merge pull request #1304 from ovruni/master
Feed Category
2 parents be3fe30 + 664338b commit d90dbcf

File tree

9 files changed

+35
-31
lines changed

9 files changed

+35
-31
lines changed

application/controllers/admin/reports.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,11 @@ public function edit($id = FALSE, $saved = FALSE)
548548
$form['location_name'] = $feed_item->location->location_name;
549549
}
550550
// HT: new code
551-
$feed_categories = ORM::factory('feed_category')->where('feed_item_id', $feed_item->id)->select_list('id', 'category_id');
552-
if ($feed_categories)
551+
$feed_item_categories = ORM::factory('feed_item_category')->where('feed_item_id', $feed_item->id)->select_list('id', 'category_id');
552+
if ($feed_item_categories)
553553
{
554-
foreach($feed_categories as $feed_category) {
555-
$form['incident_category'][] = $feed_category;
554+
foreach($feed_item_categories as $feed_item_category) {
555+
$form['incident_category'][] = $feed_item_category;
556556
}
557557
}
558558
// HT: end of new code

application/controllers/scheduler/s_alerts.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public function index()
9595
$incident_query .= "AND DATE(i.incident_date) >= DATE_SUB( CURDATE(), INTERVAL ".($alert_days-1)." DAY )";
9696
}
9797
// End of New Code
98-
98+
99+
$incidents = $db->query($incident_query);
100+
99101
foreach ($incidents as $incident)
100102
{
101103
// ** Pre-Formatting Message ** //
@@ -282,7 +284,7 @@ private function _check_categories(Alert_Model $alertee, array $category_ids) {
282284
* @return boolean
283285
*/
284286
private function _multi_subscribe(Alert_Model $alertee, $incident_id) {
285-
$multi_subscribe_ids = ORM::factory('alert')->where('alert_confirmed','1')->where('alert_recipient', $alertee->recipient)->select_list('id', 'id');
287+
$multi_subscribe_ids = ORM::factory('alert')->where('alert_confirmed','1')->where('alert_recipient', $alertee->alert_recipient)->select_list('id', 'id');
286288
$subscription_alert = ORM::factory('alert_sent')->where('incident_id', $incident_id)->in('alert_id', $multi_subscribe_ids)->find();
287289
return ((boolean) $subscription_alert->id);
288290
}

application/controllers/scheduler/s_feeds.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,27 @@ public function index()
9999
if(!empty($categories)) {
100100
foreach($categories as $category) {
101101
$categoryData = ORM::factory('category')->where('category_title', $category->term)->find();
102-
if($categoryData) {
103-
$category_ids->feed_category[$categoryData->id] = $categoryData->id;
102+
if($categoryData->loaded == TRUE) {
103+
$category_ids->feed_item_category[$categoryData->id] = $categoryData->id;
104104
} else {
105105
$newcategory = new Category_Model();
106106
$newcategory->category_title = $category->term;
107107
$newcategory->parent_id = 0;
108108
$newcategory->category_description = $category->term;
109109
$newcategory->category_color = '000000';
110+
$newcategory->category_visible = 0;
110111
$newcategory->save();
111-
$category_ids->feed_category[$newcategory->id] = $newcategory->id;
112+
$category_ids->feed_item_category[$newcategory->id] = $newcategory->id;
112113
}
114+
113115
}
114116
}
115117
// HT: End of new code
116118

117119
$newitem->save();
118120

119121
// HT: New code
120-
if(!empty($category_ids->feed_category)) {
122+
if(!empty($category_ids->feed_item_category)) {
121123
feed::save_category($category_ids, $newitem);
122124
}
123125
// HT: End of New code

application/controllers/scheduler/s_twitter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function add_hash_tweets($data)
9595
$service = $services->where('service_name', 'Twitter')->find();
9696

9797
$tweet_results = json_decode($data);
98-
foreach($tweet_results ->statuses as $tweet)
98+
foreach($tweet_results->statuses as $tweet)
9999
{
100100
$reporter = ORM::factory('reporter')
101101
->where('service_id', $service->id)

application/helpers/feed.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public static function simplepie( $feed_url = NULL )
5353
public static function save_category($post, $feed_item)
5454
{
5555
// Delete Previous Entries
56-
ORM::factory('feed_category')->where('feed_item_id', $feed_item->id)->delete_all();
56+
ORM::factory('feed_item_category')->where('feed_item_id', $feed_item->id)->delete_all();
5757

58-
foreach ($post->feed_category as $item)
58+
foreach ($post->feed_item_category as $item)
5959
{
60-
$feed_category = new Feed_Category_Model();
61-
$feed_category->feed_item_id = $feed_item->id;
62-
$feed_category->category_id = $item;
63-
$feed_category->save();
60+
$feed_item_category = new Feed_Item_Category_Model();
61+
$feed_item_category->feed_item_id = $feed_item->id;
62+
$feed_item_category->category_id = $item;
63+
$feed_item_category->save();
6464
}
6565
}
6666

67-
}
67+
}

application/libraries/Geocoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function geocode_feed ($feed_url = NULL)
5656

5757
if ($geonames_status == "200")
5858
{ // Successful
59-
$request_url = $base_url . "&feedUrl=" . urlencode($feed_url);
59+
$request_url = $base_url . "&feedUrl=" . urlencode($feed_url)."&username=ushahididev";
6060
}
6161
else
6262
{ // Down perhaps?? Use direct feed

application/models/category.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Category_Model extends ORM_Tree {
1818
* One-to-many relationship definition
1919
* @var array
2020
*/
21-
protected $has_many = array('incident' => 'incident_category', 'category_lang');
21+
protected $has_many = array('incident' => 'incident_category', 'feed_item' => 'feed_item_category', 'category_lang');
2222

2323
/**
2424
* Database table name

application/models/feed_item.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Feed_Item_Model extends ORM
1313

1414
// HT: New code
1515
protected $has_many = array(
16-
'category' => 'feed_category',
16+
'category' => 'feed_item_category',
1717
);
1818
// HT: End of new code
1919

application/models/feed_category.php application/models/feed_item_category.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php defined('SYSPATH') or die('No direct script access.');
22
// HT: New model
33
/**
4-
* Model for Categories for each Feed
4+
* Model for Categories for each Feed Item
55
*
66
* PHP version 5
77
* LICENSE: This source file is subject to LGPL license
@@ -14,15 +14,15 @@
1414
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
1515
*/
1616

17-
class Feed_Category_Model extends ORM
17+
class Feed_Item_Category_Model extends ORM
1818
{
1919
protected $belongs_to = array('feed_item', 'category');
2020

2121
// Database table name
22-
protected $table_name = 'feed_category';
22+
protected $table_name = 'feed_item_category';
2323

2424
/**
25-
* Assigns a category id to an feed if it hasn't already been assigned
25+
* Assigns a category id to an feed item if it hasn't already been assigned
2626
* @param int $feed_id feed to assign the category to
2727
* @param int $category_id category id of the category you want to assign to the feed
2828
* @return array
@@ -33,14 +33,14 @@ public static function assign_category_to_feed($feed_id,$category_id)
3333
// Check to see if it is already added to that category
3434
// If it's not, add it.
3535

36-
$feed_category = ORM::factory('feed_category')->where(array('feed_item_id'=>$feed_id,'category_id'=>$category_id))->find_all();
36+
$feed_item_category = ORM::factory('feed_item_category')->where(array('feed_item_id'=>$feed_id,'category_id'=>$category_id))->find_all();
3737

38-
if( ! $feed_category->count() )
38+
if( ! $feed_item_category->count() )
3939
{
40-
$new_feed_category = ORM::factory('feed_category');
41-
$new_feed_category->category_id = $category_id;
42-
$new_feed_category->feed_item_id = $feed_id;
43-
$new_feed_category->save();
40+
$new_feed_item_category = ORM::factory('feed_item_category');
41+
$new_feed_item_category->category_id = $category_id;
42+
$new_feed_item_category->feed_item_id = $feed_id;
43+
$new_feed_item_category->save();
4444
}
4545

4646
return true;

0 commit comments

Comments
 (0)