public function testSuperUserThatContactsAndLeadsShowZeroModelUserInterfaceCorrectly()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->assertEquals(0, count(Contact::getAll()));
     //At this point the zero model ui should show up for contacts and leads
     $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list');
     $this->assertFalse(strpos($content, 'Arthur Conan') === false);
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list');
     $this->assertFalse(strpos($content, 'Thomas Paine') === false);
     $contact = ContactTestHelper::createContactByNameForOwner('Jimmy', $super);
     //At this point leads should still show the zero model message
     $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list');
     $this->assertTrue(strpos($content, 'Arthur Conan') === false);
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list');
     $this->assertFalse(strpos($content, 'Thomas Paine') === false);
     $this->assertTrue($contact->delete());
     $this->assertEquals(0, count(Contact::getAll()));
     //Create lead.
     $lead = LeadTestHelper::createLeadByNameForOwner('Jammy', $super);
     //At this point contacts should still show the zero model message
     $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list');
     $this->assertFalse(strpos($content, 'Arthur Conan') === false);
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list');
     $this->assertTrue(strpos($content, 'Thomas Paine') === false);
 }
 public static function populateAutoresponderItem($processed, $processDateTime, $autoresponder = null, $contact = null)
 {
     assert('is_string($processed) || is_int($processed)');
     assert('is_string($processDateTime)');
     assert('is_object($autoresponder) || $autoresponder === null');
     assert('is_object($contact) || $contact === null');
     if (empty($autoresponder)) {
         $autoresponders = Autoresponder::getAll();
         if (!empty($autoresponders)) {
             $autoresponder = RandomDataUtil::getRandomValueFromArray($autoresponders);
         }
     }
     if (empty($contact)) {
         $contacts = Contact::getAll();
         if (!empty($contacts)) {
             $contact = RandomDataUtil::getRandomValueFromArray($contacts);
         }
     }
     $autoresponderItem = new AutoresponderItem();
     $autoresponderItem->processed = $processed;
     $autoresponderItem->processDateTime = $processDateTime;
     $autoresponderItem->autoresponder = $autoresponder;
     $autoresponderItem->contact = $contact;
     return $autoresponderItem;
 }
 public function testUnlinkContactForAccount()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $simpleUser = User::getByUsername('simpleUser');
     Yii::app()->user->userModel = $simpleUser;
     $simpleUser->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $simpleUser->setRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS);
     $simpleUser->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
     $simpleUser->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
     $this->assertTrue($simpleUser->save());
     $account = AccountTestHelper::createAccountByNameForOwner('simpleUserAccount', $simpleUser);
     $contact = ContactTestHelper::createContactWithAccountByNameForOwner('simpleUserContact', $simpleUser, $account);
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     $contacts = Contact::getAll();
     $this->assertEquals(1, count($contacts));
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'simpleUserAccount');
     $this->setGetArray(array('id' => $superAccountId));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     $contactId = self::getModelIdByModelNameAndName('Contact', 'simpleUserContact simpleUserContactson');
     //unlinking the contact
     $this->setGetArray(array('id' => $contactId, 'relationModelClassName' => 'Account', 'relationModelId' => $superAccountId, 'relationModelRelationName' => 'contacts'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/unlink', true);
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     $contacts = Contact::getAll();
     $contactId = $contacts[0]->id;
     $contacts[0]->forget();
     $contact = Contact::getById($contactId);
     $this->assertTrue($contact->account->id < 0);
 }
 public function testAdditionOfPortletsInEmptyRightPanel()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superLeadId = self::getModelIdByModelNameAndName('Contact', 'superLead superLeadson');
     $marketingListId = self::getModelIdByModelNameAndName('MarketingList', 'MarketingListName');
     $leads = Contact::getAll();
     $this->assertEquals(1, count($leads));
     //Load Model Detail Views
     $this->setGetArray(array('id' => $superLeadId, 'lockPortlets' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/details');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(3, count($portlets[1]));
     $this->assertFalse(array_key_exists(3, $portlets));
     $this->assertEquals(2, count($portlets[2]));
     foreach ($portlets[2] as $position => $portlet) {
         $portlet->delete();
     }
     $this->setGetArray(array('modelId' => $superLeadId, 'uniqueLayoutId' => 'LeadDetailsAndRelationsView', 'portletType' => 'MarketingListsForContactRelatedList', 'redirect' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('leads/defaultPortlet/add', true);
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(1, count($portlets[2]));
     //Test subscribe to list link
     $portlet = $portlets[2][1];
     $this->setGetArray(array('portletId' => $portlet->id, 'relationAttributeName' => 'lead', 'relationModelId' => $superLeadId, 'relationModuleId' => 'leads', 'uniqueLayoutId' => $portlet->getUniquePortletPageId(), 'relationModelClassName' => null));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/selectFromRelatedList');
     //Test subscribe a marketing list
     $this->setGetArray(array('modelId' => $marketingListId, 'portletId' => $portlet->id, 'relationAttributeName' => 'lead', 'relationModelId' => $superLeadId, 'relationModuleId' => 'leads', 'uniqueLayoutId' => $portlet->getUniquePortletPageId(), 'relationModelClassName' => null));
     $this->resetPostArray();
     $content = $this->runControllerWithRedirectExceptionAndGetContent('marketingLists/defaultPortlet/selectFromRelatedListSave');
 }
 public function indexAction()
 {
     $this->view->Title = "Danh sách đặt hàng";
     $this->view->headTitle($this->view->Title);
     $page = $this->getRequest()->getParam('page');
     $condition = array();
     list($this->view->Pager, $this->view->Contact) = Contact::getAll($condition, $page);
 }
 /**
  * Method for testing creating a simple notification for the current user.
  */
 public function actionGenerateManageSubscriptionHash()
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         throw new NotSupportedException();
     }
     $contact = RandomDataUtil::getRandomValueFromArray(Contact::getAll());
     $personId = $contact->getClassId('Person');
     $marketingList = RandomDataUtil::getRandomValueFromArray(MarketingList::getAll());
     $marketingListId = $marketingList->id;
     $model = RandomDataUtil::getRandomValueFromArray(CampaignItem::getAll());
     $modelId = $model->id;
     $modelType = get_class($model);
     $hash = GlobalMarketingFooterUtil::resolveHash($personId, $marketingListId, $modelId, $modelType, false);
     echo 'index.php/marketingLists/external/manageSubscriptions?hash=' . $hash;
 }
 /**
  * Method for testing creating a simple notification for the current user.
  */
 public function actionGenerateManageSubscriptionHash()
 {
     if (Yii::app()->user->userModel->username != 'super') {
         throw new NotSupportedException();
     }
     $contact = RandomDataUtil::getRandomValueFromArray(Contact::getAll());
     $personId = $contact->getClassId('Person');
     $marketingList = RandomDataUtil::getRandomValueFromArray(MarketingList::getAll());
     $marketingListId = $marketingList->id;
     $model = RandomDataUtil::getRandomValueFromArray(CampaignItem::getAll());
     $modelId = $model->id;
     $modelType = get_class($model);
     $hash = EmailMessageActivityUtil::resolveHashForUnsubscribeAndManageSubscriptionsUrls($personId, $marketingListId, $modelId, $modelType, false);
     echo 'index.php/marketingLists/external/manageSubscriptions?hash=' . $hash;
 }
 public static function populateMarketingListMember($unsubscribed = 0, $marketingList = null, $contact = null)
 {
     if (empty($marketingList)) {
         $marketingLists = MarketingList::getAll();
         if (!empty($marketingLists)) {
             $marketingList = RandomDataUtil::getRandomValueFromArray($marketingLists);
         }
     }
     if (empty($contact)) {
         $contacts = Contact::getAll();
         if (!empty($contacts)) {
             $contact = RandomDataUtil::getRandomValueFromArray($contacts);
         }
     }
     $marketingListMember = new MarketingListMember();
     $marketingListMember->unsubscribed = $unsubscribed;
     $marketingListMember->contact = $contact;
     $marketingListMember->marketingList = $marketingList;
     return $marketingListMember;
 }
 public static function fillAutoresponderItem($processed, $processDateTime, $autoresponder = null, $contact = null)
 {
     if (empty($autoresponder)) {
         $autoresponders = Autoresponder::getAll();
         if (!empty($autoresponders)) {
             $autoresponder = RandomDataUtil::getRandomValueFromArray($autoresponders);
         }
     }
     if (empty($contact)) {
         $contacts = Contact::getAll();
         if (!empty($contacts)) {
             $contact = RandomDataUtil::getRandomValueFromArray($contacts);
         }
     }
     $autoresponderItem = new AutoresponderItem();
     $autoresponderItem->processed = $processed;
     $autoresponderItem->processDateTime = $processDateTime;
     $autoresponderItem->autoresponder = $autoresponder;
     $autoresponderItem->contact = $contact;
     return $autoresponderItem;
 }
 /**
  * @param DemoDataHelper $demoDataHelper
  */
 public function makeAll(&$demoDataHelper)
 {
     assert('$demoDataHelper instanceof DemoDataHelper');
     assert('$demoDataHelper->isSetRange("Contact")');
     assert('$demoDataHelper->isSetRange("MarketingList")');
     $members = array();
     foreach (MarketingList::getAll() as $marketingList) {
         foreach (Contact::getAll() as $contact) {
             $interval = mt_rand(1, 30) * 86400;
             $member = new MarketingListMember();
             $member->setScenario('importModel');
             $member->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - $interval);
             $member->contact = $contact;
             $member->marketingList = $marketingList;
             $this->populateModel($member);
             $saved = $member->unrestrictedSave();
             assert('$saved');
             $members[] = $member->id;
         }
     }
     $demoDataHelper->setRangeByModelName('MarketingListMember', $members[0], $members[count($members) - 1]);
 }
 public static function populateCampaignItem($processed, $campaign = null, $contact = null)
 {
     assert('is_bool($processed)');
     assert('is_object($campaign) || $campaign === null');
     assert('is_object($contact) || $contact === null');
     if (empty($campaign)) {
         $campaigns = Campaign::getAll();
         if (!empty($campaigns)) {
             $campaign = RandomDataUtil::getRandomValueFromArray($campaigns);
         }
     }
     if (empty($contact)) {
         $contacts = Contact::getAll();
         if (!empty($contacts)) {
             $contact = RandomDataUtil::getRandomValueFromArray($contacts);
         }
     }
     $campaignItem = new CampaignItem();
     $campaignItem->processed = $processed;
     $campaignItem->campaign = $campaign;
     $campaignItem->contact = $contact;
     return $campaignItem;
 }
 public function indexAction()
 {
     $this->view->Title = "Contact list";
     $this->view->headTitle($this->view->Title);
     if ($this->getRequest()->getParam('contact_type')) {
         $params = $this->getRequest()->getParam('contact_type', 'List All');
         if ($params != 'List All') {
             $condition = array('contact_type =?' => $params);
             $_SESSION['contact_type'] = $params;
         } else {
             $condition = array();
             $this->view->contact_type = 'List All';
             $_SESSION['contact_type'] = 'List All';
         }
         $page = $this->getRequest()->getParam('page');
         list($this->view->Pager, $this->view->Contact) = Contact::getAll($condition, $page);
     } else {
         $page = $this->getRequest()->getParam('page');
         $condition = array();
         list($this->view->Pager, $this->view->Contact) = Contact::getAll($condition, $page);
         $_SESSION['contact_type'] = 'List All';
     }
 }
 public function testAccountAndContactIndustries()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $values = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments');
     $industryFieldData = CustomFieldData::getByName('Industries');
     $industryFieldData->defaultValue = $values[0];
     $industryFieldData->serializedData = serialize($values);
     $this->assertTrue($industryFieldData->save());
     unset($industryFieldData);
     $user = UserTestHelper::createBasicUser('Billy');
     $account = new Account();
     $account->name = 'Consoladores-R-Us';
     $account->owner = $user;
     $data = unserialize($account->industry->data->serializedData);
     $this->assertEquals('Automotive', $account->industry->value);
     $account->industry->value = $values[1];
     $this->assertTrue($account->save());
     unset($account);
     ContactsModule::loadStartingData();
     $states = ContactState::GetAll();
     $contact = new Contact();
     $contact->firstName = 'John';
     $contact->lastName = 'Johnson';
     $contact->owner = $user;
     $contact->state = $states[0];
     $values = unserialize($contact->industry->data->serializedData);
     $this->assertEquals(4, count($values));
     $contact->industry->value = $values[3];
     $this->assertTrue($contact->save());
     unset($contact);
     $accounts = Account::getByName('Consoladores-R-Us');
     $account = $accounts[0];
     $this->assertEquals('Adult Entertainment', $account->industry->value);
     $contacts = Contact::getAll();
     $contact = $contacts[0];
     $this->assertEquals('Mercenaries & Armaments', $contact->industry->value);
 }
 /**
  * @dataProvider dataForTestGetChartData
  */
 public function testGetChartData($activityCreationArray, $emailMessageSentDateTime, $isMultiplierOn)
 {
     $contacts = Contact::getAll();
     $this->addCampaignItem($contacts[0], $emailMessageSentDateTime, $activityCreationArray);
     $this->addAutoresponderItem($contacts[0], $emailMessageSentDateTime, $activityCreationArray);
     if ($isMultiplierOn) {
         $this->addCampaignItem($contacts[1], $emailMessageSentDateTime, $activityCreationArray);
         $this->addAutoresponderItem($contacts[1], $emailMessageSentDateTime, $activityCreationArray);
     }
     $isSent = true;
     if (!isset($emailMessageSentDateTime)) {
         $emailMessageSentDateTime = date('Y-m-d');
         $isSent = false;
     }
     //Test when beginDate < sentDate < endDate
     //Grouping by day
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'between', MarketingOverallMetricsForm::GROUPING_TYPE_DAY, $isSent, $isMultiplierOn);
     //Grouping by week
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'between', MarketingOverallMetricsForm::GROUPING_TYPE_WEEK, $isSent, $isMultiplierOn);
     //Grouping by month
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'between', MarketingOverallMetricsForm::GROUPING_TYPE_MONTH, $isSent, $isMultiplierOn);
     //Test when beginDate < endDate < sentDate
     //Grouping by day
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'after', MarketingOverallMetricsForm::GROUPING_TYPE_DAY, $isSent, $isMultiplierOn);
     //Grouping by week
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'after', MarketingOverallMetricsForm::GROUPING_TYPE_WEEK, $isSent, $isMultiplierOn);
     //Grouping by month
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'after', MarketingOverallMetricsForm::GROUPING_TYPE_MONTH, $isSent, $isMultiplierOn);
     //Test when sentDate < beginDate < endDate
     //Grouping by day
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'before', MarketingOverallMetricsForm::GROUPING_TYPE_DAY, $isSent, $isMultiplierOn);
     //Grouping by week
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'before', MarketingOverallMetricsForm::GROUPING_TYPE_WEEK, $isSent, $isMultiplierOn);
     //Grouping by month
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'before', MarketingOverallMetricsForm::GROUPING_TYPE_MONTH, $isSent, $isMultiplierOn);
     //Test when sentDate = beginDate = endDate
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'equals', MarketingOverallMetricsForm::GROUPING_TYPE_DAY, $isSent, $isMultiplierOn);
     //Grouping by week
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'equals', MarketingOverallMetricsForm::GROUPING_TYPE_WEEK, $isSent, $isMultiplierOn);
     //Grouping by month
     $this->assertChartDataAsExpectedBySentTimeAndConditionAndGroupingBy($activityCreationArray, $emailMessageSentDateTime, 'equals', MarketingOverallMetricsForm::GROUPING_TYPE_MONTH, $isSent, $isMultiplierOn);
 }
Exemple #15
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/contact.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
session_start();
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
$app->get("/", function () use($app) {
    return $app['twig']->render('home.html.twig', array('all_contacts' => Contact::getAll()));
});
$app->post("/create_contact", function () use($app) {
    $my_contact = new Contact($_POST['name'], $_POST['phone'], $_POST['address']);
    $my_contact->save();
    return $app['twig']->render('create_contact.html.twig', array('new_contact' => $my_contact));
});
$app->post("/delete_contacts", function () use($app) {
    $_SESSION['list_of_contacts'] = array();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;
Exemple #16
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contacts.php";
//this creates and checks for cookies
session_start();
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
//////////instantiate Silex and Twig/////////////
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
////////////These are the routes//////////////////
//////////////////Landing Page////////////////////
$app->get("/", function () use($app) {
    ///$app uses twig to render contacts page and passes through Contact class to build its array of contacts
    return $app['twig']->render('contacts.html.twig', array('list_of_contacts' => Contact::getAll()));
});
/////////////////Create Contact Page//////////////////////
$app->post("/create_contact", function () use($app) {
    ///////pushes new contacts to session array
    $contact = new Contact($_POST['name'], $_POST['phone_number'], $_POST['address']);
    ////saves to session array
    $contact->save();
    //////twig uses $app to render contacts page with the newly instatiated contacts
    return $app['twig']->render('create_contact.html.twig', array('newcontact' => $contact));
});
/////////////////Clear all Contacts Page//////////////////
$app->post("/delete_contacts", function () use($app) {
    //////////delete all function writes blank array to clear contacts
    Contact::deleteAll();
    //////////twig uses app to render contacts delete page.
 /**
  *Test Bug with mass delete and multiple pages when using select all
  */
 public function testRegularMassDeletePagesProperlyAndRemovesAllSelected()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $confused = User::getByUsername('confused');
     $nobody = User::getByUsername('nobody');
     //Load MassDelete view for the 8 leads.
     $leads = Contact::getAll();
     $this->assertEquals(8, count($leads));
     //Deleting all leads
     //mass Delete pagination scenario
     //Run Mass Delete using progress save for page1
     $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 8));
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/massDelete');
     $leads = Contact::getAll();
     $this->assertEquals(3, count($leads));
     //Run Mass Delete using progress save for page2
     $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 8));
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/massDeleteProgress');
     $leads = Contact::getAll();
     //BelinaLead1 was converted to a contact, so she is not removed
     $this->assertContains('BelinaLead1', serialize($leads));
     $this->assertEquals(1, count($leads));
 }
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::getAll();
     $this->assertEquals(0, count($contacts));
     $import = new Import();
     $serializedData['importRulesType'] = 'Leads';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.leads.tests.unit.files'));
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('jobTitle'), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('department'), 'column_6' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__city'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__country'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__postalCode'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__state'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street1'), 'column_13' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street2'), 'column_14' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_16' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_18' => LeadImportTestHelper::makeStateColumnMappingData(), 'column_19' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_20' => ImportMappingUtil::makeStringColumnMappingData('companyName'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Leads');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $contacts = Contact::getAll();
     $this->assertEquals(3, count($contacts));
     $contacts = Contact::getByName('contact1 contact1son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact1', $contacts[0]->firstName);
     $this->assertEquals('contact1son', $contacts[0]->lastName);
     $this->assertEquals('president', $contacts[0]->jobTitle);
     $this->assertEquals(123456, $contacts[0]->officePhone);
     $this->assertEquals(555, $contacts[0]->officeFax);
     $this->assertEquals('executive', $contacts[0]->department);
     $this->assertEquals('http://www.contact1.com', $contacts[0]->website);
     $this->assertEquals('desc1', $contacts[0]->description);
     $this->assertEquals('city1', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country1', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal1', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state1', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street11', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street21', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Self-Generated', $contacts[0]->source->value);
     $this->assertEquals('New', $contacts[0]->state->name);
     $this->assertEquals('Automotive', $contacts[0]->industry->value);
     $this->assertEquals('company1', $contacts[0]->companyName);
     $contacts = Contact::getByName('contact2 contact2son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact2', $contacts[0]->firstName);
     $this->assertEquals('contact2son', $contacts[0]->lastName);
     $this->assertEquals('president2', $contacts[0]->jobTitle);
     $this->assertEquals(223456, $contacts[0]->officePhone);
     $this->assertEquals(655, $contacts[0]->officeFax);
     $this->assertEquals('executive2', $contacts[0]->department);
     $this->assertEquals('http://www.contact2.com', $contacts[0]->website);
     $this->assertEquals('desc2', $contacts[0]->description);
     $this->assertEquals('city2', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country2', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal2', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state2', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street12', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street22', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Tradeshow', $contacts[0]->source->value);
     $this->assertEquals('Recycled', $contacts[0]->state->name);
     $this->assertEquals('Banking', $contacts[0]->industry->value);
     $this->assertEquals('company2', $contacts[0]->companyName);
     $contacts = Contact::getByName('contact3 contact3son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact3', $contacts[0]->firstName);
     $this->assertEquals('contact3son', $contacts[0]->lastName);
     $this->assertEquals('president3', $contacts[0]->jobTitle);
     $this->assertEquals(323456, $contacts[0]->officePhone);
     $this->assertEquals(755, $contacts[0]->officeFax);
     $this->assertEquals('executive3', $contacts[0]->department);
     $this->assertEquals('http://www.contact3.com', $contacts[0]->website);
     $this->assertEquals('desc3', $contacts[0]->description);
     $this->assertEquals('city3', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country3', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal3', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state3', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street13', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street23', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals('1', $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals('1', $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Inbound Call', $contacts[0]->source->value);
     $this->assertEquals('New', $contacts[0]->state->name);
     $this->assertEquals('Energy', $contacts[0]->industry->value);
     $this->assertEquals('company3', $contacts[0]->companyName);
     //Confirm 3 rows were processed as 'created'.
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED));
     //Confirm that 0 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 0 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 /**
  * @depends testMakeReportDataProviderAndResolveAttributeName
  */
 public function testGetContactIdsByReportDataProviderAndAttributeName()
 {
     $contactReports = SavedReport::getAll();
     $contactReport = $contactReports[0];
     $contacts = Contact::getAll();
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 1, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(1, $contactIds);
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 2, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(2, $contactIds);
     $this->assertContains($contacts[0]->id, $contactIds);
     $this->assertContains($contacts[1]->id, $contactIds);
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     $contacts = Contact::getAll();
     if (count($contacts)) {
         foreach ($contacts as $contact) {
             $contact->delete();
         }
     }
     $leads = array();
     for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) {
         $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account);
     }
     $this->setGetArray(array('Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('leads', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     // Now test case when multiple ids are selected
     $exportItems = ExportItem::getAll();
     if (count($exportItems)) {
         foreach ($exportItems as $exportItem) {
             $exportItem->delete();
         }
     }
     $selectedIds = "";
     foreach ($leads as $lead) {
         $selectedIds .= $lead->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => '', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('leads', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
 }
    return $app['twig']->render('index.html.twig', array('contacts' => Contact::getAll()));
});
$app->get("/add_contact", function () use($app) {
    return $app['twig']->render('index.html.twig', array('form' => true));
});
$app->post("/add_contact_success", function () use($app) {
    $new_contact = new Contact($_POST['first_name'], $_POST['last_name'], $_POST['email'], $_POST['phone'], $_POST['street_address'], $_POST['city'], $_POST['state'], $_POST['zip_code'], $_POST['notes']);
    $new_contact->saveContact();
    return $app['twig']->render('index.html.twig', array('contacts' => Contact::getAll(), 'message' => array('type' => 'success', 'text' => $new_contact->getFullName() . ' has been added to your address book.')));
});
$app->get("/delete_contact", function () use($app) {
    return $app['twig']->render('index.html.twig', array('contacts' => Contact::getAll(), 'delete' => true));
});
$app->post("/delete_contact_success", function () use($app) {
    foreach ($_SESSION['list_of_contacts'] as $key => $contact) {
        if ($contact->getContactID() == $_POST['delete_contact']) {
            break;
        }
    }
    $name_of_deleted = $_SESSION['list_of_contacts'][$key]->getFullName();
    $_SESSION['list_of_contacts'][$key]->deleteContact();
    return $app['twig']->render('index.html.twig', array('contacts' => Contact::getAll(), 'message' => array('type' => 'danger', 'text' => $name_of_deleted . ' has been successfully removed from your address book.')));
});
$app->get("/delete_all_contacts", function () use($app) {
    return $app['twig']->render('confirm_delete.html.twig');
});
$app->post("/delete_all_contacts_success", function () use($app) {
    Contact::deleteAll();
    return $app['twig']->render('index.html.twig', array('contacts' => Contact::getAll(), 'message' => array('type' => 'danger', 'text' => 'What have you done!?! All your contacts are gone...')));
});
return $app;
 function testDeleteCategoryContacts()
 {
     //arrange
     $name = "Business";
     $id = null;
     $test_category = new Category($name, $id);
     $test_category->save();
     $contact_name = "Jane Doe";
     $phone_number = "555-555-5555";
     $address = "5 Main Street, Anytown, Anystate 55555";
     $category_id = $test_category->getId();
     $test_contact = new Contact($contact_name, $phone_number, $address, $id, $category_id);
     $test_contact->save();
     //act
     $test_category->delete();
     //assert
     $this->assertEquals([], Contact::getAll());
 }
Exemple #23
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contact.php";
require_once __DIR__ . "/../src/Address.php";
session_start();
if (empty($_SESSION['contact-list'])) {
    $_SESSION['contact-list'] = array();
}
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('address_book.html.twig', array('contacts' => Contact::getAll()));
});
$app->post("/show", function () use($app) {
    $contact = new Contact($_POST['name'], $_POST['phone'], new Address($_POST['street'], $_POST['city'], $_POST['state']));
    $contact->save();
    return $app['twig']->render('contact_added.html.twig', array('contact' => $contact));
});
$app->post("/clear", function () use($app) {
    Contact::reset();
    return $app['twig']->render('deleted_contacts.html.twig', array('contacts' => Contact::getAll()));
});
$app->get("/new", function () use($app) {
    return $app['twig']->render('new_contact.html.twig');
});
return $app;
Exemple #24
0
 public function testProductSaveWithPermissions()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::getAll();
     $accounts = Account::getByName('superAccount');
     $opportunities = Opportunity::getByName('superOpportunity');
     $productTemplates = ProductTemplate::getByName('superProductTemplate');
     $account = $accounts[0];
     $user = $account->owner;
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $currencyHelper = Yii::app()->currencyHelper;
     $currencyCode = $currencyHelper->getBaseCode();
     $currency = Currency::getByCode($currencyCode);
     $postData = array('productTemplate' => array('id' => $productTemplates[0]->id), 'name' => 'ProductPermissionTest', 'quantity' => 6, 'account' => array('id' => $accounts[0]->id), 'contact' => array('id' => $contacts[0]->id), 'opportunity' => array('id' => ''), 'type' => ProductTemplate::TYPE_PRODUCT, 'priceFrequency' => ProductTemplate::PRICE_FREQUENCY_ONE_TIME, 'sellPrice' => array('currency' => array('id' => $currency->id), 'value' => 210), 'stage' => array('value' => 'Open'), 'owner' => array('id' => $user->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => ''));
     $model = new Product();
     $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $postData);
     if ($model instanceof SecurableItem) {
         $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::resolveByPostDataAndModelThenMake($sanitizedPostData, $model);
     } else {
         $explicitReadWriteModelPermissions = null;
     }
     $readyToUseData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($sanitizedPostData);
     $sanitizedOwnerData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($readyToUseData, 'owner');
     $sanitizedDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($readyToUseData, 'owner');
     $model->setAttributes($sanitizedDataWithoutOwner);
     if ($model->validate()) {
         $modelToStringValue = strval($model);
         if ($sanitizedOwnerData != null) {
             $model->setAttributes($sanitizedOwnerData);
         }
         if ($model instanceof OwnedSecurableItem) {
             $passedOwnerValidation = $model->validate(array('owner'));
         } else {
             $passedOwnerValidation = true;
         }
         if ($passedOwnerValidation && $model->save(false)) {
             if ($explicitReadWriteModelPermissions != null) {
                 $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($model, $explicitReadWriteModelPermissions);
                 //todo: handle if success is false, means adding/removing permissions save failed.
             }
             $savedSuccessfully = true;
         }
     } else {
     }
     $this->assertEquals('ProductPermissionTest', $model->name);
 }
 public function testToggleUnsubscribed()
 {
     $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingList4', 'MarketingList Description4');
     $this->assertNotNull($marketingList);
     $contact = RandomDataUtil::getRandomValueFromArray(Contact::getAll());
     $this->assertNotEmpty($contact);
     $previousUnsubcribedValue = 1;
     $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember($previousUnsubcribedValue, $marketingList, $contact);
     $marketingListMemberId = $marketingListMember->id;
     $this->assertNotNull($marketingListMember);
     $this->setGetArray(array('id' => $marketingListMemberId));
     $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/toggleUnsubscribed', true);
     $this->assertEmpty($content);
     $marketingListMember = MarketingListMember::getById($marketingListMemberId);
     $newUnsubscribedValue = $marketingListMember->unsubscribed;
     $this->assertNotEquals($previousUnsubcribedValue, $newUnsubscribedValue);
 }
 /**
  * @depends testRemoveDoesntDeleteRelatedModels
  */
 public function testRemoveAll()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $accounts = Account::getByName('Wibble Corp');
     $this->assertEquals(1, count($accounts));
     $account = $accounts[0];
     $this->assertEquals(self::CONTACTS, count(Contact::getAll()));
     $this->assertEquals(self::CONTACTS - 1, $account->contacts->count());
     $account->contacts->removeAll();
     $this->assertEquals(0, $account->contacts->count());
     $account->forget();
     unset($account);
     // None of the contacts should be removed since they are not owned by the account.
     $this->assertEquals(self::CONTACTS, count(Contact::getAll()));
 }
 /**
  *Test Bug with mass delete and multiple pages when using select all
  */
 public function testMassDeletePagesProperlyAndRemovesAllSelected()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //MassDelete for selected Record Count
     $leads = Contact::getAll();
     $this->assertEquals(9, count($leads));
     //save Model MassDelete for entire search result
     $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 6));
     //Run Mass Delete using progress save for page1.
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $this->runControllerWithExitExceptionAndGetContent('leads/default/massDelete');
     //check for previous mass delete progress
     $leads = Contact::getAll();
     $this->assertEquals(4, count($leads));
     $this->setGetArray(array('selectAll' => '1', 'Contact_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 6));
     //Run Mass Delete using progress save for page2.
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/massDeleteProgress');
     //calculating lead's count
     $leads = Contact::getAll();
     /* ContactNotLead, superLead5, superLead6 was converted to a contact.
      *  so this leads are not removed
      */
     $this->assertFalse(strpos(serialize($leads), 'ContactNotLead') === false);
     $this->assertFalse(strpos(serialize($leads), 'superLead5') === false);
     $this->assertFalse(strpos(serialize($leads), 'superLead6') === false);
     $this->assertEquals(3, count($leads));
 }
Exemple #28
0
    $_SESSION['list_of_contacts'] = array();
}
// creates a new Silex\Application object
$contact_app = new Silex\Application();
// debugging
$contact_app['debug'] = true;
// makes the twig library available to the application and tells twig to
// look for out template in the views folder
$contact_app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
// calls the get $method on the $contact_app object and receives a URL path
// as its first argument, and a function that gives us access to the
// $contact_app variable, then returns the $contact_app object (using twig)
// to call the render method (which receives a file path that contains the
// twig template and an array that contains the contact list)
$contact_app->get("/", function () use($contact_app) {
    return $contact_app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll()));
});
// calls the post method on the $contact_app object and receives a URL path
// as its first argument, and a function that gives us access to the
// $contact_app variable. the method then creats a new contact object based
// on the date it receives from the form, and then saves (or pushes) the
// new object onto the $_SESSION array. then the method returns the
// $contact_app object (using twig) to call the render method (which
// receives a file path that contains the twig template and an array that
// contains the new contact object, which is added to the list)
$contact_app->post("/contacts", function () use($contact_app) {
    $new_contact = new Contact($_POST['add_name'], $_POST['add_number'], $_POST['add_address']);
    $new_contact->save();
    return $contact_app['twig']->render('create_contact.html.twig', array('newcontact' => $new_contact));
});
// calls the post method on the $contact_app object and receives a URL path
Exemple #29
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Contact.php";
session_start();
//creates 'list_of_contacts' array if SESSION is empty
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
//root or homepage route
$app->get("/", function () use($app) {
    return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll()));
});
//saves a new contact and routes the user to /create_contact
$app->post("/create_contact", function () use($app) {
    $contact = new Contact($_POST['create_name'], $_POST['create_phone'], $_POST['create_address']);
    $contact->save();
    return $app['twig']->render('create_contact.html.twig', array('contacts' => Contact::getAll()));
});
//deletes ALL contacts and routes user to /delete_contacts
$app->post('/delete_contacts', function () use($app) {
    Contact::deleteAll();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;
Exemple #30
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Contact.php';
session_start();
if (empty($_SESSION['list_of_contacts'])) {
    $_SESSION['list_of_contacts'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('address_book.html.twig', array('contacts' => Contact::getAll()));
});
$app->get('/create_contact', function () use($app) {
    return $app['twig']->render('create_contact.html.twig');
});
$app->post('/add_contact', function () use($app) {
    $new_contact = new Contact($_POST['first_name'], $_POST['last_name'], $_POST['street'], $_POST['city'], $_POST['zip'], $_POST['phone'], $_POST['image']);
    $new_contact->save();
    return $app['twig']->render('add_contact.html.twig', array('newcontacts' => $new_contact));
});
$app->get('/delete_contacts', function () use($app) {
    Contact::deleteAll();
    return $app['twig']->render('delete_contacts.html.twig');
});
return $app;