/** * Prepare sidebar data, random tags and archive list */ private function prepareSidebar() { //if tags cache exist, skip retrieving from DB, expires every 5 minutes $cacheTagOK = Doo::cache('front')->testPart('sidebarTag', 300); if (!$cacheTagOK) { echo '<h2>Cache expired. Get Tags from DB!</h2>'; //get random 10 tags Doo::loadModel('Tag'); $tags = new Tag(); $this->data['randomTags'] = $tags->limit(10, null, null, array('custom' => 'ORDER BY RAND()')); } else { $this->data['randomTags'] = array(); } //if archive cache exist, skip retrieving from DB, archive expires when Post added, updated, deleted $cacheArchiveOK = Doo::cache('front')->testPart('sidebarArchive', 31536000); if (!$cacheArchiveOK) { echo '<h2>Cache expired. Get Archives from DB!</h2>'; //you can pass data to constructor to set the Model properties Doo::loadModel('Post'); $p = new Post(array('status' => 1)); $this->data['archives'] = $p->getArchiveSummary(); } else { $this->data['archives'] = array(); } }
public function login() { if (isset($_POST['username']) && isset($_POST['password'])) { $_POST['username'] = trim($_POST['username']); $_POST['password'] = trim($_POST['password']); //check User existance in DB, if so start session and redirect to home page. if (!empty($_POST['username']) && !empty($_POST['password'])) { $user = Doo::loadModel('User', true); $user->username = $_POST['username']; $user->pwd = $_POST['password']; $user = $this->db()->find($user, array('limit' => 1)); if ($user) { session_start(); unset($_SESSION['user']); $_SESSION['user'] = array('id' => $user->id, 'username' => $user->username, 'vip' => $user->vip, 'group' => $user->group); return Doo::conf()->APP_URL; } } } $data['baseurl'] = Doo::conf()->APP_URL; $data['title'] = 'Failed to login!'; $data['content'] = 'User with details below not found'; $data['printr'] = $_POST; $this->render('template', $data); }
function login() { session_start(); if (Session::siExisteSesion()) { header('location:' . Doo::conf()->APP_URL . 'ionadmin/index'); } else { if (isset($_POST['usuario']) && isset($_POST['passwd'])) { Doo::loadModel('CtUsuario'); $usuario = new CtUsuario(); $usuario->id_usuario = strip_tags(addslashes($_POST['usuario'])); $usuario->passwd = Session::encpass($_POST['passwd']); $usuario = $usuario->getOne(); if (!empty($usuario)) { $_SESSION['usuario'] = $usuario->id_usuario; Session::checkSumGen($usuario->id_usuario); header('location:' . Doo::conf()->APP_URL . 'ionadmin/index'); } else { header('location:' . Doo::conf()->APP_URL . 'ionadmin/login?error=1'); } } else { session_destroy(); $this->renderc('admin/login'); } } }
function borrarRespuestas() { if (!empty($this->id_pregunta)) { Doo::loadModel('CtRespuesta'); $resp = new CtRespuesta(); $resp->id_pregunta = $this->id_pregunta; $resp->delete(); } }
function borrarPreguntas() { if (!empty($this->id_encuesta)) { Doo::loadModel('CtPreguntas'); $p = new CtPreguntas(); $p->id_encuesta = $this->id_encuesta; $preguntas = $p->find(); if (!empty($preguntas)) { foreach ($preguntas as $preg) { $preg->borrarRespuestas(); $preg->delete(); } } } }
function borrarEncuestas() { if (!empty($this->id_evento)) { Doo::loadModel('CtEncuesta'); $e = new CtEncuesta(); $e->id_evento = $this->id_evento; $encuestas = $e->find(); if (!empty($encuestas)) { foreach ($encuestas as $enc) { $enc->borrarPreguntas(); $enc->delete(); } } } }
function eliminarRespuesta() { session_start(); if (Session::siExisteSesion()) { $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Doo::conf()->APP_URL . 'ionadmin/index'; $referer = strtok($referer, '?'); $this->data['idrespuesta'] = intval($this->params['idrespuesta']); Doo::loadModel('CtRespuesta'); $r = new CtRespuesta(); $r->id_respuesta = $this->data['idrespuesta']; $r->delete(); header('location:' . $referer . '?success=1'); } else { header('location:' . Doo::conf()->APP_URL . 'ionadmin/login?error=1'); } }
public function loadModel($className, $createObj = false) { if (class_exists($className, false) === true) { if ($createObj === true) { return new $className(); } return; } if (empty($this->modelPath) === true) { return Doo::loadModel($className, $createObj); } else { require_once $this->modelPath . $className . '.php'; if ($createObj === true) { return new $className(); } } }
function delete($opt = NULL) { Doo::loadModel('HtResultadoEncuesta'); if (!empty($this->id_respuesta)) { $h = new HtResultadoEncuesta(); $h->id_respuesta = $this->id_respuesta; $h->delete($opt); } else { if (!empty($this->id_pregunta)) { $f = $this->getOne(); if (!empty($f)) { $h = new HtResultadoEncuesta(); $h->id_respuesta = $f->id_respuesta; $h->delete($opt); } } } parent::delete($opt); }
function eliminar() { session_start(); if (Session::siExisteSesion()) { $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Doo::conf()->APP_URL . 'ionadmin/index'; $referer = strtok($referer, '?'); $idEvento = intval($this->params['idevento']); Doo::loadModel('CtEventos'); $evento = new CtEventos(); $evento->id_evento = $idEvento; $evento = $evento->getOne(); if (!empty($evento)) { $evento->borrarEncuestas(); $evento->delete(); header('location:' . $referer . '?success=1'); } else { header('location:' . $referer . '?error=1'); } } else { header('location:' . Doo::conf()->APP_URL . 'ionadmin/login?error=1'); } }
/** * short hand of Doo::loadModel() * @param string $class_name * @param bool $createObj * @return mixed If $createObj is True, it returns the created Object */ public function model($class_name, $createObj = false) { return Doo::loadModel($class_name, $createObj); }
public function encuestaActiva() { $result['encuesta'] = FALSE; Doo::loadModel('CtEncuesta'); $en = new CtEncuesta(); $en->activa = 1; $encuesta = $en->getOne(); if (!empty($encuesta)) { $result['encuesta'] = TRUE; } echo json_encode($result); }
<?php Doo::loadModel('base/HtResultadoEncuestaBase'); class HtResultadoEncuesta extends HtResultadoEncuestaBase { }
public static function __callStatic($name, $args) { // Food::getById( $id ); // Food::getById(14); // Food::getById(14, array('limit'=>1)) ; // Food::getById__location(14, 'Malaysia') ; // Food::getById__location(14, 'Malaysia', array('limit'=>1)) ; if (strpos($name, 'get') === 0) { if (self::$caseSensitive == false) { $field = strtolower(substr($name, 5)); } else { $field = substr($name, 5); } // if end with _first, add 'limit'=>'first' to Option array if (substr($name, -7, strlen($field)) == '__first') { $field = str_replace('__first', '', $field); $first['limit'] = 1; } // underscore _ as AND in SQL if (strpos($field, '__') !== false) { $field = explode('__', $field); } $clsname = self::$className; $obj = new $clsname(); if (is_string($field)) { $obj->{$field} = $args[0]; //if more than the field total, it must be an option array if (sizeof($args) > 1) { if (isset($first)) { $args[1]['limit'] = 1; } $id = self::toCacheId($obj, 'find', $args[1]); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj, $args[1]); } else { if (isset($first)) { $id = self::toCacheId($obj, 'find', $first); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj, $first); } else { $id = self::toCacheId($obj, 'find'); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj); } } } else { $i = 0; foreach ($field as $f) { $obj->{$f} = $args[$i++]; } //if more than the field total, it must be an option array if (sizeof($args) > $i) { if (isset($first)) { $args[$i]['limit'] = 1; } $id = self::toCacheId($obj, 'find', $args[$i]); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj, $args[$i]); } else { if (isset($first)) { $id = self::toCacheId($obj, 'find', $first); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj, $first); } else { $id = self::toCacheId($obj, 'find'); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->find($obj); } } } //if is null or false or 0 then dun store it because the cache can't differenciate the Empty values if ($value) { self::setCache($id, $value); } return $value; } else { if (strpos($name, 'relate') === 0) { $relatedClass = substr($name, 6); // if end with _first, add 'limit'=>'first' to Option array if (substr($name, -7, strlen($relatedClass)) == '__first') { $relatedClass = str_replace('__first', '', $relatedClass); $first['limit'] = 'first'; if (sizeof($args) === 0) { $args[0] = $first; } else { if (is_array($args[0])) { $args[0]['limit'] = 'first'; } else { $args[1]['limit'] = 'first'; } } } if (sizeof($args) === 0) { Doo::loadModel($relatedClass); $id = self::toCacheId(new self::$className(), 'relate' . $relatedClass); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->relate(self::$className, $relatedClass); } else { if (sizeof($args) === 1) { if (is_array($args[0])) { Doo::loadModel($relatedClass); $id = self::toCacheId(new self::$className(), 'relate' . $relatedClass, $args[0]); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->relate(self::$className, $relatedClass, $args[0]); } else { if (isset($first)) { Doo::loadModel($relatedClass); $id = self::toCacheId(new self::$className(), 'relate' . $relatedClass, $first); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->relate($args[0], $relatedClass, $first); } else { Doo::loadModel($relatedClass); $id = self::toCacheId($args[0], 'relate' . $relatedClass); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->relate($args[0], $relatedClass); } } } else { Doo::loadModel($relatedClass); $id = self::toCacheId($args[0], 'relate' . $relatedClass); if ($rs = self::getCache($id)) { return $rs; } $value = Doo::db()->relate($args[0], $relatedClass, $args[1]); } } //if is null or false or 0 then dun store it because the cache can't differenciate the Empty values if ($value) { self::setCache($id, $value); } return $value; } } }
<?php Doo::loadModel('base/UserPropertyBase'); class UserProperty extends UserPropertyBase { }
/** * Reject (delete) unapproved comment */ function rejectComment() { Doo::loadModel('Comment'); $c = new Comment(); $c->id = intval($this->params['cid']); $c->status = 0; $c->delete(array('limit' => 1)); $data['rootUrl'] = Doo::conf()->APP_URL; $data['title'] = 'Comment Rejected!'; $data['content'] = "<p>Comment is rejected & deleted successfully!</p>"; $this->render('admin_msg', $data); }
/** * Delete an existing record. (Prepares and execute the DELETE statements) * @param mixed $model The model object to be deleted. * @param array $opt Associative array of options to generate the UPDATE statement. Supported: <i>where, limit, param</i> */ public function delete($model, $opt = NULL) { if (is_object($model)) { //add values to fields where the model propertie(s) are/is set $obj = get_object_vars($model); //WHERE statement needs to change to parameterized stament =? instead of =value $wheresql = ''; $where_values = array(); foreach ($obj as $o => $v) { if (isset($v) && in_array($o, $model->_fields)) { $wheresql .= " AND {$obj['_table']}.{$o}=?"; $where_values[] = $v; } } if ($wheresql != '') { if (isset($opt['where'])) { $opt['where'] .= $wheresql; } else { $opt['where'] = substr($wheresql, 5); } } } else { //require file only when String is passed in Doo::loadModel($model); $model = new $model(); } if (isset($opt['limit'])) { $sql = "DELETE FROM {$model->_table} WHERE {$opt['where']} LIMIT {$opt['limit']}"; } else { $sql = "DELETE FROM {$model->_table} WHERE {$opt['where']}"; } //conditions WHERE param if (isset($opt['param']) && isset($where_values)) { $rs = $this->query($sql, array_merge($opt['param'], $where_values)); } else { if (isset($opt['param'])) { $rs = $this->query($sql, $opt['param']); } else { if (isset($where_values)) { $rs = $this->query($sql, $where_values); } else { $rs = $this->query($sql); } } } }
function estadisticas() { session_start(); if (Session::siExisteSesion()) { $this->data['idencuesta'] = intval($this->params['idencuesta']); $this->data['idevento'] = intval($this->params['idevento']); Doo::loadModel('CtEncuesta'); Doo::loadModel('CtPreguntas'); Doo::loadModel('CtRespuesta'); $ec = new CtEncuesta(); $ec->id_encuesta = intval($this->params['idencuesta']); $encuesta = $ec->getOne(); $this->data['encuesta'] = $encuesta; if (!empty($encuesta)) { $preguntas = new CtPreguntas(); $preguntas->id_encuesta = $encuesta->id_encuesta; $preguntas = $preguntas->relate('CtRespuesta'); $preguntasArray = array(); if (!empty($preguntas)) { foreach ($preguntas as $p) { $copyp = $p; if (!empty($p->CtRespuesta)) { $ctResp = array(); $totalRespondieron = 0; foreach ($p->CtRespuesta as $r) { $r->resultados = $r->getResultadosEncuestas(); $ctResp[] = $r; $totalRespondieron += $r->resultados['valor']; } unset($copyp->CtRespuesta); $copyp->CtRespuesta = $ctResp; $copyp->totalRespondieron = $totalRespondieron; } $preguntasArray[] = $copyp; } } $this->data['preguntas'] = $preguntasArray; $this->data['nombre_encuesta'] = $encuesta->nombre; $this->renderc('admin/encuesta-graficas', $this->data); } else { header('location:' . Doo::conf()->APP_URL . 'ionadmin/eventos?error=1'); } } else { header('location:' . Doo::conf()->APP_URL . 'ionadmin/login?error=1'); } }
public function food_ingredients_update() { if (!isset($this->params['ingredient']) && !isset($this->params['foodname']) && !isset($this->params['location'])) { return array('/db/failed/Fields cannot be empty', 404); } $food = Doo::loadModel('Food', true); $food->name = str_replace('%20', ' ', $this->params['foodname']); $food = Doo::db()->find($food, array('limit' => 1)); //needs to match exactly //if not found if (!isset($food->id)) { return array('/db/failed/Food name not found! Need to match exactly', 404); } $food->location = str_replace('%20', ' ', $this->params['location']); $ingredient = Doo::loadModel('Ingredient', true); $ingredient->name = str_replace('%20', ' ', $this->params['ingredient']); Doo::db()->relatedUpdate($food, array($ingredient), array('field' => 'location')); $data['printr'] = array($food, $ingredient); $data['title'] = 'Food with Ingredients Update'; $data['content'] = 'SQL executed. <pre>' . implode("\n\r", Doo::db()->showSQL()) . '</pre>'; $data['baseurl'] = Doo::conf()->APP_URL; $this->view()->render('template', $data); }
function __construct() { Doo::loadModel('Physical'); $this->Physical = new Physical(); }
public function index() { $data['baseurl'] = Doo::conf()->APP_URL; // include files are automatically parsed and compiled when the parent template file is compiled // if you have changes in a include file, just touch or modified & save the parent file to compile it. // However, using variable in template as an include filename would not generate any compile file, // You would need to compile in manually, <!-- include "variable_include" --> or $this->view()->render('variable_include'); $data['file'] = 'variable_include'; $data['nested'] = 'Hello! DooPHP'; $data['username'] = '******'; $data['pwd'] = '1234'; $data['messages'] = array('Please callback, thanks.', '$1000 cash to earn', 'Supernova photos', 'Weather today is very hot!'); $data['user'] = array('kee' => 'Lee Kee Seng', 'john' => 'John Smith'); // used in template as member.total.male, member.titalKids.male $data['member'] = array('total' => array('male' => 100, 'female' => 301), 'totalKids' => array('male' => 60, 'female' => 201), 'totalTeen' => array('male' => 40, 'female' => 100)); if (Doo::cache('front')->testPart('messages', 3600) == false) { echo 'Regenerated because cache has expired!'; $data['usermsg'] = array('leng' => array('Please callback, thanks.', '$1000 cash to earn', 'Supernova photos', 'Weather today is very hot!'), 'john' => array('Hi google', 'I am so happy now!', 'cool day huh?'), 'john2' => array('Hi google', 'I am so happy now!', 'cool day huh?'), 'john3' => array('Hi google', 'I am so happy now!', 'cool day huh?'), 'john4' => array('Hi google', 'I am so happy now!', 'cool day huh?'), 'john5' => array('Hi google', 'I am so happy now!', 'cool day huh?')); } $data['msgdetails'] = array(array('subject' => 'Cool stuff on my doormat', 'date' => '2009-09-13', 'attachment' => array('pdf' => 'benchmark.pdf', 'doc' => 'readme.doc')), array('subject' => 'Message 2 here hi!', 'date' => '2029-12-03', 'attachment' => array('pdf' => null, 'doc' => null))); // Objects can be used in the template too! // Used in template as winner.@fullname, winner.@Physical.@height Doo::loadModel('Winner'); $obj = new Winner(); $obj->fullname = 'Mr. Object'; $obj->gender = 'unisex'; $obj->Physical->weight = 562; $obj->Physical->height = 180; $data['winner'] = $obj; $data['winners'] = array(); for ($i = 0; $i < 4; $i++) { $obj = new Winner(); $obj->fullname = 'Mr. Object ' . $i; $obj->gender = 'unisex'; $obj->Physical->weight = rand(200, 600); $obj->Physical->height = rand(150, 200); $data['winners'][] = $obj; } //blog post with tags, template engine using loop with assoc array (Tag) Doo::loadModel('Blog'); Doo::loadModel('Tag'); $data['posts'] = array(); for ($i = 0; $i < 3; $i++) { $obj = new Blog(); $obj->title = 'This is a title ' . $i; $obj->content = 'Read this content ' . $i; $obj->Tag = array(); for ($g = 0; $g < 3; $g++) { $tag = new Tag(); $tag->name = 'tag' . $g; $obj->Tag[] = $tag; } $data['posts'][] = $obj; } $this->view()->render('about', $data); /* passing a true will enable the engine to process the template and compiled files If the template file is newer, then it will be compiled again. */ # $this->view()->render('about', $data, true); /* This is useful in production mode where DooPHP doesn't auto process it for performance. If you want it to force compile everytime, just pass in both as true */ # $this->view()->render('about', $data, true, true); }
function newComment() { foreach ($_POST as $k => $v) { $_POST[$k] = trim($v); } if ($_POST['url'] == 'http://' || empty($_POST['url'])) { unset($_POST['url']); } //strip html tags in comment if (!empty($_POST['content'])) { $_POST['content'] = strip_tags($_POST['content']); } Doo::loadModel('Comment'); $c = new Comment($_POST); $this->prepareSidebar(); // 'skip' is same as DooValidator::CHECK_SKIP if ($error = $c->validate('skip')) { $this->data['rootUrl'] = Doo::conf()->APP_URL; $this->data['title'] = 'Oops! Error Occured!'; $this->data['content'] = '<p style="color:#ff0000;">' . $error . '</p>'; $this->data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to post.</p>'; $this->render('error', $this->data); } else { Doo::autoload('DooDbExpression'); $c->createtime = new DooDbExpression('NOW()'); $c->insert(); $this->data['rootUrl'] = Doo::conf()->APP_URL; $this->render('comment', $this->data); } }
<?php Doo::loadModel('base/UserBase'); class User extends UserBase { }
<?php Doo::loadModel('base/CtUsuarioBase'); class CtUsuario extends CtUsuarioBase { }