本文整理汇总了PHP中Quote::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::model方法的具体用法?PHP Quote::model怎么用?PHP Quote::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quote
的用法示例。
在下文中一共展示了Quote::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$session = Yii::app()->session;
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$cookies = Yii::app()->request->cookies;
// If referrer is not our controller delete search parameters from session.
if (strpos(Yii::app()->request->urlReferrer, '/quote/list') === false) {
unset($session['search']);
}
if (!empty($_POST['search']) && is_array($_POST['search'])) {
$search = $_POST['search'];
$session['search'] = $search;
} else {
if (!empty($session['search'])) {
$search = $session['search'];
} else {
$search = array('text' => '', 'authorId' => 0, 'approved' => 'all');
}
}
$criteria = new CDbCriteria();
$criteria->condition = '(textRu LIKE :text OR textEn LIKE :text) ' . ($search['authorId'] ? 'AND authorId = :authorId ' : '') . ($search['approved'] == 'approved' ? 'AND approvedTime ' : '') . ($search['approved'] == 'unApproved' ? 'AND (approvedTime IS NULL OR approvedTime = 0) ' : '');
$criteria->params = array(':text' => "%{$search['text']}%") + ($search['authorId'] ? array(':authorId' => $search['authorId']) : array());
$criteria->order = 'Quote.id DESC';
$pages = new CPagination(Quote::model()->count($criteria));
$config->applyTo($pages);
$pages->applyLimit($criteria);
$quotes = Quote::model()->with('tags', 'author')->findAll($criteria);
$showSearchForm = !empty($cookies['showSearchForm']) && $cookies['showSearchForm']->value ? true : false;
$criteria = new CDbCriteria();
$criteria->order = 'name';
$authors = Author::model()->findAll($criteria);
$this->controller->render('list', array('quotes' => $quotes, 'pages' => $pages, 'authors' => $authors, 'search' => $search, 'showSearchForm' => $showSearchForm));
}
示例2: run
public function run()
{
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$form = new SearchForm();
// If referrer is not our action delete search parameters from session.
if (strpos(Yii::app()->request->urlReferrer, '/site/search') === false) {
Yii::app()->session->remove('siteSearch');
} else {
if (!empty(Yii::app()->session['SearchForm'])) {
$siteSearch = Yii::app()->session['SearchForm'];
$form->text = $siteSearch['text'];
$form->authorId = $siteSearch['authorId'];
}
}
if (!empty($_POST['SearchForm']) && is_array($_POST['SearchForm'])) {
$form->attributes = $_POST['SearchForm'];
Yii::app()->session['SearchForm'] = array('text' => $form->text, 'authorId' => $form->authorId);
}
$criteria = new CDbCriteria();
$criteria->order = 'approvedTime DESC';
$criteria->condition = 'approvedTime AND (textRu LIKE :text OR textEn LIKE :text) ' . ($form->authorId ? 'AND (authorId LIKE :authorId)' : '');
$criteria->params = array(':text' => "%{$form->text}%") + ($form->authorId ? array(':authorId' => $form->authorId) : array());
$pages = new CPagination(Quote::model()->count($criteria));
$config->applyTo($pages);
$pages->applyLimit($criteria);
$quotes = Quote::model()->with('tags')->findAll($criteria);
$criteria = new CDbCriteria();
$criteria->order = 'name';
$authors = Author::model()->findAll($criteria);
$this->controller->render('search', array('quotes' => $quotes, 'pages' => $pages, 'form' => $form, 'authors' => $authors));
}
示例3: run
public function run()
{
$criteria = new CDbCriteria();
$criteria->condition = 'approvedTime';
$quote = Quote::model()->findByPk($_GET['id'], $criteria);
if ($quote === null) {
throw new CHttpException(404, 'Quote not found');
}
$this->controller->render('quote', array('quote' => $quote));
}
示例4: run
public function run()
{
$id = !empty($_GET['id']) ? $_GET['id'] : 0;
$quote = Quote::model()->findByPk($id);
if ($quote === null) {
throw new CHttpException(404, 'Quote not found');
}
$quote->delete();
Yii::app()->user->setFlash('generalMessage', 'Quote was deleted successfully.');
$this->controller->redirect(array('list'));
}
示例5: getStatistics
private function getStatistics()
{
$staistics = array();
if ($this->controller->id == 'quote') {
// Quotes total count.
$staistics['totalCount'] = Quote::model()->count();
// Get number of unapproved quotes.
$criteria = new CDbCriteria();
$criteria->condition = 'NOT approvedTime';
$staistics['unapprovedCount'] = Quote::model()->count($criteria);
} elseif ($this->controller->id == 'tag') {
$staistics['totalCount'] = Tag::model()->count();
$tags = Tag::model()->with('quotesCount')->findAll();
// Delete tags with empty quotesCount (With PHP > 5.3 e can use closure here).
// TODO: Rewrite this code for PHP 5.3 when it will be avaliable.
function tagsFilter($tag)
{
return (bool) $tag->quotesCount;
}
$tags = array_filter($tags, 'tagsFilter');
// Sort tags by their weights (quotesCount).
function tagsSort($a, $b)
{
if ($a->quotesCount == $b->quotesCount) {
return 0;
}
return $a->quotesCount > $b->quotesCount ? -1 : 1;
}
usort($tags, 'tagsSort');
$staistics['popularTags'] = array_slice($tags, 0, 10);
} elseif ($this->controller->id == 'author') {
$staistics['totalCount'] = Author::model()->count();
$authors = Author::model()->with('quotesCount')->findAll();
// Delete authors with empty quotesCount (With PHP > 5.3 e can use closure here).
// TODO: Rewrite this code for PHP 5.3 when it will be avaliable.
function authorsFilter($author)
{
return (bool) $author->quotesCount;
}
$authors = array_filter($authors, 'authorsFilter');
// Sort tags by their weights (quotesCount).
function authorsSort($a, $b)
{
if ($a->quotesCount == $b->quotesCount) {
return 0;
}
return $a->quotesCount > $b->quotesCount ? -1 : 1;
}
usort($authors, 'authorsSort');
$staistics['popularAuthors'] = array_slice($authors, 0, 10);
}
return $staistics;
}
示例6: run
/**
* Запускаем отрисовку виджета
*
* @return void
*/
public function run()
{
// Авторизован ли пользователь
if (Yii::app()->user->isAuthenticated() === false) {
return;
}
if (($user = Yii::app()->user->getProfile()) === null) {
return;
}
if (empty($this->programId)) {
return;
}
$quote = Quote::model()->user($user->id)->program($this->programId)->find(array('order' => 't.id DESC'));
$totalCount = Quote::model()->user($user->id)->program($this->programId)->count();
$this->render($this->view, array('quote' => $quote, 'totalCount' => $totalCount));
}
示例7: run
public function run()
{
$connection = Yii::app()->db;
$command = $connection->createCommand('SELECT id FROM Quote ORDER BY id DESC LIMIT 1');
$reader = $command->query();
$row = $reader->read();
$maxId = $row['id'];
mt_srand();
$id = mt_rand(0, $maxId);
$criteria = new CDbCriteria();
$criteria->condition = 'approvedTime AND id >= :id';
$criteria->params = array(':id' => $id);
$criteria->limit = 1;
$quote = Quote::model()->find($criteria);
$this->controller->render('random', array('quote' => $quote));
}
示例8: run
public function run()
{
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$author = Author::model()->findByPk($_GET['authorId']);
if ($author === null) {
throw new CHttpException(404, 'Author not found');
}
$criteria = new CDbCriteria();
$criteria->condition = 'authorId = :authorId';
$criteria->params = array(':authorId' => $author->id);
$pages = new CPagination(Quote::model()->count($criteria));
$config->applyTo($pages);
$pages->applyLimit($criteria);
$quotes = Quote::model()->findAll($criteria);
$this->controller->render('author', array('author' => $author, 'quotes' => $quotes, 'pages' => $pages));
}
示例9: run
public function run()
{
Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->getBaseUrl() . '/css/gridview/jquery.yiigridview.js');
$relationships = Relationships::model()->findAllByAttributes(array('firstType' => 'quotes', 'secondType' => 'contacts', 'secondId' => $this->contactId));
echo '<div id="quotes-form">';
echo '<div id="wide-quote-form" class="wide form" style="overflow: visible;">';
echo '<span style="font-weight:bold; font-size: 1.5em;">' . Yii::t('quotes', "Quotes") . '</span>';
echo '<br /><br />';
// get a list of products for adding to quotes
$products = Product::model()->findAll(array('select' => 'id, name'));
$productNames = array(0 => '');
foreach ($products as $product) {
$productNames[$product->id] = $product->name;
}
$quotes = Quote::model()->findAllByAttributes(array('associatedContacts' => $this->contactId));
foreach ($quotes as $quote) {
$products = Product::model()->findAll(array('select' => 'id, name, price'));
$quoteProducts = QuoteProduct::model()->findAllByAttributes(array('quoteId' => $quote->id));
// find associated products and their quantities
$quotesProducts = QuoteProduct::model()->findAllByAttributes(array('quoteId' => $quote->id));
$orders = array();
// array of product-quantity pairs
$total = 0;
// total price for the quote
foreach ($quotesProducts as $qp) {
$price = $qp->price * $qp->quantity;
if ($qp->adjustmentType == 'percent') {
$price += $price * ($qp->adjustment / 100);
$qp->adjustment = "{$qp->adjustment}%";
} else {
$price += $qp->adjustment;
}
$orders[] = array('name' => $qp->name, 'id' => $qp->productId, 'unit' => $qp->price, 'quantity' => $qp->quantity, 'adjustment' => $qp->adjustment, 'price' => $price);
$order = end($orders);
$total += $order['price'];
}
$dataProvider = new CArrayDataProvider($orders, array('keyField' => 'name', 'sort' => array('attributes' => array('name', 'unit', 'quantity', 'price')), 'pagination' => array('pageSize' => false)));
$newProductId = "new_product_" . $quote->id;
$this->render('viewQuotes', array('quote' => $quote, 'contactId' => $this->contactId, 'dataProvider' => $dataProvider, 'products' => $products, 'productNames' => $productNames, 'orders' => $quoteProducts, 'total' => $total));
}
// Mini Create Quote Form
$model = new Quote();
$this->render('createQuote', array('model' => $model, 'contactId' => $this->contactId, 'productNames' => $productNames));
echo "</div>";
echo "</div>";
}
示例10: run
public function run()
{
$this->controller->layout = 'rss';
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$criteria = new CDbCriteria();
$criteria->order = 'approvedTime DESC';
$criteria->condition = 'approvedTime';
$criteria->limit = $config['pageSize'];
$quotes = Quote::model()->with('author')->findAll($criteria);
// Save statistics.
$req = new RssRequest();
$req->ip = Yii::app()->request->userHostAddress;
$req->requestTime = time();
$req->userAgent = Yii::app()->request->userAgent;
$req->os = '';
// TODO: Parse UA string and get OS details from it.
$req->save();
$this->controller->render('rss', array('quotes' => $quotes, 'config' => $config));
}
示例11: run
public function run()
{
if (Yii::app()->user->isAuthenticated() === false) {
$this->controller->redirect(Yii::app()->user->loginUrl);
}
if (($user = Yii::app()->user->getProfile()) === null) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
Yii::app()->user->logout();
$this->controller->redirect((array) '/user/account/login');
}
// Определяем программу, для которой необходимо загрузить интересные мысли
$programId = (int) Yii::app()->request->getParam('programId');
$program = CourseType::model()->published()->findByPk($programId);
// Определяем, подписан ли данный пользователь на эту программу
if (!$program || !Subscription::model()->isUserSubscribed($user, $program)) {
throw new CHttpException(404);
}
//$quotes = Quote::model()->user($user->id)->program($program->id)->findAll();
$dataProvider = new CActiveDataProvider(Quote::model()->user($user->id)->program($program->id)->with('user', 'courseType', 'block', 'block.entity', 'block.entity.day'), array('pagination' => array('pageVar' => 'page', 'pageSize' => 10), 'sort' => array('defaultOrder' => 't.id ASC')));
$this->controller->render('interest', array('program' => $program, 'dataProvider' => $dataProvider));
}
示例12: run
public function run()
{
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$connection = Yii::app()->db;
$tag = Tag::model()->findByAttributes(array('name' => $_GET['tag']));
if ($tag === null) {
throw new CHttpException(404, 'Tag not found');
}
/*
* Get total number of approved quotes for this tag.
*/
$countSql = "SELECT COUNT(*) AS totalCount FROM `Quote`\n LEFT JOIN QuoteTag\n ON Quote.id = QuoteTag.quoteId\n WHERE approvedTime AND tagId = {$tag->id}";
$command = $connection->createCommand($countSql);
$reader = $command->query();
$reader->next();
$row = $reader->current();
$totalCount = $row['totalCount'];
$pages = new CPagination($totalCount);
$config->applyTo($pages);
/*
* Get IDs of current page quotes.
*/
$offset = $pages->pageSize * $pages->currentPage;
$limit = $pages->pageSize;
$quotesIdSql = "SELECT id FROM Quote\n LEFT JOIN QuoteTag\n ON Quote.id = QuoteTag.quoteId\n WHERE approvedTime AND tagId = {$tag->id}\n GROUP BY quoteId\n ORDER BY approvedTime DESC\n LIMIT {$offset}, {$limit}";
$command = $connection->createCommand($quotesIdSql);
$reader = $command->query();
$ids = array();
foreach ($reader as $row) {
$ids[] = $row['id'];
}
$criteria = new CDbCriteria();
//$criteria->condition = 'approvedTime';
$criteria->addInCondition('id', $ids);
$criteria->order = 'approvedTime DESC';
$quotes = Quote::model()->findAll($criteria);
/*
foreach($quotes as $quote)
echo $quote->id, ",";
return;
*/
/*
$tagName = $_GET['tag'];
$config = new CConfiguration(Yii::app()->basePath . '/config/pager.php');
$criteria = new CDbCriteria();
$criteria->condition = 'name = :name';
$criteria->params = array(':name' => $tagName);
/*
* Find total count of this tag quotes.
*
$connection = Yii::app()->db;
$command = $connection->createCommand("SELECT COUNT(*) AS totalCount FROM QuoteTag WHERE tagId = (
SELECT id FROM Tag WHERE `name` = '{$tagName}' LIMIT 1
)");
$reader = $command->query();
$row = $reader->read();
$quotesCount = $row['totalCount'];
$pages = new CPagination($quotesCount);
$config->applyTo($pages);
//$pages->applyLimit($criteria);
$tag = Tag::model()->with(array('quotes' => array(
'condition' => 'approvedTime',
'order' => 'approvedTime DESC',
'offset' => 0,
'limit' => 1,
)))->find($criteria);
if($tag === null)
throw new CHttpException(404, 'Tag not found');
*/
$this->controller->render('tag', array('tag' => $tag, 'quotes' => $quotes, 'pages' => $pages));
}
示例13: array
$quoteAttributes = array();
foreach (Contacts::model()->getAttributeLabels() as $fieldName => $label) {
AuxLib::debugLog('Iterating over contact attributes ' . $fieldName . '=>' . $label);
$index = Yii::t('contacts', "{contact}", array('{contact}' => $modTitles['contact'])) . ": {$label}";
$contactAttributes[$index] = "{associatedContacts.{$fieldName}}";
}
foreach (Accounts::model()->getAttributeLabels() as $fieldName => $label) {
AuxLib::debugLog('Iterating over account attributes ' . $fieldName . '=>' . $label);
$index = Yii::t('accounts', "{account}", array('{account}' => $modTitles['account'])) . ": {$label}";
$accountAttributes[$index] = "{accountName.{$fieldName}}";
}
$Quote = Yii::t('quotes', "{quote}: ", array('{quote}' => $modTitles['quote']));
$quoteAttributes[$Quote . Yii::t('quotes', "Item Table")] = '{lineItems}';
$quoteAttributes[$Quote . Yii::t('quotes', "Date printed/emailed")] = '{dateNow}';
$quoteAttributes[$Quote . Yii::t('quotes', '{quote} or Invoice', array('{quote}' => $modTitles['quote']))] = '{quoteOrInvoice}';
foreach (Quote::model()->getAttributeLabels() as $fieldName => $label) {
$index = $Quote . "{$label}";
$quoteAttributes[$index] = "{" . $fieldName . "}";
}
}
if ($model->type === 'email') {
$js = 'x2.insertableAttributes = ' . CJSON::encode(array(Yii::t('contacts', '{contact} Attributes', array('{contact}' => $modTitles['contact'])) => $attributes)) . ';';
} else {
$js = 'x2.insertableAttributes = ' . CJSON::encode(array(Yii::t('docs', '{contact} Attributes', array('{contact}' => $modTitles['contact'])) => $contactAttributes, Yii::t('docs', '{account} Attributes', array('{account}' => $modTitles['account'])) => $accountAttributes, Yii::t('docs', '{quote} Attributes', array('{quote}' => $modTitles['quote'])) => $quoteAttributes)) . ';';
}
}
if ($model->type === 'email') {
// allowable association types
$associationTypeOptions = Docs::modelsWhichSupportEmailTemplates();
// insertable attributes by model type
$insertableAttributes = array();
示例14: replaceVariables
/**
* Replace tokens with model attribute values.
*
* @param type $str Input text
* @param X2Model $model Model to use for replacement
* @param array $vars List of extra variables to replace
* @param bool $encode Encode replacement values if true; use renderAttribute otherwise.
* @return string
*/
public static function replaceVariables($str, $model, $vars = array(), $encode = false, $renderFlag = true)
{
if ($encode) {
foreach (array_keys($vars) as $key) {
$vars[$key] = CHtml::encode($vars[$key]);
}
}
$str = strtr($str, $vars);
// replace any manually set variables
if ($model instanceof X2Model) {
if (get_class($model) !== 'Quote') {
$str = Formatter::replaceVariables($str, $model, '', $renderFlag, false);
} else {
// Specialized, separate method for quotes that can use details from
// either accounts or quotes.
// There may still be some stray quotes with 2+ contacts on it, so
// explode and pick the first to be on the safe side. The most
// common use case by far is to have only one contact on the quote.
$accountId = $model->accountName;
$staticModels = array('Contact' => Contacts::model(), 'Account' => Accounts::model(), 'Quote' => Quote::model());
$models = array('Contact' => $model->contact, 'Account' => empty($accountId) ? null : $staticModels['Account']->findByAttributes(array('nameId' => $accountId)), 'Quote' => $model);
$attributes = array();
foreach ($models as $name => $modelObj) {
$moduleRef = Modules::displayName(false, $name . "s");
if (empty($modelObj)) {
// Model will be blank
foreach ($staticModels[$name]->fields as $field) {
$attributes['{' . $moduleRef . '.' . $field->fieldName . '}'] = '';
}
} else {
// Insert attributes
foreach ($modelObj->attributes as $fieldName => $value) {
if ($renderFlag) {
$attributes['{' . $moduleRef . '.' . $fieldName . '}'] = $modelObj->renderAttribute($fieldName, false, true, $encode);
} else {
$attributes['{' . $moduleRef . '.' . $fieldName . '}'] = $modelObj->getAttribute($fieldName);
}
}
}
}
$quoteTitle = Modules::displayName(false, "Quotes");
$quoteParams = array('{' . $quoteTitle . '.lineItems}' => $model->productTable(true), '{' . $quoteTitle . '.dateNow}' => date("F d, Y", time()), '{' . $quoteTitle . '.quoteOrInvoice}' => Yii::t('quotes', $model->type == 'invoice' ? 'Invoice' : $quoteTitle));
// Run the replacement:
$str = strtr($str, array_merge($attributes, $quoteParams));
return $str;
}
}
return $str;
}
示例15: actionCreate
/**
* Creates a new model.
*
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @param bool $quick If true, this indicates the action is being requested via AJAX
*/
public function actionCreate($quick = false, $duplicate = false)
{
$model = new Quote();
if ($duplicate && !isset($_POST['Quote'])) {
$copiedModel = Quote::model()->findByPk($duplicate);
if (!empty($copiedModel)) {
foreach ($copiedModel->attributes as $name => $value) {
if ($name != 'id') {
$model->{$name} = $value;
}
}
$model->setLineItems($this->duplicateLineItems($copiedModel), false, true);
}
}
$users = User::getNames();
if ($quick && !Yii::app()->request->isAjaxRequest) {
throw new CHttpException(400);
}
$currency = Yii::app()->params->currency;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Quote'])) {
$model->setX2Fields($_POST['Quote']);
$model->currency = $currency;
$model->createDate = time();
$model->lastUpdated = $model->createDate;
$model->createdBy = Yii::app()->user->name;
$model->updatedBy = $model->createdBy;
if (empty($model->name)) {
$model->name = '';
}
if (isset($_POST['lineitem'])) {
$model->lineItems = $_POST['lineitem'];
}
if (!$model->hasLineItemErrors) {
if ($model->save()) {
$model->createEventRecord();
$model->createActionRecord();
$model->saveLineItems();
if (!$quick) {
$this->redirect(array('view', 'id' => $model->id));
} else {
if (isset($_GET['recordId']) && isset($_GET['recordType'])) {
$recordId = $_GET['recordId'];
$recordType = $_GET['recordType'];
$relatedModel = X2Model::model($_GET['recordType'])->findByPk($recordId);
// tie record to quote
if ($relatedModel) {
$relate = new Relationships();
$relate->firstId = $model->id;
$relate->firstType = "Quote";
$relate->secondId = $relatedModel->id;
$relate->secondType = $recordType;
$relate->save();
$model->createAssociatedAction(X2Model::getAssociationType(get_class($relatedModel)), $relatedModel->id);
}
}
return;
}
}
}
}
// get products
$products = Product::activeProducts();
$viewData = array('model' => $model, 'users' => $users, 'products' => $products, 'quick' => $quick);
if (!$quick) {
$this->render('create', $viewData);
} else {
if ($model->hasErrors() || $model->hasLineItemErrors) {
// Sneak into the response that validation failed via setting
// the response code manually:
header('HTTP/1.1 400 Validation Error');
}
$this->renderPartial('create', $viewData, false, true);
}
}