aliroDBUpdateController.php

Go to the documentation of this file.
00001 <?php
00002 
00003 abstract class aliroDBUpdateController extends aliroComponentAdminControllers {
00004 
00005     protected static $instance = null;
00006     protected $cid = array();
00007     protected $id = 0;
00008 
00009     public function getRequestData () {
00010         $this->cid = $this->getParam($_REQUEST, 'cid', array());
00011         $this->id = $this->getParam($_REQUEST, 'id', 0);
00012         if (!$this->id AND isset($this->cid[0])) $this->id = intval($this->cid[0]);
00013     }
00014 
00015     public function checkPermission () {
00016         return true;
00017     }
00018 
00019     protected function setID ($id) {
00020         if ($id) $_SESSION[$this->session_var] = $id;
00021     }
00022 
00023     protected function getID () {
00024         if (isset($_SESSION[$this->session_var])) return $_SESSION[$this->session_var];
00025         else return 0;
00026     }
00027 
00028     protected function clearID () {
00029         if (isset($_SESSION[$this->session_var])) unset ($_SESSION[$this->session_var]);
00030     }
00031 
00032     public function listTask () {
00033         $database = call_user_func(array($this->DBname, 'getInstance'));
00034         $query = "SELECT %s FROM $this->table_name";
00035         if (isset($this->limit_list)) $query .= ' WHERE '.$this->limit_list;
00036         $database->setQuery(sprintf($query, 'COUNT(id)'));
00037         $total = $database->loadResult();
00038         $this->makePageNav($total);
00039         if ($total) {
00040             $limiter = " LIMIT {$this->pageNav->limitstart}, {$this->pageNav->limit}";
00041             $database->setQuery(sprintf($query,'*').$limiter);
00042             $rows = $database->loadObjectList();
00043         }
00044         else $rows = array();
00045         $view = new $this->view_class ($this);
00046         $view->view($rows);
00047     }
00048 
00049     public function newTask () {
00050         if ($this->checkExclusion('new')) return;
00051         $this->clearID();
00052         $view = new $this->view_class ($this);
00053         $view->newclass();
00054     }
00055 
00056     public function editTask () {
00057         if ($this->checkExclusion('edit')) return;
00058         if ($this->id) {
00059             $this->setID($this->id);
00060             $database = call_user_func(array($this->DBname, 'getInstance'));
00061             $database->setQuery("SELECT * FROM $this->table_name WHERE id=$this->id");
00062             $database->loadObject($classdocs);
00063             $view = new $this->view_class ($this);
00064             $view->editclass($classdocs);
00065         }
00066         else $this->setErrorMessage(T_('No item was selected for editing'));
00067     }
00068 
00069     public function saveTask () {
00070         if ($this->checkExclusion('save')) return;
00071         $this->commonSave();
00072         $this->clearID();
00073         $this->redirect($this->optionurl);
00074     }
00075 
00076     public function applyTask () {
00077         if ($this->checkExclusion('apply')) return;
00078         $this->commonSave();
00079         $this->redirect($this->optionurl.'&task=edit&id='.$this->getID());
00080     }
00081 
00082     protected function commonSave () {
00083         $id = $this->getID();
00084         if ($id) $this->basicUpdate($this->table_name, 'id', $id);
00085         else {
00086             $newid = $this->basicInsert($this->table_name);
00087             $this->setID($newid);
00088         }
00089     }
00090 
00091     public function removeTask () {
00092         if ($this->checkExclusion('remove')) return;
00093         if (count($this->cid)) {
00094             foreach ($this->cid as &$id) $id = intval($id);
00095             $idlist = implode(',', $this->cid);
00096             $database = call_user_func(array($this->DBname, 'getInstance'));
00097             $database->doSQL("DELETE FROM $this->table_name WHERE id IN ($idlist)");
00098             $this->setErrorMessage(T_('Deletion completed'), _ALIRO_ERROR_INFORM);
00099         }
00100         else $this->setErrorMessage(T_('No items for deletion'), _ALIRO_ERROR_WARN);
00101         $this->redirect($this->optionurl);
00102     }
00103 
00104     public function cancelTask () {
00105         $this->clearID();
00106         $this->redirect($this->optionurl);
00107     }
00108 
00109 }

Generated on Thu Apr 17 13:03:26 2008 for ALIRO by  doxygen 1.5.5