Session.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. namespace Transmission\Model;
  3. use Transmission\Util\ResponseValidator;
  4. /**
  5. * @author Joysen Chellem
  6. * @author Ramon Kleiss <ramon@cubilon.nl>
  7. */
  8. class Session extends AbstractModel
  9. {
  10. /**
  11. * @var integer
  12. */
  13. protected $altSpeedDown;
  14. /**
  15. * @var boolean
  16. */
  17. protected $altSpeedEnabled;
  18. /**
  19. * @var string
  20. */
  21. protected $downloadDir;
  22. /**
  23. * @var boolean
  24. */
  25. protected $downloadQueueEnabled;
  26. /**
  27. * @var integer
  28. */
  29. protected $downloadQueueSize;
  30. /**
  31. * @var string
  32. */
  33. protected $incompleteDir;
  34. /**
  35. * @var boolean
  36. */
  37. protected $incompleteDirEnabled;
  38. /**
  39. * @var string
  40. */
  41. protected $torrentDoneScript;
  42. /**
  43. * @var boolean
  44. */
  45. protected $torrentDoneScriptEnabled;
  46. /**
  47. * @var double
  48. */
  49. protected $seedRatioLimit;
  50. /**
  51. * @var boolean
  52. */
  53. protected $seedRatioLimited;
  54. /**
  55. * @var integer
  56. */
  57. protected $seedQueueSize;
  58. /**
  59. * @var boolean
  60. */
  61. protected $seedQueueEnabled;
  62. /**
  63. * @var integer
  64. */
  65. protected $downloadSpeedLimit;
  66. /**
  67. * @var boolean
  68. */
  69. protected $downloadSpeedLimitEnabled;
  70. /**
  71. * @param integer $speed
  72. */
  73. public function setAltSpeedDown($speed)
  74. {
  75. $this->altSpeedDown = (integer) $speed;
  76. }
  77. /**
  78. * @return integer
  79. */
  80. public function getAltSpeedDown()
  81. {
  82. return $this->altSpeedDown;
  83. }
  84. /**
  85. * @param boolean $enabled
  86. */
  87. public function setAltSpeedEnabled($enabled)
  88. {
  89. $this->altSpeedEnabled = (boolean) $enabled;
  90. }
  91. /**
  92. * @return boolean
  93. */
  94. public function isAltSpeedEnabled()
  95. {
  96. return $this->altSpeedEnabled;
  97. }
  98. /**
  99. * @param string $downloadDir
  100. */
  101. public function setDownloadDir($downloadDir)
  102. {
  103. $this->downloadDir = (string) $downloadDir;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getDownloadDir()
  109. {
  110. return $this->downloadDir;
  111. }
  112. /**
  113. * @param boolean $enabled
  114. */
  115. public function setDownloadQueueEnabled($enabled)
  116. {
  117. $this->downloadQueueEnabled = (boolean) $enabled;
  118. }
  119. /**
  120. * @return boolean
  121. */
  122. public function isDownloadQueueEnabled()
  123. {
  124. return $this->downloadQueueEnabled;
  125. }
  126. /**
  127. * @param integer $size
  128. */
  129. public function setDownloadQueueSize($size)
  130. {
  131. $this->downloadQueueSize = (integer) $size;
  132. }
  133. /**
  134. * @return integer
  135. */
  136. public function getDownloadQueueSize()
  137. {
  138. return $this->downloadQueueSize;
  139. }
  140. /**
  141. * @param string $directory
  142. */
  143. public function setIncompleteDir($directory)
  144. {
  145. $this->incompleteDir = (string) $directory;
  146. }
  147. /**
  148. * @return string
  149. */
  150. public function getIncompleteDir()
  151. {
  152. return $this->incompleteDir;
  153. }
  154. /**
  155. * @param boolean $enabled
  156. */
  157. public function setIncompleteDirEnabled($enabled)
  158. {
  159. $this->incompleteDirEnabled = (boolean) $enabled;
  160. }
  161. /**
  162. * @return boolean
  163. */
  164. public function isIncompleteDirEnabled()
  165. {
  166. return $this->incompleteDirEnabled;
  167. }
  168. /**
  169. * @param string $filename
  170. */
  171. public function setTorrentDoneScript($filename)
  172. {
  173. $this->torrentDoneScript = (string) $filename;
  174. }
  175. /**
  176. * @return string
  177. */
  178. public function getTorrentDoneScript()
  179. {
  180. return $this->torrentDoneScript;
  181. }
  182. /**
  183. * @param boolean $enabled
  184. */
  185. public function setTorrentDoneScriptEnabled($enabled)
  186. {
  187. $this->torrentDoneScriptEnabled = (boolean) $enabled;
  188. }
  189. /**
  190. * @return boolean
  191. */
  192. public function isTorrentDoneScriptEnabled()
  193. {
  194. return $this->torrentDoneScriptEnabled;
  195. }
  196. /**
  197. * @param double $limit
  198. */
  199. public function setSeedRatioLimit($limit)
  200. {
  201. $this->seedRatioLimit = (double) $limit;
  202. }
  203. /**
  204. * @return double
  205. */
  206. public function getSeedRatioLimit()
  207. {
  208. return $this->seedRatioLimit;
  209. }
  210. /**
  211. * @param boolean $limited
  212. */
  213. public function setSeedRatioLimited($limited)
  214. {
  215. $this->seedRatioLimited = (boolean) $limited;
  216. }
  217. /**
  218. * @return boolean
  219. */
  220. public function isSeedRatioLimited()
  221. {
  222. return $this->seedRatioLimited;
  223. }
  224. /**
  225. * @param integer $size
  226. */
  227. public function setSeedQueueSize($size)
  228. {
  229. $this->seedQueueSize = (integer) $size;
  230. }
  231. /**
  232. * @return integer
  233. */
  234. public function getSeedQueueSize()
  235. {
  236. return $this->seedQueueSize;
  237. }
  238. /**
  239. * @param boolean $enabled
  240. */
  241. public function setSeedQueueEnabled($enabled)
  242. {
  243. $this->seedQueueEnabled = (boolean) $enabled;
  244. }
  245. /**
  246. * @return boolean
  247. */
  248. public function isSeedQueueEnabled()
  249. {
  250. return $this->seedQueueEnabled;
  251. }
  252. /**
  253. * @param integer $limit
  254. */
  255. public function setDownloadSpeedLimit($limit)
  256. {
  257. $this->downloadSpeedLimit = (integer) $limit;
  258. }
  259. /**
  260. * @return integer
  261. */
  262. public function getDownloadSpeedLimit()
  263. {
  264. return $this->downloadSpeedLimit;
  265. }
  266. /**
  267. * @param boolean $enabled
  268. */
  269. public function setDownloadSpeedLimitEnabled($enabled)
  270. {
  271. $this->downloadSpeedLimitEnabled = (boolean) $enabled;
  272. }
  273. /**
  274. * @return boolean
  275. */
  276. public function isDownloadSpeedLimitEnabled()
  277. {
  278. return $this->downloadSpeedLimitEnabled;
  279. }
  280. /**
  281. * {@inheritDoc}
  282. */
  283. public static function getMapping()
  284. {
  285. return array(
  286. 'alt-speed-down' => 'altSpeedDown',
  287. 'alt-speed-enabled' => 'altSpeedEnabled',
  288. 'download-dir' => 'downloadDir',
  289. 'download-queue-enabled' => 'downloadQueueEnabled',
  290. 'download-queue-size' => 'downloadQueueSize',
  291. 'incomplete-dir' => 'incompleteDir',
  292. 'incomplete-dir-enabled' => 'incompleteDirEnabled',
  293. 'script-torrent-done-filename' => 'torrentDoneScript',
  294. 'script-torrent-done-enabled' => 'torrentDoneScriptEnabled',
  295. 'seedRatioLimit' => 'seedRatioLimit',
  296. 'seedRatioLimited' => 'seedRatioLimited',
  297. 'seed-queue-size' => 'seedQueueSize',
  298. 'seed-queue-enabled' => 'seedQueueEnabled',
  299. 'speed-limit-down' => 'downloadSpeedLimit',
  300. 'speed-limit-down-enabled' => 'downloadSpeedLimitEnabled',
  301. );
  302. }
  303. public function save()
  304. {
  305. $arguments = array();
  306. $method = 'session-set';
  307. foreach ($this->getMapping() as $key => $value) {
  308. $arguments[$key] = $this->$value;
  309. }
  310. if (!($client = $this->getClient())) {
  311. return;
  312. }
  313. ResponseValidator::validate(
  314. $method,
  315. $client->call($method, $arguments)
  316. );
  317. }
  318. }