Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1745

Přidáno uživatelem Ondřej Fibich před téměř 12 roky(ů)

Opravy:

- #380: opet nelze pridat tel.c. - chyba ve validatorech
- #381: vadne validatory u tel. cisel

Zobrazit rozdíly:

freenetis/branches/testing/application/helpers/callback.php
* @param type $name
* @param type $args
*/
public function not_empty($item, $name, $args = array())
public static function not_empty($item, $name, $args = array())
{
if ($item->$name === NULL)
{
......
* @param type $item
* @param type $name
*/
public function port_mode_field($item, $name)
public static function port_mode_field($item, $name)
{
echo Iface_Model::get_port_mode($item->port_mode);
}
freenetis/branches/testing/application/models/contact.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Contact are user for user contacts, private contacts.
* Each contact has it's type and value.
* Phone contacts are connected to countries by pivo table.
*
* @author Ondrej Fibich
* @package Model
*
* @property int $id
* @property int $type
* @property string $value
* @property ORM_Iterator $countries
* @property ORM_Iterator $users_contacts
* @property ORM_Iterator $private_users_contacts
*/
class Contact_Model extends ORM
{
// type column constants from enum_types id
const TYPE_ICQ = 18;
const TYPE_JABBER = 19;
const TYPE_EMAIL = 20;
const TYPE_PHONE = 21;
const TYPE_SKYPE = 22;
const TYPE_MSN = 23;
const TYPE_WEB = 25;
protected $has_many = array
(
'users' => 'private_users_contacts'
);
protected $has_and_belongs_to_many = array
(
'users_contacts' => 'users', 'countries'
);
/**
* Check if user own this contact
*
* @param integer $user_id
* @return boolean
*/
public function is_users_contact($user_id)
{
if (!$this->id)
{
return false;
}
return $this->db->query("
SELECT COUNT(contact_id) AS count
FROM users_contacts
WHERE contact_id = ? AND user_id = ?
", $this->id, $user_id)->current()->count;
}
/**
* Search for relation between users and countacts (users_contacts)
*
* @return integer Number of relation
*/
public function count_all_users_contacts_relation()
{
if (!$this->id)
{
return 0;
}
return $this->db->query("
SELECT COUNT(contact_id) AS count
FROM users_contacts
WHERE contact_id = ?
", $this->id, $this->id)->current()->count;
}
/**
* Search for all relation between users and countacts (users_contacts, private_users_contacts)
*
* @return integer Number of relation
*/
public function count_all_relation()
{
if (!$this->id)
{
return 0;
}
return $this->db->query("
SELECT (
(
SELECT COUNT(contact_id)
FROM users_contacts
WHERE contact_id = ?
) +
(
SELECT COUNT(contact_id)
FROM private_users_contacts
WHERE contact_id = ?
)
) AS count
", $this->id, $this->id)->current()->count;
}
/**
* Returns count of users contacts
*
* @param int $user_id
* @param int $type Contacts type
* @return int
*/
public function count_all_users_contacts($user_id, $type = NULL)
{
return $this->db->query("
SELECT COUNT(c.id) AS count
FROM contacts c
LEFT JOIN users_contacts u ON u.contact_id = c.id
WHERE u.user_id = ?" . ($type ? " AND c.type = ?" : "") . "
ORDER BY c.type
", $user_id, $type)->current()->count;
}
/**
* Returns all users contacts (id is from table contacts)
*
* @param int $user_id
* @param int $type Contacts type
* @return Mysql_Result
*/
public function find_all_users_contacts($user_id, $type = NULL)
{
return $this->db->query("
SELECT c.id, c.type, IF(n.country_code IS NULL, c.value,
CONCAT(n.country_code, c.value)) AS value
FROM contacts c
LEFT JOIN users_contacts u ON u.contact_id = c.id
LEFT JOIN contacts_countries o ON o.contact_id = c.id
LEFT JOIN countries n ON n.id = o.country_id
WHERE u.user_id = ?" . ($type ? " AND c.type = ?" : "") . "
ORDER BY c.type
", $user_id, $type);
}
/**
* Returns all private users contacts (id is from table private_users_contacts)
*
* @param int $user_id
* @return Mysql_Result
*/
public function find_all_private_users_contacts($user_id)
{
return $this->db->query("
SELECT IF(n.country_code IS NULL, c.value,
CONCAT(n.country_code, c.value)) AS value,
c.type, p.description, p.contact_id, p.id
FROM contacts c
LEFT JOIN private_users_contacts p ON p.contact_id = c.id
LEFT JOIN contacts_countries o ON o.contact_id = c.id
LEFT JOIN countries n ON n.id = o.country_id
WHERE p.user_id = ? ORDER BY p.description
", $user_id);
}
/**
* Find for contact id
*
* @param string $type Type of contact
* @param string $value Value of contact
* @return id or false if does't exists
*/
public function find_contact_id($type, $value)
{
$query = $this->db->query("
SELECT c.id
FROM contacts c
WHERE c.type = ? AND c.value = ?
", $type, $value);
return ($query->count() > 0) ? $query->current()->id : FALSE;
}
/**
* Gets prefix of phone country code
*
* @author Ondřej Fibich
* @return string Prefix or empty string
*/
public function get_phone_prefix()
{
if (!$this->id || $this->type != self::TYPE_PHONE)
{
return '';
}
foreach ($this->countries as $country)
{
return $country->country_code;
}
return '';
}
}
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Contact are user for user contacts, private contacts.
* Each contact has it's type and value.
* Phone contacts are connected to countries by pivo table.
*
* @author Ondrej Fibich
* @package Model
*
* @property int $id
* @property int $type
* @property string $value
* @property ORM_Iterator $countries
* @property ORM_Iterator $users_contacts
* @property ORM_Iterator $private_users_contacts
*/
class Contact_Model extends ORM
{
// type column constants from enum_types id
const TYPE_ICQ = 18;
const TYPE_JABBER = 19;
const TYPE_EMAIL = 20;
const TYPE_PHONE = 21;
const TYPE_SKYPE = 22;
const TYPE_MSN = 23;
const TYPE_WEB = 25;
protected $has_many = array
(
'users' => 'private_users_contacts'
);
protected $has_and_belongs_to_many = array
(
'users_contacts' => 'users', 'countries'
);
/**
* Check if user own this contact
*
* @param integer $user_id
* @return boolean
*/
public function is_users_contact($user_id)
{
if (!$this->id)
{
return false;
}
return $this->db->query("
SELECT COUNT(contact_id) AS count
FROM users_contacts
WHERE contact_id = ? AND user_id = ?
", $this->id, $user_id)->current()->count;
}
/**
* Search for relation between users and countacts (users_contacts)
*
* @param integer $contact_id
* @return integer Number of relation
*/
public function count_all_users_contacts_relation($contact_id = NULL)
{
if ($contact_id == NULL && $this)
{
$contact_id = $this->id;
}
return $this->db->query("
SELECT COUNT(contact_id) AS count
FROM users_contacts
WHERE contact_id = ?
", $contact_id)->current()->count;
}
/**
* Search for all relation between users and countacts (users_contacts, private_users_contacts)
*
* @return integer Number of relation
*/
public function count_all_relation()
{
if (!$this->id)
{
return 0;
}
return $this->db->query("
SELECT (
(
SELECT COUNT(contact_id)
FROM users_contacts
WHERE contact_id = ?
) +
(
SELECT COUNT(contact_id)
FROM private_users_contacts
WHERE contact_id = ?
)
) AS count
", $this->id, $this->id)->current()->count;
}
/**
* Returns count of users contacts
*
* @param int $user_id
* @param int $type Contacts type
* @return int
*/
public function count_all_users_contacts($user_id, $type = NULL)
{
return $this->db->query("
SELECT COUNT(c.id) AS count
FROM contacts c
LEFT JOIN users_contacts u ON u.contact_id = c.id
WHERE u.user_id = ?" . ($type ? " AND c.type = ?" : "") . "
ORDER BY c.type
", $user_id, $type)->current()->count;
}
/**
* Returns all users contacts (id is from table contacts)
*
* @param int $user_id
* @param int $type Contacts type
* @return Mysql_Result
*/
public function find_all_users_contacts($user_id, $type = NULL)
{
return $this->db->query("
SELECT c.id, c.type, IF(n.country_code IS NULL, c.value,
CONCAT(n.country_code, c.value)) AS value
FROM contacts c
LEFT JOIN users_contacts u ON u.contact_id = c.id
LEFT JOIN contacts_countries o ON o.contact_id = c.id
LEFT JOIN countries n ON n.id = o.country_id
WHERE u.user_id = ?" . ($type ? " AND c.type = ?" : "") . "
ORDER BY c.type
", $user_id, $type);
}
/**
* Returns all private users contacts (id is from table private_users_contacts)
*
* @param int $user_id
* @return Mysql_Result
*/
public function find_all_private_users_contacts($user_id)
{
return $this->db->query("
SELECT IF(n.country_code IS NULL, c.value,
CONCAT(n.country_code, c.value)) AS value,
c.type, p.description, p.contact_id, p.id
FROM contacts c
LEFT JOIN private_users_contacts p ON p.contact_id = c.id
LEFT JOIN contacts_countries o ON o.contact_id = c.id
LEFT JOIN countries n ON n.id = o.country_id
WHERE p.user_id = ? ORDER BY p.description
", $user_id);
}
/**
* Find for contact id
*
* @param string $type Type of contact
* @param string $value Value of contact
* @return id or false if does't exists
*/
public function find_contact_id($type, $value)
{
$query = $this->db->query("
SELECT c.id
FROM contacts c
WHERE c.type = ? AND c.value = ?
", $type, $value);
return ($query->count() > 0) ? $query->current()->id : FALSE;
}
/**
* Find for contacts
*
* @param string $type Type of contact
* @param string $value Value of contact
* @return Mysql_Result
*/
public function find_contacts($type, $value)
{
return $this->db->query("
SELECT c.*
FROM contacts c
WHERE c.type = ? AND c.value = ?
", $type, $value);
}
/**
* Gets prefix of phone country code
*
* @author Ondřej Fibich
* @return string Prefix or empty string
*/
public function get_phone_prefix()
{
if (!$this->id || $this->type != self::TYPE_PHONE)
{
return '';
}
foreach ($this->countries as $country)
{
return $country->country_code;
}
return '';
}
}
freenetis/branches/testing/application/controllers/contacts.php
Controller::error(RECORD);
}
$this->_contact_id = NULL;
$contact_model = new Contact_Model($contact_id);
$country_model = new Country_Model();
......
if ($form->validate())
{
if ($contact_model->value != $form->value->value &&
$contact_model->find_contact_id(
$contact_model->type, $form->value->value
))
{
status::warning('Contact is already in database');
}
else
{
$issaved = TRUE;
$contact_model->value = $form->value->value;
$issaved = $issaved && $contact_model->save();
if ($issaved)
if ($contact_model->save())
{
status::success('Additional contacts have been successfully updated');
}
......
{
status::error('Error - cant update additional contacts');
}
}
$this->redirect('contacts/show_by_user/',$user_id);
}
......
$contact_model = new Contact_Model();
// search for contacts
$contact_id = $contact_model->find_contact_id(
$type, trim($input->value)
);
$duplicip_contacts = $contact_model->find_contacts($type, trim($input->value));
if ($contact_id && $contact_id != $this->_contact_id)
foreach ($duplicip_contacts as $c)
{
$contact_model = ORM::factory('contact', $contact_id);
if ($contact_model->count_all_users_contacts_relation() > 0)
if ($c->id && ($c->id != $this->_contact_id))
{
if ($contact_model->count_all_users_contacts_relation($c->id) > 0)
{
$input->add_error('required', __('Contact is already in database'));
break;
}
}
}
}
}
}

Také k dispozici: Unified diff