2014-02-05 14:03:04 +02:00
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
|
|
|
/**
|
|
|
|
* Subscription model.
|
|
|
|
* Subscription is a list of emails. An administrator can mail a letter to everyone on this list.
|
|
|
|
* @package Models
|
|
|
|
* @author Oreolek
|
|
|
|
**/
|
|
|
|
class Model_Subscription extends ORM {
|
|
|
|
protected $_has_many = array(
|
2014-02-18 10:11:50 +02:00
|
|
|
'clients' => array(
|
2014-02-05 14:03:04 +02:00
|
|
|
'model' => 'Client',
|
|
|
|
'through' => 'clients_subscriptions'
|
|
|
|
),
|
|
|
|
'instants' => array(
|
|
|
|
'model' => 'Instant'
|
2016-10-12 06:22:02 +03:00
|
|
|
),
|
|
|
|
'group' => array(
|
|
|
|
'model' => 'Group',
|
|
|
|
'through' => 'subscriptions_groups'
|
|
|
|
),
|
2014-02-05 14:03:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array validation rules
|
|
|
|
**/
|
|
|
|
public function rules()
|
2016-10-05 06:44:39 +03:00
|
|
|
{
|
|
|
|
return array(
|
2014-02-05 14:03:04 +02:00
|
|
|
'title' => array(
|
2016-10-05 06:44:39 +03:00
|
|
|
array('not_empty'),
|
|
|
|
array('min_length', array(':value', 4)),
|
|
|
|
array('max_length', array(':value', 100)),
|
2014-02-05 14:03:04 +02:00
|
|
|
),
|
|
|
|
'description' => array(
|
2016-10-05 06:44:39 +03:00
|
|
|
array('not_empty'),
|
|
|
|
array('min_length', array(':value', 20)),
|
2014-02-05 14:03:04 +02:00
|
|
|
),
|
|
|
|
'welcome' => array(
|
2016-10-05 06:44:39 +03:00
|
|
|
array('min_length', array(':value', 20)),
|
2014-02-05 14:03:04 +02:00
|
|
|
),
|
|
|
|
'price' => array(
|
|
|
|
array('numeric')
|
|
|
|
)
|
2016-10-05 06:44:39 +03:00
|
|
|
);
|
|
|
|
}
|
2014-02-05 14:03:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of field labels.
|
|
|
|
* Used in forms.
|
|
|
|
**/
|
|
|
|
protected $_labels = array(
|
|
|
|
'title' => 'Title',
|
|
|
|
'price' => 'Subscription price',
|
|
|
|
'description' => 'Description (for the clients)'
|
|
|
|
);
|
2014-02-18 09:45:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return subscriber count
|
|
|
|
**/
|
|
|
|
public function count_clients()
|
|
|
|
{
|
|
|
|
return DB::select(array(DB::expr('COUNT(client_id)'), 'cnt'))->from('clients_courses')->where('course_id', '=', $this->id)->execute()->get('cnt');
|
|
|
|
}
|
2014-02-05 14:03:04 +02:00
|
|
|
}
|