14 use \Gino\ManyToManyField;
15 use \Gino\BooleanField;
17 use \Gino\DatetimeField;
36 public static $table =
'news_article';
47 $this->_controller = $instance;
48 $this->_tbl_data = self::$table;
50 $this->_fields_label = array(
51 'insertion_date'=>_(
'Data inserimento'),
52 'last_edit_date'=>_(
'Data ultima modifica'),
54 'categories'=>_(
"Categorie"),
56 'slug'=>array(_(
"Slug"), _(
'utilizzato per creare un permalink alla risorsa')),
58 'tags'=>array(_(
'Tag'), _(
"elenco separato da virgola")),
60 'attachment'=>_(
'Allegato'),
61 'private'=>array(_(
'Privata'), _(
'le news private sono visualizzabili solamente dagli utenti che hanno il permesso \'visualizzazione news private\'')),
62 'social'=>_(
'Condivisione social networks'),
63 'published'=>_(
'Pubblicata'),
66 parent::__construct($id);
68 $this->_model_label = _(
'Articolo');
76 return (
string) $this->title;
88 $structure = parent::structure($id);
90 $structure[
'categories'] =
new ManyToManyField(array(
91 'name' =>
'categories',
93 'm2m' =>
'\Gino\App\News\Category',
94 'm2m_where' =>
'instance=\''.$this->_controller->getInstance().
'\'',
95 'm2m_controller' => $this->_controller,
96 'join_table' => self::$table_ctgs,
97 'add_related' => TRUE,
98 'add_related_url' => $this->_controller->linkAdmin(array(),
'block=ctg&insert=1')
101 $structure[
'slug'] =
new SlugField(array(
105 'autofill' => array(
'date',
'title')
108 $structure[
'tags'] =
new TagField(array(
111 'model_controller_class' =>
'news',
112 'model_controller_instance' => $this->_controller->getInstance()
115 $structure[
'published'] =
new BooleanField(array(
116 'name' =>
'published',
118 'enum' => array(1 => _(
'si'), 0 => _(
'no')),
121 $structure[
'private'] =
new BooleanField(array(
124 'enum' => array(1 => _(
'si'), 0 => _(
'no'))
127 $structure[
'social'] =
new BooleanField(array(
130 'enum' => array(1 => _(
'si'), 0 => _(
'no'))
133 $structure[
'insertion_date'] =
new DatetimeField(array(
134 'name' =>
'insertion_date',
137 'auto_now_add' => TRUE
140 $structure[
'last_edit_date'] =
new DatetimeField(array(
141 'name' =>
'last_edit_date',
144 'auto_now_add' => TRUE
147 $base_path = $this->_controller->getBaseAbsPath() . OS .
'img';
148 $structure[
'img'] =
new ImageField(array(
151 'extensions' => self::$_extension_img,
152 'path' => $base_path,
155 'width' => $this->_controller->getImageWidth()
158 $base_path = $this->_controller->getBaseAbsPath() . OS .
'attachment';
159 $structure[
'attachment'] =
new FileField(array(
160 'name' =>
'attachment',
162 'extensions' => self::$_extension_attachment,
163 'path' => $base_path,
164 'check_type' => FALSE
177 foreach($this->categories as $ctgid) {
178 $res[] =
new Category($ctgid, $this->_controller);
192 public static function getCount($controller, $options = null) {
196 $private = \Gino\gOpt(
'private', $options, FALSE);
197 $published = \Gino\gOpt(
'published', $options, TRUE);
198 $ctg = \Gino\gOpt(
'ctg', $options,
false);
200 $db = Db::instance();
201 $selection =
'COUNT(id) AS tot';
203 $where_arr = array(
"instance='".$controller->getInstance().
"'");
205 $where_arr[] =
"private='0'";
208 $where_arr[] =
"published='1'";
211 $where_arr[] =
"id IN (SELECT article_id FROM ".self::$table_ctgs.
" WHERE category_id='".$ctg.
"')";
213 $where = implode(
' AND ', $where_arr);
215 $rows = $db->select($selection,
$table, $where, null, null);
217 if($rows && count($rows)) {
218 $res = $rows[0][
'tot'];
231 return $this->_controller->link($this->_controller->getInstanceName(),
'detail', array(
'id' => $this->slug));
240 return $this->_controller->getBasePath().
'/img/'.$this->img;
249 return $this->_controller->getBasePath().
'/attachment/'.$this->attachment;
258 return $this->_controller->link($this->_controller->getInstanceName(),
'download', array(
'id' => $this->
id));
268 $datetime = new \Datetime($this->date);
269 return $datetime->format(
'c');
dateIso()
Data in formato iso 8601.
objCategories()
Lista di oggetti categoria associati alla news.
attachmentDownloadUrl()
Path relativo al download dell'allegato.
structure($id)
Sovrascrive la struttura di default.
static getCount($controller, $options=null)
Restituisce il numero di news che soddisfano le condizioni date.
Classe tipo Gino.Model che rappresenta una singola news.
getImgPath()
Path relativo dell'immagine associata.
static $_extension_attachment
__construct($id, $instance)
Costruttore.
Classe di tipo Gino.Model che rappresenta una categoria di news.
__toString()
Rappresentazione a stringa dell'oggetto.
getUrl()
Url relativo al dettaglio della news.
getAttachmentPath()
Path relativo dell'allegato.
Namespace dell'applicazione News