当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::model方法代码示例

本文整理汇总了PHP中Query::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::model方法的具体用法?PHP Query::model怎么用?PHP Query::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Query的用法示例。


在下文中一共展示了Query::model方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uniqueQueryName

 /**
  * Custom validation for unqiue name for query and user *
  **/
 public function uniqueQueryName($attribute, $params)
 {
     $user_id = Yii::app()->user->getId();
     $result = Query::model()->findByAttributes(array('user_id' => $user_id, 'name' => $this->name));
     //check name is unqie
     if ($result) {
         $this->addError($attribute, 'You already have a query with that name.');
     }
 }
开发者ID:newga,项目名称:newga,代码行数:12,代码来源:Query.php

示例2: actionCreateUpdate

 /**
  * Create or update a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionCreateUpdate()
 {
     $step = 1;
     if ($_GET['step']) {
         $step = $_GET['step'];
     }
     $Campaign = new Campaign();
     $Campaign->scenario = "insiderCampaign";
     $CampaignFile = new CampaignFile();
     $NewOutcome = new CampaignOutcome();
     $NewGroup = new CampaignGroup();
     $letters = array('A', 'B', 'C', 'D');
     if ($_GET['id']) {
         $Campaign = $this->loadModel($_GET['id']);
         $this->redirectRunCampaign($Campaign);
         // the following is to cope with groups on various dev environments with no groups
         if (!sizeof($Campaign->groups)) {
             foreach (array('A', 'B') as $letter) {
                 $CampaignGroup = new CampaignGroup();
                 $CampaignGroup->campaign_id = $Campaign->id;
                 $CampaignGroup->name = $letter;
                 $CampaignGroup->fraction = 50;
                 $CampaignGroup->save();
             }
             $this->refresh();
         }
     }
     if (!$Campaign->isNewRecord && !is_null($Campaign->query) && (int) $Campaign->query->invite === 1) {
         // not allowed here as it's an invite campaign.
         throw new CHttpException('401', 'Forbidden');
     }
     if (!$Campaign->isNewRecord && isset($_GET['add-initial']) && !sizeof($Campaign->outcomes)) {
         // add an initial default outcome
         $NewOutcome = new CampaignOutcome();
         $NewOutcome->campaign_id = $Campaign->id;
         $NewOutcome->name = 'An Outcome';
         $NewOutcome->description = 'An outcome description can help explain the desired result of this outcome. Delete this outcome and create your own below.';
         $NewOutcome->save();
         $this->redirect(array('campaign/createUpdate', 'id' => $Campaign->id));
     }
     if (sizeof($_POST['CampaignOutcome'])) {
         // adding outcome to campaign
         $NewOutcome = new CampaignOutcome();
         $NewOutcome->campaign_id = $Campaign->id;
         $NewOutcome->name = $_POST['CampaignOutcome']['name'];
         $NewOutcome->description = $_POST['CampaignOutcome']['description'];
         $NewOutcome->url = $_POST['CampaignOutcome']['url'];
         if (!strlen($NewOutcome->url)) {
             // save null, not
             $NewOutcome->url = null;
         }
         if ($NewOutcome->save()) {
             Yii::app()->user->setFlash('outcome-success', "Successfully created new outcome '" . $NewOutcome->name . "'");
             $this->redirect(array('campaign/createUpdate', 'id' => $Campaign->id, 'step' => 2, '#' => 'outcomes'));
         } else {
             Yii::app()->user->setFlash('outcome-danger', 'Failed to create new outcome. See errors below.');
         }
     }
     if (isset($_GET['remove-outcome'])) {
         $Criteria = new CDbCriteria();
         $Criteria->compare('id', (int) $_GET['remove-outcome']);
         $Criteria->compare('campaign_id', (int) $_GET['campaign_id']);
         $Outcomes = CampaignOutcome::model()->findAll($Criteria);
         if (sizeof($Outcomes) === 1) {
             // deleting one
             $Outcomes[0]->delete();
         }
         Yii::app()->user->setFlash('outcome-success', "Successfully removed the outcome.");
         $this->redirect(array('campaign/createUpdate', 'id' => $Campaign->id, 'step' => 2, '#' => 'outcomes'));
     }
     if (isset($_GET['remove-group'])) {
         $Criteria = new CDbCriteria();
         $Criteria->compare('id', (int) $_GET['remove-group']);
         $Criteria->compare('campaign_id', $Campaign->id);
         CampaignGroup::model()->deleteAll($Criteria);
         Yii::app()->user->setFlash('group-success', "Successfully removed the group.");
         $this->redirect(array('campaign/createUpdate', 'id' => $Campaign->id, 'step' => 3, '#' => 'groups'));
     }
     if (sizeof($_POST['CampaignGroup'])) {
         $step = 3;
         if ($_POST['CampaignGroup']['id']) {
             $CampaignGroup = CampaignGroup::model()->findByPk($_POST['CampaignGroup']['id']);
             $CampaignGroup->setAttributes($_POST['CampaignGroup']);
             if ($CampaignGroup->save()) {
                 Yii::app()->user->setFlash('group-success', 'Group "' . $CampaignGroup->name . '" updated successfully');
                 $this->redirect(array('campaign/createUpdate', 'id' => $Campaign->id, 'step' => 3, '#' => 'groups'));
             } else {
                 $errors = '';
                 foreach ($CampaignGroup->errors as $error) {
                     $errors .= $error[0] . ' ';
                 }
                 Yii::app()->user->setFlash('group-danger', $errors);
             }
         } else {
             //its new
//.........这里部分代码省略.........
开发者ID:newga,项目名称:newga,代码行数:101,代码来源:CampaignController.php

示例3: switch

 switch ($Question->option_id) {
     case QueryQuestion::OPTION_VENUE:
         if (is_null($Venues)) {
             $Venues = Venue::model()->findAll(array('condition' => 'active = 1', 'index' => 'id'));
         }
         print ' ' . $Venues[$row->query_option];
         break;
     case QueryQuestion::OPTION_ORGANISATION:
         if (is_null($Organisations)) {
             $Organisations = Organisation::model()->findAll(array('condition' => 'active = 1', 'index' => 'id'));
         }
         print ' ' . $Organisations[$row->query_option]->title;
         break;
     case QueryQuestion::OPTION_INVITE:
         if (is_null($InviteQueries)) {
             $InviteQueries = Query::model()->findAll(array('condition' => 'invite = 1', 'index' => 'id'));
         }
         print ' ' . $InviteQueries[$row->query_option]->name;
         break;
     case QueryQuestion::OPTION_CS:
         if (is_null($CultureSegments)) {
             $CultureSegments = CultureSegment::model()->findAll(array('index' => 'id'));
         }
         print ' ' . $CultureSegments[$row->query_option]->name;
         break;
     case QueryQuestion::OPTION_ARTFORM:
         if (is_null($Artforms)) {
             $Artforms = Artform::model()->findAll(array('index' => 'id', 'order' => 'title ASC'));
         }
         print ' ' . $CultureSegments[$row->query_option]->title;
         break;
开发者ID:newga,项目名称:newga,代码行数:31,代码来源:rules.php

示例4: switch

switch ($Question->option_id) {
    // Venue
    case QueryQuestion::OPTION_VENUE:
        $Venue = Venue::model()->findByPk($query_option);
        print $Venue->title;
        break;
        // Organisation
    // Organisation
    case QueryQuestion::OPTION_ORGANISATION:
        $Organisation = Organisation::model()->findByPk($query_option);
        print $Organisation->title;
        break;
        // Invite
    // Invite
    case QueryQuestion::OPTION_INVITE:
        $InviteQuery = Query::model()->findByPk($query_option);
        print $InviteQuery->name;
        break;
        // Culture Segment
    // Culture Segment
    case QueryQuestion::OPTION_CS:
        $CultureSegment = CultureSegment::model()->findByPk($query_option);
        print $CultureSegment->name;
        break;
        // Artforms
    // Artforms
    case QueryQuestion::OPTION_ARTFORM:
        $Artforms = Artform::model()->findByPk($query_option);
        print $Artform->title;
        // Level of engagement
    // Level of engagement
开发者ID:newga,项目名称:newga,代码行数:31,代码来源:_textOptions.php

示例5: delete

 /**
  * Delete an entry in the source
  *
  * @param Query $query
  * @param array $options
  * @return boolean
  */
 public function delete($query, array $options = array())
 {
     $model = $query->model();
     $source = $model::meta('source');
     $key = $this->locate($source, array('id' => $options['record']->id));
     if ($key === false) {
         return false;
     }
     if ($this->__data[$source][$key] == end($this->__data[$source])) {
         unset($this->__data[$source][$key]);
     } else {
         $this->__data[$source][$key] = array_pop($this->__data[$source]);
     }
     return true;
 }
开发者ID:alkemann,项目名称:AL13,代码行数:22,代码来源:TestSource.php

示例6: actionDownload

 public function actionDownload($id)
 {
     // do not include log info in generated file
     foreach (Yii::app()->log->routes as $route) {
         if ($route instanceof CProfileLogRoute) {
             $route->enabled = false;
         }
     }
     // download (filtered) results of a query
     $Query = Query::model()->findByAttributes(array('id' => $id));
     if (is_null($Query)) {
         throw new CHttpException('404', 'File not found');
     }
     $result = $Query->run(array('*'), (int) Yii::app()->user->organisation_id ? (int) Yii::app()->user->organisation_id : null);
     if (!sizeof($result['rows'])) {
         throw new CHttpException('404', 'Results not found');
     }
     $cleanQueryName = preg_replace(array("@[^a-z0-9\\-\\s]@i", "@\\s+@", "@\\-{2,}@"), array("", "-", "-"), $Query->name) . '-' . date("Y-m-d");
     $csv = fopen('php://output', 'w');
     header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
     header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header('Content-Encoding: UTF-8');
     header('Content-type: text/csv; charset=UTF-8');
     // disposition / encoding on response body
     header("Content-Disposition: attachment;filename=" . $cleanQueryName . ".csv");
     header("Content-Transfer-Encoding: binary");
     $columns = array('contact_warehouse_id', 'salutation', 'first_name', 'last_name', 'email', 'phone', 'mobile', 'address_line_1', 'address_line_2', 'address_line_3', 'address_line_4', 'address_town', 'address_postcode', 'address_county');
     // header row
     fputcsv($csv, $columns);
     $Store = new Store();
     foreach ($result['rows'] as $row) {
         $data = array();
         foreach ($columns as $column) {
             switch ($column) {
                 case 'email':
                     $data[$column] = $Store->decryptEmail($row[$column]);
                     break;
                 case 'last_name':
                     $data[$column] = $Store->decryptLastName($row[$column]);
                     break;
                 case 'phone':
                     $data[$column] = $Store->decryptPhone($row[$column]);
                     if (strlen($data[$column]) && mb_substr($data[$column], 0, 1, 'utf-8') != 0) {
                         // add a zero to anything missing one
                         $data[$column] = '0' . $data[$column];
                     }
                     break;
                 case 'mobile':
                     $data[$column] = $Store->decryptMobile($row[$column]);
                     if (strlen($data[$column]) && mb_substr($data[$column], 0, 1, 'utf-8') != 0) {
                         // add a zero to anything missing one
                         $data[$column] = '0' . $data[$column];
                     }
                     break;
                 case 'address_line_1':
                     $data[$column] = $Store->decryptAddress1($row[$column]);
                     break;
                 default:
                     $data[$column] = $row[$column];
             }
         }
         fputcsv($csv, $data);
     }
     fclose($csv);
     exit;
 }
开发者ID:newga,项目名称:newga,代码行数:67,代码来源:QueryController.php


注:本文中的Query::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。