|
Server IP : 10.2.73.233 / Your IP : 216.73.216.59 Web Server : Apache/2.4.59 (Debian) System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : www-data ( 33) PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/leksykografia/application/models/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
class Application_Model_DictionaryMapper
{
protected $_dbTable;
public function setDbTable($dbTable)
{
if (is_string($dbTable)) {
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Dictionary');
}
return $this->_dbTable;
}
public function save(Application_Model_Dictionary $dictionary)
{
$data = array(
'active' => $dictionary->active,
'title' => $dictionary->title,
'slug' => $dictionary->slug,
'author' => $dictionary->author,
'author_lastname' => $dictionary->authorLastname,
'year' => $dictionary->year,
'type' => $dictionary->type,
'cover' => $dictionary->cover,
'entry_pdf' => $dictionary->entryPdf,
'entry_image' => $dictionary->entryImage,
'full_title' => $dictionary->fullTitle,
'languages' => $dictionary->languages,
'entrys_number' => $dictionary->entrysNumber,
'entrys_layout' => $dictionary->entrysLayout,
'full_author' => $dictionary->fullAuthor,
'characteristic' => $dictionary->characteristic,
'workshop_innovation' => $dictionary->workshopInnovation,
'entry_construction' => $dictionary->entryConstruction,
'others' => $dictionary->others,
'interest' => $dictionary->interest,
'issues' => $dictionary->issues,
'electronic_version' => $dictionary->electronicVersion,
'monographs' => $dictionary->monographs,
'description_author' => $dictionary->descriptionAuthor,
'consultation' => $dictionary->consultation,
'created' => date('Y-m-d H:i:s')
);
if (null === ($id = $dictionary->id)) {
unset($data['id']);
return $this->getDbTable()->insert($data);
} else {
return $this->getDbTable()->update($data, array('id = ?' => $id));
}
}
public function delete($dictionaryId)
{
return $this->getDbTable()->delete('id = '.$dictionaryId);
}
public function find($id, Application_Model_Dictionary $dictionary)
{
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return false;
}
$row = $result->current();
$dictionary->id = $row->id;
$dictionary->active = $row->active;
$dictionary->title = $row->title;
$dictionary->slug = $row->slug;
$dictionary->author = $row->author;
$dictionary->authorLastname = $row->author_lastname;
$dictionary->year = $row->year;
$dictionary->type = $row->type;
$dictionary->cover = $row->cover;
$dictionary->entryPdf = $row->entry_pdf;
$dictionary->entryImage = $row->entry_image;
$dictionary->fullTitle = $row->full_title;
$dictionary->languages = $row->languages;
$dictionary->entrysNumber = $row->entrys_number;
$dictionary->entrysLayout = $row->entrys_layout;
$dictionary->fullAuthor = $row->full_author;
$dictionary->characteristic = $row->characteristic;
$dictionary->workshopInnovation = $row->workshop_innovation;
$dictionary->entryConstruction = $row->entry_construction;
$dictionary->others = $row->others;
$dictionary->interest = $row->interest;
$dictionary->issues = $row->issues;
$dictionary->electronicVersion = $row->electronic_version;
$dictionary->monographs = $row->monographs;
$dictionary->descriptionAuthor = $row->description_author;
$dictionary->consultation = $row->consultation;
$dictionary->created = $row->created;
return true;
}
public function fetchAll($options = array())
{
$select = $this->getDbTable()->select();
$orderSort = false;
if(!$orderSort)
{
$select->order('sort desc');
$orderSort = true;
}
if(isset($options['order']))
{
foreach($options['order'] as $key => $value)
{
if($key == 'range')
{
$select->from(array('d' => 'dictionary'))
->setIntegrityCheck(false)
->joinLeft(array('dvr' => 'dictionary_vocabulary_range'), 'dvr.dictionary_id = d.id',array("vocabulary_range_id"))
->order('vocabulary_range_id asc');
}
else {
$type = 'asc';
if($key == 'year')
$type = 'desc';
$select->order($key.' '.$type);
}
}
}
$select->order('year desc');
if(isset($options['where']))
{
foreach($options['where'] as $key => $value)
{
if($key == 'range')
{
$select->from(array('d' => 'dictionary'))
->joinLeft(array('dvr' => 'dictionary_vocabulary_range'), 'dvr.dictionary_id = d.id',null)
->where('vocabulary_range_id = ?', $value);
}
else {
$select->where("$key = ?", $value);
}
}
}
if(isset($options['search']))
{
$select->where('(title LIKE "%'.$options['search'].'%"')
->orWhere('full_title LIKE "%'.$options['search'].'%"')
->orWhere('year LIKE "%'.$options['search'].'%"')
->orWhere('languages LIKE "%'.$options['search'].'%"')
->orWhere('entrys_number LIKE "%'.$options['search'].'%"')
->orWhere('entrys_layout LIKE "%'.$options['search'].'%"')
->orWhere('full_author LIKE "%'.$options['search'].'%"')
->orWhere('characteristic LIKE "%'.$options['search'].'%"')
->orWhere('workshop_innovation LIKE "%'.$options['search'].'%"')
->orWhere('entry_construction LIKE "%'.$options['search'].'%"')
->orWhere('others LIKE "%'.$options['search'].'%"')
->orWhere('interest LIKE "%'.$options['search'].'%"')
->orWhere('issues LIKE "%'.$options['search'].'%"')
->orWhere('electronic_version LIKE "%'.$options['search'].'%"')
->orWhere('monographs LIKE "%'.$options['search'].'%"')
->orWhere('description_author LIKE "%'.$options['search'].'%"')
->orWhere('consultation LIKE "%'.$options['search'].'%"')
->orWhere('author LIKE "%'.$options['search'].'%")');
}
$resultSet = $this->getDbTable()->fetchAll($select);
$entries = array();
foreach ($resultSet as $row) {
$dictionary = new Application_Model_Dictionary();
$dictionary->id = $row->id;
$dictionary->active = $row->active;
$dictionary->title = $row->title;
$dictionary->slug = $row->slug;
$dictionary->author = $row->author;
$dictionary->authorLastname = $row->author_lastname;
$dictionary->year = $row->year;
$dictionary->type = $row->type;
$dictionary->cover = $row->cover;
$dictionary->entryPdf = $row->entry_pdf;
$dictionary->entryImage = $row->entry_image;
$dictionary->fullTitle = $row->full_title;
$dictionary->languages = $row->languages;
$dictionary->entrysNumber = $row->entrys_number;
$dictionary->entrysLayout = $row->entrys_layout;
$dictionary->fullAuthor = $row->full_author;
$dictionary->characteristic = $row->characteristic;
$dictionary->workshopInnovation = $row->workshop_innovation;
$dictionary->entryConstruction = $row->entry_construction;
$dictionary->others = $row->others;
$dictionary->interest = $row->interest;
$dictionary->issues = $row->issues;
$dictionary->electronicVersion = $row->electronic_version;
$dictionary->monographs = $row->monographs;
$dictionary->descriptionAuthor = $row->description_author;
$dictionary->created = $row->created;
if(isset($row->vocabulary_range_id))
$dictionary->vocabularyRangeId = $row->vocabulary_range_id;
$entries[] = $dictionary;
}
return $entries;
}
}