/** * Data retreival */ public function sort(array $fields = array()) { $fields_query = new Query($fields, $this->collection); $fields_query->compress(); $this->native->sort($fields_query->compressed); return $this; }
function updateDate($catalogue_id, $msgid) { $q = new Query(); $q->sql("UPDATE {messages} SET updated_at = NOW() WHERE msgid=? AND catalogue_id=?", $msgid, $catalogue_id)->execute(); //var_dump($catalogue_id); //echo "true"; }
/** * Save model data. * If model is new PK is null - we generate INSERT SQL request. * If model data already exists in DB, PK > 0 - we generate UPDATE request. * Method return true if model data saved successfully. False if error. */ public function save($validate = true) { if ($validate === true && $this->validate() === false) { return false; } $columns = $this->getClearColumns(); $values = array(); foreach ($columns as $column) { $values[] = $this->{$column}; } $keyPosition = array_search($this->pkColumnName(), $columns); array_splice($columns, $keyPosition, 1); array_splice($values, $keyPosition, 1); if ((int) $this->{$this->pkColumnName()} > 0) { $query = new Query("update"); $query->addTable($this->tableName()); foreach ($columns as $key => $column) { $query->addField($column, $values[$key]); } $query->where->add($this->pkColumnName() . " = " . $this->{$this->pkColumnName()}); $result = $query->exec(); } else { $query = new Query("insert"); $query->addTable($this->tableName()); foreach ($columns as $key => $column) { $query->addField($column, $values[$key]); } $result = $query->exec(); $this->ADDRESSID = $query->last_insert_id(); } return $result; }
/** * Filters a query object * * @param Query $query * @param Eloquent $model * * @return void */ public function filterQuery(&$query, $model) { //if the field is if ($this->value !== '') { $query->where($model->table() . '.' . $this->field, '=', $this->value); } }
public function testExecuteQueryFailed() { self::$functions->expects($this->once())->method('ldap_search')->with($this->equalTo('my_ldap_resource'), $this->equalTo('ou=People,dc=kanboard,dc=local'), $this->equalTo('uid=my_user'), $this->equalTo(array('displayname')))->will($this->returnValue(false)); $query = new Query(); $query->execute('my_ldap_resource', 'ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname')); $this->assertFalse($query->hasResult()); }
/** * Add clause to match the relationship we want to delete * * @param IdentityInterface $identity * @param $object $entity * @param Query $query * * @return Query */ private function matchRelationship(IdentityInterface $identity, $entity, Query $query) : Query { $meta = $this->metadatas->get(get_class($entity)); $name = $this->name->sprintf(md5($identity->value())); $this->variables = $this->variables->add((string) $name); return $query->match()->linkedTo()->through((string) $meta->type(), (string) $name)->withProperty($meta->identity()->property(), (string) $name->prepend('{')->append('_identity}'))->withParameter((string) $name->append('_identity'), $identity->value()); }
/** * Gets the classes whose objects the user can execute certain action * * @param $action object - The action that the user should be allowed to do * @param $user User - The user that holds de permissions * @return Array - an array of class objects */ function &findByPermission($action, $user) { $classQuery = new Query("Class"); // Navigate relationships $folderClassQuery =& $classQuery->queryRelationedClass("FolderClass"); $permissionQuery =& $folderClassQuery->queryRelationedClass("Permission"); $actionQuery =& $permissionQuery->queryRelationedClass("Action", Relationship::ManyToOneType()); $roleQuery =& $permissionQuery->queryRelationedClass("Role", Relationship::ManyToOneType()); $roleUserQuery =& $roleQuery->queryRelationedClass("RoleUser"); $userQuery =& $roleUserQuery->queryRelationedClass("User", Relationship::ManyToOneType()); // Criterias $criteriaGroup = new CriteriaGroup(); $actionCriteria = new Criteria($actionQuery, "action", $action->getAction()); $userCriteria = new Criteria($userQuery, "ID", $user->getId()); $criteriaGroup->addCriterion($actionCriteria); $criteriaGroup->addCriterion($userCriteria); $classQuery->setCriterion($criteriaGroup); // sorting $order = new Order($classQuery, "title", "ASC"); $classQuery->addOrder($order); // Execute the query $recordset =& $classQuery->execute(); $array = $this->mapAll($recordset); return $array; }
/** * Inenhåller menun som passar till Art * subkategprierna ordnas efter orderNo i matrushkan. */ public function setContent() { $q = new Query("matruschkaShowAtPlaces"); $q->showAt($this->title, $this->m->lang, "msapOrderNo", "ASC", 100); $i = 1; while ($row = mysql_fetch_object($q->getResult())) { $this->content .= '<div class="leftMenu">'; $this->content .= '<span class="subSecTitle">' . $row->mButtonTitle . '</span>'; $qq = new Query("matruschka"); $qq->whereCustom("mButtonTitle, mRowid", "mParent = '" . $row->mRowid . "' AND mPublished='1' AND mLang='" . $this->m->lang . "' ", "mOrderNo", "ASC", 0); if ($qq->getNumRows()) { // om det finns nån som har denna som parent $this->content .= '<div class="subSection">'; while ($row2 = mysql_fetch_object($qq->getResult())) { /** Svart om aktiv **/ if ($this->getActive($this->m->ID, $row2->mRowid) == 1) { $this->content .= '<span class="sideMenuActive"><a href="?ID=' . $row2->mRowid . '">' . $row2->mButtonTitle . '</a></span><br/>'; } else { $this->content .= '<a href="?ID=' . $row2->mRowid . '">' . $row2->mButtonTitle . '</a><br/>'; } } $this->content .= '</div>'; } $this->content .= '</div>'; if ($i != $q->getNumRows()) { $this->content .= '<img src="' . Settings::$graphics . 'stripes.gif" />' . "\n"; } $i++; } }
function add_error($_id) { $c = new Query(); $c->where_eq('id', $_id); $c->value('error_cnt', 'error_cnt+1', true); $this->update($c); }
function check($_type) { $c = new Query(); $c->where_eq("name", $_type); $res = $this->fetch_one("id", $c); return $res; }
public function __construct($settings) { $query = new Query($settings, array('xtimes' => 1, 'ytimes' => 1)); $query->acceptInteger('xtimes', '/^[1-9][0-9]*$/'); $query->acceptInteger('ytimes', '/^[1-9][0-9]*$/'); $this->settings = $query->results(); }
/** * get an array of data to use in the response * @param Query $query the query to use to retrieve the data * @param Paginator $paginator * @param array $additionalData an associative array of data to merge with the data array */ protected function getData($query, $additionalData = array()) { //use this hook to alter the parameters $paginator = null; if (Input::get('page') || $this->paginate) { $beforePagination = Event::fire('before.pagination', array(&$query)); //check if $object is a model or a relation $model = $query->getModel(); $model = method_exists($model, 'getRelated') ? $model->getRelated() : $model; $perPage = Input::get('pp') ?: $model->getPerPage(); $paginator = $query->paginate($perPage); //preserve the url query in the paginator $paginator->appends(Input::except('page')); } $results = isset($paginator) ? $paginator->getCollection() : $query->get(); $data = array(); $data[$this->resultsKey] = $this->isAjaxRequest() ? $results->toArray() : $results; $data['total'] = isset($paginator) ? $paginator->getTotal() : $data->{$this->resultsKey}->count(); if ($paginator) { $data['paginator'] = $paginator; } if (is_array($additionalData)) { $data = array_merge($data, $additionalData); } return $data; }
public function setContent() { $q = new Query("matruschkaShowAtPlaces"); $q->showAt("Menubar", $this->m->lang, "mOrderNo", "ASC", 10); $a = array(); $i = 0; while ($row = mysql_fetch_object($q->getResult())) { // Get the id and image $a[$i][0] = $row->mRowid; $a[$i][1] = $row->mButtonTitle; $a[$i][2] = $row->mButtonImage; $i++; } for ($i = 0; $i < count($a); $i++) { $im = split(',', $a[$i][2]); $this->content .= '<span class="menuItem">' . "\n"; $this->content .= "<a href=\"?ID=" . $a[$i][0] . "\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('" . $im[1] . "','','" . Settings::$graphics . "menu/" . $this->m->lang . "/" . $im[1] . "',1)\">"; // Den man är inne på blir röd $image = $this->getActive($this->m->ID, $a[$i][0]) ? $im[1] : $im[0]; $this->content .= '<img src="' . Settings::$graphics . 'menu/' . $this->m->lang . '/' . $image . '" alt="' . $im[1] . '" name="' . $im[1] . '" border="0" id="' . $im[1] . '" />'; $this->content .= '</a>'; if ($i < count($a) - 1) { $this->content .= '<img src="' . Settings::$graphics . 'menu/' . $this->m->lang . '/stripe.gif" width="7" height="12" />'; } $this->content .= "</span>\n"; } }
function edit($_id, $_state) { $c = new Query(); $c->value("visible", $_state); $c->where_eq("id", $_id); $this->update($c); }
public function startQuery($sql, $parameters = null, $stack = array()) { if (!$this->enabled) { return null; } // try to detect the query type switch (strtolower(substr(ltrim($sql), 0, 6))) { case 'select': $queryType = static::SELECT; break; case 'insert': $queryType = static::INSERT; break; case 'update': $queryType = static::UPDATE; break; case 'delete': $queryType = static::DELETE; break; default: $queryType = static::QUERY; break; } $profile = new Query($sql, $queryType, $parameters, $stack); $this->profiles[] = $profile; $profile->start(); end($this->profiles); return key($this->profiles); }
/** * utility function to pass individual item links to a caller * * @param $args['itemids'] array of item ids to get * @return array Array containing the itemlink(s) for the item(s). */ function publications_userapi_getitemlinks($args) { $itemlinks = array(); sys::import('xaraya.structures.query'); $xartable = xarDB::getTables(); $q = new Query('SELECT', $xartable['publications']); $q->addfield('id'); $q->addfield('title'); $q->addfield('description'); $q->addfield('pubtype_id'); $q->in('state', array(3, 4)); if (!empty($args['itemids'])) { $itemids = explode(',', $args['itemids']); $q->in('id', $itemids); } $q->addorder('title'); $q->run(); $result = $q->output(); if (empty($result)) { return $itemlinks; } foreach ($result as $item) { if (empty($item['title'])) { $item['title'] = xarML('Display Publication'); } $itemlinks[$item['id']] = array('url' => xarModURL('publications', 'user', 'display', array('id' => $item['id'])), 'title' => $item['title'], 'label' => $item['description']); } return $itemlinks; }
/** * Parse a query string into a Query object. * * @param Query $query Query object to populate * @param string $str Query string to parse * @param bool|string $urlEncoding How the query string is encoded */ public function parseInto(Query $query, $str, $urlEncoding = true) { if ($str === '') { return; } $result = []; $this->duplicates = false; $this->numericIndices = true; $decoder = self::getDecoder($urlEncoding); foreach (explode('&', $str) as $kvp) { $parts = explode('=', $kvp, 2); $key = $decoder($parts[0]); $value = isset($parts[1]) ? $decoder($parts[1]) : null; // Special handling needs to be taken for PHP nested array syntax if (strpos($key, '[') !== false) { $this->parsePhpValue($key, $value, $result); continue; } if (!isset($result[$key])) { $result[$key] = $value; } else { $this->duplicates = true; if (!is_array($result[$key])) { $result[$key] = [$result[$key]]; } $result[$key][] = $value; } } $query->replace($result); if (!$this->numericIndices) { $query->setAggregator(Query::phpAggregator(false)); } elseif ($this->duplicates) { $query->setAggregator(Query::duplicateAggregator()); } }
public function listDemos(Paging $paging){ while($row = mysql_fetch_assoc($paging->pagingResult)){ if($row['rowid']==$_GET['demo_id']) continue; // Got to make a new query beacuse of error in mysql_fetch_assoc $query = new Query($this->q->getTable()); $query->whereLeftJoinImageQuery("*","image_id",$row['image_id'],"rowid","ASC"); $image_id = $query->getResultRow("image_id"); $file_name=$query->getResultRow("file"); ?> <table border="0" cellpadding="0" cellspacing="0" class="demoTable"> <tr> <?php if(Helper::hasValue($image_id)){ ?> <td width="80" class="noPadding" rowspan="2"><img src="image_crop.php?source=<?php echo Settings::getUploadedImages().'/'.$file_name ?>&dest=&thumb_size=80" class="flowPic" /></td> <?php } ?> <td width="270" class="tdPadding" colspan="2"><span class="boldGrey"><?php echo $row['name']; ?></span></td> </tr> <tr> <td class="tdVertBottom"><span class="smallPink"><a href="?demo_id=<?php echo $row['rowid']; ?>">Läs mer</a></span></td> <td align="right" class="tdVertBottom"><span class="smallGrey"><?php echo date("Y-m-d",strtotime($row['date'])); ?></span></td> </tr> </table> <? } }
/** * Метод получает все содержимое таблицы $this->tableName по запросу SELECT и записывает в свойство $this->tableFormDB * вызывает метод draw() и возвращет готовую таблицу * @return string */ public function getTable(){ $query = new Query(); $sql = "SELECT * FROM `{$this->tableName}`"; $this->tableFromDB = $query->runSql($sql); return $this->draw(); }
public function setItems() { // Items at level $date = $this->matruschka ? $this->matruschka->pubDate : date("Y-m-d H:i:s"); // Order number $orderQ = new Query("matruschka"); if ($parent) { $orderQ->whereQuery("mOrderNo", "mParent", $parent, 'mOrderNo', 'DESC', 1); $order = $orderQ->getResultRow('mOrderNo') + 1; } else { $order = 1; } $orderNo = $this->matruschka ? $this->matruschka->orderNo : $order; $this->items[0][] = new ItemImage($this->matruschka->ID, $this->matruschka->images, "Bild. 200 x _ px", 1); $this->items[0][] = new ItemTitle($this->matruschka->ID, $this->matruschka->title, "Titel", 0); $this->items[0][] = new ItemButtonTitle($this->matruschka->ID, $this->matruschka->buttonTitle, "KnappTitel (Mest för navigering i adminsidan)", 0); $this->items[0][] = new ItemButtonImage($this->matruschka->ID, $this->matruschka->buttonImage, "Knappbild t.ex (bild1.gif,bild2.gif)", 0); $this->items[0][] = new ItemDescription($this->matruschka->ID, $this->matruschka->description, "Text", 0); $this->items[0][] = new ItemPublished($this->matruschka->ID, $this->matruschka->published, "Publicerad", 0); $this->items[0][] = new ItemOrderNo($this->matruschka->ID, $orderNo, "Ordningsnummer. Till menyraden.", 0); $this->items[1][] = new ItemButtonTitle($this->matruschka->ID, $this->matruschka->buttonTitle, "Knapptitel", 0); $this->items[1][] = new ItemPublished($this->matruschka->ID, $this->matruschka->published, "Publicerad", 0); $this->items[1][] = new ItemOrderNo($this->matruschka->ID, $orderNo, "Ordningsnummer. Till vänstermenyn.", 0); $this->items[2][] = new ItemImage($this->matruschka->ID, $this->matruschka->images, "Bild. 200 x _ px", 1); $this->items[2][] = new ItemButtonTitle($this->matruschka->ID, $this->matruschka->buttonTitle, "Knapptitel", 0); $this->items[2][] = new ItemTitle($this->matruschka->ID, $this->matruschka->title, "Titel", 0); $this->items[2][] = new ItemDescription($this->matruschka->ID, $this->matruschka->description, "Text (All text här)", 0); $this->items[2][] = new ItemPublished($this->matruschka->ID, $this->matruschka->published, "Publicerad", 0); $this->items[2][] = new ItemOrderNo($this->matruschka->ID, $orderNo, "Ordningsnummer. Till vänstermenyn.", 0); }
/** * Returns a string representing the SQL query corresonding to the specified Query object. * @param object QueryInterface $query The object from which to generate the SQL string. * @return mixed Either a string (this would be the case, normally) or an array of strings. * Each string is corresponding to an SQL query. * @static * @access public */ static function generateSQLQuery(Query $query) { switch ($query->getType()) { case INSERT: $result = MySQL_SQLGenerator::generateInsertSQLQuery($query); break; case UPDATE: $result = MySQL_SQLGenerator::generateUpdateSQLQuery($query); break; case DELETE: $result = MySQL_SQLGenerator::generateDeleteSQLQuery($query); break; case SELECT: $result = MySQL_SQLGenerator::generateSelectSQLQuery($query); break; case GENERIC: $result = MySQL_SQLGenerator::generateGenericSQLQuery($query); break; default: throw new DatabaseException("Unsupported query type."); } // switch // echo "<pre>\n"; // echo $result; // echo "</pre>\n"; return $result; }
public function toArray() { $data = $this->_cache->getData(); // print_r($data); if (empty($data)) { $query = new Query($this->_callChain); try { $data = $query->execute(); if (! empty($data)) { $this->_cache->populate($data[0]); } $data = $this->_cache->getData(); } catch (Exception $e) { throw $e; } } return $data; }
function deleting($table, $where) { $q = new Query(); $q->table = $table; $q->where = $where; $q->delete(); }
/** * Returns the SQL representation of the provided query after generating * the placeholders for the bound values using the provided generator * * @param \Cake\Database\Query $query The query that is being compiled * @param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions * @return \Closure */ public function compile(Query $query, ValueBinder $generator) { $sql = ''; $type = $query->type(); $query->traverse($this->_sqlCompiler($sql, $query, $generator), $this->{'_' . $type . 'Parts'}); return $sql; }
/** * Gets a Role object * * @param id the Role Id * @return the Role object */ function &get($id) { $query = new Query("Role"); $criteria = new Criteria($query, "ID", $id); $query->setCriterion($criteria); return $this->mapOne($query->execute()); }
/** * Gets a list with permissions for a folderClass object * @param $folderClassId FolderClass - the folderClass object * @return Array with permission objects */ function findByFolderClassId($folderClassId) { $query = new Query("Permission"); $criteria = new Criteria($query, "folderClassID", $folderClassId); $query->setCriterion($criteria); return $this->mapAll($query->execute()); }
/** * Gets RoleUser objects by a roleId * * @param $roleId role id looked up * @return Array - array with RoleUser objects */ function &findByRoleId($roleId) { $query = new Query("RoleUser"); $criteria = new Criteria($query, "roleID", $roleId); $query->setCriterion($criteria); return $this->mapAll($query->execute()); }
public function article($id) { $query = new Query(); $query->where(["id = {$id}"]); $post = $query->findOne('Posts'); $this->render('article.html.twig', array('post' => $post)); }
public function loadContents($method, $params = null) { switch ($method) { case 'id+countParents': //$content = $this->loadContents('id', $params); $contents = $this->loadContents('id-deep', ['id' => $params, 'depth' => 2]); $content = $contents->one(); if ($content) { // Set the relations number to content, and content is contents->get($id) //$content->get($params)->setCountParents($this->loadContents('countParents', $params)); $content->setCountParents($this->loadContents('countParents', $params)); $content->setCountAliasId($this->loadContents('count-alias-id', ['alias_id' => $content->getAliasId()])); } return $content; break; default: /* Get metainformation */ $this->loadStructure(); $persistentManager = $this->getManager(); $query = new Query(); $query->setType($method); $query->setCondition($params); $query->setLimits($this->getLimits()); return $persistentManager->load($this, $query); break; } }
public function login($login_name) { $result = array("error_code" => 0, "error_desc" => ""); $user = $this->Users->get_by_login_name($login_name); if (!$user) { $result["error_code"] = "404"; $result["error_desc"] = "Non-exist user"; echo json_encode($result); exit(0); } $ticket = $this->Mobile_tickets->get_login_ticket($user["id"]); $datas = array(); $pw_string = sha256($user["password"] . $ticket["login_ticket"]); $pw_input = $_REQUEST["confirm_key"]; if ($pw_string == $pw_input) { $session = $this->Mobile_sessions->new_session($user["id"]); $datas["session_key"] = $session["session_key"]; $datas["session_id"] = $session["id"]; } else { $result["error_code"] = "403"; $result["error_desc"] = "Key error"; echo json_encode($result); exit(0); return; } $c = new Query(); $c->where("id_users = " . $user["id"]); $this->Mobile_tickets->delete_cond($c); $result["result"] = $datas; echo json_encode($result); exit(0); }