public function autocompleteAction()
 {
     $this->_helper->layout()->disableLayout();
     $name = (string) $this->getRequest()->getParam('name');
     $contact = new Default_Model_Contact();
     $this->view->contacts = $contact->search($name);
 }
Esempio n. 2
0
 public function indexAction()
 {
     $addressBook = new Default_Model_AddressBook();
     $contact = new Default_Model_Contact();
     $id = (int) $this->getRequest()->getParam('addressbook');
     $name = (string) $this->getRequest()->getParam('name');
     $this->view->contacts = $contact->search($name, $id);
     $form = new Default_Form_AddressBookSelector();
     $form->populate(array('addressbook' => $id));
     $form->populate(array('name' => $name));
     $this->view->form = $form;
 }
Esempio n. 3
0
 public function findByName($name, $addressBook = null)
 {
     $select = $this->getDbTable()->select()->where('CONCAT(first_name, \' \', last_name) LIKE ?', '%' . $name . '%');
     if ($addressBook != null) {
         $select->where('address_book_id = ?', $addressBook);
     }
     $resultSet = $this->getDbTable()->fetchAll($select);
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Default_Model_Contact();
         $entry->setId($row->id)->setAddressBookId($row->address_book_id)->setFirstName($row->first_name)->setLastName($row->last_name)->setAddress1($row->address_1)->setAddress2($row->address_2)->setTown($row->town)->setCounty($row->county)->setCountry($row->country)->setPostCode($row->post_code)->setHomeTel($row->home_tel)->setWorkTel($row->work_tel)->setMobileTel($row->mobile_tel)->setFax($row->fax)->setEmail($row->email)->setMapper($this);
         $entries[] = $entry;
     }
     return $entries;
 }
 public function findContacts($id)
 {
     $result = $this->getDbTable()->find($id);
     if (0 == count($result)) {
         return array();
     }
     $row = $result->current();
     $resultSet = $row->findDependentRowset('Default_Model_DbTable_Contacts');
     $contacts = array();
     foreach ($resultSet as $row) {
         $contact = new Default_Model_Contact();
         $contact->setId($row->id)->setAddressBookId($row->address_book_id)->setFirstName($row->first_name)->setLastName($row->last_name)->setAddress1($row->address_1)->setAddress2($row->address_2)->setCounty($row->county)->setCountry($row->country)->setPostCode($row->post_code)->setHomeTel($row->home_tel)->setWorkTel($row->work_tel)->setMobileTel($row->mobile_tel)->setFax($row->fax)->setEmail($row->email);
         $contacts[] = $contact;
     }
     return $contacts;
 }
Esempio n. 5
0
 /**  
  * implementation of abstract parse() operation from RestXMLParser.
  *
  * @xml SimpleXMLElement the root element of the application XML representation
  * 
  * @return Default_Model_Researcher
  * @access public
  */
 public function parse($xml)
 {
     if (!is_null($this->_user)) {
         $person = new Default_Model_Researcher();
         try {
             $xml = new SimpleXMLElement($xml);
         } catch (Exception $e) {
             $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION;
             $this->_extError = $e->getMessage();
             return $person;
         }
         $xmli = $xml->xpath('//person:person');
         if (count($xmli) === 0) {
             $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION;
             return $person;
         }
         $xml = $xmli[0];
         if ($this->_parent->getMethod() === RestMethodEnum::RM_POST) {
             if ($xml->attributes()->id) {
                 $person->id = strval($xml->attributes()->id);
             } else {
                 $this->_error = RestErrorEnum::RE_INVALID_REPRESENTATION;
                 $this->_extError = 'Resource ID missing';
                 return $person;
             }
         }
         if ($xml->attributes()->nodissemination) {
             $person->noDissemination = strval($xml->attributes()->nodissemination) === "true" ? true : false;
         }
         if ($xml->attributes()->cname) {
             $person->cname = strval($xml->attributes()->cname);
         }
         $firstname = $this->el($xml, "person:firstname");
         if (!is_null($firstname) && trim(strval($firstname)) !== "") {
             $person->firstName = trim(strval($firstname));
         }
         $lastname = $this->el($xml, "person:lastname");
         if (!is_null($lastname) && trim(strval($lastname)) !== "") {
             $person->lastName = trim(strval($lastname));
         }
         $gender = $this->el($xml, "person:gender");
         if (!is_null($gender)) {
             if (trim(strval($gender->attributes(RestAPIHelper::XMLNS_XSI())->nil)) === "true") {
                 $person->gender = 'n/a';
             } elseif (trim(strval($gender)) !== "") {
                 if (trim(strtolower(strval($gender))) === "male") {
                     $person->gender = "male";
                 } elseif (trim(strtolower(strval($gender))) === "female") {
                     $person->gender = "female";
                 }
             }
         }
         if ($this->_parent->getMethod() === RestMethodEnum::RM_PUT) {
             $person->dateInclusion = date("Y-m-d");
             $person->addedByID = $this->_parent->getUser()->id;
         }
         $person->lastUpdated = date('Y-m-d');
         $institute = trim(strval($this->el($xml, "person:institute")));
         if (!is_null($institute)) {
             $person->institution = trim(strval($institute));
         }
         $country = $this->el($xml, "regional:country");
         if (!is_null($country) && trim(strval($country->attributes()->id)) !== "") {
             $person->countryID = trim(strval($country->attributes()->id));
         }
         $role = $this->el($xml, "person:role");
         if (!is_null($role) && trim(strval($role->attributes()->id)) !== "") {
             $person->positionTypeID = trim(strval($role->attributes()->id));
         }
         $image = $this->el($xml, "person:image");
         $removeImageCache = false;
         if (!is_null($image)) {
             if (trim(strval($image->attributes(RestAPIHelper::XMLNS_XSI())->nil)) === "true") {
                 $person->clearImage();
                 $removeImageCache = true;
             } else {
                 if (!is_null($image->attributes()->type) && trim(strval($image->attributes()->type)) === "base64") {
                     // image is given as byte64 encoded string
                     if (trim(strval($image)) != '') {
                         $person->image = pg_escape_bytea(trim(strval($image)));
                         $removeImageCache = true;
                     }
                 } else {
                     // image is given as URL
                     if (trim(parse_url(strval($image), PHP_URL_SCHEME)) == '') {
                         // no URL scheme present; assume uploaded file though
                         // portal's uploadimage action in AppsController
                         if (trim(strval($image)) != '') {
                             try {
                                 $person->image = pg_escape_bytea(base64_encode(file_get_contents(APPLICATION_PATH . "/../public/" . trim(strval($image)))));
                                 $removeImageCache = true;
                             } catch (Exception $e) {
                                 $this->_error = RestErrorEnum::RE_BACKEND_ERROR;
                                 $this->_extError = $e->getMessage();
                                 return $person;
                             }
                         }
                     } else {
                         // URL scheme present; assume remote file
                         if (trim(strval($image)) != '') {
                             try {
                                 $person->image = pg_escape_bytea(base64_encode(file_get_contents(trim(strval($image)))));
                                 $removeImageCache = true;
                             } catch (Exception $e) {
                                 $this->_error = RestErrorEnum::RE_BACKEND_ERROR;
                                 $this->_extError = $e->getMessage();
                                 return $person;
                             }
                         }
                     }
                 }
             }
         }
         if ($removeImageCache === true) {
             if ($person->id != '' && file_exists(APPLICATION_PATH . "/../cache/ppl-image-" . $person->id . ".png")) {
                 unlink(APPLICATION_PATH . "/../cache/ppl-image-" . $person->id . ".png");
             }
         }
         $person->save();
         if ($this->_parent->getMethod() === RestMethodEnum::RM_POST) {
             //remove existing contact info
             $conts = new Default_Model_Contacts();
             $conts->filter->researcherid->equals($person->id);
             $conts->refresh();
             for ($i = count($conts->items) - 1; $i >= 0; $i--) {
                 $conts->remove($conts->items[$i]);
             }
         }
         //add new contact info
         $cts = new Default_Model_ContactTypes();
         $cts->refresh();
         $xmli = $xml->xpath("//person:contact");
         $conts2 = new Default_Model_Contacts();
         foreach ($xmli as $x) {
             if (trim(strval($x)) !== '') {
                 $cont = new Default_Model_Contact();
                 $cont->researcherID = $person->id;
                 $ct = trim(strval($x->attributes()->type));
                 $ctid = null;
                 for ($i = 0; $i < count($cts->items); $i++) {
                     if (strtolower($ct) == strtolower($cts->items[$i]->description)) {
                         $ctid = $cts->items[$i]->id;
                         break;
                     }
                 }
                 if (!is_null($ctid)) {
                     $cont->contactTypeID = $ctid;
                 } else {
                     $cont->contactTypeID = 7;
                     //e-mail by default
                 }
                 $cont->data = trim(strval($x));
                 if (strval($x->attributes()->primary) === "true") {
                     $cont->isPrimary = true;
                 }
                 $conts2->filter->data->equals($cont->data)->and($conts2->filter->contacttypeid->equals(7))->and($conts2->filter->researcherid->notequals($person->id));
                 $conts2->refresh("xml");
                 if (count($conts2->items) == 0) {
                     $cont->save();
                 } else {
                     $this->_error = RestErrorEnum::RE_BACKEND_ERROR;
                     $this->_extError = "e-mail address `" . $cont->data . "' already exists";
                     return $person;
                 }
             }
         }
         if ($this->_parent->getMethod() === RestMethodEnum::RM_POST || $this->_parent->getMethod() === RestMethodEnum::RM_PUT) {
             $xrels = $xml->xpath("person:relation");
             $ps = new Default_Model_Researchers();
             $ps->filter->id->equals($person->id);
             $p = null;
             if (count($ps->items) > 0) {
                 $p = $ps->items[0];
             }
             if ($p !== null) {
                 $rels = array();
                 if (count($xml->xpath('person:relation[@xsi:nil="true"]')) === 0) {
                     foreach ($xrels as $x) {
                         $targuid = trim(strval($x->attributes()->targetguid));
                         $subguid = trim(strval($x->attributes()->subjectguid));
                         $rel = array("id" => trim(strval($x->attributes()->id)), "parentid" => trim(strval($x->attributes()->parentid)));
                         if ($targuid === "") {
                             $rel["subjectguid"] = $subguid;
                         } else {
                             if ($subguid === "") {
                                 $rel["targetguid"] = $targuid;
                             }
                         }
                         if ($rel["parentid"] === "") {
                             $rel["parentid"] = null;
                         }
                         $rels[] = $rel;
                     }
                 }
                 try {
                     $res = PersonRelations::syncRelations($p->guid, $this->_user->id, $rels);
                 } catch (Exception $ex) {
                     $res = $ex->getMessage();
                 }
                 if (is_string($res)) {
                     $this->_error = RestErrorEnum::RE_BACKEND_ERROR;
                     $this->_extError = $res;
                     return $p;
                 }
             }
         }
     }
     $this->_error = RestErrorEnum::RE_OK;
     return $person;
 }
Esempio n. 6
0
 public function save(Default_Model_Contact $value)
 {
     global $application;
     $data = array();
     if (!isnull($value->getId())) {
         $data['id'] = $value->getId();
     }
     if (!isnull($value->getResearcherID())) {
         $data['researcherid'] = $value->getResearcherID();
     }
     if (!isnull($value->getContactTypeID())) {
         $data['contacttypeid'] = $value->getContactTypeID();
     }
     if (!isnull($value->getData())) {
         $data['data'] = $value->getData();
     }
     if (!isnull($value->getIsPrimary())) {
         $data['isprimary'] = $this->pgBool($value->getIsPrimary());
     }
     $q1 = 'id = ?';
     $q2 = $value->id;
     if (null === ($id = $value->id)) {
         unset($data['id']);
         $value->id = $this->getDbTable()->insert($data);
     } else {
         $s = $this->getDbTable()->getAdapter()->quoteInto($q1, $q2);
         $this->getDbTable()->update($data, $s);
     }
 }