/application/models/ContentHasIndustries.php

https://github.com/jiiarra/site · PHP · 129 lines · 66 code · 14 blank · 49 comment · 10 complexity · b9629a9dce4e23178620bfecbf0c09b6 MD5 · raw file

  1. <?php
  2. /**
  3. * ContentHasIndustries -> ContentHasIndustries database model for content has industries link table.
  4. *
  5. * Copyright (c) <2009>, Markus Riihelä
  6. * Copyright (c) <2009>, Mikko Sallinen
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
  16. * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * License text found in /license/
  19. */
  20. /**
  21. * ContentHasIndustries - class
  22. *
  23. * @package models
  24. * @author Markus Riihelä & Mikko Sallinen
  25. * @copyright 2009 Markus Riihelä & Mikko Sallinen
  26. * @license GPL v2
  27. * @version 1.0
  28. */
  29. class Default_Model_ContentHasIndustries extends Zend_Db_Table_Abstract
  30. {
  31. // Table name
  32. protected $_name = 'cnt_has_ind';
  33. // Table reference map
  34. protected $_referenceMap = array(
  35. 'IndustryContent' => array(
  36. 'columns' => array('id_cnt'),
  37. 'refTableClass' => 'Default_Model_Content',
  38. 'refColumns' => array('id_cnt')
  39. ),
  40. 'IndustryIndustry' => array(
  41. 'columns' => array('id_ind'),
  42. 'refTableClass' => 'Default_Model_Industries',
  43. 'refColumns' => array('id_ind')
  44. )
  45. );
  46. /**
  47. * addIndustryToContent
  48. *
  49. * Add industry to content
  50. *
  51. * @param integer $id_cnt
  52. * @param integer $id_ind
  53. */
  54. public function addIndustryToContent($id_cnt = 0, $id_ind = 0)
  55. {
  56. // If id values not 0
  57. if($id_cnt != 0 && $id_ind != 0)
  58. {
  59. // Create a new row
  60. $row = $this->createRow();
  61. // Set id values
  62. $row->id_cnt = $id_cnt;
  63. $row->id_ind = $id_ind;
  64. // Add row to database
  65. $row->save();
  66. } // end if
  67. } // end of addIndustryToContent
  68. /**
  69. * removeIndustriesFromContent
  70. * Removes industries from content
  71. *
  72. * @param int id_cnt Id of the content
  73. * $return bool $return
  74. * @author Pekka Piispanen
  75. */
  76. public function removeIndustriesFromContent($id_cnt)
  77. {
  78. $return = false;
  79. if($this->getIndustryIdOfContent($id_cnt)) {
  80. $where = $this->getAdapter()->quoteInto('id_cnt = ?', $id_cnt);
  81. if($this->delete($where)) {
  82. $return = true;
  83. }
  84. } else {
  85. $return = true;
  86. }
  87. return $return;
  88. } // end of removeIndustriesFromContent
  89. public function getIndustryIdOfContent($id_cnt)
  90. {
  91. $select = $this->select()
  92. ->from($this, array('id_ind'))
  93. ->where("`id_cnt` = $id_cnt");
  94. $result = $this->fetchAll($select)->toArray();
  95. if (isset($result[0])) {
  96. return $result[0]['id_ind'];
  97. } else {
  98. return '';
  99. }
  100. }
  101. public function updateIndustryToContent($id_ind, $id_cnt)
  102. {
  103. $return = false;
  104. $id_ind = (int)$id_ind;
  105. $id_cnt = (int)$id_cnt;
  106. $data = array('id_ind' => $id_ind);
  107. $where = $this->getAdapter()->quoteInto('id_cnt = ?', $id_cnt);
  108. if($this->update($data, $where))
  109. {
  110. $return = true;
  111. }
  112. return $return;
  113. }
  114. } // end of class
  115. ?>