Revize 423
Přidáno uživatelem Michal Kliment před asi 15 roky(ů)
freenetis/trunk/kohana/application/models/address_point.php | ||
---|---|---|
{
|
||
protected $has_many = array('members', 'devices', 'item_locations');
|
||
protected $belongs_to = array('town', 'street');
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Check if address point exists
|
||
* Exists - return it
|
||
* Not exists - create it a return it
|
||
* @param $town_id id of town
|
||
* @param $street_id id of street
|
||
* @param $street_number street number
|
||
* @return address point object
|
||
*/
|
||
function get_address_point($town_id = NULL, $street_id = NULL, $street_number = NULL)
|
||
{
|
||
$address_points = $this->where(array('town_id' => $town_id, 'street_id' => $street_id, 'street_number' => $street_number))->find_all();
|
||
|
||
if (count($address_points)==0)
|
||
{
|
||
$this->clear();
|
||
$this->town_id = $town_id;
|
||
$this->street_id = $street_id;
|
||
$this->street_number = $street_number;
|
||
$this->save();
|
||
return $this;
|
||
}
|
||
else if (count($address_points)==1) return $address_points->current();
|
||
else return NULL;
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/street.php | ||
---|---|---|
class Street_Model extends ORM
|
||
{
|
||
protected $has_many = array('address_points');
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Check if town exists
|
||
* Exists - return it
|
||
* Not exists - create it a return it
|
||
* @param $street name of street
|
||
* @return street object
|
||
*/
|
||
function get_street($street = NULL)
|
||
{
|
||
$streets = $this->where('street',$street)->find_all();
|
||
if (count($streets)==0)
|
||
{
|
||
$this->clear();
|
||
$this->street = $street;
|
||
$this->save();
|
||
return $this;
|
||
}
|
||
else if (count($streets)==1) return $streets->current();
|
||
else return NULL;
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/models/member.php | ||
---|---|---|
}
|
||
}
|
||
}
|
||
return self::$db->query("SELECT
|
||
m.id, m.registration, m.name, m.street, m.street_number, m.town, m.quarter, u.phone
|
||
FROM members m
|
||
JOIN users u ON m.id = u.member_id AND u.type = ".User_Model::$member."
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
return self::$db->query("SELECT m.id, m.registration, m.name, s.street, ap.street_number, t.town, t.quarter, u.phone
|
||
FROM members m
|
||
JOIN users u ON m.id = u.member_id AND u.type = ".User_Model::$member."
|
||
LEFT JOIN address_points ap ON m.address_point_id = ap.id
|
||
LEFT JOIN streets s ON ap.street_id = s.id
|
||
LEFT JOIN towns t ON ap.town_id = t.id
|
||
$where
|
||
ORDER BY $order_by $order_by_direction
|
||
LIMIT $limit_from, $limit_results"
|
||
);
|
||
}
|
||
|
||
... | ... | |
public function get_member($id)
|
||
{
|
||
return self::$db->select(
|
||
array('members.registration', 'members.name as namem', 'members.street', 'members.street_number',
|
||
array('members.registration', 'members.name as namem', 'members.address_point_id', 'members.street', 'members.street_number',
|
||
'members.town', 'members.quarter','members.ZIP_code',
|
||
'members.type as typem', 'members.organization_identifier', 'members.qos_ceil', 'members.qos_rate',
|
||
'members.entrance_fee', 'members.debt_payment_rate', 'members.entrance_fee_left',
|
freenetis/trunk/kohana/application/models/town.php | ||
---|---|---|
class Town_Model extends ORM
|
||
{
|
||
protected $has_many = array('address_points');
|
||
|
||
/**
|
||
* @author Michal Kliment
|
||
* Check if town exists
|
||
* Exists - return it
|
||
* Not exists - create it a return it
|
||
* @param $zip_code zip code
|
||
* @param $town town
|
||
* @param $quarter quarter
|
||
* @return town object
|
||
*/
|
||
function get_town($zip_code = NULL, $town = NULL, $quarter = NULL)
|
||
{
|
||
$towns = $this->where(array('zip_code' => $zip_code, 'town' => $town, 'quarter' => $quarter))->find_all();
|
||
|
||
if (count($towns)==0)
|
||
{
|
||
$this->clear();
|
||
$this->zip_code = $zip_code;
|
||
$this->town = $town;
|
||
$this->quarter = $quarter;
|
||
$this->save();
|
||
return $this;
|
||
}
|
||
else if (count($towns)==1) return $towns->current();
|
||
else return NULL;
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/controllers/members.php | ||
---|---|---|
if (count($model_members->get_member($member_id)) == 0)
|
||
url::redirect(url_lang::base().'members/show_all');
|
||
$member_data = $model_members->get_member($member_id)->current();
|
||
|
||
$address_point = new Address_point_Model($member_data->address_point_id);
|
||
|
||
$model_translation = new Translation_Model();
|
||
$member_type = $model_translation->get_translation($member_data->member_type);
|
||
$model_contacts = new Contact_Model();
|
||
... | ... | |
$member_data->registration = $registration_value[(bool)$member_data->registration];
|
||
$view->content->member_data = $member_data;
|
||
$view->content->member_type = $member_type;
|
||
$view->content->address_point = $address_point;
|
||
$view->content->contact_types = $arr_contact_types;
|
||
$view->content->contacts = $contacts;
|
||
$view->content->message = $this->session->get_once('message');
|
||
... | ... | |
$entrance_fee = $fee->fee;
|
||
else
|
||
$entrance_fee = 0;
|
||
|
||
$street_model = new Street_Model();
|
||
$streets = $street_model->find_all();
|
||
|
||
$arr_streets = array();
|
||
|
||
foreach ($streets as $street)
|
||
{
|
||
$arr_streets[$street->id] = $street->street;
|
||
}
|
||
asort($arr_streets, SORT_LOCALE_STRING);
|
||
|
||
$town_model = new Town_Model();
|
||
$towns = $town_model->find_all();
|
||
|
||
$arr_towns = array();
|
||
|
||
foreach ($towns as $town)
|
||
{
|
||
$arr_towns[$town->id] = $town->town;
|
||
$arr_towns[$town->id] .= ($town->quarter) ? '-'.$town->quarter : '';
|
||
$arr_towns[$town->id] .= ', '.$town->zip_code;
|
||
}
|
||
asort($arr_towns, SORT_LOCALE_STRING);
|
||
|
||
// form
|
||
$form = new Forge(url_lang::base().'members/add', '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
... | ... | |
$form->password('passwd')->label(url_lang::lang('texts.password').':')->rules('required|length[3,50]')->class('required');
|
||
$form->password('confirm_password')->label(url_lang::lang('texts.confirm password').':')->rules('required|length[3,50]')->matches($form->passwd);
|
||
|
||
$form->group('')->label(url_lang::lang('texts.Address'));
|
||
$form->dropdown('street_id')->label(url_lang::lang('texts.street').':')->rules('required')->options($arr_streets);
|
||
$form->input('street_number')->label(url_lang::lang('texts.street number').':')->rules('required|length[1,50]|valid_numeric');
|
||
$form->dropdown('town_id')->label(url_lang::lang('texts.town').':')->rules('required')->options($arr_towns);
|
||
$form->group('')->label(url_lang::lang('texts.Contact information'));
|
||
$form->input('street')->label(url_lang::lang('texts.street').':')->rules('required|length[1,200]');
|
||
$form->input('street_number')->label(url_lang::lang('texts.street number').':')->rules('required|length[1,50]|valid_numeric');
|
||
$form->input('quarter')->label(url_lang::lang('texts.Quarter').':')->rules('length[1,50]');
|
||
$form->input('town')->label(url_lang::lang('texts.town').':')->rules('required|length[1,200]');
|
||
$form->input('zip_code')->label(url_lang::lang('texts.zip code').':')->rules('required|length[5,10]');
|
||
$form->input('phone')->label(url_lang::lang('texts.phone').':')->rules('required|length[9,40]')->callback(array($this, 'valid_phone'));
|
||
$form->input('email')->label(url_lang::lang('texts.email').':')
|
||
->rules('length[3,50]|valid_email')
|
||
... | ... | |
$user = new User_Model();
|
||
$member = new Member_Model();
|
||
$account = new Account_Model();
|
||
|
||
$address_point_model = new Address_point_Model();
|
||
$address_point = $address_point_model->get_address_point($form_data['town_id'],$form_data['street_id'],$form_data['street_number']);
|
||
|
||
$account->account_attribute_id = Account_attribute_Model::$credit;
|
||
if ($form_data['membername'] == '')
|
||
... | ... | |
$user->email = $form_data['email'];
|
||
$user->password = sha1($form_data['passwd']);
|
||
$user->type = User_Model::$member;
|
||
$user->application_password = security::generate_password();
|
||
$user->application_password = security::generate_password();
|
||
|
||
$member->comment = $form_data['comment'];
|
||
$member->entrance_date = date("Y-m-d",$form_data['entrance_date']);
|
||
... | ... | |
$member->name = $form_data['name'].' '.$form_data['surname'];
|
||
else
|
||
$member->name = $form_data['membername'];
|
||
$member->street = $form_data['street'];
|
||
$member->street_number = $form_data['street_number'];
|
||
$member->town = $form_data['town'];
|
||
$member->quarter = $form_data['quarter'];
|
||
$member->address_point_id = $address_point->id;
|
||
$member->type = $form_data['type'];
|
||
$member->organization_identifier = $form_data['organization_identifier'];
|
||
$member->ZIP_code = $form_data['zip_code'];
|
||
$member->qos_ceil = $form_data['qos_ceil'];
|
||
$member->qos_rate = $form_data['qos_rate'];
|
||
$member->entrance_fee = $form_data['entrance_fee'];
|
||
... | ... | |
Controller::error(ACCESS);
|
||
|
||
$this->user_id = $user_model->id;
|
||
unset($user_model);
|
||
unset($user_model);
|
||
|
||
$model_members = new Member_Model();
|
||
$member_data = $model_members->get_member($member_id)->current();
|
||
|
||
$address_point = new Address_point_Model($member_data->address_point_id);
|
||
|
||
$street_model = new Street_Model();
|
||
$streets = $street_model->find_all();
|
||
|
||
$arr_streets = array();
|
||
|
||
foreach ($streets as $street)
|
||
{
|
||
$arr_streets[$street->id] = $street->street;
|
||
}
|
||
asort($arr_streets, SORT_LOCALE_STRING);
|
||
|
||
$town_model = new Town_Model();
|
||
$towns = $town_model->find_all();
|
||
|
||
$arr_towns = array();
|
||
|
||
foreach ($towns as $town)
|
||
{
|
||
$arr_towns[$town->id] = $town->town;
|
||
$arr_towns[$town->id] .= ($town->quarter) ? '-'.$town->quarter : '';
|
||
$arr_towns[$town->id] .= ', '.$town->zip_code;
|
||
}
|
||
asort($arr_towns, SORT_LOCALE_STRING);
|
||
|
||
$form = new Forge(url_lang::base().'members/edit/'.$member_id, '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
... | ... | |
->callback(array($this, 'valid_username'))
|
||
->value($member_data->login);
|
||
|
||
$form->group('')->label(url_lang::lang('texts.Contact information'));
|
||
$form->group('')->label(url_lang::lang('texts.Address'));
|
||
if ($this->acl_check_edit(get_class($this),'address',$member_id))
|
||
{
|
||
$form->input('street')->label(url_lang::lang('texts.street').':')->rules('required|length[1,200]')->value($member_data->street);
|
||
$form->input('street_number')->label(url_lang::lang('texts.street number').':')->rules('required|length[1,50]|valid_numeric')->value($member_data->street_number);
|
||
$form->input('town')->label(url_lang::lang('texts.town').':')->rules('required|length[1,200]')->value($member_data->town);
|
||
$form->input('quarter')->label(url_lang::lang('texts.quarter').':')->rules('length[1,50]')->value($member_data->quarter);
|
||
$form->input('zip_code')->label(url_lang::lang('texts.zip code').':')->rules('required|length[5,10]')->value($member_data->ZIP_code);
|
||
$form->dropdown('street_id')->label(url_lang::lang('texts.street').':')->rules('required')->options($arr_streets)->selected($address_point->street_id);
|
||
$form->input('street_number')->label(url_lang::lang('texts.street number').':')->rules('required|length[1,50]|valid_numeric')->value($address_point->street_number);
|
||
$form->dropdown('town_id')->label(url_lang::lang('texts.town').':')->rules('required')->options($arr_towns)->selected($address_point->town_id);
|
||
}
|
||
$form->group('')->label(url_lang::lang('texts.Contact information'));
|
||
if ($this->acl_check_edit('Users_Controller','phone',$member_id))
|
||
$form->input('phone')->label(url_lang::lang('texts.phone').':')->rules('required|length[3,40]')->callback(array($this, 'valid_phone'))->value($member_data->phone);
|
||
if ($this->acl_check_edit('Users_Controller','email',$member_id))
|
||
... | ... | |
$member_data = new Member_Model;
|
||
|
||
$member_data->find_by_id($member_id);
|
||
|
||
$address_point_model = new Address_point_Model();
|
||
$address_point = $address_point_model->get_address_point($form_data['town_id'],$form_data['street_id'],$form_data['street_number']);
|
||
|
||
$user_data->where('type!=', User_Model::$user);
|
||
$user_data->find_by_member_id($member_id);
|
||
|
||
... | ... | |
if ($this->acl_check_edit(get_class($this),'name',$member_id))
|
||
$member_data->name = $form_data['membername'];
|
||
if ($this->acl_check_edit(get_class($this),'address',$member_id)) {
|
||
$member_data->street = $form_data['street'];
|
||
$member_data->street_number = $form_data['street_number'];
|
||
$member_data->town = $form_data['town'];
|
||
$member_data->quarter = $form_data['quarter'];
|
||
$member_data->ZIP_code = $form_data['zip_code'];
|
||
$member_data->address_point_id = $address_point->id;
|
||
|
||
}
|
||
if ($this->acl_check_edit(get_class($this),'qos_ceil',$member_id))
|
||
$member_data->qos_ceil = $form_data['qos_ceil'];
|
freenetis/trunk/kohana/application/controllers/address_points.php | ||
---|---|---|
class Address_points_Controller extends Controller
|
||
{
|
||
|
||
function streets()
|
||
function migrate()
|
||
{
|
||
$db = new Database();
|
||
$streets = $db->query("SELECT DISTINCT street FROM members");
|
||
|
||
$member_model = new Member_Model();
|
||
$town_model = new Town_Model();
|
||
$street_model = new Street_Model();
|
||
$address_point_model = new Address_point_Model();
|
||
|
||
$members = $member_model->find_all();
|
||
|
||
foreach ($members as $member)
|
||
{
|
||
$town = $town_model->get_town($member->ZIP_code, $member->town, $member->quarter);
|
||
$street = $street_model->get_street($member->street);
|
||
|
||
$address_point = $address_point_model->get_address_point($town->id, $street->id, $member->street_number);
|
||
|
||
$member->address_point_id = $address_point->id;
|
||
$member->save();
|
||
}
|
||
}
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/views/members/show.php | ||
---|---|---|
<?php } ?>
|
||
<tr>
|
||
<th><?php echo url_lang::lang('texts.Address') ?></th>
|
||
<td><?php echo $member_data->street.' '.$member_data->street_number?></td>
|
||
<td><?php echo $address_point->street->street.' '.$address_point->street_number?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo url_lang::lang('texts.Town') ?></th>
|
||
<td><?php echo $member_data->town.' '.$member_data->quarter?></td>
|
||
<td><?php echo $address_point->town->town.''.$address_point->street->quarter?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo url_lang::lang('texts.ZIP code') ?></th>
|
||
<td><?php echo $member_data->ZIP_code ?></td>
|
||
<td><?php echo $address_point->town->zip_code ?></td>
|
||
</tr>
|
||
<?php if ($member_data->member_id != 1) { ?>
|
||
<tr>
|
Také k dispozici: Unified diff
Vsechny adresy clenu predelany na adresni body.