PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/app/plugins/javan/models/group.php

https://github.com/ata/steak
PHP | 81 lines | 69 code | 10 blank | 2 comment | 5 complexity | f1f0863d8e814cd80d9930be7e72a30e MD5 | raw file
  1. <?php
  2. class Group extends JavanAppModel {
  3. var $name = 'Group';
  4. var $actsAs = array('Acl' => array('requester'));
  5. //The Associations below have been created with all possible keys, those that are not needed can be removed
  6. var $belongsTo = array(
  7. 'Parent' => array(
  8. 'className' => 'Group',
  9. 'foreignKey' => 'parent_id',
  10. 'conditions' => '',
  11. 'fields' => '',
  12. 'order' => ''
  13. )
  14. );
  15. var $hasMany = array(
  16. 'User' => array(
  17. 'className' => 'User',
  18. 'foreignKey' => 'group_id',
  19. 'dependent' => false,
  20. 'conditions' => '',
  21. 'fields' => '',
  22. 'order' => '',
  23. 'limit' => '',
  24. 'offset' => '',
  25. 'exclusive' => '',
  26. 'finderQuery' => '',
  27. 'counterQuery' => ''
  28. )
  29. );
  30. var $hasAndBelongsToMany = array(
  31. 'Link' => array(
  32. 'className' => 'Link',
  33. 'joinTable' => 'groups_links',
  34. 'foreignKey' => 'group_id',
  35. 'associationForeignKey' => 'link_id',
  36. 'unique' => true,
  37. 'conditions' => '',
  38. 'fields' => '',
  39. 'order' => '',
  40. 'limit' => '',
  41. 'offset' => '',
  42. 'finderQuery' => '',
  43. 'deleteQuery' => '',
  44. 'insertQuery' => ''
  45. )
  46. );
  47. function parentNode() {
  48. if(isset($this->data['Group']['parent_id']) && $this->data['Group']['parent_id'] != null){
  49. return array('Group'=>array('id' => $this->data['Group']['parent_id']));
  50. }else{
  51. return false;
  52. }
  53. }
  54. function afterSave($created) {
  55. //create
  56. if ($created) {
  57. $parent = $this->parentNode();
  58. $node = $this->node();
  59. $aro = $node[0];
  60. if($parent){
  61. $parent = $this->node($parent);
  62. $aro['Aro']['parent_id'] = $parent[0]['Aro']['id'];
  63. }else{
  64. $aro['Aro']['parent_id'] = null;
  65. }
  66. $aro['Aro']['alias'] = $this->data['Group']['name'];
  67. $this->Aro->save($aro);
  68. }
  69. }
  70. }
  71. ?>