Guest User

Untitled

a guest
May 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. <?php
  2. class Profile extends AppModel {
  3.  
  4. var $name = 'Profile';
  5. var $actsAs = array('Containable');
  6.  
  7. var $hasMany = array(
  8. 'Answer' => array(
  9. 'className' => 'Answer',
  10. 'foreignKey' => 'profile_id',
  11. 'dependent' => true,
  12. 'exclusive' => true
  13. )
  14. );
  15.  
  16. var $hasAndBelongsToMany = array(
  17. 'Media' => array(
  18. 'className' => 'Media',
  19. 'joinTable' => 'media_profiles',
  20. 'foreignKey' => 'profile_id',
  21. 'associationForeignKey' => 'media_id',
  22. 'unique' => true,
  23. )
  24. );
  25.  
  26. function beforeSave() {
  27. if(isset($this->data['Profile']['id'])) {
  28. // Delete all associated Answers so the resave is clean.
  29. $this->delete($this->data['Profile']['id'], true);
  30. }
  31.  
  32. // Process the media.
  33. if(!empty($this->data['Media'])) {
  34.  
  35. $results = array();
  36. foreach ($this->data['Media'] as &$item) {
  37. $this->Media->id = null;
  38. $this->Media->save($item);
  39. $results[] = $this->Media->id;
  40. }
  41. $this->data['Media'] = $results;
  42. }
  43.  
  44. return true;
  45. }
  46.  
  47. function getAllProfiles($page) {
  48. $params = array(
  49. 'conditions' => array('Profile.visible' => true),
  50. 'fields' => array(
  51. 'Profile.id',
  52. 'Profile.first_name',
  53. 'Profile.last_name',
  54. 'Profile.intro',
  55. 'Profile.first_year',
  56. 'Profile.college_profession',
  57. 'Profile.last_updated',
  58. ),
  59. 'contain' => array(
  60. 'Media' => array(
  61. 'order' => array('Media.order ASC')
  62. )
  63. ),
  64. 'page' => $page,
  65. 'limit' => 20,
  66. 'order' => array('Profile.last_updated DESC'),
  67. );
  68.  
  69. return $this->find('all', $params);
  70. }
  71.  
  72.  
  73. function getByFirstLetter($letter) {
  74. $params = array(
  75. 'conditions' => array('Profile.visible' => true, 'Profile.last_name LIKE' => $letter.'%'),
  76. 'fields' => array(
  77. 'Profile.id',
  78. 'Profile.first_name',
  79. 'Profile.last_name',
  80. 'Profile.last_updated',
  81. ),
  82. 'contain' => array(),
  83. 'order' => array('Profile.last_name DESC'),
  84. );
  85.  
  86. return $this->find('all', $params);
  87. }
  88.  
  89.  
  90. function getAllCompleteProfiles() {
  91. $params = array(
  92. 'recursive' => 1,
  93. 'order' => array('Profile.last_updated DESC'),
  94. 'contain' => array(
  95. 'Media' => array(
  96. 'order' => array('Media.order ASC')
  97. ),
  98. 'Answer' => array('Question')
  99. )
  100. );
  101.  
  102. return $this->find('all', $params);
  103. }
  104.  
  105. function getProfile($id) {
  106. $params = array(
  107. 'conditions' => array('Profile.id' => $id, 'Profile.visible' => true),
  108. 'recursive' => 2,
  109. 'fields' => array(
  110. 'Profile.id',
  111. 'Profile.first_name',
  112. 'Profile.last_name',
  113. 'Profile.college_profession',
  114. 'Profile.intro',
  115. 'Profile.bio',
  116. 'Profile.scripture_quote',
  117. 'Profile.first_year',
  118. 'Profile.years_camper',
  119. 'Profile.years_staff',
  120. 'Profile.positions',
  121. ),
  122. 'contain' => array(
  123. 'Media' => array(
  124. 'order' => array('Media.order ASC')
  125. ),
  126. 'Answer' => array(
  127. 'Question'
  128. )
  129. ),
  130. 'limit' => 1
  131. );
  132.  
  133. return $this->find('first', $params);
  134. }
  135.  
  136. function getFooterProfiles() {
  137. $params = array(
  138. 'conditions' => array('Profile.visible' => true),
  139. 'fields' => array(
  140. 'Profile.id',
  141. 'Profile.college_profession',
  142. 'Profile.first_year',
  143. 'Profile.first_name',
  144. 'Profile.last_name'
  145. ),
  146. 'limit' => 4,
  147. 'contain' => array('Media'),
  148. 'order' => array('Profile.last_updated DESC')
  149. );
  150.  
  151. return $this->find('all', $params);
  152. }
  153.  
  154. function getNumPages() {
  155. $params = array(
  156. 'recursive' => -1,
  157. 'conditions' => array('Profile.visible' => true)
  158. );
  159.  
  160. return ceil( $this->find('count', $params) / 20 );
  161. }
  162.  
  163. function getUniverseInfo($id) {
  164. $params = array(
  165. 'conditions' => array('Profile.id' => $id),
  166. 'fields' => array(
  167. 'Profile.id',
  168. 'Profile.first_name',
  169. 'Profile.last_name',
  170. 'Profile.college_profession',
  171. 'Profile.first_year',
  172. 'Profile.years_camper',
  173. 'Profile.years_staff',
  174. 'Profile.last_updated',
  175. 'Profile.intro'
  176. ),
  177. 'contain' => array('Media')
  178. );
  179.  
  180. return $this->find('first', $params);
  181. }
  182.  
  183. function getProfileIDs($sortBy, $omitPhotoless) {
  184. if($omitPhotoless) {
  185. $this->bindModel(array('hasOne' => array('MediaProfile')));
  186. $params = array(
  187. 'fields' => array('Profile.id'),
  188. 'conditions' => array(
  189. 'NOT' => array('MediaProfile.media_id' => null),
  190. 'contain' => '',
  191. 'order' => array('Profile.'.$sortBy.' DESC')
  192. )
  193. );
  194.  
  195. $results = $this->find('all', $params);
  196.  
  197. } else {
  198. $params = array(
  199. 'conditions' => $conditions,
  200. 'fields' => array(
  201. 'Profile.id'),
  202. 'contain' => '',
  203. 'order' => array('Profile.'.$sortBy.' DESC')
  204. );
  205.  
  206. $results = $this->find('all', $params);
  207. }
  208.  
  209. return $results;
  210. }
  211. }
  212. ?>
Add Comment
Please, Sign In to add comment