- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
while ($this->tariffs_model->getCarsCheckedByTariff($user_id, $tariff_info[0]['id']) > $tariff_info[0]['cars_count'])
{
$cars = $this->tariffs_model->getCarsChecked($tariff_info[0]['id'], $user_id);
if ($cars)
{
//удаляем одну объяву
$this->tariffs_model->delCarChecked($cars[0]);
$this->sms_model->removeSmsByCarId($cars[0]);
}
}
/*-=-=-=-=-=-=-=-=-=-=-=-=- реализация ф-ций -=-=-=-=-=-=-=-=-=-=-=-=-*/
/**
* Получаем кол-во реально отмеченых объявлений
* @param int $user_id
* @param int $tariff_id
*/
function getCarsCheckedByTariff($user_id, $tariff_id)
{
$query = "SELECT COUNT(*) as count FROM tariffs_cars_checked WHERE car_id IN
(SELECT id FROM a2_cars WHERE user = ? AND expire_date >= ?) AND tariff_id = ?";
$result = $this->db->query($query, array($user_id, MYSQL_CURDATE, $tariff_id));
//echo $this->db->last_query();
if ($result && $result->num_rows() == 1)
{
return $result->row()->count;
}
else
{
return null;
}
}
/**
* Список ID отмеченных объявлений по тарифу пользователя
*
* @param Int $tariff_id
* @return Array[]
* @author КОЕ-КТО 21.12.2009 12:35
* @uses Controller::Profile
*/
function getCarsChecked($tariff_id, $user_id)
{
$this->db->select('tariffs_cars_checked.car_id')->from('tariffs_cars_checked')
->join('a2_cars', 'a2_cars.id = tariffs_cars_checked.car_id', 'inner')
->where(array('tariffs_cars_checked.tariff_id' => intval($tariff_id), 'a2_cars.user' => intval($user_id)));
$result = $this->db->get();
if ($result && $result->num_rows() > 0)
{
$cars = array();
foreach ($result->result_array() as $row)
{
$cars[] = $row['car_id'];
}
return $cars;
}
else
{
return null;
}
}