/** * Internal function to do the multisite check on the model. * If the model supports a site attribute and none requested, then set it to the current site. */ private function _performMultisiteCheck(){ $m = $this->_model; $ref = new ReflectionClass($m); $schema = $ref->getMethod('GetSchema')->invoke(null); $index = $ref->getMethod('GetIndexes')->invoke(null); //$schema = $m::GetSchema(); //$index = $m:: // Is there a site property? If not I don't even care. if( isset($schema['site']) && $schema['site']['type'] == Model::ATT_TYPE_SITE && Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled() ){ // I want to look it up because if the script actually set the site, then // it evidently wants it for a reason. $siteexact = (sizeof($this->_dataset->getWhereClause()->findByField('site')) > 0); $idexact = false; // The primary check will allow a model to be instantiated with the exact primary key string. $pri = isset($index['primary']) ? $index['primary'] : null; if($pri && !is_array($pri)) $pri = [$pri]; if($pri){ $allids = true; foreach($pri as $k){ if(sizeof($this->_dataset->getWhereClause()->findByField($k)) == 0){ $allids = false; break; } } if($allids) $idexact = true; } if(!($siteexact || $idexact)){ $w = new \Core\Datamodel\DatasetWhereClause(); $w->setSeparator('or'); $w->addWhere('site = ' . MultiSiteHelper::GetCurrentSiteID()); $w->addWhere('site = -1'); $this->_dataset->where($w); //$this->_dataset->where('site = ' . MultiSiteHelper::GetCurrentSiteID()); } } }
public function pagemetas_autocompletekeyword(){ $request = $this->getPageRequest(); $view = $this->getView(); $view->mode = View::MODE_AJAX; $view->contenttype = View::CTYPE_JSON; $term = $request->getParameter('term'); $view->record = false; // This is an ajax-only request. if(!$request->isAjax()){ return View::ERROR_BADREQUEST; } $ds = new Core\Datamodel\Dataset(); $ds->table('page_meta'); $ds->uniquerecords = true; $ds->select('meta_value', 'meta_value_title'); $ds->where('meta_key = keyword'); $ds->where('meta_value_title LIKE ' . $term . '%'); // Just in case there are a huge number of records... $stream = new DatasetStream($ds); $view->jsondata = array(); while(($record = $stream->getRecord())){ $view->jsondata[] = array( 'id' => $record['meta_value'], 'label' => $record['meta_value_title'], 'value' => $record['meta_value'], ); } // Does the user have access to search for users? // if so include that search here to! This is for the subject matter tag, or "This x is about person y!" if(\Core\user()->checkAccess('p:/user/search/autocomplete')){ $results = UserModel::Search($term); foreach($results as $r){ /** @var $r \Core\Search\ModelResult */ /** @var UserModel $user */ $user = $r->_model; $view->jsondata[] = array( 'id' => 'u:' . $user->get('id'), 'label' => $user->getDisplayName(), 'value' => 'u:' . $user->get('id'), ); } } }
/** * Internal function to parse and handle the dataset in the <upgrade> and <install> tasks. * This is used for installations and upgrades. * * Unlike the other parse functions, this handles a single node at a time. * * @param $node DOMElement * @param $verbose bool * * @throws InstallerException */ private function _parseDatasetNode(DOMElement $node, $verbose = false){ $action = $node->getAttribute('action'); $table = $node->getAttribute('table'); $haswhere = false; $sets = array(); $renames = array(); $ds = new Core\Datamodel\Dataset(); $ds->table($table); foreach($node->getElementsByTagName('datasetset') as $el){ $sets[$el->getAttribute('key')] = $el->nodeValue; } foreach($node->getElementsByTagName('datasetrenamecolumn') as $el){ // <datasetrenamecolumn oldname="ID" newname="id"/> $renames[$el->getAttribute('oldname')] = $el->getAttribute('newname'); } foreach($node->getElementsByTagName('datasetwhere') as $el){ $haswhere = true; $ds->where(trim($el->nodeValue)); } switch($action){ case 'alter': if(sizeof($sets)) throw new InstallerException('Invalid mix of arguments on ' . $action . ' dataset request, datasetset is not supported!'); if($haswhere) throw new InstallerException('Invalid mix of arguments on ' . $action . ' dataset request, datasetwhere is not supported!'); foreach($renames as $k => $v){ // ALTER TABLE `controllers` CHANGE `ID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT $ds->renameColumn($k, $v); } break; case 'update': foreach($sets as $k => $v){ $ds->update($k, $v); } break; case 'insert': foreach($sets as $k => $v){ $ds->insert($k, $v); } break; case 'delete': if(sizeof($sets)) throw new InstallerException('Invalid mix of arguments on ' . $action . ' dataset request'); if(!$haswhere) throw new InstallerException('Cowardly refusing to delete with no where statement'); $ds->delete(); break; default: throw new InstallerException('Invalid action type, '. $action); } // and GO! if($verbose){ CLI::PrintActionStart('Executing dataset ' . $action . ' command on ' . $table); } $ds->execute(); if($ds->num_rows){ CLI::PrintActionStatus(true); return array($action . ' on table ' . $table . ' affected ' . $ds->num_rows . ' records.'); } else{ CLI::PrintActionStatus(false); return false; } }