本文整理汇总了PHP中Contacts::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Contacts::model方法的具体用法?PHP Contacts::model怎么用?PHP Contacts::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contacts
的用法示例。
在下文中一共展示了Contacts::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubscription
/**
* Test subscribing and then receiving data:
*/
public function testSubscription()
{
// 1: Request to subscribe:
$hookName = 'ContactsCreate';
$hook = array('event' => 'RecordCreateTrigger', 'target_url' => TEST_WEBROOT_URL . '/api2HooksTest.php?name=' . $hookName);
$ch = $this->getCurlHandle('POST', array('{suffix}' => ''), 'admin', $hook, array(CURLOPT_HEADER => 1));
$response = curl_exec($ch);
$this->assertResponseCodeIs(201, $ch, VERBOSE_MODE ? $response : '');
$trigger = ApiHook::model()->findByAttributes($hook);
// 2. Create a contact
$contact = array('firstName' => 'Walter', 'lastName' => 'White', 'email' => 'walter.white@sandia.gov', 'visibility' => 1);
$ch = curl_init(TEST_BASE_URL . 'api2/Contacts');
$options = array(CURLOPT_POSTFIELDS => json_encode($contact), CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true);
foreach ($this->authCurlOpts() as $opt => $optVal) {
$options[$opt] = $optVal;
}
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$c = Contacts::model()->findByAttributes($contact);
$this->assertResponseCodeIs(201, $ch);
$this->assertNotEmpty($c);
// 3. Test that the receiving end got the payload
$outputDir = implode(DIRECTORY_SEPARATOR, array(Yii::app()->basePath, 'tests', 'data', 'output'));
$this->assertFileExists($outputDir . DIRECTORY_SEPARATOR . "hook_{$hookName}.json");
$contactPulled = json_decode(file_get_contents($outputDir . DIRECTORY_SEPARATOR . "hook_pulled_{$hookName}.json"), 1);
foreach ($contact as $field => $value) {
$this->assertEquals($value, $contactPulled[$field]);
}
}
示例2: fetchSpecificContact
private function fetchSpecificContact()
{
$con_model = Contacts::model()->findAllByAttributes($this->contacts);
foreach ($con_model as $data) {
$this->data[] = $data->attributes;
}
}
示例3: testContacts
/**
* Ensure that update and create trigger appropriate flows
*/
public function testContacts()
{
X2FlowTestingAuxLib::clearLogs($this);
$this->action = 'model';
$this->assertEquals(array(), TriggerLog::model()->findAll());
// Create
$contact = array('firstName' => 'Walt', 'lastName' => 'White', 'email' => 'walter.white@sandia.gov', 'visibility' => 1, 'trackingKey' => '1234');
$ch = $this->getCurlHandle('POST', array('{modelAction}' => 'Contacts'), 'admin', $contact);
$response = json_decode(curl_exec($ch), 1);
$id = $response['id'];
$this->assertResponseCodeIs(201, $ch);
$this->assertTrue((bool) ($newContact = Contacts::model()->findBySql('SELECT * FROM x2_contacts
WHERE firstName="Walt"
AND lastName="White"
AND email="walter.white@sandia.gov"
AND trackingKey="1234"')));
$logs = TriggerLog::model()->findAll();
$this->assertEquals(1, count($logs));
$trace = X2FlowTestingAuxLib::getTraceByFlowId($this->flows('flow1')->id);
$this->assertTrue(is_array($trace));
$this->assertTrue(X2FlowTestingAuxLib::checkTrace($trace));
// Update
$contact['firstName'] = 'Walter';
$ch = $this->getCurlHandle('PUT', array('{modelAction}' => "Contacts/{$id}.json"), 'admin', $contact);
$response = json_decode(curl_exec($ch), 1);
$this->assertResponseCodeIs(200, $ch);
$newContact->refresh();
$this->assertEquals($contact['firstName'], $newContact['firstName']);
$logs = TriggerLog::model()->findAll();
$this->assertEquals(2, count($logs));
$trace = X2FlowTestingAuxLib::getTraceByFlowId($this->flows('flow2')->id);
$this->assertTrue(is_array($trace));
$this->assertTrue(X2FlowTestingAuxLib::checkTrace($trace));
}
示例4: run
public function run()
{
$actionParams = Yii::app()->controller->getActionParams();
$address = '';
if (Yii::app()->controller->module != null && Yii::app()->controller->module->id == 'contacts' && Yii::app()->controller->action->id == 'view' && isset($actionParams['id'])) {
// must have an actual ID value
$currentRecord = Contacts::model()->findByPk($actionParams['id']);
if (!empty($currentRecord->city)) {
if (!empty($currentRecord->address)) {
$address .= $currentRecord->address . ', ';
}
$address .= $currentRecord->city . ', ';
}
if (!empty($currentRecord->state)) {
$address .= $currentRecord->state . ' ';
}
if (!empty($currentRecord->zipcode)) {
$address .= $currentRecord->zipcode . ' ';
}
if (!empty($currentRecord->country)) {
$address .= $currentRecord->country;
}
}
$this->render('googleMaps', array('address' => $address));
}
示例5: setRecipients
private static function setRecipients()
{
if (self::$model->recipients_source === MsgSmsOutbox::RECIPIENTS_SOURCE_GROUPS) {
if (empty(self::$model->group_id)) {
throw new CException("group_id cannot be empty");
}
self::$model->recipients = ContactsInGroupView::model()->getPhoneNumbers(self::$model->group_id);
} else {
if (self::$model->recipients_source === MsgSmsOutbox::RECIPIENTS_SOURCE_PHONEBOOK) {
self::$model->recipients = Contacts::model()->getAllPhoneNumbers(self::$model->org_id);
}
}
}
示例6: run
public function run()
{
$actionParams = Yii::app()->controller->getActionParams();
$twitter = null;
if (isset(Yii::app()->controller->module) && Yii::app()->controller->module instanceof ContactsModule && Yii::app()->controller->action->id == 'view' && isset($actionParams['id'])) {
// must have an actual ID value
$currentRecord = Contacts::model()->findByPk($actionParams['id']);
if (!empty($currentRecord->twitter)) {
$twitter = $currentRecord->twitter;
}
}
$this->render('twitterFeed', array('twitter' => $twitter));
}
示例7: deleteContact
private function deleteContact($con)
{
//var_dump($con);
//exit;
$con_model = \Contacts::model()->findAllByAttributes($con);
foreach ($con_model as $data) {
try {
if (!$data->delete()) {
new \Error(5, null, json_encode($data->getErrors()));
}
} catch (Exception $e) {
new \Error(5, null, $e->getMessage());
}
}
}
示例8: actionWhatsNew
public function actionWhatsNew()
{
if (!Yii::app()->user->isGuest) {
$user = User::model()->findByPk(Yii::app()->user->getId());
$lastLogin = $user->lastLogin;
$contacts = Contacts::model()->findAll("lastUpdated > {$lastLogin} ORDER BY lastUpdated DESC LIMIT 50");
$actions = Actions::model()->findAll("lastUpdated > {$lastLogin} AND (assignedTo='" . Yii::app()->user->getName() . "' OR assignedTo='Anyone') ORDER BY lastUpdated DESC LIMIT 50");
$sales = Sales::model()->findAll("lastUpdated > {$lastLogin} ORDER BY lastUpdated DESC LIMIT 50");
$accounts = Accounts::model()->findAll("lastUpdated > {$lastLogin} ORDER BY lastUpdated DESC LIMIT 50");
$arr = array_merge($contacts, $actions, $sales, $accounts);
$records = Record::convert($arr);
$dataProvider = new CArrayDataProvider($records, array('id' => 'id', 'pagination' => array('pageSize' => ProfileChild::getResultsPerPage()), 'sort' => array('attributes' => array('lastUpdated', 'name'))));
$this->render('whatsNew', array('records' => $records, 'dataProvider' => $dataProvider));
} else {
$this->redirect('login');
}
}
示例9: actionIndex
public function actionIndex()
{
//$this->render('index');
$this->prepareContacts();
$this->prepareNewContacts();
$con_model = \Contacts::model()->findAllByAttributes($this->contacts);
if (count($con_model) == 0) {
new \Error(5, null, "no such contacts");
}
foreach ($con_model as $data) {
$data->attributes = $this->newContacts;
try {
if (!$data->save()) {
new \Error(5, null, json_encode($data->getErrors()));
}
} catch (Exception $e) {
new \Error(5, null, $e->getMessage());
}
}
new \Error(1);
}
示例10: run
public function run()
{
$contact = array();
$address = '';
$array = array();
$lat = '';
//For Profile
$lang = Yii::app()->language;
$actionParams = Yii::app()->controller->getActionParams();
if (Yii::app()->controller->module != null && Yii::app()->controller->module->id == 'contacts' && Yii::app()->controller->action->id == 'view' && isset($actionParams['id'])) {
// must have an actual ID value
$currentRecord = Contacts::model()->findByPk($actionParams['id']);
if (empty($currentRecord->timezone)) {
//Compose an address to be appended to google maps URL to be
//implemented through the google api.
if (!empty($currentRecord->city)) {
if (!empty($currentRecord->address)) {
$address .= $currentRecord->address . ',+';
}
$address .= $currentRecord->city . ',+';
}
if (!empty($currentRecord->state)) {
$address .= $currentRecord->state;
}
$address = str_replace(" ", "+", $address);
$address .= "&sensor=true";
//Necessary to obtain privilege to see results.
$address .= "®ion=" . $lang;
//If contact isn't in the US, find location.
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $address;
//Set up a way to obtain results from URL
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
$array = CJSON::decode($data, false);
//Get latitude and longitude from results.
if (isset($array->results[0])) {
$long = $array->results[0]->geometry->location->lng;
$lat = $array->results[0]->geometry->location->lat;
//Use of earth tools api to obtain time zone.
$url = "http://www.earthtools.org/timezone/" . $lat . "/" . $long;
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$contact = (array) simplexml_load_string($data);
$offset = $contact["offset"];
$retVL = strstr($offset, ".");
if ($retVL == FALSE) {
$value = intval($offset);
if ($value < 12) {
$currentRecord->timezone = "UTC-0" . $offset . ":00";
} else {
$currentRecord->timezone = "UTC-" . $offset . ":00";
}
$currentRecord->save();
} else {
$retVLFIRST = strstr($offset, ".", true);
$valueFIRST = intval($retVLFIRST);
$valueSEC = intval($retVL);
$append = "";
if ($retVL == 50) {
$append = "30";
} else {
if ($retVL == 66) {
$append = "45";
}
}
if ($valueFIRST < 12) {
$currentRecord->timezone = "UTC-0" . $valueFIRST . ":" . $append;
} else {
$currentRecord->timezone = "UTC-" . $valueSEC . ":" . $append;
}
}
$contact = $currentRecord->timezone;
}
} else {
$contact = $currentRecord->timezone;
}
}
$this->render('timeZone', array('contact' => $contact));
}
示例11: assertContactCreated
/**
* To be called after submitWebForm to assert that contact was created by web form submission
* @return Contact the contact that was created
*/
protected function assertContactCreated()
{
$contact = Contacts::model()->findByAttributes(array('firstName' => 'test', 'lastName' => 'test', 'email' => 'test@test.com'));
$this->assertTrue($contact !== null);
X2_TEST_DEBUG_LEVEL > 1 && println('contact created. new contact\'s tracking key = ' . $contact->trackingKey);
return $contact;
}
示例12: processCriteria
/**
* Save associated criterion objects for a dynamic list
*
* Takes data from the dynamic list criteria designer form and turns them
* into {@link X2ListCriterion} records.
*/
public function processCriteria()
{
X2ListCriterion::model()->deleteAllByAttributes(array('listId' => $this->id));
// delete old criteria
foreach (array('attribute', 'comparison', 'value') as $property) {
// My lazy refactor: bring properties into the current scope as
// temporary variables with their names pluralized
${"{$property}s"} = $this->criteriaInput[$property];
}
$comparisonList = self::getComparisonList();
$contactModel = Contacts::model();
$fields = $contactModel->getFields(true);
for ($i = 0; $i < count($attributes); $i++) {
// create new criteria
if ((array_key_exists($attributes[$i], $contactModel->attributeLabels()) || $attributes[$i] == 'tags') && array_key_exists($comparisons[$i], $comparisonList)) {
$fieldRef = isset($fields[$attributes[$i]]) ? $fields[$attributes[$i]] : null;
if ($fieldRef instanceof Fields && $fieldRef->type == 'link') {
$nameList = explode(',', $values[$i]);
$namesParams = AuxLib::bindArray($nameList);
$namesIn = AuxLib::arrToStrList(array_keys($namesParams));
$lookupModel = X2Model::model(ucfirst($fieldRef->linkType));
$lookupModels = $lookupModel->findAllBySql('SELECT * FROM `' . $lookupModel->tableName() . '` ' . 'WHERE `name` IN ' . $namesIn, $namesParams);
if (!empty($lookupModels)) {
$values[$i] = implode(',', array_map(function ($m) {
return $m->nameId;
}, $lookupModels));
//$lookup->nameId;
}
}
$criterion = new X2ListCriterion();
$criterion->listId = $this->id;
$criterion->type = 'attribute';
$criterion->attribute = $attributes[$i];
$criterion->comparison = $comparisons[$i];
$criterion->value = $values[$i];
$criterion->save();
}
}
}
示例13: Getorgan
protected function Getorgan()
{
//获取自身机构ID
$organID = Yii::app()->user->getOrganID();
$businessContacts = Contacts::model()->findAll('OrganID=:organID and Status=:stu', array(':organID' => $organID, ':stu' => '0'));
foreach ($businessContacts as $val) {
if ($val['ContactID']) {
$ids[] = $val['ContactID'];
}
}
//新增的联系人不能是本人
$ids[] = $organID;
$ids = implode(',', $ids);
$result = Organ::model()->findAll("ID not in({$ids}) and !ISNULL(OrganName)");
return $result;
}
示例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: run
public function run()
{
$preview = false;
$emailBody = '';
$signature = '';
$template = null;
if (!isset($this->model)) {
$this->model = new InlineEmail();
}
if (isset($_POST['InlineEmail'])) {
if (isset($_GET['preview']) || isset($_POST['InlineEmail']['submit']) && $_POST['InlineEmail']['submit'] == Yii::t('app', 'Preview')) {
$preview = true;
}
$this->model->attributes = $_POST['InlineEmail'];
// if the user specified a template, look it up and use it for the message
if ($this->model->template != 0) {
$matches = array();
if (preg_match('/<!--BeginSig-->(.*)<!--EndSig-->/u', $this->model->message, $matches) && count($matches) > 1) {
// extract signature
$signature = $matches[1];
}
$this->model->message = preg_replace('/<!--BeginSig-->(.*)<!--EndSig-->/u', '', $this->model->message);
// remove signatures
$matches = array();
if (preg_match('/<!--BeginMsg-->(.*)<!--EndMsg-->/u', $this->model->message, $matches) && count($matches) > 1) {
$this->model->message = $matches[1];
}
if (empty($signature)) {
$signature = Yii::app()->params->profile->getSignature(true);
}
// load default signature if empty
$template = CActiveRecord::model('Docs')->findByPk($this->model->template);
if (isset($template)) {
$this->model->message = str_replace('\\\\', '\\\\\\', $this->model->message);
$this->model->message = str_replace('$', '\\$', $this->model->message);
$emailBody = preg_replace('/{content}/u', '<!--BeginMsg-->' . $this->model->message . '<!--EndMsg-->', $template->text);
$emailBody = preg_replace('/{signature}/u', '<!--BeginSig-->' . $signature . '<!--EndSig-->', $emailBody);
// check if subject is empty, or is from another template
if (empty($this->model->subject) || CActiveRecord::model('Docs')->countByAttributes(array('type' => 'email', 'title' => $this->model->subject))) {
$this->model->subject = $template->title;
}
if (isset($this->model->modelName, $this->model->modelId)) {
// if there is a model name/id available, look it up and use its attributes
$targetModel = CActiveRecord::model($this->model->modelName)->findByPk($this->model->modelId);
if (isset($targetModel)) {
$attributes = $targetModel->getAttributes();
$attributeNames = array_keys($attributes);
$attributeNames[] = 'content';
$attributes = array_values($attributes);
$attributes[] = $this->model->message;
foreach ($attributeNames as &$name) {
$name = '/{' . $name . '}/';
}
unset($name);
$emailBody = preg_replace($attributeNames, $attributes, $emailBody);
}
}
// $this->model->template = 0;
$this->model->message = $emailBody;
}
} elseif (!empty($this->model->message)) {
// if no template, use the user's custom message, and include a signature
$emailBody = $this->model->message;
// } elseif(!empty($this->model->message)) { // if no template, use the user's custom message, and include a signature
// $emailBody = $this->model->message.'<br><br>'.Yii::app()->params->profile->getSignature(true);
}
if ($this->model->template == 0) {
$this->model->setScenario('custom');
}
if ($this->model->validate() && !$preview) {
$this->model->status = $this->controller->sendUserEmail($this->model->mailingList, $this->model->subject, $emailBody);
if (in_array('200', $this->model->status)) {
foreach ($this->model->mailingList['to'] as &$target) {
$contact = Contacts::model()->findByAttributes(array('email' => $target[1]));
if (isset($contact)) {
$action = new Actions();
$action->associationType = 'contacts';
$action->associationId = $contact->id;
$action->associationName = $contact->name;
$action->visibility = $contact->visibility;
$action->complete = 'Yes';
$action->type = 'email';
$action->completedBy = Yii::app()->user->getName();
$action->assignedTo = $contact->assignedTo;
$action->createDate = time();
$action->dueDate = time();
$action->completeDate = time();
if ($template == null) {
$action->actionDescription = '<b>' . $this->model->subject . "</b>\n\n" . $this->model->message;
} else {
$action->actionDescription = CHtml::link($template->title, array('/docs/' . $template->id));
}
if ($action->save()) {
}
// $message="2";
// $email=$toEmail;
// $id=$contact['id'];
// $note.="\n\nSent to Contact";
}
}
//.........这里部分代码省略.........