/** * Creates a new tag * * @throws SwatException if no database connection is set on this tag * entry control. */ protected function insertTag($title, $index) { if ($this->app === null) { throw new SwatException('An application must be set on the tag entry control during ' . 'the widget init phase.'); } // check to see if the tag already exists $instance_id = $this->app->getInstanceId(); $sql = sprintf('select * from PinholeTag where lower(title) = lower(%s) and instance %s %s', $this->app->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $tags = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholeTagDataObjectWrapper')); // only insert if no tag already exists (prevents creating two tags on // reloading) if (count($tags) > 0) { $tag_obj = $tags->getFirst(); } else { $tag_obj = new PinholeTagDataObject(); $tag_obj->setDatabase($this->app->db); $tag_obj->instance = $instance_id; $tag_obj->title = $title; $tag_obj->save(); $message = new SwatMessage(sprintf(Pinhole::_('ā%sā tag has been added'), SwatString::minimizeEntities($tag_obj->title))); $message->content_type = 'text/xml'; $message->secondary_content = sprintf(Pinhole::_('You can <a href="Tag/Edit?id=%d">edit this tag</a> ' . 'to customize it.'), $tag_obj->id); $this->app->messages->add($message); } $this->tag_array[$tag_obj->name] = $tag_obj->title; $this->selected_tag_array[$tag_obj->name] = $tag_obj->title; }
protected function getComments($limit = null, $offset = null) { $sql = sprintf('select BlorgComment.* from BlorgComment left outer join BlorgAuthor on BlorgComment.author = BlorgAuthor.id where %s order by createdate desc', $this->getWhereClause()); $this->app->db->setLimit($limit, $offset); $wrapper = SwatDBClassMap::get('BlorgCommentWrapper'); $comments = SwatDB::query($this->app->db, $sql, $wrapper); // efficiently load posts for all comments $instance_id = $this->app->getInstanceId(); $post_sql = sprintf('select id, title, bodytext from BlorgPost where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper'); $comments->loadAllSubDataObjects('post', $this->app->db, $post_sql, $post_wrapper); // efficiently load authors for all comments $instance_id = $this->app->getInstanceId(); $author_sql = sprintf('select id, name from BlorgAuthor where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $author_wrapper = SwatDBClassMap::get('BlorgAuthorWrapper'); $comments->loadAllSubDataObjects('author', $this->app->db, $author_sql, $author_wrapper); return $comments; }
protected function getComments($limit = null, $offset = null) { $sql = sprintf('select PinholeComment.* from PinholeComment left outer join PinholePhotographer on PinholeComment.photographer = PinholePhotographer.id where %s order by createdate desc', $this->getWhereClause()); $this->app->db->setLimit($limit, $offset); $wrapper = SwatDBClassMap::get('PinholeCommentWrapper'); $comments = SwatDB::query($this->app->db, $sql, $wrapper); // efficiently load photos for all comments $instance_id = $this->app->getInstanceId(); $photo_sql = sprintf('select PinholePhoto.* from PinholePhoto inner join ImageSet on ImageSet.id = PinholePhoto.image_set where ImageSet.instance %s %s and PinholePhoto.id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $photo_wrapper = SwatDBClassMap::get('PinholePhotoWrapper'); $comments->loadAllSubDataObjects('photo', $this->app->db, $photo_sql, $photo_wrapper); // efficiently load photographers for all comments $instance_id = $this->app->getInstanceId(); $photographer_sql = sprintf('select id, fullname from PinholePhotographer where instance %s %s and id in (%%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $photographer_wrapper = SwatDBClassMap::get('PinholePhotographerWrapper'); $comments->loadAllSubDataObjects('photographer', $this->app->db, $photographer_sql, $photographer_wrapper); return $comments; }
public function loadProviders($read_only = true) { $providers_wrapper_class = SwatDBClassMap::get('CMEProviderWrapper'); $providers_wrapper = new $providers_wrapper_class(); $providers_wrapper->setOptions('read_only', $read_only); $providers = SwatDB::query($this->db, 'select * from CMEProvider', $providers_wrapper); $sql = sprintf('select CMEFrontMatterProviderBinding.front_matter, CMEFrontMatterProviderBinding.provider from CMEFrontMatterProviderBinding inner join CMEProvider on CMEProvider.id = CMEFrontMatterProviderBinding.provider where CMEFrontMatterProviderBinding.front_matter in (%s) order by CMEFrontMatterProviderBinding.front_matter, CMEProvider.displayorder, CMEProvider.id', $this->db->implodeArray($this->getIndexes(), 'integer')); $rows = SwatDB::query($this->db, $sql); $front_matter_id = null; foreach ($rows as $row) { if ($row->front_matter !== $front_matter_id) { $front_matter_id = $row->front_matter; $front_matter = $this->getByIndex($row->front_matter); $front_matter->providers = new $providers_wrapper_class(); $front_matter->providers->setOptions('read_only', $read_only); } $provider = $providers->getByIndex($row->provider); $front_matter->providers->add($provider); } return $providers; }
protected function getSegments() { $sql = 'select * from MailingListCampaignSegment where %s and instance %s %s'; $sql = sprintf($sql, $this->force_all ? '1 = 1' : sprintf('enabled = %s', $this->db->quote(true, 'boolean')), SwatDB::equalityOperator($this->getInstanceId()), $this->db->quote($this->getInstanceId(), 'integer')); return SwatDB::query($this->db, $sql, SwatDBClassMap::get('DeliveranceCampaignSegmentWrapper')); }
protected function buildInternal() { parent::buildInternal(); $locale = SwatI18NLocale::get(); $item_list = $this->getItemList('integer'); $dep = new AdminListDependency(); $dep->setTitle(CME::_('CME front matter'), CME::_('CME front matters')); $sql = sprintf('select CMEFrontMatter.id, sum(CMECredit.hours) as hours from CMEFrontMatter left outer join CMECredit on CMECredit.front_matter = CMEFrontMatter.id where CMEFrontMatter.id in (%s) group by CMEFrontMatter.id', $item_list); $rs = SwatDB::query($this->app->db, $sql); $class_name = SwatDBClassMap::get('CMEFrontMatter'); foreach ($rs as $row) { $front_matter = new $class_name($row); $front_matter->setDatabase($this->app->db); $row->status_level = AdminDependency::DELETE; $row->parent = null; // not using ngettext because hours is a float $row->title = sprintf($row->hours == 1 ? CME::_('%s (1 hour)') : CME::_('%s (%s hours)'), $front_matter->getProviderTitleList(), $locale->formatNumber($row->hours)); $dep->entries[] = new AdminDependencyEntry($row); } $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) { $this->switchToCancelButton(); } }
/** * Creates a new tag * * @throws SwatException if no database connection is set on this tag * entry control. */ protected function insertTag($title, $index) { if ($this->app === null) { throw new SwatException('An application must be set on the tag entry control during ' . 'the widget init phase.'); } // check to see if the tag already exists $instance_id = $this->app->getInstanceId(); $sql = sprintf('select * from BlorgTag where lower(title) = lower(%s) and instance %s %s', $this->app->db->quote($title, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $tags = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgTagWrapper')); // only insert if no tag already exists (prevents creating two tags on // reloading) if (count($tags) > 0) { $tag = $tags->getFirst(); } else { $tag = new BlorgTag(); $tag->setDatabase($this->app->db); $tag->instance = $instance_id; $tag->title = $title; $tag->save(); if (isset($this->app->memcache)) { $this->app->memcache->flushNs('tags'); } $message = new SwatMessage(sprintf(Blorg::_('The tag ā%sā has been added.'), $tag->title)); $this->app->messages->add($message); } $this->tag_array[$tag->shortname] = $tag->title; $this->selected_tag_array[$tag->shortname] = $tag->title; }
/** * Gets earned CME credits to include in the quarterly report * * Credits are included if and only if: * * - the credit is earned * - the provider is the specified provider * - the earned date is within the quarter * - the account is not deleted * * @return array */ protected function getEarnedCredits() { $sql = sprintf('select AccountEarnedCMECredit.* from AccountEarnedCMECredit inner join Account on AccountEarnedCMECredit.account = Account.id inner join CMECredit on AccountEarnedCMECredit.credit = CMECredit.id inner join CMEFrontMatter on CMECredit.front_matter = CMEFrontMatter.id where CMEFrontMatter.id in ( select CMEFrontMatterProviderBinding.front_matter from CMEFrontMatterProviderBinding where CMEFrontMatterProviderBinding.provider = %s ) and convertTZ(earned_date, %s) >= %s and convertTZ(earned_date, %s) < %s and Account.delete_date is null', $this->app->db->quote($this->provider->id, 'integer'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->start_date->getDate(), 'date'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->end_date->getDate(), 'date')); $earned_credits = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper')); // efficiently load accounts $accounts = $this->loadAccounts($earned_credits); // load addresses $addresses = $this->loadAccountAddresses($accounts); // efficiently load credits $credits = $this->loadCredits($earned_credits); // sort earned credits (sorting is application specific) $earned_credits_array = $earned_credits->getArray(); usort($earned_credits_array, array($this, 'compareEarnedCredit')); return $earned_credits_array; }
protected function initSideBar() { $this->sidebar = new SiteSidebar(); $gadget_instances = false; if (isset($this->app->memcache)) { $gadget_instances = $this->app->memcache->get('gadget_instances'); } if ($gadget_instances === false) { $sql = sprintf('select * from GadgetInstance where instance %s %s order by displayorder', SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer')); $gadget_instances = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('SiteGadgetInstanceWrapper')); $gadget_instances->loadAllSubRecordsets('setting_values', SwatDBClassMap::get('SiteGadgetInstanceSettingValueWrapper'), 'GadgetInstanceSettingValue', 'gadget_instance'); if (isset($this->app->memcache)) { $this->app->memcache->set('gadget_instances', $gadget_instances); } } else { $gadget_instances->setDatabase($this->app->db); } foreach ($gadget_instances as $gadget_instance) { $gadget = SiteGadgetFactory::get($this->app, $gadget_instance); $this->sidebar->add($gadget); } $this->sidebar->init(); }
protected function buildInternal() { parent::buildInternal(); $item_list = $this->getItemList('integer'); $instance_id = $this->app->getInstanceId(); $dep = new AdminListDependency(); $dep->setTitle(Blorg::_('post'), Blorg::_('posts')); $sql = sprintf('select id, title, bodytext from BlorgPost where instance %s %s and id in (%s) order by publish_date desc, title', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list); $posts = SwatDB::query($this->app->db, $sql, 'BlorgPostWrapper'); $entries = array(); foreach ($posts as $post) { $entry = new AdminDependencyEntry(); $entry->id = $post->id; $entry->title = $post->getTitle(); $entry->status_level = AdminDependency::DELETE; $entry->parent = null; $entries[] = $entry; } $dep->entries = $entries; $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) == 0) { $this->switchToCancelButton(); } }
protected function buildInternal() { parent::buildInternal(); $locale = SwatI18NLocale::get(); $item_list = $this->getItemList('integer'); $dep = new AdminListDependency(); $dep->setTitle(CME::_('CME credit'), CME::_('CME credits')); $sql = sprintf('select CMECredit.* from CMECredit where CMECredit.id in (%s)', $item_list); $credits = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMECreditWrapper')); foreach ($credits as $credit) { $data = new stdClass(); $data->id = $credit->id; $data->status_level = AdminDependency::DELETE; $data->parent = null; $data->title = $credit->getTitle(); $dep->entries[] = new AdminDependencyEntry($data); } $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) { $this->switchToCancelButton(); } }
protected function getPhoto($filename) { $sql = sprintf('select PinholePhoto.* from PinholePhoto inner join ImageSet on PinholePhoto.image_set = ImageSet.id where PinholePhoto.filename = %s and ImageSet.instance %s %s', $this->app->db->quote($filename, 'text'), SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer')); $wrapper_class = SwatDBClassMap::get('PinholePhotoWrapper'); $photos = SwatDB::query($this->app->db, $sql, $wrapper_class); if (count($photos) == 0) { $instance = $this->app->getInstance(); if ($instance === null) { $message = sprintf("Photo with filename '%s' does not exist.", $filename); } else { $message = sprintf("Photo with filename '%s' does not exist " . "in the instance '%s'.", $filename, $instance->shortname); } throw new SiteNotFoundException($message); } $photo = $photos->getFirst(); if ($photo->private && !$this->app->session->isLoggedIn()) { $message = sprintf("Photo with filename '%s' is private and user " . "is not logged in.", $filename); throw new SiteNotFoundException($message); } $photo->setFileBase('../photos'); return $photo; }
/** * Gets the metadata for display * * @return SwatTableModel with metadata information. */ protected function getTableModel(SwatView $view) { $sql = 'select * from PinholeMetaData where PinholeMetaData.instance %s %s order by %s'; $instance_id = $this->app->getInstanceId(); $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->getOrderByClause($view, 'visible desc, displayorder, title')); $metadata = SwatDB::query($this->app->db, $sql); $store = new SwatTableStore(); foreach ($metadata as $data) { $ds = new SwatDetailsView(); $ds->title = $data->title; $ds->shortname = $data->shortname; $ds->id = $data->id; $ds->visible = $data->visible; $ds->machine_tag = $data->machine_tag; if ($ds->visible) { $ds->group_title = 'Shown'; } else { $ds->group_title = 'Not Shown'; } $store->add($ds); } return $store; }
protected function initReport() { $quarter = SiteApplication::initVar('quarter', null, SiteApplication::VAR_GET); if ($quarter === null || preg_match('/^2[0-9]{3}-0[1-4]$/', $quarter) === 0) { throw new AdminNotFoundException('Invalid quarter.'); } list($year, $quarter) = explode('-', $quarter, 2); $start_month = (intval($quarter) - 1) * 3 + 1; $quarter = new SwatDate(); $quarter->setTime(0, 0, 0); $quarter->setDate($year, $start_month, 1); $quarter->setTZ($this->app->default_time_zone); $quarter->toUTC(); $type = SiteApplication::initVar('type', null, SiteApplication::VAR_GET); $provider = new CMEProvider(); $provider->setDatabase($this->app->db); if (!$provider->loadByShortname($type)) { throw new AdminNotFoundException('Invalid CME provider.'); } $sql = sprintf('select * from QuizReport where quarter = %s and provider = %s', $this->app->db->quote($quarter->getDate(), 'date'), $this->app->db->quote($provider->id, 'integer')); $this->report = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEQuizReportWrapper'))->getFirst(); if (!$this->report instanceof CMEQuizReport) { throw new AdminNotFoundException(sprintf('Report not found for quarter %s.', $quarter->getDate())); } $this->report->setFileBase('../../system/quiz-report-updater'); if (!file_exists($this->report->getFilePath())) { throw new AdminNotFoundException(sprintf('Report file ā%sā not found', $this->report->getFilePath())); } }
/** * Loads this comment * * @param integer $id the database id of this comment. * @param SiteInstance $instance optional. The instance to load the comment * in. If the application does not use * instances, this should be null. If * unspecified, the instance is not checked. * * @return boolean true if this comment and false if it was not. */ public function load($id, SiteInstance $instance = null) { $this->checkDB(); $loaded = false; $row = null; if ($this->table !== null && $this->id_field !== null) { $id_field = new SwatDBField($this->id_field, 'integer'); $sql = sprintf('select %1$s.* from %1$s inner join PinholePhoto on %1$s.photo = PinholePhoto.id inner join ImageSet on ImageSet.id = PinholePhoto.image_set where %1$s.%2$s = %3$s', $this->table, $id_field->name, $this->db->quote($id, $id_field->type)); $instance_id = $instance === null ? null : $instance->id; if ($instance_id !== null) { $sql .= sprintf(' and ImageSet.instance %s %s', SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer')); } $rs = SwatDB::query($this->db, $sql, null); $row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC); } if ($row !== null) { $this->initFromRow($row); $this->generatePropertyHashes(); $loaded = true; } return $loaded; }
protected function initComments($page) { // get comments for this page $this->comments = false; if (isset($this->app->memcache)) { $key = $this->getCommentsCacheKey(); $this->comments = $this->app->memcache->getNs('posts', $key); /* * Note: The limit of comments per page is somewhat important here. * In extreme cases, we could run over the 1M size limit for cached * values. This would occur when every comment is close to the * maximum size in bodytext (8K) and the associated posts also have * a very large bodytext (about 8K each). In these rare cases, * caching will fail. */ } if ($this->comments === false) { $sql = sprintf('select BlorgComment.* from BlorgComment %s where %s order by BlorgComment.createdate desc', $this->getJoinClause(), $this->getWhereClause()); $offset = ($page - 1) * $this->getPageSize(); $this->app->db->setLimit($this->getPageSize(), $offset); $wrapper = SwatDBClassMap::get('BlorgCommentWrapper'); $this->comments = SwatDB::query($this->app->db, $sql, $wrapper); // efficiently load posts $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper'); $post_sql = 'select id, title, shortname, bodytext, publish_date from BlorgPost where id in (%s)'; $this->comments->loadAllSubDataObjects('post', $this->app->db, $post_sql, $post_wrapper); // efficiently load authors $author_wrapper = SwatDBClassMap::get('BlorgAuthorWrapper'); $author_sql = 'select id, name, shortname, email, visible from BlorgAuthor where id in (%s)'; $this->comments->loadAllSubDataObjects('author', $this->app->db, $author_sql, $author_wrapper); if (isset($this->app->memcache)) { $this->app->memcache->setNs('posts', $key, $this->comments); } } else { $this->comments->setDatabase($this->app->db); } // if we're not on the first page and there are no comments, 404 if ($page > 1 && count($this->comments) === 0) { throw new SiteNotFoundException('Page not found.'); } // get total number of comments $this->total_count = false; if (isset($this->app->memcache)) { $total_key = $this->getTotalCountCacheKey(); $this->total_count = $this->app->memcache->getNs('posts', $total_key); } if ($this->total_count === false) { $sql = sprintf('select count(1) from BlorgComment %s where %s', $this->getJoinClause(), $this->getWhereClause()); $this->total_count = SwatDB::queryOne($this->app->db, $sql); if (isset($this->app->memcache)) { $this->app->memcache->setNs('posts', $total_key, $this->total_count); } } }
/** * Creates a new author index page * * @param SiteWebApplication $app the application. * @param SiteLayout $layout */ public function __construct(SiteWebApplication $app, SiteLayout $layout, array $arguments = array()) { parent::__construct($app, $layout, $arguments); $instance_id = $this->app->getInstanceId(); $sql = sprintf('select * from BlorgAuthor where instance %s %s and visible = %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean')); $this->authors = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgAuthorWrapper')); }
public function getFrontMatter() { require_once 'CME/dataobjects/CMEFrontMatterWrapper.php'; $this->checkDB(); $inquisition_id = $this->getInternalValue('inquisition'); $sql = sprintf('select * from CMEFrontMatter where evaluation = %s', $this->db->quote($inquisition_id, 'integer')); return SwatDB::query($this->db, $sql, SwatDBClassMap::get('CMEFrontMatterWrapper'))->getFirst(); }
protected function initFrontMatter() { $sql = sprintf('select * from CMEFrontMatter where evaluation = %s', $this->app->db->quote($this->inquisition->id, 'integer')); $this->front_matter = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEFrontMatterWrapper'))->getFirst(); if (!$this->front_matter instanceof CMEFrontMatter) { throw new AdminNotFoundException(sprintf('Evaluation with id of %s not found.', $this->id)); } }
protected function validateShortname($shortname) { $sql = 'select shortname from BlorgTag where shortname = %s and id %s %s and instance %s %s'; $instance_id = $this->app->getInstanceId(); $sql = sprintf($sql, $this->app->db->quote($shortname, 'text'), SwatDB::equalityOperator($this->id, true), $this->app->db->quote($this->id, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $query = SwatDB::query($this->app->db, $sql); return count($query) == 0; }
protected function getArticles() { $sql = sprintf('select title, shortname, description from Article where enabled = %s and visible = %s and parent is null and instance %s %s order by title asc', $this->app->db->quote(true, 'boolean'), $this->app->db->quote(true, 'boolean'), SwatDB::equalityOperator($this->app->getInstanceId()), $this->app->db->quote($this->app->getInstanceId(), 'integer')); $wrapper = SwatDBClassMap::get('SiteArticleWrapper'); return SwatDB::query($this->app->db, $sql, $wrapper); }
private function getPhotos($photo_ids) { $instance_id = $this->app->getInstance() === null ? null : $this->app->getInstanceId(); $sql = sprintf('select PinholePhoto.* from PinholePhoto inner join ImageSet on PinholePhoto.image_set = ImageSet.id where PinholePhoto.status = %s and ImageSet.instance %s %s and PinholePhoto.id in (%s) order by PinholePhoto.publish_date desc', $this->app->db->quote(PinholePhoto::STATUS_PUBLISHED, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->implodeArray($photo_ids, 'integer')); $this->app->db->setLimit($this->max_photos); return SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholePhotoWrapper')); }
protected function getPendingIds() { $sql = sprintf('select id from BlorgComment where status = %s and spam = %s order by createdate asc', $this->app->db->quote(SiteComment::STATUS_PENDING, 'integer'), $this->app->db->quote(false, 'boolean')); $rows = SwatDB::query($this->app->db, $sql); $ids = array(); foreach ($rows as $row) { $ids[] = $row->id; } return $ids; }
/** * Excludes quiz responses that were reset. We save the old quiz response * but don't use it for display or for credit calculations. */ public function getResponseByAccount(CMEAccount $account) { $this->checkDB(); $sql = sprintf('select * from InquisitionResponse where account = %s and inquisition = %s and reset_date is null', $this->db->quote($account->id, 'integer'), $this->db->quote($this->id, 'integer')); $wrapper = $this->getResolvedResponseWrapperClass(); $response = SwatDB::query($this->db, $sql, $wrapper)->getFirst(); if ($response instanceof CMEQuizResponse) { $response->inquisition = $this; } return $response; }
/** * Gets photographer data * * @return SwatTableModel with photographer information. */ protected function getTableModel(SwatView $view) { $sql = 'select * from PinholePhotographer where instance %s %s order by %s'; $instance_id = $this->app->getInstanceId(); $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->getOrderByClause($view, 'id')); $rs = SwatDB::query($this->app->db, $sql); foreach ($rs as $row) { $row->status_title = PinholePhotographer::getStatusTitle($row->status); } return $rs; }
protected function getNewTags(PinholePhoto $photo) { $sql = sprintf('select title, id from PinholeTag where id in ( select tag from PinholePhotoTagBinding where photo = %1$s) and id not in (select tag from PinholePhotoTagBinding where photo != %1$s)', $this->app->db->quote($photo->id, 'integer')); $tags = SwatDB::query($this->app->db, $sql); $response = array(); foreach ($tags as $tag) { $response[] = array('id' => $tag->id, 'title' => $tag->title); } return $response; }
protected function setDefaultProviders(CMEProviderWrapper $providers) { $shortnames = $this->getDefaultProviderShortnames(); if (count($shortnames) > 0) { $sql = sprintf('select id from CMEProvider where shortname in (%s)', $this->app->db->datatype->implodeArray($shortnames, 'text')); $rows = SwatDB::query($this->app->db, $sql); foreach ($rows as $row) { $this->ui->getWidget('providers')->values[] = $row->id; } } if (count($this->ui->getWidget('providers')->values) === 0) { $this->ui->getWidget('providers')->values[] = $providers->getFirst()->id; } }
/** * Loads this data-object's properties from the database given an id * * If this object is associeted with an instance through the * {@link PinholeInstanceDataObject::setInstance()} method, load internal * will only load rows matching the specified instance. * * @param mixed $id the id of the database row to set this object's * properties with. * * @return mixed this object's data row or null is no such row exists. */ protected function loadInternal($id) { $row = null; if ($this->instance === null) { $row = parent::loadInternal($id); } else { if ($this->table !== null && $this->id_field !== null) { $id_field = new SwatDBField($this->id_field, 'integer'); $sql = 'select * from %s where %s = %s and instance = %s'; $sql = sprintf($sql, $this->table, $id_field->name, $this->db->quote($id, $id_field->type), $this->db->quote($this->instance->id, 'integer')); $rs = SwatDB::query($this->db, $sql, null); $row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC); } } return $row; }
public function loadByShortname($shortname) { $this->checkDB(); $row = null; if ($this->table !== null) { $sql = sprintf('select * from %s where shortname = %s', $this->table, $this->db->quote($shortname, 'text')); $rs = SwatDB::query($this->db, $sql, null); $row = $rs->fetchRow(MDB2_FETCHMODE_ASSOC); } if ($row === null) { return false; } $this->initFromRow($row); $this->generatePropertyHashes(); return true; }
private function generateShortname($instance, $text, $iteration = 0) { $shortname = SwatString::condenseToName($text); if ($iteration != 0) { $shortname = $shortname . (string) $iteration; } $sql = 'select id from BlorgAuthor where shortname = %s and instance = %s'; $sql = sprintf($sql, $this->table->process->dst_db->quote($shortname, 'text'), $this->table->process->dst_db->quote($instance, 'integer')); $rs = SwatDB::query($this->table->process->dst_db, $sql); if (count($rs) == 0) { return $shortname; } else { return $this->generateShortname($instance, $text, $iteration + 1); } }