public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         $search = strval(Tools::getValue('search'));
         $string = strval(Tools::getValue('alias'));
         $aliases = explode(',', $string);
         if (empty($search) or empty($string)) {
             $this->_errors[] = $this->l('aliases and result are both required');
         }
         if (!Validate::isValidSearch($search)) {
             $this->_errors[] = $search . ' ' . $this->l('is not a valid result');
         }
         foreach ($aliases as $alias) {
             if (!Validate::isValidSearch($alias)) {
                 $this->_errors[] = $alias . ' ' . $this->l('is not a valid alias');
             }
         }
         if (!sizeof($this->_errors)) {
             foreach ($aliases as $alias) {
                 $obj = new Alias(NULL, trim($alias), trim($search));
                 $obj->save();
             }
         }
     } else {
         parent::postProcess();
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Alias a')->where('NOT EXISTS( SELECT id FROM alias a WHERE a.entity_id = e.id AND a.context IS NULL AND a.name = e.name)')->limit($options['limit']);
     foreach ($q->execute() as $entity) {
         try {
             $db->beginTransaction();
             $primary = $entity->primary_ext;
             if ($primary == 'Person') {
                 $name = $entity->getExtensionObject('Person')->getFullName(false, $filterSuffix = true);
                 //change entity name
                 $entity->setEntityField('name', $name);
                 $entity->save();
             } else {
                 $name = $entity->rawGet('name');
             }
             //create primary Alias
             $a = new Alias();
             $a->Entity = $entity;
             $a->name = $name;
             $a->is_primary = true;
             $a->save();
             //create another Alias if there's a nickname
             if ($primary == 'Person' && $entity->name_nick) {
                 $a = new Alias();
                 $a->Entity = $entity;
                 $a->name = $primary == 'Person' ? $entity->name_nick . ' ' . $entity->name_last : $entity->name_nick;
                 $a->is_primary = false;
                 $a->save();
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollback();
             throw $e;
         }
     }
     LsCli::beep();
 }
Example #3
0
 public function import($school)
 {
     if (EntityTable::getByExtensionQuery('Org')->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->instnm) . "%")->fetchOne()) {
         $this->printDebug("School exists in database: " . $school->instnm);
     } else {
         $address = new Address();
         $address->street1 = isset($school->addr) ? $school->addr : null;
         $address->street2 = isset($school->street2) ? $school->street2 : null;
         $address->city = $school->city;
         if ($state = AddressStateTable::retrieveByText($school->stabbr)) {
             $address->State = $state;
         }
         $address->postal = $school->zip;
         $aliases = explode("|", $school->ialias);
         $website = null;
         if (!preg_match('/^http\\:\\/\\//i', trim($school->webaddr))) {
             $website = "http://" . strtolower($school->webaddr);
         }
         $this->printDebug($website);
         $newschool = new Entity();
         $newschool->addExtension('Org');
         $newschool->addExtension('School');
         $newschool->name = $school->instnm;
         $newschool->website = $website;
         $newschool->addAddress($address);
         $newschool->save();
         foreach ($aliases as $alias) {
             try {
                 $newalias = new Alias();
                 $newalias->Entity = $newschool;
                 $newalias->name = $alias;
                 $newalias->save();
             } catch (Exception $e) {
                 $this->printDebug("An alias exception. No biggie. It's most likely that the name already exists. so we ignore it and move on: " . $e);
             }
         }
         $this->printDebug("Adding new school: " . $school->instnm);
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     //CREATE NEW PRIMARY ALIASES
     $q = Doctrine_Query::create()->from('Entity e')->where('NOT EXISTS (SELECT id FROM Alias a WHERE a.entity_id = e.id AND a.is_primary = ?)', true)->limit($options['limit']);
     foreach ($q->fetchArray() as $entity) {
         $a = new Alias();
         $a->name = $entity['name'];
         $a->is_primary = true;
         $a->entity_id = $entity['id'];
         $a->save(false);
     }
     //REMOVE DUPLIATE PRIMARY ALIASES
     $q = Doctrine_Query::create()->from('Alias a1')->where('a1.is_primary = ?', true)->andWhere('EXISTS (SELECT a2.id FROM Alias a2 WHERE a1.entity_id = a2.entity_id AND a2.is_primary = ? AND a1.id > a2.id)', true);
     foreach ($q->execute() as $alias) {
         $alias->delete();
     }
     //DONE
     LsCli::beep();
 }
 function import(Entity $person, $possible_persons)
 {
     //loop through the people we found. usually just one.
     foreach ($possible_persons as $possible_person) {
         $this->printDebug('Query returned ' . count($possible_person) . ' person named ' . $possible_person->name);
         //this person does not provide education. we skip
         if (count($possible_person->education)) {
             $this->printDebug('Education found');
         } else {
             $this->printDebug('No education history found');
             continue;
         }
         //get employement info for this possible match
         $possible_person_bio = $possible_person->summary;
         if (count($possible_person->employment_history)) {
             foreach ($possible_person->employment_history as $employment) {
                 $possible_person_bio .= ' ' . $employment->company . " ";
             }
             $this->printDebug('Employment found');
         } else {
             $this->printDebug('No employment history found');
             continue;
         }
         //get employment info for the person in our database
         $relationship_orgs = $person->getRelatedEntitiesQuery('Org', RelationshipTable::POSITION_CATEGORY, null, null, null, false, 1)->execute();
         $person_bio = $person->summary;
         foreach ($relationship_orgs as $org) {
             $person_bio .= ' ' . $org->name;
         }
         //lets see how many matches we get
         $matches = LsLanguage::getCommonPronouns($person_bio, trim($possible_person_bio), LsLanguage::$business);
         if (count($matches)) {
             foreach ($possible_person->education as $school) {
                 $school->institution = mb_convert_encoding($school->institution, 'UTF-8');
                 $school->institution = preg_replace('/–/isu', ' ', $school->institution);
                 $this->printDebug('Looking for the school: ' . $school->institution);
                 $current_school = EntityTable::findByAlias($school->institution, $context = 'bw_school');
                 //find school
                 if ($current_school) {
                     $this->printDebug('Found school');
                 } else {
                     $current_school = EntityTable::getByExtensionQuery(array('Org', 'School'))->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->institution) . "%")->fetchOne();
                     if (!$current_school) {
                         $new_school = new Entity();
                         $new_school->addExtension('Org');
                         $new_school->addExtension('School');
                         $new_school->name = $school->institution;
                         $wikipedia = new LsWikipedia();
                         $wikipedia->request($school->institution);
                         if ($wikipedia->execute() && !$wikipedia->isDisambiguation()) {
                             $info_box = $wikipedia->getInfoBox();
                             if (isset($info_box['students']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['students']['clean'], $match)) {
                                 $new_school->students = LsNumber::clean($match[1]);
                             } else {
                                 $student_types = array('undergrad', 'postgrad', 'grad', 'doctoral');
                                 $num_students = 0;
                                 foreach ($student_types as $st) {
                                     if (isset($info_box[$st]) && preg_match('/([\\d\\,]{2,})/isu', $info_box[$st]['clean'], $match)) {
                                         $num_students += LsNumber::clean($match[1]);
                                     }
                                 }
                                 if ($num_students > 0) {
                                     $new_school->students = $num_students;
                                 }
                             }
                             if (isset($info_box['faculty']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['faculty']['clean'], $match)) {
                                 $new_school->faculty = LsNumber::clean($match[1]);
                             }
                             if (isset($info_box['type'])) {
                                 if (stristr($info_box['type']['clean'], 'public')) {
                                     $new_school->is_private = 0;
                                 } else {
                                     if (stristr($info_box['type']['clean'], 'private')) {
                                         $new_school->is_private = 1;
                                     }
                                 }
                             }
                             if (isset($info_box['endowment'])) {
                                 if (preg_match('/(\\$[\\d\\,\\.\\s]+)(million|billion)/isu', $info_box['endowment']['clean'], $match)) {
                                     if (strtolower($match[2]) == 'billion') {
                                         $factor = 1000000000;
                                     } else {
                                         $factor = 1000000;
                                     }
                                     $new_school->endowment = LsNumber::formatDollarAmountAsNumber($match[1], $factor);
                                 }
                             }
                             if (isset($info_box['established'])) {
                                 $year = null;
                                 if ($date = LsDate::convertDate($info_box['established']['clean'])) {
                                     $new_school->start_date = $date;
                                 } else {
                                     if (preg_match('/\\b(\\d\\d\\d\\d)\\b/isu', $info_box['established']['clean'], $match)) {
                                         $new_school->start_date = $match[1];
                                     }
                                 }
                             }
                             $summary = trim($wikipedia->getIntroduction());
                             $summary = preg_replace('/\\n\\s*\\n/isu', '', $summary);
                             if (strlen($summary) > 10) {
                                 $new_school->summary = $summary;
                             }
                             $new_school->save();
                             $new_school->addReference($source = $wikipedia->getUrl(), $excerpt = null, $fields = array('summary'), $name = 'Wikipedia');
                         } else {
                             $new_school->save();
                         }
                         $current_school = $new_school;
                         $this->printDebug('Adding new school');
                     }
                     $alias = new Alias();
                     $alias->name = $school->institution;
                     $alias->context = 'bw_school';
                     $alias->Entity = $current_school;
                     $alias->save();
                 }
                 //find degree
                 $degree = null;
                 if (!($degree = DegreeTable::getByText($school->degree))) {
                     $degree = DegreeTable::addDegree($school->degree);
                     $this->printDebug('Adding new degree');
                 }
                 //find relationship
                 $relationship = null;
                 $relationships = $person->getRelationshipsWithQuery($current_school, RelationshipTable::EDUCATION_CATEGORY)->execute();
                 foreach ($relationships as $existing_relationship) {
                     if ($existing_relationship->degree_id == $degree->id) {
                         $relationship = $existing_relationship;
                         break;
                     }
                 }
                 if ($relationship) {
                     $this->printDebug('Relationship between person and school exists');
                 } else {
                     $relationship = new Relationship();
                     $relationship->Entity1 = $person;
                     $relationship->Entity2 = $current_school;
                     $relationship->description1 = 'student';
                     $relationship->is_current = 0;
                     if ($school->year) {
                         $relationship->end_date = $school->year;
                     }
                     $relationship->setCategory('Education');
                     $this->printDebug('Creating new relationship between person and school');
                 }
                 //save
                 $relationship->save();
                 //add degree and reference
                 if ($relationship->degree_id == null) {
                     $reference_name = strstr($school->source, 'wikipedia') ? "Wikipedia" : "BusinessWeek";
                     $relationship->Degree = $degree;
                     $relationship->save();
                     $relationship->addReference($source = $school->source, $excerpt = null, $fields = array('degree_id'), $name = $reference_name, $detail = null, $date = null);
                     $this->printDebug('Adding degree and reference');
                 }
             }
         } else {
             $this->printDebug('No organization matches');
             return false;
         }
     }
     return true;
 }
Example #6
0
 /**
  * Edit a mailbox.
  */
 public function editAction()
 {
     if (!$this->_mailbox) {
         $this->_mailbox = new Mailbox();
     }
     $this->view->mailboxModel = $this->_mailbox;
     $domainList = DomainTable::getDomains($this->getAdmin());
     $editForm = new ViMbAdmin_Form_Mailbox_Edit(null, $domainList);
     $editForm->setDefaults($this->_mailbox->toArray());
     if ($this->_mailbox['id']) {
         $editForm->removeElement('password');
         $editForm->getElement('local_part')->setAttrib('disabled', 'disabled')->setRequired(false);
         $editForm->getElement('domain')->setAttrib('disabled', 'disabled')->setRequired(false);
     } else {
         $editForm->getElement('domain')->setValue($this->_domain->id);
     }
     if ($this->getRequest()->isPost() && $editForm->isValid($_POST)) {
         do {
             // do we have a domain
             if (!$this->_domain) {
                 $this->_domain = Doctrine::getTable('Domain')->find($editForm->getElement('domain')->getValue());
                 if (!$this->_domain || !$this->authorise(false, $this->_domain, false)) {
                     $this->addMessage(_("Invalid, unauthorised or non-existent domain."), ViMbAdmin_Message::ERROR);
                     $this->_redirect('domain/list');
                 }
             }
             if ($this->_mailbox['id']) {
                 $this->_domain = $this->_mailbox->Domain;
                 $editForm->removeElement('local_part');
                 $editForm->removeElement('domain');
                 $editForm->removeElement('password');
                 $this->_mailbox->fromArray($editForm->getValues());
                 $op = 'edit';
             } else {
                 // do we have available mailboxes?
                 if (!$this->getAdmin()->isSuper() && $this->_domain['mailboxes'] != 0 && $this->_domain->countMailboxes() >= $this->_domain['mailboxes']) {
                     $this->_helper->viewRenderer->setNoRender(true);
                     $this->addMessage(_('You have used all of your allocated mailboxes.'), ViMbAdmin_Message::ERROR);
                     break;
                 }
                 $this->_mailbox->fromArray($editForm->getValues());
                 $this->_mailbox['domain'] = $this->_domain['domain'];
                 $this->_mailbox['username'] = "******";
                 $this->_mailbox['homedir'] = $this->_options['defaults']['mailbox']['homedir'];
                 $this->_mailbox['uid'] = $this->_options['defaults']['mailbox']['uid'];
                 $this->_mailbox['gid'] = $this->_options['defaults']['mailbox']['gid'];
                 $this->_mailbox->formatMaildir($this->_options['defaults']['mailbox']['maildir']);
                 $plainPassword = $this->_mailbox['password'];
                 $this->_mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $this->_mailbox['password'], $this->_options['defaults']['mailbox']['password_hash']);
                 // is the mailbox address valid?
                 if (!Zend_Validate::is("{$this->_mailbox['local_part']}@{$this->_mailbox['domain']}", 'EmailAddress', array(1, null))) {
                     $editForm->getElement('local_part')->addError(_('Invalid email address.'));
                     break;
                 }
                 // does a mailbox of the same name exist?
                 $dup = Doctrine_Query::create()->from('Mailbox m')->where('m.local_part = ?', $this->_mailbox['local_part'])->andWhere('m.domain = ?', $this->_mailbox['domain'])->execute(null, Doctrine_Core::HYDRATE_ARRAY);
                 if (count($dup)) {
                     $this->addMessage(_('Mailbox already exists for') . " {$this->_mailbox['local_part']}@{$this->_mailbox['domain']}", ViMbAdmin_Message::ERROR);
                     break;
                 }
                 if ($this->_options['mailboxAliases'] == 1) {
                     $aliasModel = new Alias();
                     $aliasModel->address = $this->_mailbox['username'];
                     $aliasModel->goto = $this->_mailbox['username'];
                     $aliasModel->domain = $this->_domain['domain'];
                     $aliasModel->active = 1;
                     $aliasModel->save();
                 }
                 $op = 'add';
             }
             // check quota
             if ($this->_domain['quota'] != 0) {
                 if ($this->_mailbox['quota'] <= 0 || $this->_mailbox['quota'] > $this->_domain['quota']) {
                     $this->_mailbox['quota'] = $this->_domain['quota'];
                     $this->addMessage(_("Mailbox quota set to ") . $this->_domain['quota'], ViMbAdmin_Message::ALERT);
                 }
             }
             $this->_mailbox->save();
             if ($editForm->getValue('welcome_email')) {
                 if (!$this->_sendSettingsEmail($editForm->getValue('cc_welcome_email') ? $editForm->getValue('cc_welcome_email') : false, $plainPassword, true)) {
                     $this->addMessage(_('Could not sent welcome email'), ViMbAdmin_Message::ALERT);
                 }
             }
             LogTable::log('MAILBOX_' . ($op == 'add' ? 'ADD' : 'EDIT'), print_r($this->_mailbox->toArray(), true), $this->getAdmin(), $this->_mailbox['domain']);
             $this->_helper->viewRenderer->setNoRender(true);
             $this->addMessage(_('You have successfully added/edited the mailbox record.'), ViMbAdmin_Message::SUCCESS);
             return print $this->view->render('close_colorbox_reload_parent.phtml');
         } while (false);
         // break-able clause
     }
     if ($this->_domain) {
         $editForm->getElement('domain')->setValue($this->_domain['id']);
     }
     $this->view->editForm = $editForm;
 }
Example #7
0
 public function executeAddAlias($request)
 {
     if (!$request->isMethod('post')) {
         $this->forward('error', 'invalid');
     }
     $this->checkEntity($request, false, false);
     if (!($name = $request->getParameter('alias'))) {
         $request->setError('alias', 'Alias is required');
         $this->setTemplate('editAliases');
         return sfView::SUCCESS;
     }
     $alias = new Alias();
     $alias->entity_id = $this->entity->id;
     $alias->name = $name;
     if ($context = $request->getParameter('context')) {
         $alias->context = $context;
     }
     $alias->save();
     $this->clearCache($this->entity);
     $this->redirect($this->entity->getInternalUrl('editAliases'));
 }
Example #8
0
 public static function disable_alias($aliasId)
 {
     if (!Validate::isUnsignedId($aliasId)) {
         echo "Error, {$aliasId} is not a valid alias ID\n";
         return false;
     }
     $alias = new Alias($aliasId);
     if (!$alias->active) {
         echo "alias {$aliasId} is already disabled\n";
         return true;
     }
     $alias->active = false;
     if ($alias->save()) {
         echo "Sucessfully disabled alias {$aliasId}\n";
         return true;
     } else {
         echo "Could not disable alias {$aliasId}\n";
         return false;
     }
 }
//next, delete and then re-insert the aliases
$alias = new Alias();
foreach ($resource->getAliases() as $alias) {
    $alias->delete();
}
$aliasTypeArray = array();
$aliasTypeArray = explode(':::', $_POST['aliasTypes']);
$aliasNameArray = array();
$aliasNameArray = explode(':::', $_POST['aliasNames']);
foreach ($aliasTypeArray as $key => $value) {
    if ($value && $aliasNameArray[$key]) {
        $alias = new Alias();
        $alias->resourceID = $resourceID;
        $alias->aliasTypeID = $value;
        $alias->shortName = $aliasNameArray[$key];
        $alias->save();
    }
}
//now delete and then re-insert the organizations
$resource->removeResourceOrganizations();
$organizationRoleArray = array();
$organizationRoleArray = explode(':::', $_POST['organizationRoles']);
$organizationArray = array();
$organizationArray = explode(':::', $_POST['organizations']);
foreach ($organizationRoleArray as $key => $value) {
    if ($value && $organizationArray[$key]) {
        $resourceOrganizationLink = new ResourceOrganizationLink();
        $resourceOrganizationLink->resourceID = $resourceID;
        $resourceOrganizationLink->organizationRoleID = $value;
        $resourceOrganizationLink->organizationID = $organizationArray[$key];
        $resourceOrganizationLink->save();
Example #10
0
 public static function importIn($strXml, $intElementId, $intTemplateId, $intAccountId, $importTemplates = true, $importElements = true, $validate = true)
 {
     global $objLiveAdmin, $intDefaultLanguage, $_CONF;
     $objReturn = NULL;
     $objSettings = NULL;
     $blnZip = false;
     $validTemplateStructure = false;
     //*** Init DOM object.
     $objDoc = new DOMDocument("1.0", "UTF-8");
     $objDoc->formatOutput = false;
     $objDoc->preserveWhiteSpace = true;
     if (is_file($strXml)) {
         $objZip = new dUnzip2($strXml);
         if (is_object($objZip)) {
             //*** Zip file.
             $strXml = $objZip->unzip('data.xml');
             if ($strXml !== false) {
                 //*** Fix a unicode bug. Replace forbidden characters (The first 8).
                 for ($intCount = 1; $intCount < 9; $intCount++) {
                     $strHex = str_pad(dechex($intCount), 4, "0", STR_PAD_LEFT);
                     $strXml = preg_replace('/\\x{' . $strHex . '}/u', "", $strXml);
                 }
                 $strXml = preg_replace('/\\x{001f}/u', "", $strXml);
                 $objDoc->loadXML($strXml);
                 $blnZip = true;
             }
         } else {
             //*** XML file.
             $objDoc->load($strXml);
         }
     } else {
         $objDoc->loadXML($strXml);
     }
     $arrUserIds = array();
     $arrGroupIds = array();
     $arrStorageIds = array();
     $arrFeedIds = array();
     $arrLanguageIds[0] = 0;
     $arrTemplateIds[0] = 0;
     $arrTemplateFieldIds[0] = 0;
     $arrLinkFieldIds = array();
     $arrElementIds[0] = 0;
     $arrElementFieldIds = array();
     $arrElementFieldIds["link"][0] = 0;
     $arrElementFieldIds["largeText"][0] = 0;
     if ($validate) {
         //*** validate template structure
         foreach ($objDoc->childNodes as $rootNode) {
             foreach ($rootNode->childNodes as $logicNode) {
                 if ($logicNode->nodeName == "logic") {
                     foreach ($logicNode->childNodes as $childNode) {
                         switch ($childNode->nodeName) {
                             case "templates":
                                 $validTemplateStructure = ImpEx::validateImportTemplates($childNode, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds, $intTemplateId);
                                 break;
                         }
                     }
                 }
             }
         }
     }
     if ($validTemplateStructure || !$validate) {
         //*** Import elements
         foreach ($objDoc->childNodes as $rootNode) {
             foreach ($rootNode->childNodes as $logicNode) {
                 if ($logicNode->nodeName == "logic") {
                     foreach ($logicNode->childNodes as $childNode) {
                         switch ($childNode->nodeName) {
                             case "languages":
                                 // Get all languages
                                 $arrCurrentLangs = array();
                                 $objContentLangs = ContentLanguage::select();
                                 $objDefaultLang = NULL;
                                 foreach ($objContentLangs as $objContentLang) {
                                     $arrCurrentLangs[$objContentLang->getAbbr()] = $objContentLang->getId();
                                     if ($objContentLang->default == 1) {
                                         $objDefaultLang = $objContentLang;
                                     }
                                 }
                                 $arrLanguageIds[0] = 0;
                                 // loop trough languages from export
                                 foreach ($childNode->childNodes as $languageNode) {
                                     // if abbreviations match, use that language ID
                                     if (array_key_exists($languageNode->getAttribute('abbr'), $arrCurrentLangs)) {
                                         $arrLanguageIds[$languageNode->getAttribute("id")] = $arrCurrentLangs[$languageNode->getAttribute('abbr')];
                                     } else {
                                         // if no match, use default current language
                                         $arrLanguageIds[$languageNode->getAttribute("id")] = $arrCurrentLangs[$objDefaultLang->getAbbr()];
                                     }
                                 }
                                 break;
                             case "templates":
                                 if ($importTemplates) {
                                     //*** Add templates to the account.
                                     self::importTemplates($childNode, $_CONF['app']['account']->getId(), $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds, $intTemplateId);
                                 }
                                 break;
                             case "elements":
                                 if ($importElements) {
                                     if ($intElementId == NULL) {
                                         $strSql = sprintf("SELECT * FROM pcms_element WHERE templateId = '%s' AND accountId = '%s' ORDER BY sort LIMIT 1", $intTemplateId, $intAccountId);
                                         $objElements = Element::select($strSql);
                                         foreach ($objElements as $objElement) {
                                             self::importElements($childNode, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, $arrElementIds, $arrElementFieldIds, $arrLinkFieldIds, $arrLanguageIds, $arrUserIds, $arrGroupIds, $arrStorageIds, $arrFeedIds, $objElement->getId());
                                         }
                                     } else {
                                         self::importElements($childNode, $intAccountId, $arrTemplateIds, $arrTemplateFieldIds, $arrElementIds, $arrElementFieldIds, $arrLinkFieldIds, $arrLanguageIds, $arrUserIds, $arrGroupIds, $arrStorageIds, $arrFeedIds, $intElementId);
                                     }
                                 }
                                 break;
                             case "aliases":
                                 if ($importElements) {
                                     //*** Add aliases to the account.
                                     foreach ($childNode->childNodes as $aliasNode) {
                                         if (in_array($aliasNode->getAttribute("url"), $arrElementIds)) {
                                             $objAlias = new Alias();
                                             $objAlias->setAccountId($_CONF['app']['account']->getId());
                                             $objAlias->setAlias($aliasNode->getAttribute("alias"));
                                             $objAlias->setUrl($arrElementIds[$aliasNode->getAttribute("url")]);
                                             $objAlias->setLanguageId($arrLanguageIds[$aliasNode->getAttribute("language")]);
                                             // check for existence of alias
                                             $objTmpAliases = Alias::selectByAlias($aliasNode->getAttribute("alias"));
                                             $objTmpAlias = $objTmpAliases->current();
                                             if (!is_object($objTmpAlias)) {
                                                 $objAlias->setCascade($aliasNode->getAttribute("cascade"));
                                                 $objAlias->setActive($aliasNode->getAttribute("active"));
                                                 $objAlias->setSort($aliasNode->getAttribute("sort"));
                                                 $objAlias->setCreated($aliasNode->getAttribute("created"));
                                                 $objAlias->setModified($aliasNode->getAttribute("modified"));
                                                 $objAlias->save();
                                             }
                                         }
                                     }
                                 }
                                 break;
                         }
                         if ($importElements) {
                             //*** Adjust the links for deeplink fields.
                             self::adjustDeeplinks($arrElementFieldIds["link"], $arrElementIds, $arrLanguageIds);
                             //*** Adjust the links in large text fields.
                             self::adjustTextlinks($arrElementFieldIds["largeText"], $arrElementIds, $arrLanguageIds, array(0));
                         }
                     }
                 }
             }
         }
         //*** Import files
         $objAccount = Account::selectByPK($_CONF['app']['account']->getId());
         if ($blnZip && is_object($objAccount) && $importElements) {
             self::importFiles($objZip, $objAccount);
             //*** Move files to remote server.
             self::moveImportedFiles($objAccount);
         }
         return true;
     }
     return false;
 }
Example #11
0
 private function importFiling($org, $lda_filing)
 {
     try {
         $this->printTimeSince();
         $this->printDebug('Starting import...');
         $excerpt = array();
         //$time = microtime(1);
         $this->db->beginTransaction();
         $date = null;
         $excerpt['Federal Filing Id'] = $lda_filing->federal_filing_id;
         $excerpt['Year'] = $lda_filing->year;
         $excerpt['Type'] = $lda_filing->LdaType->description;
         if (preg_match('/^[^T]*/su', $lda_filing->received, $match)) {
             $date = $match[0];
             $date = str_replace('/', '-', $date);
         }
         $lda_registrant = Doctrine::getTable('LdaRegistrant')->find($lda_filing->registrant_id);
         $excerpt['Registrant'] = $lda_registrant->name;
         if ($lda_filing->client_id) {
             $lda_client = Doctrine::getTable('LdaClient')->find($lda_filing->client_id);
             $excerpt['Client'] = $lda_client->name;
         } else {
             $this->db->rollback();
             return null;
         }
         $lobbying_entity = null;
         //DETERMINE (& CREATE) LOBBYING ENTITY
         //$this->printTimeSince();
         //$this->printDebug('determine/create...');
         if (strtolower(OrgTable::stripNamePunctuation($lda_client->name)) == strtolower(OrgTable::stripNamePunctuation($lda_registrant->name))) {
             $lobbying_entity = $org;
             $client_entity = null;
             if (!$lobbying_entity->lda_registrant_id) {
                 $lobbying_entity->lda_registrant_id = $lda_registrant->federal_registrant_id;
                 $lobbying_entity->save();
                 $lobbying_entity->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $lobbying_entity->getAllModifiedFields(), 'LDA Filing', null, $date, false);
             } else {
                 if ($lobbying_entity->lda_registrant_id != $lda_registrant->federal_registrant_id) {
                     $this->printDebug("LDA registrant ids did not match up for {$lobbying_entity->name} and {$lda_registrant->name} even though names matched {$lda_client->name}\n");
                     $this->db->rollback();
                     return null;
                 }
             }
             $this->printDebug($lobbying_entity->name . ' noted (same as client ' . $lda_client->name . ')');
         } else {
             $client_entity = $org;
             if ($lda_client->description) {
                 $description = trim($lda_client->description);
                 if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) {
                     if (strlen($description) < 200) {
                         if (!$org->blurb || $org->blurb == '') {
                             $org->blurb = $description;
                         }
                     } else {
                         if (!$org->summary || $org->summary == '') {
                             $org->summary = $description;
                         }
                     }
                 }
             }
             $org->save();
             $this->printDebug($lda_client->name . ' is distinct from ' . $lda_registrant->name);
         }
         $lda_lobbyists = $lda_filing->LdaLobbyists;
         $excerpt['Lobbyists'] = array();
         foreach ($lda_lobbyists as $lda_lobbyist) {
             $excerpt['Lobbyists'][] = $lda_lobbyist->name;
         }
         $excerpt['Lobbyists'] = implode('; ', $excerpt['Lobbyists']);
         if (!$lobbying_entity) {
             $lobbyist_name = null;
             if (count($lda_lobbyists)) {
                 $lobbyist_parts = explode(',', $lda_lobbyists[0]->name);
                 if (count($lobbyist_parts) > 1) {
                     $lobbyist_last = trim($lobbyist_parts[0]);
                     $arr = LsString::split($lobbyist_parts[1]);
                     $lens = array_map('strlen', $arr);
                     arsort($lens);
                     $keys = array_keys($lens);
                     $lobbyist_longest = $arr[$keys[0]];
                     $lobbyist_name = trim($lobbyist_parts[1]) . ' ' . trim($lobbyist_parts[0]);
                     $existing_lobbyist_registrant = null;
                 } else {
                     $lobbyist_name = preg_replace('/^(Mr|MR|MS|Dr|DR|MRS|Mrs|Ms)\\b\\.?/su', '', $lda_lobbyists[0]->name);
                     $arr = LsString::split(trim($lobbyist_name));
                     $arr = LsArray::strlenSort($arr);
                     $lobbyist_last = array_pop($arr);
                     if (count($arr)) {
                         $lobbyist_longest = array_shift(LsArray::strlenSort($arr));
                     } else {
                         $lobbyist_longest = '';
                     }
                 }
             }
             //check to see if registrant and lobbyist are same
             if (count($lda_lobbyists) == 1 && (strtoupper($lda_lobbyists[0]->name) == strtoupper($lda_registrant->name) || $lobbyist_last && stripos($lda_registrant->name, $lobbyist_last) == strlen($lda_registrant->name) - strlen($lobbyist_last) && stristr($lda_registrant->name, $lobbyist_longest))) {
                 $existing_lobbyist_registrant = EntityTable::getByExtensionQuery('Lobbyist')->addWhere('lobbyist.lda_registrant_id = ?', $lda_registrant->federal_registrant_id)->execute()->getFirst();
                 if ($existing_lobbyist_registrant) {
                     $lobbying_entity = $existing_lobbyist_registrant;
                     $this->printDebug('Existing lobbyist is lobbying entity: ' . $lobbying_entity->name);
                 } else {
                     $lobbyist = $this->prepLobbyistName($lda_lobbyists[0]->name);
                     if ($lobbyist) {
                         $lobbyist->lda_registrant_id = $lda_registrant->federal_registrant_id;
                         $lobbyist->save();
                         $lobbyist->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                         $this->printDebug('New lobbyist/lobbying entity saved: ' . $lobbyist->name);
                         $lobbying_entity = $lobbyist;
                     }
                 }
             } else {
                 if ($existing_firm = EntityTable::getByExtensionQuery('Org')->addWhere('org.lda_registrant_id = ? ', $lda_registrant->federal_registrant_id)->execute()->getFirst()) {
                     $modified = array();
                     $lobbying_entity = $existing_firm;
                     if ($lda_registrant->description) {
                         $description = trim($lda_registrant->description);
                         if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) {
                             if (strlen($description) < 200) {
                                 if (!$existing_firm->blurb || $existing_firm->blurb == '') {
                                     $existing_firm->blurb = $description;
                                     $modified[] = 'blurb';
                                 }
                             } else {
                                 if (!$existing_firm->summary || $existing_firm->summary == '') {
                                     $existing_firm->summary = $description;
                                     $modified[] = 'summary';
                                 }
                             }
                         }
                     }
                     if ($lda_registrant->address && $lda_registrant->address != '' && count($existing_firm->Address) == 0) {
                         if ($address = $existing_firm->addAddress($lda_registrant->address)) {
                             $existing_firm->save();
                             $address->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $address->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                         }
                     }
                     $existing_firm->save();
                     if (count($modified)) {
                         $existing_firm->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $modified, 'LDA Filing', null, $date, false);
                     }
                     $this->printDebug('Existing firm is lobbying entity: ' . $lobbying_entity->name);
                 } else {
                     $firm = new Entity();
                     $firm->addExtension('Org');
                     $firm->addExtension('Business');
                     $firm->addExtension('LobbyingFirm');
                     $firm->name = LsLanguage::titleize(OrgTable::stripNamePunctuation($lda_registrant->name), true);
                     $firm->lda_registrant_id = $lda_registrant->federal_registrant_id;
                     if ($lda_registrant->description) {
                         $description = trim($lda_registrant->description);
                         if ($description != '' && preg_match('/[\\/\\-]\\d+[\\/\\-]/isu', $description) == 0) {
                             if (strlen($description) < 200) {
                                 $firm->blurb = $description;
                             } else {
                                 $firm->summary = $description;
                             }
                         }
                     }
                     if ($lda_registrant->address && $lda_registrant->address != '') {
                         if ($address = $firm->addAddress($lda_registrant->address)) {
                             $firm->save();
                             $address->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $address->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                         }
                     }
                     $firm->save();
                     $this->printDebug('New lobbying firm/lobbying entity saved: ' . $firm->name);
                     $firm->addReference(self::$filing_url . $lda_filing->federal_filing_id, null, $firm->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                     $lobbying_entity = $firm;
                 }
             }
         }
         //PREP GOVT ENTITIES
         //$this->printTimeSince();
         //$this->printDebug('gov entities...');
         $lda_govts = $lda_filing->LdaGovts;
         //$this->printDebug('count of lda govs is ***** ' . count($lda_govts));
         $govt_entities = array();
         $excerpt['Government Bodies'] = array();
         foreach ($lda_govts as $lda_govt) {
             $excerpt['Government Bodies'][] = $lda_govt->name;
             $name_arr = $this->prepGovtName($lda_govt->name);
             if (!$name_arr) {
                 continue;
             }
             if ($govt_entity = EntityTable::findByAlias($lda_govt->name, $context = 'lda_government_body')) {
                 $govt_entities[] = $govt_entity;
                 //$this->printDebug('Existing govt entity: ' . $govt_entity->name);
             } else {
                 if ($govt_entity = EntityTable::getByExtensionQuery(array('Org', 'GovernmentBody'))->addWhere('name = ?', array($name_arr[0]))->fetchOne()) {
                     $govt_entities[] = $govt_entity;
                     $alias = new Alias();
                     $alias->context = 'lda_government_body';
                     $alias->name = $lda_govt->name;
                     $alias->entity_id = $govt_entity->id;
                     $alias->save();
                 } else {
                     $govt_entity = new Entity();
                     $govt_entity->addExtension('Org');
                     $govt_entity->addExtension('GovernmentBody');
                     $govt_entity->name = $name_arr[0];
                     $govt_entity->name_nick = $name_arr[1];
                     $govt_entity->is_federal = 1;
                     $govt_entity->save();
                     $alias = new Alias();
                     $alias->context = 'lda_government_body';
                     $alias->name = $lda_govt->name;
                     $alias->entity_id = $govt_entity->id;
                     $alias->save();
                     $govt_entity->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $govt_entity->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                     $govt_entities[] = $govt_entity;
                 }
             }
         }
         $excerpt['Government Bodies'] = implode('; ', $excerpt['Government Bodies']);
         $excerpt_str = '';
         foreach ($excerpt as $k => $v) {
             $excerpt_str .= $k . ": ";
             $excerpt_str .= $v . "\n";
         }
         $excerpt = trim($excerpt_str);
         $this->printDebug($excerpt);
         $relationships = array();
         $lobbying_entity_extensions = $lobbying_entity->getExtensions();
         //CREATE LOBBYIST POSITION RELATIONSHIPS
         //$this->printTimeSince();
         //$this->printDebug('lobbyist positions...');
         $category = Doctrine::getTable('RelationshipCategory')->findOneByName('Position');
         if (!in_array('Lobbyist', $lobbying_entity_extensions)) {
             $firm_lobbyists = array();
             if ($lobbying_entity->exists()) {
                 $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Relationship r ON (r.entity1_id = e.id)')->where('r.entity2_id = ? AND r.category_id = ?', array($lobbying_entity->id, RelationshipTable::POSITION_CATEGORY));
                 $firm_lobbyists = $q->execute();
             }
             $lobbyists = array();
             foreach ($lda_lobbyists as $lda_lobbyist) {
                 $lobbyist = $this->prepLobbyistName($lda_lobbyist->name);
                 if (!$lobbyist) {
                     continue;
                 }
                 $existing_lobbyist = null;
                 foreach ($firm_lobbyists as $fl) {
                     if (PersonTable::areNameCompatible($fl, $lobbyist)) {
                         $existing_lobbyist = $fl;
                         break;
                     }
                 }
                 //echo "before lobb save or rel save: ";
                 //$this->printTimeSince();
                 if (!$existing_lobbyist) {
                     $lobbyist->save();
                     $lobbyist->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                     //$this->printDebug('New lobbyist saved: ' . $lobbyist->name);
                     $r = new Relationship();
                     $r->Entity1 = $lobbyist;
                     $r->Entity2 = $lobbying_entity;
                     $r->setCategory('Position');
                     $r->description1 = 'Lobbyist';
                     $r->is_employee = 1;
                     $r->save();
                     $r->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbyist->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                     //$this->printDebug('New position relationship saved: ' . $lobbying_entity->name . ' and ' . $lobbyist->name);
                     $lobbyists[] = $lobbyist;
                 } else {
                     //$this->printDebug('Lobbyist exists: ' . $lobbyist->name . ' is same as ' . $existing_lobbyist->name);
                     $lobbyists[] = $existing_lobbyist;
                 }
             }
         }
         //PREP ISSUES
         //$this->printTimeSince();
         //$this->printDebug('issues...');
         $issues = array();
         $lda_issues = Doctrine_Query::create()->from('LdaFilingIssue f')->leftJoin('f.LdaIssue i')->where('f.filing_id = ?', $lda_filing->id)->execute();
         foreach ($lda_issues as $lda_issue) {
             $name = LsLanguage::nameize($lda_issue->LdaIssue->name);
             if (!($issue = Doctrine::getTable('LobbyIssue')->findOneByName($name))) {
                 $issue = new LobbyIssue();
                 $issue->name = $name;
                 $issue->save();
                 //$this->printDebug('Lobbying issue saved: ' . $issue->name);
             }
             $issues[] = array($issue, $lda_issue->specific_issue);
         }
         //CREATE LOBBY FILING
         //$this->printTimeSince();
         //$this->printDebug('creating lobby filing:');
         $lobby_filing = new LobbyFiling();
         $lobby_filing->year = $lda_filing->year;
         $lobby_filing->amount = $lda_filing->amount;
         $lobby_filing->federal_filing_id = $lda_filing->federal_filing_id;
         $period = $lda_filing->LdaPeriod->description;
         $lobby_filing->start_date = $date;
         if ($paren = strpos($period, '(')) {
             $lobby_filing->period = trim(substr($period, 0, $paren));
         } else {
             $lobby_filing->period = 'Undetermined';
         }
         $lobby_filing->report_type = LsLanguage::nameize($lda_filing->LdaType->description);
         foreach ($issues as $issue) {
             $filing_issue = new LobbyFilingLobbyIssue();
             $filing_issue->Issue = $issue[0];
             $filing_issue->Filing = $lobby_filing;
             $filing_issue->specific_issue = $issue[1];
             $filing_issue->save();
         }
         if (in_array('Lobbyist', $lobbying_entity_extensions)) {
             $lobby_filing->Lobbyist[] = $lobbying_entity;
             //$this->printDebug('Lobbying entity lobbyist added to lobbying relationship: ' . $lobbying_entity->name);
         } else {
             foreach ($lobbyists as $lobbyist) {
                 $lobby_filing->Lobbyist[] = $lobbyist;
             }
         }
         //var_dump($lobby_filing->toArray());
         $lobby_filing->save();
         //CREATE TRANSACTION RELATIONSHIP, IF ANY
         //$this->printTimeSince();
         //$this->printDebug('starting transaction relationships:');
         $transaction = null;
         if ($client_entity != null) {
             $transaction = RelationshipTable::getByCategoryQuery('Transaction')->addWhere('r.entity1_id = ?', $client_entity->id)->addWhere('r.entity2_id = ?', $lobbying_entity->id)->addWhere('transaction.is_lobbying = ?', 1)->fetchOne();
             if ($transaction) {
                 $transaction->updateDateRange($date, true);
                 if ($lda_filing->amount && $lda_filing->amount != '') {
                     if (!$transaction->amount || $transaction->amount == '') {
                         $transaction->amount = $lda_filing->amount;
                     } else {
                         $transaction->amount += $lda_filing->amount;
                     }
                 }
                 $transaction->filings++;
                 $transaction->save();
                 $transaction->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $transaction->getAllModifiedFields(), 'LDA Filing', null, $date, false);
             } else {
                 $transaction = new Relationship();
                 $transaction->Entity1 = $client_entity;
                 $transaction->Entity2 = $lobbying_entity;
                 $transaction->setCategory('Transaction');
                 $transaction->description1 = 'Lobbying Client';
                 $transaction->is_lobbying = 1;
                 $transaction->filings = 1;
                 $transaction->updateDateRange($date, true);
                 if (in_array('Person', $lobbying_entity_extensions)) {
                     $transaction->description2 = 'Hired Lobbyist';
                 } else {
                     $transaction->description2 = 'Lobbying Firm';
                 }
                 if ($lda_filing->amount && $lda_filing->amount != '') {
                     $transaction->amount = $lda_filing->amount;
                 }
                 $transaction->save();
                 $transaction->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $transaction->getAllModifiedFields(), 'LDA Filing', null, $date, false);
                 //$this->printDebug('New lobbying transaction saved between client ' . $client_entity->name . ' and lobbying firm ' . $lobbying_entity->name);
             }
             $relationships[] = $transaction;
         }
         //CREATE LOBBYING RELATIONSHIP
         //$this->printTimeSince();
         //$this->printDebug('starting lobbying relationships:');
         foreach ($govt_entities as $govt_entity) {
             $lobbying_relationship = RelationshipTable::getByCategoryQuery('Lobbying')->addWhere('r.entity1_id = ?', $lobbying_entity->id)->addWhere('r.entity2_id = ?', $govt_entity->id)->fetchOne();
             if ($lobbying_relationship) {
                 $lobbying_relationship->updateDateRange($date);
                 $lobbying_relationship->filings++;
                 $lobbying_relationship->save();
             } else {
                 $lobbying_relationship = new Relationship();
                 $lobbying_relationship->Entity1 = $lobbying_entity;
                 $lobbying_relationship->Entity2 = $govt_entity;
                 $lobbying_relationship->setCategory('Lobbying');
                 if ($transaction) {
                     $lobbying_relationship->description1 = 'Lobbying (for client)';
                 } else {
                     $lobbying_relationship->description1 = 'Direct Lobbying';
                 }
                 $lobbying_relationship->description2 = $lobbying_relationship->description1;
                 $lobbying_relationship->updateDateRange($date, true);
                 $lobbying_relationship->filings = 1;
                 $lobbying_relationship->save();
                 $lobbying_relationship->addReference(self::$filing_url . $lda_filing->federal_filing_id, $excerpt, $lobbying_relationship->getAllModifiedFields(), 'LDA Filing', null, $date, false);
             }
             $relationships[] = $lobbying_relationship;
         }
         foreach ($relationships as $relationship) {
             $lobby_filing->Relationship[] = $relationship;
         }
         $lobby_filing->save();
         //$this->printTimeSince();
         $this->printDebug("Import Completed\n");
         $this->db->commit();
     } catch (Exception $e) {
         $this->db->rollback();
         throw $e;
     }
 }
Example #12
0
 public function getParentAlias()
 {
     if ($this->ival('category_parent_id') > 0) {
         $p = new Category($this->db, $this->ival('category_parent_id'));
         $pa = new Alias($this->db, $p->ival('category_alias_id'));
         if (!$pa->is_loaded) {
             $pa->setUrl($p->getAliasUrl());
             $pa->data['alias_path'] = $p->getAliasPath();
             $pa->save();
             $p->data['category_alias_id'] = $pa->val('alias_id');
             $p->save();
         }
         return $pa;
     }
 }
 public function addAliasesToEntityById($id, array $aliases)
 {
     Doctrine_Manager::getInstance()->setCurrentConnection('main');
     $existingAliases = array_map('strtolower', EntityTable::getAliasNamesById($id, $includePrimary = true, $excludeContext = true));
     foreach ($aliases as $alias) {
         if (!in_array(strtolower($alias), $existingAliases)) {
             $a = new Alias();
             $a->entity_id = $id;
             $a->name = $alias;
             $a->is_primary = false;
             $a->save();
             if ($this->debugMode) {
                 print "+ Added alias " . $alias . " to entity " . $id . "\n";
             }
         }
     }
 }
 private function addGovernmentBodyEntity($name, $fedspending_name, $parent_id = null)
 {
     $new_gov_body = new Entity();
     $new_gov_body->addExtension('Org');
     $new_gov_body->addExtension('GovernmentBody');
     $new_gov_body->name = $name;
     $new_gov_body->is_federal = 1;
     if ($parent_id) {
         $new_gov_body->parent_id = $parent_id;
     }
     $new_gov_body->save();
     $alias = new Alias();
     $alias->context = 'fedspending_government_body';
     $alias->name = $fedspending_name;
     $alias->entity_id = $new_gov_body->id;
     $alias->save();
     return $new_gov_body;
 }
Example #15
0
function parseAlias($intAliasId, $strCommand)
{
    global $_PATHS, $_CLEAN_POST, $_CONF, $objLang, $objLiveUser;
    $objTpl = new HTML_Template_IT($_PATHS['templates']);
    $objTpl->loadTemplatefile("alias.tpl.htm");
    $blnError = false;
    switch ($strCommand) {
        case CMD_LIST:
        case CMD_ADD:
        case CMD_EDIT:
            //*** Post the profile form if submitted.
            if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "editAlias") {
                //*** The element form has been posted.
                //*** Check sanitized input.
                if (is_null($_CLEAN_POST["frm_active"])) {
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_alias"])) {
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_language"])) {
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["frm_element"])) {
                    $blnError = true;
                }
                if (is_null($_CLEAN_POST["dispatch"])) {
                    $blnError = true;
                }
                if ($blnError === true) {
                    //*** Display global error.
                    $objTpl->setVariable("FORM_ACTIVE_VALUE", $_POST["frm_active"] == "on" ? "checked=\"checked\"" : "");
                    $objTpl->setVariable("FORM_ALIAS_VALUE", $_POST["frm_alias"]);
                    $objTpl->setVariable("ERROR_ALIAS_MAIN", $objLang->get("main", "formerror"));
                } else {
                    //*** Input is valid. Save the alias.
                    if ($strCommand == CMD_EDIT) {
                        $objAlias = Alias::selectByPK($intAliasId);
                    } else {
                        $objAlias = new Alias();
                    }
                    $objAlias->setAccountId($_CONF['app']['account']->getId());
                    $objAlias->setActive($_POST["frm_active"] == "on" ? 1 : 0);
                    $objAlias->setLanguageId(empty($_CLEAN_POST["frm_language"]) ? 0 : $_CLEAN_POST["frm_language"]);
                    $objAlias->setAlias($_CLEAN_POST["frm_alias"]);
                    $objAlias->setUrl($_CLEAN_POST["frm_element"]);
                    $objAlias->save();
                    header("Location: " . Request::getURI() . "/?cid=" . NAV_PCMS_ALIASES);
                    exit;
                }
            }
            //*** Initiate child element loop.
            $objAliases = Alias::selectSorted();
            $totalCount = 0;
            $listCount = 0;
            $intPosition = request("pos");
            $intPosition = !empty($intPosition) && is_numeric($intPosition) ? $intPosition : 0;
            $intPosition = floor($intPosition / $_SESSION["listCount"]) * $_SESSION["listCount"];
            //*** Find total count.
            foreach ($objAliases as $objAlias) {
                $strAlias = $objAlias->getAlias();
                if (!empty($strAlias)) {
                    $totalCount++;
                }
            }
            $objAliases->seek($intPosition);
            $objLanguages = ContentLanguage::select();
            foreach ($objAliases as $objAlias) {
                $strAlias = $objAlias->getAlias();
                if (!empty($strAlias)) {
                    $strUrl = $objAlias->getUrl();
                    if (is_numeric($strUrl)) {
                        $objElement = Element::selectByPk($strUrl);
                        if (is_object($objElement)) {
                            $strUrlHref = "?eid={$strUrl}&amp;cmd=" . CMD_EDIT . "&amp;cid=" . NAV_PCMS_ELEMENTS;
                            $strUrl = Element::recursivePath($strUrl);
                        } else {
                            $strUrlHref = "?cid=" . NAV_PCMS_ALIASES;
                            $strUrl = "<b>" . $objLang->get("aliasUnavailable", "label") . "</b>";
                        }
                    }
                    $objTpl->setCurrentBlock("multiview-item");
                    $objTpl->setVariable("MULTIITEM_VALUE", $objAlias->getId());
                    $objTpl->setVariable("BUTTON_REMOVE_HREF", "javascript:Alias.remove({$objAlias->getId()});");
                    $objTpl->setVariable("BUTTON_REMOVE", $objLang->get("delete", "button"));
                    $objTpl->setVariable("MULTIITEM_HREF", "?cid=" . NAV_PCMS_ALIASES . "&amp;eid={$objAlias->getId()}&amp;cmd=" . CMD_EDIT);
                    $objTpl->setVariable("MULTIITEM_TYPE_CLASS", "alias");
                    $objTpl->setVariable("MULTIITEM_ALIAS", $objAlias->getAlias());
                    $objTpl->setVariable("MULTIITEM_POINTS_TO", $objLang->get("pointsTo", "label"));
                    $objTpl->setVariable("MULTIITEM_URL", $strUrl);
                    $objTpl->setVariable("MULTIITEM_URL_HREF", $strUrlHref);
                    if ($objLanguages->count() > 1) {
                        if ($objAlias->getLanguageId() > 0) {
                            $strLanguage = ContentLanguage::selectByPK($objAlias->getLanguageId())->getName();
                            $objTpl->setVariable("MULTIITEM_LANGUAGE", sprintf($objLang->get("forLanguage", "label"), $strLanguage));
                        } else {
                            $objTpl->setVariable("MULTIITEM_LANGUAGE", $objLang->get("forAllLanguages", "label"));
                        }
                    } else {
                        $objTpl->setVariable("MULTIITEM_LANGUAGE", "");
                    }
                    if (!$objAlias->getActive()) {
                        $objTpl->setVariable("MULTIITEM_ACTIVE", " class=\"inactive\"");
                    }
                    $objTpl->parseCurrentBlock();
                    $listCount++;
                    if ($listCount >= $_SESSION["listCount"]) {
                        break;
                    }
                }
            }
            //*** Render page navigation.
            $pageCount = ceil($totalCount / $_SESSION["listCount"]);
            if ($pageCount > 0) {
                $currentPage = ceil(($intPosition + 1) / $_SESSION["listCount"]);
                $previousPos = $intPosition - $_SESSION["listCount"] > 0 ? $intPosition - $_SESSION["listCount"] : 0;
                $nextPos = $intPosition + $_SESSION["listCount"] < $totalCount ? $intPosition + $_SESSION["listCount"] : $intPosition;
                $objTpl->setVariable("PAGENAV_PAGE", sprintf($objLang->get("pageNavigation", "label"), $currentPage, $pageCount));
                $objTpl->setVariable("PAGENAV_PREVIOUS", $objLang->get("previous", "button"));
                $objTpl->setVariable("PAGENAV_PREVIOUS_HREF", "?cid=" . NAV_PCMS_ALIASES . "&amp;pos={$previousPos}");
                $objTpl->setVariable("PAGENAV_NEXT", $objLang->get("next", "button"));
                $objTpl->setVariable("PAGENAV_NEXT_HREF", "?cid=" . NAV_PCMS_ALIASES . "&amp;pos={$nextPos}");
                //*** Top page navigation.
                for ($intCount = 0; $intCount < $pageCount; $intCount++) {
                    $objTpl->setCurrentBlock("multiview-pagenavitem-top");
                    $position = $intCount * $_SESSION["listCount"];
                    if ($intCount != $intPosition / $_SESSION["listCount"]) {
                        $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_ALIASES . "&amp;pos={$position}\"");
                    }
                    $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1);
                    $objTpl->parseCurrentBlock();
                }
                //*** Bottom page navigation.
                for ($intCount = 0; $intCount < $pageCount; $intCount++) {
                    $objTpl->setCurrentBlock("multiview-pagenavitem-bottom");
                    $position = $intCount * $_SESSION["listCount"];
                    if ($intCount != $intPosition / $_SESSION["listCount"]) {
                        $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_ALIASES . "&amp;pos={$position}\"");
                    }
                    $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1);
                    $objTpl->parseCurrentBlock();
                }
            }
            //*** Render list action pulldown.
            $arrActions[$objLang->get("choose", "button")] = 0;
            $arrActions[$objLang->get("delete", "button")] = "delete";
            foreach ($arrActions as $key => $value) {
                $objTpl->setCurrentBlock("multiview-listactionitem");
                $objTpl->setVariable("LIST_ACTION_TEXT", $key);
                $objTpl->setVariable("LIST_ACTION_VALUE", $value);
                $objTpl->parseCurrentBlock();
            }
            $objTpl->setCurrentBlock("multiview");
            $objTpl->setVariable("ACTIONS_OPEN", $objLang->get("pcmsOpenActionsMenu", "menu"));
            $objTpl->setVariable("ACTIONS_CLOSE", $objLang->get("pcmsCloseActionsMenu", "menu"));
            $objTpl->setVariable("LIST_LENGTH_HREF_10", "href=\"?list=10&amp;cid=" . NAV_PCMS_ALIASES . "\"");
            $objTpl->setVariable("LIST_LENGTH_HREF_25", "href=\"?list=25&amp;cid=" . NAV_PCMS_ALIASES . "\"");
            $objTpl->setVariable("LIST_LENGTH_HREF_100", "href=\"?list=100&amp;cid=" . NAV_PCMS_ALIASES . "\"");
            switch ($_SESSION["listCount"]) {
                case 10:
                    $objTpl->setVariable("LIST_LENGTH_HREF_10", "");
                    break;
                case 25:
                    $objTpl->setVariable("LIST_LENGTH_HREF_25", "");
                    break;
                case 100:
                    $objTpl->setVariable("LIST_LENGTH_HREF_100", "");
                    break;
            }
            $objTpl->setVariable("LIST_LENGTH_HREF", "&amp;cid=" . NAV_PCMS_ALIASES);
            $objTpl->setVariable("LIST_WITH_SELECTED", $objLang->get("withSelected", "label"));
            $objTpl->setVariable("LIST_ACTION_ONCHANGE", "Alias.multiDo(this, this[this.selectedIndex].value)");
            $objTpl->setVariable("LIST_ITEMS_PER_PAGE", $objLang->get("itemsPerPage", "label"));
            $objTpl->setVariable("BUTTON_LIST_SELECT", $objLang->get("selectAll", "button"));
            $objTpl->setVariable("BUTTON_LIST_SELECT_HREF", "javascript:Alias.multiSelect()");
            $objTpl->parseCurrentBlock();
            //*** Form variables.
            $intActiveLanguage = 0;
            if ($strCommand == CMD_EDIT) {
                $objAlias = Alias::selectByPK($intAliasId);
                $intActiveLanguage = $objAlias->getLanguageId();
                $objTpl->setVariable("FORM_ACTIVE_VALUE", $objAlias->getActive() ? "checked=\"checked\"" : "");
                $objTpl->setVariable("FORM_ALIAS_VALUE", $objAlias->getAlias());
                $objTpl->setVariable("FORM_URL_VALUE", $objAlias->getUrl());
                $objTpl->setVariable("FRM_HEADER", $objLang->get("editAlias", "form"));
                $objTpl->setVariable("FRM_STYLE", "");
                $objTpl->setVariable("CMD", CMD_EDIT);
                $objTpl->touchBlock("alias.edit");
            } else {
                $objTpl->setVariable("FORM_ACTIVE_VALUE", "checked=\"checked\"");
                $objTpl->setVariable("FRM_HEADER", $objLang->get("addAlias", "form"));
                if (!$blnError) {
                    $objTpl->setVariable("FRM_STYLE", " style=\"display:none\"");
                }
                $objTpl->setVariable("CMD", CMD_ADD);
                $objTpl->touchBlock("alias.add");
            }
            //*** Languages.
            $objLanguages = ContentLanguage::select();
            foreach ($objLanguages as $objLanguage) {
                $objTpl->setCurrentBlock("language.item");
                $objTpl->setVariable("ID", $objLanguage->getId());
                $objTpl->setVariable("LABEL", $objLanguage->getName());
                $objTpl->setVariable("SELECTED", $intActiveLanguage == $objLanguage->getId() ? " selected=\"selected\"" : "");
                $objTpl->parseCurrentBlock();
            }
            $objTpl->setVariable("ALIASES", $objLang->get("aliases", "label"));
            $objTpl->setVariable("BUTTON_ADD", $objLang->get("aliasAdd", "button"));
            $objTpl->setVariable("FRM_LABEL_ACTIVE", $objLang->get("active", "form"));
            $objTpl->setVariable("FRM_LABEL_ALIAS", $objLang->get("alias", "form"));
            $objTpl->setVariable("FRM_DESCR_ALIAS", $objLang->get("alias", "tip"));
            $objTpl->setVariable("FRM_LABEL_LANGUAGE", $objLang->get("language", "form"));
            $objTpl->setVariable("FRM_DESCR_LANGUAGE", $objLang->get("language", "tip"));
            $objTpl->setVariable("FRM_LABEL_ALL_LANGUAGES", $objLang->get("allLanguages", "form"));
            $objTpl->setVariable("FRM_LABEL_URL", $objLang->get("element", "form"));
            $objTpl->setVariable("FRM_LABEL_SAVE", $objLang->get("save", "button"));
            $objTpl->setVariable("CID", NAV_PCMS_ALIASES);
            $objTpl->setVariable("EID", $intAliasId);
            $objTpl->parseCurrentBlock();
            $strReturn = $objTpl->get();
            break;
        case CMD_REMOVE:
            if (strpos($intAliasId, ',') !== false) {
                //*** Multiple elements submitted.
                $arrAliases = explode(',', $intAliasId);
                $objAliases = Alias::selectByPK($arrAliases);
                foreach ($objAliases as $objAlias) {
                    $objAlias->delete();
                }
            } else {
                //*** Single element submitted.
                $objAlias = Alias::selectByPK($intAliasId);
                $objAlias->delete();
            }
            //*** Redirect the page.
            $strReturnTo = request('returnTo');
            if (empty($strReturnTo)) {
                header("Location: " . Request::getUri() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST);
                exit;
            } else {
                header("Location: " . Request::getURI() . $strReturnTo);
                exit;
            }
            break;
    }
    return $strReturn;
}
Example #16
0
             if (!isset($zCategory) || isset($category) && $category->level > $zCategory->level) {
                 $zCategory = $category;
             }
         }
         if (isset($zCategory)) {
             $zProduct->data['product_category_id'] = $zCategory->ival('category_id');
             $zProduct->data['product_name'] = $product_name;
             $zProduct->data['product_price'] = $product_price;
             $zProduct->data['product_stock'] = $product_stock;
             $zProduct->save();
             // update alias
             $a = new Alias($db, $zProduct->val('product_alias_id'));
             if (!$a->is_loaded) {
                 $a->setUrl($zProduct->getAliasUrl());
                 $a->data['alias_path'] = $zProduct->getAliasPath();
                 $a->save();
                 $zProduct->data['product_alias_id'] = $a->ival('alias_id');
                 $zProduct->save();
             }
         } else {
             echo sprintf('Cannot find category with ABX id %s for product "%s"<br/>', $cat, $product_name);
         }
     }
 }
 // if $save_product
 if (isset($zVariant) && $zProduct->val('product_id') != null) {
     $zVariant->data['product_variant_ext_id'] = $prod_id;
     $zVariant->data['product_variant_name'] = $variant_name;
     $zVariant->data['product_variant_product_id'] = $zProduct->ival('product_id');
     $zVariant->data['product_variant_price'] = $product_price;
     $zVariant->data['product_variant_stock'] = $product_stock;
Example #17
0
 public static function addById($intId, $intParentId = 0)
 {
     global $_CONF;
     $objDoc = Structure::getXmlDoc($intId);
     $arrUserIds = array();
     $arrGroupIds = array();
     $arrStorageIds = array();
     $arrFeedIds = array();
     $arrLanguageIds[0] = 0;
     $arrTemplateIds[0] = 0;
     $arrTemplateFieldIds[0] = 0;
     $arrLinkFieldIds = array();
     $arrElementIds[0] = 0;
     $arrElementFieldIds = array();
     $arrElementFieldIds["link"][0] = 0;
     $arrElementFieldIds["largeText"][0] = 0;
     $intTemplateParentId = 0;
     $intElementParentId = 0;
     //*** Get structure fields from selects.
     if (Structure::hasSelect($intId)) {
         $objSelects = Structure::getSelectsById($intId);
         foreach ($objSelects as $objSelect) {
             switch ($objSelect->getType()) {
                 case "language":
                     $intId = Request::get("frm_select_{$objSelect->getId()}");
                     $arrLanguageIds[$objSelect->getLogicId()] = $intId;
                     break;
                 case "element":
                     $intId = Request::get("frm_select_{$objSelect->getId()}");
                     if ($objSelect->getLogicId() == "PARENT") {
                         $intElementParentId = $intId;
                     } else {
                         $arrElementIds[$objSelect->getLogicId()] = $intId;
                     }
                     break;
             }
         }
     }
     foreach ($objDoc->childNodes as $rootNode) {
         if ($rootNode->nodeName == "structure") {
             //*** Valid structure XML.
             switch ($rootNode->getAttribute("type")) {
                 case "template":
                     $intTemplateParentId = $intParentId;
                     break;
                 case "element":
                     $intElementParentId = $intParentId;
                     break;
             }
             foreach ($rootNode->childNodes as $logicNode) {
                 if ($logicNode->nodeName == "logic") {
                     foreach ($logicNode->childNodes as $childNode) {
                         switch ($childNode->nodeName) {
                             case "languages":
                                 //*** Add languages to the account.
                                 foreach ($childNode->childNodes as $languageNode) {
                                     $objLanguage = new ContentLanguage();
                                     $objLanguage->setAccountId($_CONF['app']['account']->getId());
                                     $objLanguage->setName($languageNode->getAttribute("name"));
                                     $objLanguage->setAbbr($languageNode->getAttribute("abbr"));
                                     $objLanguage->default = $languageNode->getAttribute("default");
                                     $objLanguage->setActive($languageNode->getAttribute("active"));
                                     $objLanguage->setSort($languageNode->getAttribute("sort"));
                                     $objLanguage->setUsername($languageNode->getAttribute("username"));
                                     $objLanguage->save();
                                     $arrLanguageIds[$languageNode->getAttribute("id")] = $objLanguage->getId();
                                     if ($languageNode->getAttribute("default") == 1) {
                                         $intDefaultLanguage = $objLanguage->getId();
                                     }
                                 }
                                 break;
                             case "templates":
                                 //*** Add templates to the account.
                                 ImpEx::importTemplates($childNode, $_CONF['app']['account']->getId(), $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds, $intTemplateParentId);
                                 break;
                             case "elements":
                                 //*** Add elements to the account.
                                 ImpEx::importElements($childNode, $_CONF['app']['account']->getId(), $arrTemplateIds, $arrTemplateFieldIds, $arrElementIds, $arrElementFieldIds, $arrLinkFieldIds, $arrLanguageIds, $arrUserIds, $arrGroupIds, $arrStorageIds, $arrFeedIds, $intElementParentId);
                                 break;
                             case "aliases":
                                 //*** Add aliases to the account.
                                 foreach ($childNode->childNodes as $aliasNode) {
                                     $objAlias = new Alias();
                                     $objAlias->setAccountId($_CONF['app']['account']->getId());
                                     $objAlias->setAlias($aliasNode->getAttribute("alias"));
                                     if (array_key_exists($aliasNode->getAttribute("url"), $arrElementIds)) {
                                         $objAlias->setUrl($arrElementIds[$aliasNode->getAttribute("url")]);
                                     } else {
                                         $objAlias->setUrl(0);
                                     }
                                     if (array_key_exists($aliasNode->getAttribute("language"), $arrLanguageIds)) {
                                         $objAlias->setLanguageId($arrLanguageIds[$aliasNode->getAttribute("language")]);
                                     } else {
                                         $objAlias->setLanguageId(0);
                                     }
                                     $objAlias->setCascade($aliasNode->getAttribute("cascade"));
                                     $objAlias->setActive($aliasNode->getAttribute("active"));
                                     $objAlias->setSort($aliasNode->getAttribute("sort"));
                                     $objAlias->setCreated($aliasNode->getAttribute("created"));
                                     $objAlias->setModified($aliasNode->getAttribute("modified"));
                                     $objAlias->save();
                                 }
                                 break;
                         }
                         //*** Adjust the links for deeplink fields.
                         ImpEx::adjustDeeplinks($arrElementFieldIds["link"], $arrElementIds, $arrLanguageIds);
                         //*** Adjust the links in large text fields.
                         ImpEx::adjustTextlinks($arrElementFieldIds["largeText"], $arrElementIds, $arrLanguageIds, array(0));
                     }
                 }
             }
         }
     }
 }
Example #18
0
     $aliasUpdate = $conn->prepare($aliasUpdate);
     $aliasUpdate->bindParam(':ALIASID', $file->getAliasID());
     if ($aliasUpdate->execute()) {
         echo "Alias deleted Successfully.";
     }
 } else {
     //new or Update
     //ensure it is available!
     $alias = new Alias($conn);
     $alias->setAlias($fileAlias);
     $numAliases = sizeof($alias->getObjectsLikeThis());
     if ($numAliases == 0) {
         if ($file->getAliasID() == 0) {
             $alias->setPointer($file->getId());
             $alias->setType('file');
             if ($alias->save() > 0) {
                 //echo "Alias Saved";
                 $fileUpdate->setAliasID($alias->getId());
             }
         } else {
             $aliasUpdate = "UPDATE `alias` set `alias` = :NEWALIAS where `id` = :ALIASID";
             $aliasUpdate = $conn->prepare($aliasUpdate);
             $aliasUpdate->bindParam(':NEWALIAS', $fileAlias);
             $aliasUpdate->bindParam(':ALIASID', $file->getAliasID());
             $fileUpdate->setAliasID($file->getAliasID());
             if ($aliasUpdate->execute() > 0) {
                 //echo "Alias updated Successfully.";
             }
         }
     } else {
         echo "Alias '" . $fileAlias . "' already exists!";
 public function processSave()
 {
     $search = strval(Tools::getValue('search'));
     $string = strval(Tools::getValue('alias'));
     $aliases = explode(',', $string);
     if (empty($search) || empty($string)) {
         $this->errors[] = $this->l('Aliases and results are both required.');
     }
     if (!Validate::isValidSearch($search)) {
         $this->errors[] = $search . ' ' . $this->l('Is not a valid result');
     }
     foreach ($aliases as $alias) {
         if (!Validate::isValidSearch($alias)) {
             $this->errors[] = $alias . ' ' . $this->l('Is not a valid alias');
         }
     }
     if (!count($this->errors)) {
         foreach ($aliases as $alias) {
             $obj = new Alias(null, trim($alias), trim($search));
             $obj->save();
         }
     }
     if (empty($this->errors)) {
         $this->confirmations[] = $this->l('Creation successful');
     }
 }
Example #20
0
 /**
  * Saves Entity and (by default) adds/removes/updates extensions
  *
  * @param   Doctrine_Connection   $conn             Optional connection instance
  * @param   boolean               $saveExtensions   Whether to save extensions & their data; true by default
  * @return  Entity                                  The saved Entity
  *
  * @see Doctrine_record
  */
 public function save(Doctrine_Connection $conn = null, $saveExtensions = true, array $networkIds = null)
 {
     if (!$this->exists()) {
         $this->_isFirstSave = true;
     }
     if ($conn === null) {
         $conn = Doctrine_Manager::connection();
     }
     //make sure extensions are loaded
     $this->_loadExtensions();
     try {
         $conn->beginTransaction();
         if ($saveExtensions) {
             //run extensions' onEntitySave methods
             foreach ($this->_extensionObjects as $name => $object) {
                 if (method_exists($object, 'onEntitySave')) {
                     $object->onEntitySave($this);
                 }
             }
         }
         //set primary extension
         if (!$this->primary_ext) {
             $this->primary_ext = $this->getPrimaryExtension();
         }
         if ($this->primary_ext == 'Person') {
             $this->name = PersonTable::nameizePersonName($this->name);
         }
         //set delta field for sphinx indexing (in rails)
         $this->delta = true;
         //save entity
         $ret = parent::save($conn);
         //add primary alias if needed
         if (!LsDoctrineQuery::create()->from('Alias a')->where('a.entity_id = ?', $this->id)->count()) {
             $a = new Alias();
             $a->entity_id = $this->id;
             $a->name = $this->rawGet('name');
             $a->is_primary = true;
             $a->save(null, false);
         }
         if ($saveExtensions) {
             //save extensions
             foreach ($this->_extensionObjects as $name => $object) {
                 //set entity_id in case it isn't set
                 $object->entity_id = $this->id;
                 $object->save($conn);
             }
             //save new extensions
             foreach (array_keys($this->_extensionsAdded) as $name) {
                 $def = $this->_extensionDefinitions[$name];
                 //record shouldn't already exist
                 if ($this->getExtensionRecordForDefinition($def)) {
                     throw new Exception("Can't add record for extension " . $name . "; alrady exists");
                 }
                 //create record
                 $record = new ExtensionRecord();
                 $record->Entity = $this;
                 $record->Definition = $def;
                 $record->save($conn);
             }
             $this->_extensionsAdded = array();
             //remove extensions
             foreach ($this->_extensionsRemoved as $name => $extAry) {
                 $def = $extAry['definition'];
                 if ($def->has_fields) {
                     $object = $extAry['object'];
                     $object->delete($conn);
                 }
                 if (!($record = $this->getExtensionRecordForDefinition($def))) {
                     throw new Exception("Can't remove record for extension " . $name . "; doesn't exist");
                 }
                 $record->delete($conn);
             }
         }
         //if creating, add entity to specified networks, otherwise, default network
         if ($this->_isFirstSave) {
             if ($networkIds) {
                 foreach ($networkIds as $networkId) {
                     $le = new LsListEntity();
                     $le->list_id = $networkId;
                     $le->entity_id = $this->id;
                     $le->save(null, true, false);
                     //prevents it from trying to update the entity updated_at and last_user_id fields
                 }
             } else {
                 if (sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser()->getGuardUser())) {
                     $networkId = $user->Profile->home_network_id;
                 } else {
                     $networkId = LsListTable::US_NETWORK_ID;
                 }
                 $le = new LsListEntity();
                 $le->list_id = $networkId;
                 $le->entity_id = $this->id;
                 $le->save(null, true, false);
                 //prevents it from trying to update the entity updated_at and last_user_id fields
             }
         }
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
     $this->_isFirstSave = false;
     return $ret;
 }
Example #21
0
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
    $aliasText = issetOrBlank($_POST['alias']);
    $pointer = issetOrBlank($_POST['pointer']);
    //echo "Alias: ".$alias.", pointer: ".$pointer;
    if ($aliasText != "" && $pointer != "") {
        //we can add them if the alias doesn't already exist.
        if (!startsWith($aliasText, "/")) {
            $aliasText = "/" . $aliasText;
        }
        $alias = new Alias($conn);
        $alias->setAlias($aliasText);
        //must start with '/'
        $numAliases = sizeof($alias->getObjectsLikeThis());
        $alias->setType("url");
        $alias->setPointer($pointer);
        if ($alias->getAlias() != "/" && $numAliases == 0 && $alias->save() > 0) {
            echo '<h1>Alias created OK!</h1>';
            echo $alias->getAlias() . " will now point to: " . $pointer;
        } else {
            if ($numAliases > 0) {
                echo '<p>The Alias: ' . $alias->getAlias() . ' already exists</p>';
            } else {
                if ($alias->getAlias() == "/") {
                    echo '<p>Alias cannot be saved as /</p>';
                    //shouldnt occur
                } else {
                    echo '<p>Couldnt save...</p>';
                }
            }
        }
    }
Example #22
0
         continue;
     }
     if ($alias['delimiter'] !== "") {
         $aliasArray = array_map('trim', explode($alias['delimiter'], $data[intval($alias['column']) - 1]));
     } else {
         $aliasArray = array(trim($data[intval($alias['column']) - 1]));
     }
     foreach ($aliasArray as $currentAlias) {
         if ($currentAlias === $resource->titleText) {
             continue;
         }
         $aliasObj = new Alias();
         $aliasObj->resourceID = $resource->primaryKey;
         $aliasObj->aliasTypeID = $alias['aliasType'];
         $aliasObj->shortName = $currentAlias;
         $aliasObj->save();
         $aliasInserted++;
     }
 }
 // If Note is mapped, check to see if it exists
 foreach ($jsonData['note'] as $note) {
     if ($note['column'] === "") {
         continue;
     }
     if ($note['delimiter'] !== "") {
         $noteArray = array_map('trim', explode($note['delimiter'], $data[intval($note['column']) - 1]));
     } else {
         $noteArray = array(trim($data[intval($note['column']) - 1]));
     }
     foreach ($noteArray as $currentNote) {
         $noteObj = new ResourceNote();