public function execute() { $view = $this->getView(); $fac = new ModelFactory('PageModel'); $fac->where('baseurl LIKE /blog/view/%'); $fac->where('published_status = published'); $fac->where('published <= ' . \Core\Date\DateTime::NowGMT()); $fac->limit($this->getSetting('count')); switch ($this->getSetting('sort')) { case 'newest': $fac->order('published DESC'); break; case 'popular': $fac->order('popularity DESC'); break; case 'random': $fac->order('RAND()'); break; } if (!$fac->count()) { // If there are no results found, then do not display the widget. return ''; } $view->assign('sort', $this->getSetting('sort')); $view->assign('title', $this->getSetting('title')); $view->assign('links', $fac->get()); }
/** * @dataProvider modelServiceIdProvider * @covers \Graviton\SecurityBundle\User\Model\ModelFactory::__construct * @covers \Graviton\SecurityBundle\User\Model\ModelFactory::create * * @param string $serviceId service id * @param string[] $expectedService resulting class * * @return void */ public function testCreate($serviceId, $expectedService) { $containerMock = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->disableOriginalConstructor()->setMethods(array('getParameter', 'has', 'get'))->getMockForAbstractClass(); $containerMock->expects($this->once())->method('getParameter')->with($this->equalTo('graviton.security.authentication.provider.model'))->will($this->returnValue($serviceId)); $containerMock->expects($this->atLeastOnce())->method('get')->will($this->onConsecutiveCalls($this->returnValue(new \Graviton\SecurityBundle\User\Model\NullModel()), $this->returnValue(new \Graviton\SecurityBundle\User\Model\NullModel()))); $containerMock->expects($this->any())->method('has')->with($this->equalTo($serviceId))->will($this->returnValue(true)); $factory = new ModelFactory($containerMock); $service = $factory->create(); $this->assertInstanceOf('\\Graviton\\RestBundle\\Model\\ModelInterface', $service); $this->assertEquals($expectedService, get_class($service)); }
public function execute() { $view = $this->getView(); $fac = new ModelFactory('PageModel'); if ($this->getSetting('blog')) { $fac->where('parenturl = /blog/view/' . $this->getSetting('blog')); } $fac->where('parenturl LIKE /blog/view/%'); $fac->where('published_status = published'); $fac->where('published <= ' . \Core\Date\DateTime::NowGMT()); $fac->limit($this->getSetting('count')); switch ($this->getSetting('sort')) { case 'newest': $fac->order('published DESC'); break; case 'popular': $fac->order('popularity DESC'); break; case 'random': $fac->order('RAND()'); break; } if (!$fac->count()) { // If there are no results found, then do not display the widget. return ''; } $view->assign('count', $this->getSetting('count')); $view->assign('sort', $this->getSetting('sort')); $view->assign('title', $this->getSetting('title')); // The template is expecting an array, if count is 1, only a single Model is returned from the factory. $view->assign('links', $this->getSetting('count') == 1 ? [$fac->get()] : $fac->get()); }
public function edit() { if (!isset($this->request->params['passed']['id'])) { return $this->redirect(ROOT . '/blogs/index'); } $id = $this->request->params['passed']['id']; $entry = ModelFactory::createModel('Entry'); if (isset($this->request->params['passed']['title']) && isset($this->request->params['passed']['content']) && isset($this->request->params['passed']['category'])) { $title = $this->request->params['passed']['title']; $content = $this->request->params['passed']['content']; $category = $this->request->params['passed']['category']; $entry = $entry->constructEntryByID($id); $entry->setTitle($title); $entry->setContent(nl2br($this->h($content))); $entry->setCatById($category); if ($entry->update()) { return $this->redirect(ROOT . '/entry/show?id=' . $id); } return $this->redirect(ROOT . '/blogs/index?flash=Could not edit entry&title=Fail while editing entry'); } else { $cat = ModelFactory::createModel('Category'); $c = $cat->getAll(); $e = $entry->constructEntryByID($id); $this->view->assign('entry', $e); $this->view->assign('categories', $c); } }
/** * Set Metadata * * @return void */ protected function setMetadata() { $metadata = $this->getDataProperty('metadata'); if (is_array($metadata)) { $this->metadata = ModelFactory::make($metadata); } }
function testLoadFromStringN3() { $mem =& ModelFactory::getDefaultModel(); $n3String = '<http://example.com/res1> <http://example.com/label> "ttt" .'; $mem->loadFromString($n3String, 'n3'); $this->assertTrue($mem->contains(new Statement(new Resource('http://example.com/res1'), new Resource('http://example.com/label'), new Literal('ttt')))); }
public function profile() { $profile['user_id'] = $this->me['id']; $avatar = $this->input->post("avatar_url"); $fav_tag = $this->input->post("fav_tag"); $profile['type'] = $this->input->post("type"); $profile['company'] = $this->input->post("company"); $profile['station'] = $this->input->post("station"); $profile['school'] = $this->input->post("school"); $profile['professional'] = $this->input->post("professional"); if ($avatar) { ModelFactory::User()->edit($this->me['id'], ['avatar' => $avatar]); } $tags = explode(' ', $fav_tag); foreach ($tags as $tag) { $trim = trim($tag); if ($trim) { $tag = ModelFactory::Tag()->get_tag_withtype($tag); if (!$tag && $trim) { ModelFactory::Tag()->add_tag($tag); $tag = ModelFactory::Tag()->get_tag_withtype($tag); } $is_col = ModelFactory::Tag()->is_collect_tag($tag['id']); if (!$is_col) { ModelFactory::Tag()->collect_tag($tag['id']); } } } if (!($pro = ModelFactory::UserProfile()->getbyuserid($this->me['id']))) { ModelFactory::UserProfile()->create($profile); } else { ModelFactory::UserProfile()->edit($pro['id'], $profile); } header("location: /home?home=index&uid=" . $this->me['id']); }
/** * Constructor * */ public function __construct($dataObject = null) { $this->logger = new Logger(get_class($this)); //Los models if (isset($this->defaultUses)) { foreach ($this->defaultUses as $model) { $varName = $model; $varName[0] = strtolower($varName[0]); $this->{$varName} = ModelFactory::getModel($model); } } if (isset($this->uses)) { foreach ($this->uses as $model) { $varName = $model; $varName[0] = strtolower($varName[0]); $this->{$varName} = ModelFactory::getModel($model); } } if ($dataObject == null) { $dataObject = str_replace('Model', "", get_class($this)); $this->dataObject = $dataObject; } else { if ($dataObject != "") { $this->dataObject = $dataObject; } } }
public function getListView(&$criteria, $return = false) { $dp = new EActiveDataProvider(get_class($this->model), array( 'criteria' => $criteria, //'pagination' => $this->settings['pagination'], )); //default params $params = array( 'dataProvider'=>$dp, 'pager'=>array( 'id'=>$this->widgetModel->pk.'Pager', 'class'=>'LinkPager', 'htmlOptions'=>array('class'=>'pager'), 'cssFile'=>Yii::app()->baseUrl.'/css/pager.css' ), 'ajaxUpdate'=>true, 'template'=>$this->render('listTemplate', array(), true), 'afterAjaxUpdate' => ModelFactory::getAfterAjaxUpdateFunction($this->category->type), 'beforeAjaxUpdate' => ModelFactory::getBeforeAjaxUpdateFunction($this->category->type), 'category' => $this->category, 'contextWidget' => $this ); try { $res = Y::controller()->widget('ListView', $params, true); } catch (CException $e) { Y::dump($e->__toString()); } if ($return) return $res; else echo $res; }
function replace_task_id($user_id, $task_id, $params) { $do_task = ModelFactory::Usertask()->get(['user_id' => $user_id, 'task_id' => $task_id]); $params['user_id'] = $user_id; $params['task_id'] = $task_id; return $this->replace(isset($do_task) ? $do_task['id'] : 0, $params); }
/** * Page to display and manage all gallery widgets. */ public function admin() { $view = $this->getView(); $request = $this->getPageRequest(); if (!\Core\user()->checkAccess('p:/gallery/manage_all')) { return View::ERROR_ACCESSDENIED; } $factory = new ModelFactory('WidgetModel'); $factory->where('baseurl LIKE /gallery/view/%'); $factory->order('title'); $widgets = $factory->get(); $view->title = 'Gallery Widgets'; $view->assign('can_manage_theme', \Core\user()->checkAccess('g:admin')); $view->assign('widgets', $widgets); $view->addControl('Create Gallery Widget', '/gallerywidget/update', 'add'); }
function testGetOntModelIsBasedOnThisModel() { $mem =& ModelFactory::getDefaultModel(); $ont = $mem->getOntModel(RDFS_VOCABULARY); $this->assertIdentical(0, $ont->size()); $mem->add(new Statement(new Resource('http://example.org/#Fred'), new Resource('http://example.org/#name'), new Literal('Fred'))); $this->assertIdentical(1, $ont->size()); }
function test_present(&$db) { $now = time(); $present = ModelFactory::Present($db); $now = time(); $data = array('user_id' => 1, 'donor_id' => 2, 'message' => 'wahaha', 'item_id' => 3, 'done' => 0, 'created_at' => date(TM_FORMAT, $now)); $present->insert($data); }
/** * 拜访 * @param $params * @return unknown_type */ public function visit($params) { //todo: $uid = $params['u']; $fid = $params['f']; $item = ModelFactory::UserFriend(); $item->put_super($params['item'], $uid); }
public function index(){ $view = $this->getView(); $permissionmanager = \Core\user()->checkAccess('p:/user/permissions/manage'); $factory = new ModelFactory('UserGroupModel'); if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){ if(MultiSiteHelper::GetCurrentSiteID()){ // Child site, only display global and site-specific sites. $w = new \Core\Datamodel\DatasetWhereClause(); $w->setSeparator('or'); $w->addWhere('site = ' . MultiSiteHelper::GetCurrentSiteID()); $w->addWhere('site = -1'); $factory->where($w); $displayglobal = true; $multisite = false; } else { // Root site, display all groups across all sites. $factory->where('site != -2'); $displayglobal = false; $multisite = true; } $site = MultiSiteHelper::GetCurrentSiteID(); } else{ $displayglobal = false; $multisite = false; $site = null; } $factory->order('name'); $groups = $factory->get(); $view->title = 'User Group Administration'; $view->assign('groups', $groups); $view->assign('permissionmanager', $permissionmanager); $view->assign('display_global', $displayglobal); $view->assign('site', $site); $view->assign('multisite', $multisite); $view->addControl('Add Group', '/usergroupadmin/create', 'add'); }
/** * 结算收入 * * @param $params * require u -- uid * @return * s -- ok */ public function checkout($params) { $uid = $params['u']; $db = ServerConfig::getdb_by_userid($uid); $ug = ModelFactory::UserGood(); $ua = ModelFactory::UserAccount($db); $ret['s'] = 'ok'; return $ret; }
/** * 卖出 * @param $params * require u -- user id * require d -- item ids * * @return * s -- OK ,or other fail */ public function sale($params) { //todo:添加购买验证逻辑 $uid = $params['u']; $item = ModelFactory::UserItem(); $item->put_super($params['d'], $uid); $ret['s'] = 'ok'; return $ret; }
function rdf2php($doc) { // Prepare RDF #$rdfInput = $data; // Show the submitted RDF // Create a new MemModel $model = ModelFactory::getDefaultModel(); $model->load($doc); return $model; }
function testMemUnequal() { foreach ($_SESSION['NegativeModelEqualstests'] as $name) { $_SESSION['test'] = 'testfileNegative' . $name . ' test'; $model1 = ModelFactory::getMemModel(); $model2 = ModelFactory::getMemModel(); $model1->load(MODEL_TESTFILES . 'data/testfileNegative' . $name . '_1.nt'); $model2->load(MODEL_TESTFILES . 'data/testfileNegative' . $name . '_2.nt'); $this->assertFalse($model1->equals($model2)); } }
public function add() { if (!isset($this->request->params['passed']['name'])) { return $this->redirect(ROOT . '/blogs/index'); } $name = $this->h($this->request->params['passed']['name']); $blog = ModelFactory::createModel('Blog'); $blog->setName($name); $blog->setUserById($this->request->session['user_id']); $blog->create(); return $this->redirect(ROOT . '/blogs/index'); }
function getResFromDbpedia($label, $language = "en") { $c = ModelFactory::getSparqlClient("http://dbpedia.org/sparql"); $q = new ClientQuery(); $qs = "SELECT ?x, ?comment\r\n WHERE { ?x rdfs:comment ?comment .\r\n FILTER (lang(?comment) = '{$language}')\r\n ?x rdfs:label '{$label}'@{$language}\r\n }"; $q->query($qs); $r = $c->query($q); $res = array(); foreach ($r as $i) { $res[$i['?x']->getLabel()] = $i['?comment']->getLabel(); } return $res; }
/** * Sends a query over the RAP API * * @param String @query Query to be send * @return Array @result RAP Result set * */ function doQueryRAP($query) { $GLOBALS['dbConf']['type'] = 'MySQL'; $GLOBALS['dbConf']['host'] = $this->options["host"]; $GLOBALS['dbConf']['database'] = $this->options["db"]; $GLOBALS['dbConf']['user'] = $this->options["user"]; $GLOBALS['dbConf']['password'] = $this->options["pass"]; $database = ModelFactory::getDbStore($GLOBALS['dbConf']['type'], $GLOBALS['dbConf']['host'], $GLOBALS['dbConf']['database'], $GLOBALS['dbConf']['user'], $GLOBALS['dbConf']['password']); $dbModel = $database->getModel($this->options["model"]); $result = $dbModel->sparqlQuery($query); #var_dump($result); return $result; }
/** * The hook catch for the "/core/admin/view" hook. */ public static function AdminHook() { // If this user doesn't have access to manage crons, just continue. if (!\Core\user()->checkAccess('p:/cron/viewlog')) { return; } $suffixtext = 'This could be a problem if you have scripts relying on it! <a href="' . \Core\resolve_link('/cron/howto') . '">Read how to resolve this issue</a>.'; // Lookup and make sure that the cron hooks have ran recently enough! $checks = [['cron' => 'hourly', 'modify' => '-1 hour', 'label' => 'hour'], ['cron' => 'daily', 'modify' => '-1 day', 'label' => 'day'], ['cron' => 'weekly', 'modify' => '-1 week', 'label' => 'week'], ['cron' => 'monthly', 'modify' => '-1 month', 'label' => 'month']]; foreach ($checks as $check) { $time = new CoreDateTime(); $cronfac = new ModelFactory('CronLogModel'); $cronfac->where('cron = ' . $check['cron']); $time->modify($check['modify']); $cronfac->where('created >= ' . $time->getFormatted('U', Time::TIMEZONE_GMT)); $count = $cronfac->count(); if ($count == 0) { \Core\set_message('Your ' . $check['cron'] . ' cron has not run in the last ' . $check['label'] . '! ' . $suffixtext, 'error'); // Only complain to the admin once per view. return; } } }
function testOntmodel_Tests() { $_SESSION['test'] = 'Ont Model test'; $res = ModelFactory::getOntModel(INFMODELB, RDFS_VOCABULARY, 'http://www.example.orgURI'); $ontClass1 = $res->createOntClass('class1'); $literal1 = $res->createLiteral('ein Label', 'de'); $literal2 = $res->createLiteral('a comment', 'en'); $resource1 = $res->createResource('http:\\www.example.orgDefinedBy'); $resource2 = $res->createResource('http:\\www.example.orgRDFType'); $resource3 = $res->createResource('http:\\www.example.orgSeeAlso'); $instance1 = $ontClass1->createInstance('testInstance'); $instance1->addLabelProperty($literal1); $instance1->addComment($literal2); $instance1->addIsDefinedBy($resource1); $instance1->addRDFType($resource2); $instance1->addSeeAlso($resource3); $this->assertEqual($instance1->getLabelProperty(), $literal1); $this->assertEqual($instance1->getComment(), $literal2); $this->assertEqual($instance1->getIsDefinedBy(), $resource1); $list = $instance1->listRDFTypes(); $this->assertEqual(2, count($list)); $this->assertEqual($instance1->getSeeAlso(), $resource3); $ontClass2 = $res->createOntClass('class2'); $ontClass1->addSubClass($ontClass2); $this->assertEqual($res->size(), 8); $instance2 = $ontClass2->createInstance('testInstance2'); $literal3 = new ResLiteral('other comment'); $instance2->addComment($literal3); $this->assertEqual($res->size(), 11); $ontClass3 = $res->createOntClass('class3'); $ontClass1->addSuperClass($ontClass3); $this->assertEqual($res->size(), 15); $this->assertEqual(count($instance1->listRDFTypes()), 3); $this->assertEqual(count($instance2->listRDFTypes()), 3); $instance1->removeRDFType($resource2); $this->assertEqual(count($instance1->listRDFTypes()), 2); $this->assertEqual(count($instance2->listRDFTypes()), 3); $individual1 = $res->createIndividual('http:\\individual1'); $individual1->addLabelProperty($literal1); $this->assertEqual($res->size(), 15); $instance3 = $ontClass2->createInstance('instance3'); $instance3->addLabelProperty($literal1); $this->assertEqual(19, $res->size()); $iter = $ontClass2->listInstances(); $i = 0; for ($iter->rewind(); $iter->valid(); $iter->next()) { $i++; } $this->assertEqual(2, $i); }
/** * The view for the admin dashboard. Gets the last executed crons and displays that to the admin. */ public function dashboard() { // This dashboard has no effect if the user can't view crons. if (!\Core\user()->checkAccess('p:/cron/viewlog')) { return ''; } $view = $this->getView(); // Get the latest cron and its execution information and display that to the dashboard. $checks = [['cron' => 'hourly', 'modify' => '-1 hour', 'label' => 'hour'], ['cron' => 'daily', 'modify' => '-1 day', 'label' => 'day'], ['cron' => 'weekly', 'modify' => '-1 week', 'label' => 'week'], ['cron' => 'monthly', 'modify' => '-1 month', 'label' => 'month']]; $crons = array(); foreach ($checks as $k => $check) { $time = new CoreDateTime(); $cronfac = new ModelFactory('CronLogModel'); $cronfac->limit(1); $cronfac->where('cron = ' . $check['cron']); $cronfac->order('created desc'); $c = $cronfac->get(); if ($c) { $crons[] = $c; } } $view->title = 't:STRING_LATEST_CRON_RESULTS'; $view->assign('crons', $crons); }
public function accept($extractionResult) { $model1 = ModelFactory::getDefaultModel("http://dbpedia.org/"); // RAP model $count = 0; foreach (new ArrayObject($extractionResult->getTriples()) as $triple) { $count++; $tripleString = explode(">", $triple->toString()); $s = str_replace("<", "", $tripleString[0]); $p = str_replace("<", "", $tripleString[1]); // $s = preg_replace("/<|>/","",$triple->getSubject()); // $p = preg_replace("/<|>/","",$triple->getPredicate()); $o = $tripleString[2]; $subject = new Resource($s); $predicate = new Resource($p); if (strpos($o, "<")) { // echo "<br>" . $s. $p . $p; if (!strpos($o, "^^")) { // echo " a"; $o = str_replace("<", "", $o); $object = new Resource($o); } else { // echo " b"; $pos = strpos($o, "^^"); $literal = substr($o, 0, $pos); $object = new Literal($literal); $object->setDatatype(substr($o, $pos + 3, strlen($o) - $pos - 3)); } } else { // $lang = "en"; if (preg_match("/(.*)(@)([a-zA-Z]+) \\.\$/", $o, $match)) { $o = $match[1]; $lang = $match[3]; $object = new Literal($o, $lang); } else { $object = new Literal($o); } } $statement = new Statement($subject, $predicate, $object); $model1->add($statement); } if ($count > 0) { echo "<br><br><h3>" . $extractionResult->getExtractorID() . "</h3>"; echo $model1->writeAsHtmlTable(); } }
public function add() { $user = ModelFactory::createModel('User'); $name = $this->request->params['passed']['username']; $email = $this->request->params['passed']['email']; $pw = $this->request->params['passed']['password']; $pwconfirm = $this->request->params['passed']['password_confirmed']; if (!empty($name) && Validator::validateEmail($email) && $user->isUniqueEmail($email) && !Validator::validatePW($pw) && Validator::confirmPW($pw, $pwconfirm)) { $user->setNickname($name); $user->setEmail($email); $user->setPassword($pw); $user->create(); $_SESSION['user_id'] = $user->getId(); $_SESSION['nickname'] = $user->getNickname(); return $this->redirect(ROOT . '/blogs/index'); } return $this->redirect(ROOT . '/login/index?flash=Please adjust the wrong input fields&title=Registration failed'); }
public function index() { $userdata = $this->user_model->check_login(); // 课程处理通用Tab $userdata['type_name'] = $this->input->get('type'); if (isset($_GET['type'])) { switch ($userdata['type_name']) { case 'u3d': $type = 0; break; case 'Egret': $type = 1; break; case 'Web': $type = 2; break; case 'Cocos2d-x': $type = 3; break; case 'Android': $type = 4; break; default: $type = 0; $userdata['type_name'] = "u3d"; break; } $userdata['types'] = $type; } else { $userdata['types'] = 0; $userdata['type_name'] = "u3d"; } // 分页通用 $userdata["page"] = !isset($_GET['page']) ? "1" : $this->input->get("page"); $userdata['page_max'] = $this->user_model->get_count(array("type" => 1, "father_tag" => $userdata['types'])); $userdata['data'] = (array) $this->user_model->get_god_list(array("type" => 1, "father_tag" => $userdata['types']), $userdata["page"] - 1, 10); foreach ($userdata['data'] as $key => $god) { $level_id = ModelFactory::User()->get_god_level(0, $god); $level_name = ModelFactory::User()->get_god_level_name($level_id); $god['level_name'] = $level_name; $userdata['data'][$key] = $god; } $this->load->view('miaoda/god/list.php', $userdata); }
public function init() { parent::init(); //attach events from $this->eventMap foreach ($this->handlers() as $event=>$handler) $this->addHandler($event, $handler); //dataTypes register ModelFactory::registerDataTypes($this->dataTypes()); //register widets Y::resources()->registerWidgets($this->widgets()); //set assets path if (is_dir($path = Yii::getPathOfAlias($this->getId().'.assets'))) { $this->scriptPath = Yii::app()->getAssetManager()->publish($path); } }
public function show() { if (empty($this->request->params['passed']['id'])) { return $this->redirect(ROOT . '/blogs/index'); } if (isset($this->request->params['passed']['flash']) && isset($this->request->params['passed']['title'])) { $this->view->assign('flash', urldecode($this->request->params['passed']['flash'])); $this->view->assign('title', urldecode($this->request->params['passed']['title'])); } $bid = $this->request->params['passed']['id']; $blog = ModelFactory::createModel('Blog'); $entries = ModelFactory::createModel('Entry'); $categories = ModelFactory::createModel('Category'); $b = $blog->constructBlogByID($bid); $e = $entries->getByBlog($b); $c = $categories->getAll(); $this->view->assign('categories', $c); $this->view->assign('blog', $b); $this->view->assign('entries', $e); }