-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1291 from HTSolution/develop
#623 Feed Category
- Loading branch information
Showing
10 changed files
with
166 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
// HT: New model | ||
/** | ||
* Model for Categories for each Feed | ||
* | ||
* PHP version 5 | ||
* LICENSE: This source file is subject to LGPL license | ||
* that is available through the world-wide-web at the following URI: | ||
* http://www.gnu.org/copyleft/lesser.html | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi - http://source.ushahididev.com | ||
* @subpackage Models | ||
* @copyright Ushahidi - http://www.ushahidi.com | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
class Feed_Category_Model extends ORM | ||
{ | ||
protected $belongs_to = array('feed_item', 'category'); | ||
|
||
// Database table name | ||
protected $table_name = 'feed_category'; | ||
|
||
/** | ||
* Assigns a category id to an feed if it hasn't already been assigned | ||
* @param int $feed_id feed to assign the category to | ||
* @param int $category_id category id of the category you want to assign to the feed | ||
* @return array | ||
*/ | ||
public static function assign_category_to_feed($feed_id,$category_id) | ||
{ | ||
|
||
// Check to see if it is already added to that category | ||
// If it's not, add it. | ||
|
||
$feed_category = ORM::factory('feed_category')->where(array('feed_item_id'=>$feed_id,'category_id'=>$category_id))->find_all(); | ||
|
||
if( ! $feed_category->count() ) | ||
{ | ||
$new_feed_category = ORM::factory('feed_category'); | ||
$new_feed_category->category_id = $category_id; | ||
$new_feed_category->feed_item_id = $feed_id; | ||
$new_feed_category->save(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Table structure for table `feed_item_category` | ||
* | ||
*/ | ||
|
||
CREATE TABLE IF NOT EXISTS `feed_item_category` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`feed_item_id` bigint(20) unsigned NOT NULL DEFAULT '0', | ||
`category_id` int(11) unsigned NOT NULL DEFAULT '0', | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `feed_item_category_ids` (`feed_item_id`,`category_id`), | ||
KEY `feed_item_id` (`feed_item_id`), | ||
KEY `category_id` (`category_id`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores fetched feed items categories' AUTO_INCREMENT=1 ; |