public function index() { $am = FLite::getInstance()->getAuthManager(); $user = $am->getCurrentUser(); var_dump($user); return FController::OK; }
public function query($sql) { $this->_queriesCounter++; FLite::getInstance()->getLogger()->log($sql, LOG_DEBUG); $sql = trim($sql); list($qryType, ) = explode(" ", strtolower($sql)); $this->_lastResult = null; $this->_lastInsertId = null; $this->_rowsAffected = null; $start = microtime(true); $q = mysql_query($sql); $this->_exec_time += microtime(true) - $start; if (!$q) { return null; } if ($qryType == "select") { $res = array(); while ($row = mysql_fetch_assoc($q)) { $res[] = $row; } $this->_lastResult = $res; return $this->_lastResult; } else { $this->_rowsAffected = mysql_affected_rows($this->_conn); if ($qryType == "insert" || $qryType == "replace") { $this->_lastInsertId = mysql_insert_id($this->_conn); } return true; } }
public function removeTask(TaskModel $task) { FLite::getInstance()->getLogger()->log('removing task: ' . json_encode($task), LOG_DEBUG); FLite::getInstance()->getLogger()->log('list->tasks: ' . json_encode($this->_tasks), LOG_DEBUG); $tasksT = array_flip($this->_tasks); //not such a task in the list if (!isset($tasksT[$task->getId()])) { return false; } $idx = $tasksT[$task->getId()]; unset($this->_tasks[$idx]); $this->_tasks_cnt--; return true; }
public function index() { $am = FLite::getInstance()->getAuthManager(); if (isset($_POST['login']) && isset($_POST['pass'])) { if ($am->login($_POST['login'], $_POST['pass'])) { $this->redirect(ROOT_WWW); } } $us = $am->getCurrentUser(); if ($us) { $listID = 1; $this->setPage('main/home'); $this->assign('current', $am->getCurrentUser()); $this->assign('tasks', $tasks); $this->assign('list_id', $listID); } return FController::OK; }
/** * @param int $userId task owner's id * @param int $listId list * @param bool $asArrays whether function should return data as array of arrays of array of objects * * @return TaskModel[]|array[] user's tasks sorted by id desc * @author Karol */ public function getTasks(ListModel $list, $asArrays = false) { $tasks = $list->getTasks(); if (!count($tasks)) { return array(); } $tasksT = array_flip($tasks); $this->dump($tasks); $sql = sprintf("SELECT * FROM task WHERE id IN (%s)", implode(',', $tasks)); $db = FLite::getInstance()->getDB(); $res = $db->getResults($sql); if (!is_array($res)) { return null; } foreach ($res as $row) { $task = new TaskModel($row); $tasksT[$task->getId()] = $asArrays ? $task->toArray() : $task; } return $tasksT; }
<?php define("ROOT_DIR", "../.."); require_once ROOT_DIR . "/app/config/config.php"; $flite = FLite::getInstance(); set_error_handler(array($flite, 'errorHandler')); $flite->setMode(FLite::MODE_WWW); ob_start(); $flite->go(); ob_end_flush();
public function update() { $class = get_class($this); $table = strtolower(str_ireplace('Model', '', $class)); $db = FLite::getInstance()->getDB(); $fields = array(); foreach ($this->_modifiedFields as $f => $tmp) { if ($f == '_id') { continue; } //$f = (substr($f,0,1) == '_') ? substr($f,1) : $f; $fields[] = sprintf("`%s` = '%s'", substr($f, 0, 1) == '_' ? substr($f, 1) : $f, is_array($this->{$f}) ? $db->escape(json_encode($this->{$f})) : $db->escape($this->{$f})); } $q = sprintf("UPDATE {$table} SET %s WHERE id = '%d'", implode(',', $fields), $this->_id); return $db->query($q); }
public function delete() { $user = FLite::getInstance()->getAuthManager()->getCurrentUser(); if (!$user) { $this->assign('resp', "not logged"); $this->setPage('ajax/default'); return FController::ERR; } $taskId = $_POST['task_id']; if (!is_numeric($taskId)) { $this->assign('resp', "task_id must be numeric"); $this->setPage('ajax/default'); return FController::ERR; } $listId = $_POST['list_id']; if (!is_numeric($listId)) { $this->assign('resp', "list id must be numeric"); return FController::ERR; } $list = $this->List->getList($listId); if (!$list) { $this->assign('resp', "list does not exist"); return FController::ERR; } if ($user['id'] != $list->getUserId()) { $this->assign('resp', "not list's owner"); return FController::ERR; } //TODO: sprawdzic czy user jest wlasicicelem taska $data = array('id' => $taskId); $db = FLite::getInstance()->getDB(); $db->begin(); $status = $this->Task->fillFromArray($data)->delete(); if ($status) { $status = $list->removeTask($this->Task); } if ($status) { $status = $list->save(); } if (!$status) { $db->rollback(); $this->assign('resp', "error deleting task"); $this->setPage('ajax/default'); return FController::ERR; } else { $db->commit(); $this->assign('resp', json_encode("a")); $this->setPage('ajax/default'); return FController::OK; } }
protected function setLayout($lay) { FLite::getInstance()->setLayout($lay); }