[Isocial-svn] SF.net SVN: isocial: [249] app
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <di...@us...> - 2008-06-25 16:23:39
|
Revision: 249 http://isocial.svn.sourceforge.net/isocial/?rev=249&view=rev Author: dim0s77 Date: 2008-06-25 09:23:46 -0700 (Wed, 25 Jun 2008) Log Message: ----------- remove DB triggers. Stabled group's work Modified Paths: -------------- app/controllers/groupapp/group_controller.php app/helpers/auto_complete_helper.php app/installers/groupapp/group_installer.php app/locales/groupapp/group/ru.php app/models/groupapp_member.php app/views/groupapp/group/browse.tpl app/views/groupapp/group/customize.tpl Modified: app/controllers/groupapp/group_controller.php =================================================================== --- app/controllers/groupapp/group_controller.php 2008-06-24 17:45:34 UTC (rev 248) +++ app/controllers/groupapp/group_controller.php 2008-06-25 16:23:46 UTC (rev 249) @@ -14,17 +14,21 @@ $this->is_guest = true; if (!empty($this->params['id']) && $this->GroupappGroup->find($this->params['id'])) { - if ($this->group = $this->GroupappGroup->findFirst(array( 'id = ?' => $this->params['id'] ))) { - $members = $this->_getGroupMembers($this->group); + $group = $this->GroupappGroup->find( $this->params['id'] ); + if (isset($group) && $group) { + $this->group = $group; + $members = $this->_getGroupMembers($this->group->getId()); $current_user_id = $this->current_user->getId(); - foreach ($members as $member) { - if ($member->groupapp_member_role_id < 3 && $current_user_id == $member->getId()) { - $this->is_admin = true; + if ($members) { + foreach ($members as $member) { + if ($member->groupapp_member_role_id < 3 && $current_user_id == $member->getId()) { + $this->is_admin = true; + } + if ($current_user_id == $member->getId()) { + $this->is_member = true; + $this->is_guest = false; + } } - if ($current_user_id == $member->getId()) { - $this->is_member = true; - $this->is_guest = false; - } } } } @@ -46,6 +50,7 @@ $this->step = 'group_info'; if (!empty($this->params['group'])){ $this->GroupappGroup->setAttributes($this->params['group']); + $this->GroupappGroup->members_count = 1; if ($this->Request->isPost() && $this->GroupappGroup->save()){ $owner = $this->GroupappMemberRole->find(1); $group_member = $this->GroupappGroup->group_member->build(); @@ -54,10 +59,11 @@ if ($group_member->save()) { $this->step = 'group_customize'; $this->redirectTo(array('action' => 'customize', 'id' => $this->GroupappGroup->getId())); + } else { + $this->GroupappGroup->destroy(); } - } else { - $this->importErrors( $this->GroupappGroup->getErrors() ); } + $this->importErrors( $this->GroupappGroup->getErrors() ); } } @@ -109,18 +115,22 @@ if ($this->Request->isPost() && $this->GroupappGroup->save()){ return; } - } else if ($this->group) { - $this->members = $this->_getGroupMembers($this->group); + } else if (isset($this->group)) { + $this->members = $this->_getGroupMembers($this->group->getId()); $this->owners_count = 0; $this->admins_count = 0; $this->moderators_count = 0; $this->members_count = 0; - foreach ($this->members as $member) { - if ($member->groupapp_member_role_id == 1) $this->owners_count++; - elseif ($member->groupapp_member_role_id == 2) $this->admins_count++; - elseif ($member->groupapp_member_role_id == 3) $this->moderators_count++; - elseif ($member->groupapp_member_role_id == 4) $this->members_count++; + if ($members) { + foreach ($this->members as $member) { + if ($member->groupapp_member_role_id == 1) $this->owners_count++; + elseif ($member->groupapp_member_role_id == 2) $this->admins_count++; + elseif ($member->groupapp_member_role_id == 3) $this->moderators_count++; + elseif ($member->groupapp_member_role_id == 4) $this->members_count++; + } } + } else { + $this->redirectTo(array('action' => 'index')); } $this->importErrors( $this->GroupappGroup->getErrors() ); } @@ -130,11 +140,22 @@ !empty($this->params['groupapp_member_role_id']) && !empty($this->params['list_id'])) { $this->group = $this->GroupappGroup->find($this->params['groupapp_group_id']); - $this->GroupappMember->destroyAll("id = " . $this->params['member_id']); - $members = $this->_getGroupMembers(); + if (!$this->group) { return; } + $this->group->members_count -= 1; + if (!$this->group->save()) { return; } + if (!$this->GroupappMember->destroy($this->params['member_id'])) { + $this->group->members_count += 1; + $this->group->save(); + $this->importErrors( $this->GroupappMember->getErrors() ); + return; + }; + + $members = $this->_getGroupMembers($this->group->getId()); $members_count = 0; - foreach ($members as $member) { - if ($member->groupapp_member_role_id == $this->params['groupapp_member_role_id']) { $members_count++; } + if ($members) { + foreach ($members as $member) { + if ($member->groupapp_member_role_id == $this->params['groupapp_member_role_id']) { $members_count++; } + } } $members_group_name = ''; $empty_message = ''; @@ -163,33 +184,37 @@ } } - function _getGroupMembers () { + function _getGroupMembers ($group_id) { return $this->GroupappMember->find('all', array('conditions' => array("groupapp_group_id = ?", - $this->group->getId()), + $group_id), 'include' => 'user')); } function show_group () { if (isset($this->group)) { - $this->members = $this->_getGroupMembers($this->group); - $this->members_count = count($this->members); + $this->members = $this->_getGroupMembers($this->group->getId()); $this->admins = array(); $this->is_admin = false; $this->is_member = false; $this->is_guest = true; $current_user_id = $this->current_user->getId(); - foreach ($this->members as $member) { - if ($member->groupapp_member_role_id < 3) { - $member->role->load(); - $this->admins[] = $member; + if ($members) { + $this->members_count = count($this->members); + foreach ($this->members as $member) { + if ($member->groupapp_member_role_id < 3) { + $member->role->load(); + $this->admins[] = $member; + if ($current_user_id == $member->getId()) { + $this->is_admin = true; + } + } if ($current_user_id == $member->getId()) { - $this->is_admin = true; + $this->is_member = true; + $this->is_guest = false; } } - if ($current_user_id == $member->getId()) { - $this->is_member = true; - $this->is_guest = false; - } + } else { + $this->members_count = 0; } $this->group_type = $this->group->group_type->load()->get('name'); $messages = $this->GroupappMessage->find('all', @@ -225,9 +250,30 @@ } function browse () { + $all_groups = $this->GroupappGroup->find('all'); + $this->all_groups_count = count($all_groups); if (!empty($this->params['g'])) { - $this->group_types = $this->GroupappGroupType->find('all', array('conditions' => array("parent_id = 0"))); + $all_group_types = $this->GroupappGroupType->find('all'); + foreach($all_group_types as $group_type) { + if ($group_type->parent_id == 0) { + $gt = array("id" => $group_type->id, "name" => $group_type->get('name')); + $this->group_types[] = $gt; + } else if (is_numeric($this->params['g']) && $group_type->parent_id == $this->params['g']) { + $this->subgroup_types[] = $group_type; + } + } } else { + $all_group_types = $this->GroupappGroupType->find('all'); + $this->group_types = array(); + foreach($all_group_types as $group_type) { + if ($group_type->parent_id == 0) { + $gt = array("name" => $group_type->get('name'), "id" => $group_type->id); + $this->group_types[] = $gt; + } else if ($group_type->parent_id == 1) { + $gt = array("id" => $group_type->id, "name" => $group_type->get('name')); + $this->subgroup_types[] = $gt; + } + } } } Modified: app/helpers/auto_complete_helper.php =================================================================== --- app/helpers/auto_complete_helper.php 2008-06-24 17:45:34 UTC (rev 248) +++ app/helpers/auto_complete_helper.php 2008-06-25 16:23:46 UTC (rev 249) @@ -53,22 +53,22 @@ $this->value = ''; if ($this->object) { - $id = $this->object->get($method); - if ($id) { - $model = @$completion_options['model']; - if (!$model) { - foreach ($this->object->getAssociated('belongsTo') as $name => $association) { - if ($association->getAssociationOption('primary_key_name') == $method) { - $model = $association; - break; - } - } - } - $dep = $model->find($id); - if (!empty($dep)) { + $id = $this->object->get($method); + if ($id) { + $model = @$completion_options['model']; + if (!$model) { + foreach ($this->object->getAssociated('belongsTo') as $name => $association) { + if ($association->getAssociationOption('primary_key_name') == $method) { + $model = $association; + break; + } + } + } + $dep = $model->find($id); + if (!empty($dep)) { $this->value = $dep->name; - } - } + } + } } $tag_options = array_merge(array( Modified: app/installers/groupapp/group_installer.php =================================================================== --- app/installers/groupapp/group_installer.php 2008-06-24 17:45:34 UTC (rev 248) +++ app/installers/groupapp/group_installer.php 2008-06-25 16:23:46 UTC (rev 249) @@ -233,20 +233,6 @@ ) ENGINE=InnoDB"); $this->execute( - "CREATE TRIGGER gapp_group_insert AFTER INSERT ON groupapp_members - FOR EACH ROW BEGIN - UPDATE `groupapp_groups` SET members_count = members_count + 1 WHERE id = NEW.groupapp_group_id; - END; - "); - - $this->execute( - "CREATE TRIGGER gapp_group_delete AFTER DELETE ON groupapp_members - FOR EACH ROW BEGIN - UPDATE `groupapp_groups` SET members_count = members_count - 1 WHERE id = OLD.groupapp_group_id; - END; - "); - - $this->execute( "CREATE TABLE `groupapp_messages` ( `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `groupapp_group_id` int(11) NOT NULL DEFAULT '0', Modified: app/locales/groupapp/group/ru.php =================================================================== --- app/locales/groupapp/group/ru.php 2008-06-24 17:45:34 UTC (rev 248) +++ app/locales/groupapp/group/ru.php 2008-06-25 16:23:46 UTC (rev 249) @@ -63,7 +63,7 @@ $dictionary['Group type is missing'] = 'Тип группы отсутствует'; $dictionary['please enter the group category'] = 'выберите, пожалуйста, категорию группы'; -$dictionary['Edit'] = 'Редактирование'; +$dictionary['Edit group'] = 'Редактирование группы'; $dictionary['Website'] = 'Адрес сайта'; $dictionary['Options'] = 'Настройки'; $dictionary['Show related groups'] = 'Показывать похожие группы'; Modified: app/models/groupapp_member.php =================================================================== --- app/models/groupapp_member.php 2008-06-24 17:45:34 UTC (rev 248) +++ app/models/groupapp_member.php 2008-06-25 16:23:46 UTC (rev 249) @@ -12,6 +12,7 @@ var $has_many = array( 'messages' => array('class_name' => 'GroupappMessage', 'foreign_key' => 'user_id') ); + } ?> Modified: app/views/groupapp/group/browse.tpl =================================================================== --- app/views/groupapp/group/browse.tpl 2008-06-24 17:45:34 UTC (rev 248) +++ app/views/groupapp/group/browse.tpl 2008-06-25 16:23:46 UTC (rev 249) @@ -1,17 +1,20 @@ <?= $controller->renderPartial("menu") ?> -{?groups} - +{?all_groups_count} +<div class="info">_{You are in groups}: <? if (isset($user_groups)) echo count($user_groups); else echo 0; ?></div> <div class="two_column"> <div class="right_small"> <div class="right_content"> - blablabla + <ul class="actions_list"> + {loop group_types} + <li><a href="#">{group_type-name}</a></li> + {end} + </ul> </div> </div> <div class="left_big"> <div class="groups_list"> - <div class="info">_{You are in groups}: <? if (isset($user_groups)) echo count($user_groups); else echo 0; ?></div> <div class="container"> {loop user_groups} Modified: app/views/groupapp/group/customize.tpl =================================================================== --- app/views/groupapp/group/customize.tpl 2008-06-24 17:45:34 UTC (rev 248) +++ app/views/groupapp/group/customize.tpl 2008-06-25 16:23:46 UTC (rev 249) @@ -2,7 +2,7 @@ <div class="title_bar"> <div class="head"> - <div class="name groupapp">_{Edit} {group.name?}</div> + <div class="name groupapp">_{Edit group} '{group.name?}'</div> </div> </div> <div class="clearfix"></div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |