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


PHP Contacts::getFields方法代码示例

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


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

示例1: actionBuildIndex

 /**
  * Rebuilds the search index.
  */
 public function actionBuildIndex()
 {
     $contact = new Contacts();
     $fieldData = $contact->getFields();
     // lookup searchable fields
     $fields = array();
     for ($i = 0; $i < count($fieldData); $i++) {
         if (in_array($fieldData[$i]->type, array('dropdown', 'text', 'varchar', 'assignment')) && !in_array($fieldData[$i]->fieldName, array('firstName', 'lastName', 'updatedBy', 'priority', 'id'))) {
             //,'phone','url','email','link',
             // || !$fields[$i]->searchable
             if ($fieldData[$i]->relevance == 'High') {
                 $relevance = 3;
             } elseif ($fieldData[$i]->relevance == 'Medium') {
                 $relevance = 2;
             } else {
                 $relevance = 1;
             }
             $fields[$fieldData[$i]->fieldName] = array('type' => $fieldData[$i]->type, 'linkType' => $fieldData[$i]->linkType, 'relevance' => $relevance);
         }
     }
     $t0 = microtime(true);
     $totalCount = Yii::app()->db->createCommand('SELECT count(*) from x2_contacts;')->queryScalar();
     $dataProvider = new CSqlDataProvider('SELECT ' . implode(',', array_merge(array_keys($fields), array('id', 'visibility'))) . ' FROM x2_contacts', array('totalItemCount' => $totalCount, 'sort' => array('defaultOrder' => 'id ASC'), 'pagination' => array('pageSize' => 500)));
     $dataProvider->getData();
     $pages = $dataProvider->pagination->getPageCount();
     echo $pages . ' pages.<br>';
     $searchTerms = array();
     // $fh = fopen('search.csv','w+');
     ob_end_flush();
     $keys = array();
     $tokenChars = " \n\r\t!\$%^&*()_+-=~[]{}\\|:;'\",.<>?/`‘’•–—“”";
     $noiseWords = array('a', 'about', 'after', 'all', 'also', 'an', 'and', 'another', 'any', 'are', 'arent', 'as', 'at', 'back', 'be', 'because', 'been', 'before', 'being', 'between', 'both', 'but', 'by', 'came', 'can', 'cant', 'come', 'contact', 'contacts', 'contacted', 'could', 'data', 'did', 'didnt', 'do', 'dont', 'does', 'doesnt', 'each', 'for', 'from', 'get', 'go', 'going', 'goes', 'got', 'has', 'hasnt', 'had', 'hadnt', 'he', 'hes', 'his', 'hed', 'have', 'havent', 'her', 'hers', 'here', 'heres', 'him', 'himself', 'how', 'i', 'if', 'in', 'into', 'is', 'it', 'its', 'like', 'make', 'made', 'makes', 'many', 'me', 'might', 'mightnt', 'more', 'most', 'much', 'must', 'mustnt', 'my', 'mine', 'never', 'no', 'now', 'not', 'of', 'on', 'only', 'onto', 'or', 'other', 'our', 'out', 'over', 'said', 'same', 'see', 'she', 'shes', 'should', 'shouldnt', 'since', 'some', 'still', 'such', 'take', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'theres', 'these', 'they', 'theyre', 'this', 'those', 'through', 'to', 'too', 'today', 'under', 'up', 'very', 'want', 'wants', 'wanted', 'was', 'wasnt', 'way', 'ways', 'we', 'well', 'were', 'what', 'whats', 'where', 'which', 'while', 'who', 'why', 'will', 'with', 'would', 'wont', 'you', 'your', 'youre');
     for ($i = 1; $i <= $pages; ++$i) {
         // for($i = 1; $i<=1; ++$i) {
         $links = array();
         $dataProvider->pagination->setCurrentPage($i);
         foreach ($dataProvider->getData($i > 1) as $record) {
             // var_dump($record);
             foreach ($fields as $fieldName => &$field) {
                 // $fieldName = $field['fieldName'];
                 if (!empty($record[$fieldName])) {
                     // break string into words, and eliminate any contractions so we can safely tokenize on ' characters
                     $token = strtok(preg_replace('/(?<=\\w)\'(?=\\w)/u', '', $record[$fieldName]), $tokenChars);
                     while ($token !== false) {
                         $token = strtolower($token);
                         if (strlen($token) <= 50 && !in_array($token, $noiseWords)) {
                             $links[] = array($token, 'Contacts', $record['id'], $field['relevance'], $record['assignedTo'], $record['visibility']);
                         }
                         $token = strtok($tokenChars);
                     }
                 }
             }
             unset($field);
         }
         $sql = 'INSERT INTO x2_search (keyword, modelType, modelId, relevance, assignedTo, visibility) VALUES ';
         for ($j = 0; $j < count($links); ++$j) {
             $sql .= '(?,?,?,?,?,?)';
             if ($j < count($links) - 1) {
                 $sql .= ',';
             }
         }
         // echo $sql;
         // var_dump($links);
         // die();
         $query = Yii::app()->db->createCommand($sql);
         for ($j = 0; $j < count($links); ++$j) {
             $query = $query->bindValues(array(6 * $j + 1 => $links[$j][0], 6 * $j + 2 => $links[$j][1], 6 * $j + 3 => $links[$j][2], 6 * $j + 4 => $links[$j][3], 6 * $j + 5 => $links[$j][4], 6 * $j + 6 => $links[$j][5]));
         }
         // die(var_dump($links));
         // echo $query->getText();
         $query->execute();
         // break;
         echo "Page {$i}...done<br>";
         flush();
     }
     // Yii::app()->db->createCommand();
     echo 'Time: ' . (microtime(true) - $t0) . '<br>';
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:81,代码来源:SearchController.php

示例2: actionUpdateList

 public function actionUpdateList($id)
 {
     $list = X2List::model()->findByPk($id);
     if (!isset($list)) {
         throw new CHttpException(400, Yii::t('app', 'This list cannot be found.'));
     }
     if (!$this->checkPermissions($list, 'edit')) {
         throw new CHttpException(403, Yii::t('app', 'You do not have permission to modify this list.'));
     }
     $contactModel = new Contacts();
     $comparisonList = X2List::getComparisonList();
     $fields = $contactModel->getFields(true);
     if ($list->type == 'dynamic') {
         $criteriaModels = X2ListCriterion::model()->findAllByAttributes(array('listId' => $list->id), new CDbCriteria(array('order' => 'id ASC')));
         if (isset($_POST['X2List'], $_POST['X2List']['attribute'], $_POST['X2List']['comparison'], $_POST['X2List']['value'])) {
             $attributes =& $_POST['X2List']['attribute'];
             $comparisons =& $_POST['X2List']['comparison'];
             $values =& $_POST['X2List']['value'];
             if (count($attributes) > 0 && count($attributes) == count($comparisons) && count($comparisons) == count($values)) {
                 $list->attributes = $_POST['X2List'];
                 $list->modelName = 'Contacts';
                 $list->lastUpdated = time();
                 if ($list->save()) {
                     $this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
                 }
             }
         }
     } else {
         //static or campaign lists
         if (isset($_POST['X2List'])) {
             $list->attributes = $_POST['X2List'];
             $list->modelName = 'Contacts';
             $list->lastUpdated = time();
             $list->save();
             $this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
         }
     }
     if (empty($criteriaModels)) {
         $default = new X2ListCriterion();
         $default->value = '';
         $default->attribute = '';
         $default->comparison = 'contains';
         $criteriaModels[] = $default;
     } else {
         if ($list->type = 'dynamic') {
             foreach ($criteriaModels as $criM) {
                 if (isset($fields[$criM->attribute])) {
                     if ($fields[$criM->attribute]->type == 'link') {
                         $criM->value = implode(',', array_map(function ($c) {
                             list($name, $id) = Fields::nameAndId($c);
                             return $name;
                         }, explode(',', $criM->value)));
                     }
                 }
             }
         }
     }
     $this->render('updateList', array('model' => $list, 'criteriaModels' => $criteriaModels, 'users' => User::getNames(), 'comparisonList' => $comparisonList, 'listTypes' => array('dynamic' => Yii::t('contacts', 'Dynamic'), 'static' => Yii::t('contacts', 'Static')), 'itemModel' => $contactModel));
 }
开发者ID:shuvro35,项目名称:X2CRM,代码行数:59,代码来源:ContactsController.php


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