Blame view

administrator/components/com_jmap/tables/pingomatic.php 3.42 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
<?php
// namespace administrator\components\com_jmap\tables;
/**
 *
 * @package JMAP::PINGOMATIC::administrator::components::com_jmap
 * @subpackage tables
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );

/**
 * ORM Table for Pingomatic urls
 *
 * @package JMAP::PINGOMATIC::administrator::components::com_jmap
 * @subpackage tables
 * @since 2.0
 */
class TablePingomatic extends JTable{
	/**
	 * @var int
	 */
	public $id;
	
	/**
	 * @var string
	 */
	public $title;
	
	/**
	 * @var string
	 */
	public $blogurl;
	
	/**
	 * @var string
	 */
	public $rssurl;
	
	/**
	 * @var string
	 */
	public $services = '{}';
	
	/**
	 * @var datetime
	 */
	public $lastping;
	
	/**
	 * @var int
	 */
	public $checked_out = 0;
	
	/**
	 * @var datetime
	 */
	public $checked_out_time = 0;

	/**
	 * Bind Table override
	 * @override
	 * 
	 * @see JTable::bind()
	 */
	public function bind($fromArray, $saveTask = false, $sessionTask = false) {
		parent::bind ( $fromArray );
		
		if ($saveTask) {
			$services = array();
			foreach ($fromArray as $key => $value) {
				if (strpos($key, 'chk_') === 0 || strpos($key, 'ajs_') === 0) {
					$services[$key] = $value;
				}
			}
			if (is_array ( $services )) {
				$this->services = json_encode ( $services );
			}
		}
		
		// Manage complex attributes during session recovering bind/load
		if($sessionTask) {
			$services = array();
			foreach ($fromArray as $key => $value) {
				if (strpos($key, 'chk_') === 0) {
					$services[$key] = $value;
				}
			}
			$registry = new JRegistry ( $services );
			$this->services = $registry;
		}
		
		return true;
	}
	
	/**
	 * Load Table override
	 * @override
	 * 
	 * @see JTable::load()
	 */
	public function load($idEntity = null, $reset = true) {
		// If not $idEntity set return empty object
		if($idEntity) {
			if(!parent::load ( $idEntity )) {
				return false;
			}
		}
		
		// Decoding services on load and wrap into JRegistry object
		if ($this->services) {
			$this->services = json_decode ( $this->services );
			$servicesRegistry = new JRegistry();
			$servicesRegistry->loadObject($this->services);
			// New assignment
			$this->services = $servicesRegistry;
		}
		
		return true;
	}
	
	/**
	 * Check Table override
	 * @override
	 * 
	 * @see JTable::check()
	 */
	public function check() {
		// Title required
		if (! $this->title) {
			$this->setError ( JText::_('COM_JMAP_VALIDATION_ERROR' ) );
			return false;
		}
		
		// Check if the validation is enabled and not based on server settings limit management
		if(JComponentHelper::getParams('com_jmap')->get('resources_limit_management', 1)) {
			// Link url required and to be valid
			$blogurl = filter_var($this->blogurl, FILTER_SANITIZE_URL);
			if (! $this->blogurl || !filter_var($blogurl, FILTER_VALIDATE_URL)) {
				$this->setError ( JText::_('COM_JMAP_VALIDATION_ERROR_URL' ) );
				return false;
			}
			
			// LinkRss url to be valid
			$rssurl = filter_var($this->rssurl, FILTER_SANITIZE_URL);
			if ( $this->rssurl && !filter_var($rssurl, FILTER_VALIDATE_URL)) {
				$this->setError ( JText::_('COM_JMAP_VALIDATION_ERROR_URL' ) );
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * Class constructor
	 * @param Object& $_db
	 *
	 * return Object&
	 */
	public function __construct(&$_db) {
		parent::__construct ( '#__jmap_pingomatic', 'id', $_db );
	}
}