Exemplo n.º 1
0
 /**
  * Given this relationship record, this will update the "linked" relationship record with the same stats and details.
  * 
  * This will CREATE the Linked Relationship record if none yet exists.
  * 
  */
 public function UpdateLinkedRelationship()
 {
     $objPerson = $this->Person;
     $objRelatedPerson = $this->RelatedToPerson;
     $objLinkedRelationship = Relationship::LoadByPersonIdRelatedToPersonId($objRelatedPerson->Id, $objPerson->Id);
     if (!$objLinkedRelationship) {
         $objLinkedRelationship = new Relationship();
         $objLinkedRelationship->Person = $objRelatedPerson;
         $objLinkedRelationship->RelatedToPerson = $objPerson;
     }
     // Figure out the "Opposite" relationship to create
     switch ($this->intRelationshipTypeId) {
         case RelationshipType::Child:
             $objLinkedRelationship->RelationshipTypeId = RelationshipType::Parental;
             break;
         case RelationshipType::Parental:
             $objLinkedRelationship->RelationshipTypeId = RelationshipType::Child;
             break;
         case RelationshipType::Sibling:
             $objLinkedRelationship->RelationshipTypeId = RelationshipType::Sibling;
             break;
         case RelationshipType::Grandchild:
             $objLinkedRelationship->RelationshipTypeId = RelationshipType::Grandparent;
             break;
         case RelationshipType::Grandparent:
             $objLinkedRelationship->RelationshipTypeId = RelationshipType::Grandchild;
             break;
         default:
             throw new Exception('Invalid Relationship Type Id: ' . $intRelationshipTypeId);
     }
     $objLinkedRelationship->Save();
 }
Exemplo n.º 2
0
 function getMarriages(&$search, $limit = 0)
 {
     global $tblprefix, $err_marriage, $currentRequest;
     $res = array();
     $query = "SELECT DISTINCT CONCAT_WS('-', YEAR(NOW()), LPAD(MONTH(e.date1), 2, '0'), LPAD(DAYOFMONTH(e.date1), 2, '0')) AS fake_marriage, " . "DATE_FORMAT(e.date1, " . $currentRequest->datefmt . ") AS DOM, e.date1, " . PersonDetail::getFields("groom", "ng", "bg", "dg") . "," . PersonDetail::getFields("bride", "nb", "bb", "db") . ", sp.dissolve_date, sp.dissolve_reason," . " DATE_FORMAT(sp.dissolve_date, " . $currentRequest->datefmt . ") AS DOD, e.event_id " . " FROM " . $tblprefix . "event e" . " JOIN " . $tblprefix . "spouses sp ON sp.event_id = e.event_id" . " LEFT JOIN " . $tblprefix . "people bride ON sp.bride_id = bride.person_id " . " LEFT JOIN " . $tblprefix . "people groom ON sp.groom_id = groom.person_id " . PersonDetail::getJoins("LEFT", "groom", "ng", "bg", "dg") . PersonDetail::getJoins("LEFT", "bride", "nb", "bb", "db");
     // if the user is not logged in, only show people pre $restrictdate
     $query .= $this->addPersonRestriction(" WHERE ", "bb", "db");
     $query .= $this->addPersonRestriction(" AND ", "bg", "dg");
     $query .= " AND (e.etype = " . BANNS_EVENT . " OR e.etype = " . MARRIAGE_EVENT . ") ";
     if ($limit > 0) {
         $query .= " HAVING fake_marriage >= now() AND fake_marriage <= DATE_ADD(NOW(), INTERVAL {$limit} DAY) ORDER BY fake_marriage";
     }
     $this->addLimit($search, $query);
     $result = $this->runQuery($query, $err_marriage);
     $search->numResults = 0;
     while ($row = $this->getNextRow($result)) {
         $rel = new Relationship();
         $rel->person->loadFields($row, L_HEADER, "groom_");
         $rel->person->name->loadFields($row, "ng_");
         $rel->relation->loadFields($row, L_HEADER, "bride_");
         $rel->relation->name->loadFields($row, "nb_");
         $rel->loadFields($row);
         $rel->marriage_date = $row["date1"];
         $rel->dom = $row["DOM"];
         $search->numResults++;
         $res[] = $rel;
     }
     $this->freeResultSet($result);
     $search->results = $res;
 }
Exemplo n.º 3
0
 public function test_specified_foreign_key_in_constructor_takes_precedence()
 {
     $factory = M::mock('AdamWathan\\Faktory\\Factory');
     $relationship = new Relationship('Foo\\Bar\\Post', $factory, 'post');
     $expected = 'post';
     $this->assertSame($expected, $relationship->getForeignKey());
 }
Exemplo n.º 4
0
function setup_edit()
{
    $rel = new Relationship();
    $rel->setFromRequest();
    if (!$rel->relation->person_id) {
        $rel->relation->person_id = -1;
    }
    $pdao = getPeopleDAO();
    if ($rel->person->person_id > 0) {
        $dao = getRelationsDAO();
        $dao->getRelationshipDetails($rel);
        if ($rel->numResults > 0) {
            $ret = $rel->results[0];
            $pdao->getParents($ret->relation);
        }
    } else {
        $ret = $rel;
    }
    $pdao->getParents($ret->person);
    $dao = getEventDAO();
    $e = new Event();
    $e->event_id = $ret->event->event_id;
    $dao->getEvents($e, Q_REL, true);
    if ($e->numResults == 0) {
        $e = new Event();
        $e->type = MARRIAGE_EVENT;
        $ret->event = $e;
    } else {
        $ret->event = $e->results[0];
    }
    $ret->event->person->person_id = 'null';
    return $ret;
}
Exemplo n.º 5
0
 /**
  * That method decode the event criteria string and insert into an array when
  * the expType is MODULE for evaluate purpose.
  * @param string eventCriteria
  * @param object event
  * @return array
  * @codeCoverageIgnore
  */
 private function processEventCriteria($eventCriteria, $event)
 {
     $criteria = json_decode($eventCriteria);
     $resultArray = array();
     if (is_array($criteria)) {
         foreach ($criteria as $token) {
             if ($token->expType == 'MODULE') {
                 $tmpObj = new stdClass();
                 $tmpObj->pro_id = $event->pro_id;
                 $tmpBean = BeanFactory::getBean('pmse_BpmProcessDefinition');
                 //$this->beanFactory->getBean('BpmProcessDefinition');
                 $tmpBean->retrieve_by_string_fields(array('id' => $tmpObj->pro_id));
                 $tmpObj->rel_process_module = $tmpBean->pro_module;
                 $tmpObj->rel_element_id = $event->evn_id;
                 $tmpObj->rel_element_type = $event->evn_type . '_EVENT';
                 $tmpObj->rel_element_relationship = $token->expModule;
                 if ($tmpObj->rel_process_module == $token->expModule) {
                     $tmpObj->rel_element_module = $token->expModule;
                 } else {
                     // @codeCoverageIgnoreStart
                     $relBean = new Relationship();
                     $tmpObj->rel_element_module = $relBean->get_other_module($token->expModule, $tmpObj->rel_process_module, $this->db);
                     // @codeCoverageIgnoreEnd
                 }
                 $resultArray[] = $tmpObj;
             }
         }
     }
     return $resultArray;
 }
Exemplo n.º 6
0
 public function setUp()
 {
     $this->client = $this->getMock('Everyman\\Neo4j\\Client', array(), array(), '', false);
     $this->path = new Path($this->client);
     $rel = new Relationship($this->client);
     $rel->setStartNode(new Node($this->client));
     $rel->setEndNode(new Node($this->client));
     $this->path->appendRelationship($rel);
     $this->rels[0] = $rel;
     $rel = new Relationship($this->client);
     $rel->setStartNode(new Node($this->client));
     $rel->setEndNode(new Node($this->client));
     $this->path->appendRelationship($rel);
     $this->rels[1] = $rel;
     $node = new Node($this->client);
     $this->path->appendNode($node);
     $this->nodes[0] = $node;
     $node = new Node($this->client);
     $this->path->appendNode($node);
     $this->nodes[1] = $node;
     $node = new Node($this->client);
     $this->path->appendNode($node);
     $this->nodes[2] = $node;
     $node = new Node($this->client);
     $this->path->appendNode($node);
     $this->nodes[3] = $node;
 }
 public function addRelationship(Relationship $relationship)
 {
     if ($relationship->getOneEntity() != $this and $relationship->getOtherEntity() != $this) {
         throw new Exception("Invalid argument: cannot add relationship with entity '" . $relationship->getOtherEntity()->getName() . "' as a relationship of entity '{$this->name}'.");
     }
     $this->relationships[] = $relationship;
 }
Exemplo n.º 8
0
 static function addLobbyFilingToRelationship(Relationship $relationship, LobbyFiling $filing)
 {
     $generatedAmount = self::getFecFilingAmountSumByRelationshipId($relationship->id) + $filing->amount;
     $relationship->amount = max($generatedAmount, $relationship->amount);
     $relationship->updateDateRange($filing->start_date);
     $relationship->filings = $this->getLobbyFilingsByRelationshipId($relationship->id)->count() + 1;
     $relationship->save();
     $filing->relationship_id = $relationship->id;
     $filing->save();
 }
Exemplo n.º 9
0
 /**
  * Builds the relationship object based on user schema
  *
  * @param  array        $relInfo relationship info from user schema
  * @return Relationship
  */
 public function buildRelationship(array $relInfo)
 {
     $relationship = new Relationship($relInfo['start'], $relInfo['end'], $relInfo['type']);
     $relationship->setCardinality($relInfo['mode']);
     if (isset($relInfo['properties'])) {
         foreach ($relInfo['properties'] as $name => $info) {
             $property = $this->buildRelationshipProperty($name, $info);
             $relationship->addProperty($property);
         }
     }
     return $relationship;
 }
Exemplo n.º 10
0
 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative'))->addWhere('summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ? OR summary like ?', array('(daughter%', '(son%', '(father%', '(mother%', '(cousin%', '(husband%', '(wife%', '(brother%', '(sister%'))->orderBy('person.name_last');
     $members = $q->execute();
     foreach ($members as $member) {
         if (preg_match('/\\([^\\)]*\\)/isu', $member->summary, $match)) {
             echo $member->name . ":\n";
             if (preg_match_all('/(brother|sister|daughter|mother|father|wife|husband|cousin)\\sof\\s+([^\\;\\)\\,]*)(\\;|\\)|\\,)/isu', $match[0], $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $m) {
                     echo "\t\t" . $m[1] . ' : of : ' . $m[2] . "\n";
                     $m[2] = str_replace('.', '', $m[2]);
                     $parts = LsString::split($m[2]);
                     $q = EntityTable::getByExtensionQuery(array('Person', 'ElectedRepresentative'));
                     foreach ($parts as $part) {
                         $q->addWhere('e.name like ?', '%' . $part . '%');
                     }
                     $people = $q->execute();
                     $family = array();
                     foreach ($people as $person) {
                         echo "\t\t\t\t" . $person->name . "\n";
                         if ($person->id != $member->id) {
                             $family[] = $person;
                         }
                     }
                     if (count($family) == 1) {
                         $q = LsDoctrineQuery::create()->from('Relationship r')->where('(r.entity1_id = ? or r.entity2_id =?) and (r.entity1_id = ? or r.entity2_id = ?)', array($member->id, $member->id, $person->id, $person->id));
                         if (!$q->count()) {
                             if ($description2 = FamilyTable::getDescription2($m[1], $family[0]->Gender->id)) {
                                 $relationship = new Relationship();
                                 $relationship->setCategory('Family');
                                 $relationship->Entity1 = $member;
                                 $relationship->Entity2 = $person;
                                 $relationship->description1 = $m[1];
                                 $relationship->description2 = $description2;
                                 $relationship->save();
                                 $ref = LsQuery::getByModelAndFieldsQuery('Reference', array('object_model' => 'Entity', 'object_id' => $member->id, 'name' => 'Congressional Biographical Directory'))->fetchOne();
                                 if ($ref) {
                                     $relationship->addReference($ref->source, null, null, $ref->name, $ref->source_detail, $ref->publication_date);
                                 }
                                 echo "-------------------------------added relationship\n";
                             }
                         }
                     }
                 }
             }
             echo "\n";
         }
     }
 }
Exemplo n.º 11
0
 public function testDelete_PropertyContainerEntities_ReturnsIntegerOperationIndex()
 {
     $nodeA = new Node($this->client);
     $nodeA->setId(123);
     $nodeB = new Node($this->client);
     $nodeB->setId(456);
     $nodeC = new Node($this->client);
     $rel = new Relationship($this->client);
     $rel->setId(987)->setStartNode($nodeA)->setEndNode($nodeB);
     $this->assertEquals(0, $this->batch->delete($nodeA));
     $this->assertEquals(1, $this->batch->delete($nodeB));
     $this->assertEquals(2, $this->batch->delete($nodeC));
     $this->assertEquals(3, $this->batch->delete($rel));
 }
Exemplo n.º 12
0
 /**
  * Gets the classes whose objects the user can execute certain action
  *
  * @param $action object - The action that the user should be allowed to do
  * @param $user User - The user that holds de permissions
  * @return Array - an array of class objects
  */
 function &findByPermission($action, $user)
 {
     $classQuery = new Query("Class");
     // Navigate relationships
     $folderClassQuery =& $classQuery->queryRelationedClass("FolderClass");
     $permissionQuery =& $folderClassQuery->queryRelationedClass("Permission");
     $actionQuery =& $permissionQuery->queryRelationedClass("Action", Relationship::ManyToOneType());
     $roleQuery =& $permissionQuery->queryRelationedClass("Role", Relationship::ManyToOneType());
     $roleUserQuery =& $roleQuery->queryRelationedClass("RoleUser");
     $userQuery =& $roleUserQuery->queryRelationedClass("User", Relationship::ManyToOneType());
     // Criterias
     $criteriaGroup = new CriteriaGroup();
     $actionCriteria = new Criteria($actionQuery, "action", $action->getAction());
     $userCriteria = new Criteria($userQuery, "ID", $user->getId());
     $criteriaGroup->addCriterion($actionCriteria);
     $criteriaGroup->addCriterion($userCriteria);
     $classQuery->setCriterion($criteriaGroup);
     // sorting
     $order = new Order($classQuery, "title", "ASC");
     $classQuery->addOrder($order);
     // Execute the query
     $recordset =& $classQuery->execute();
     $array = $this->mapAll($recordset);
     return $array;
 }
Exemplo n.º 13
0
 public function actionProfile()
 {
     try {
         $is_followed = FALSE;
         $request = Yii::app()->request;
         if ($request->getQuery('ref_api') == Yii::app()->params['REF_API']) {
             $user_id = $request->getQuery('user_id');
         } else {
             if ($request->getQuery('ref_web') == 'ref_web') {
                 $user_id = $request->getQuery('user_id');
             } else {
                 $user_id = Yii::app()->session['user_id'];
             }
         }
         $data = User::model()->getProfile($user_id);
         $posts = Posts::model()->getPostByUserForWeb($user_id);
         if ($user_id != Yii::app()->session['user_id']) {
             $check_block = Relationship::model()->findByAttributes(array('user_id_2' => Yii::app()->session['user_id'], 'user_id_1' => $user_id, 'user_type' => 'USER'));
             $is_followed = User::model()->isFollowedByUser(Yii::app()->session['user_id'], $user_id, 'USER');
             if ($check_block) {
                 return;
             }
         }
         $arr = array('profile' => $data, 'posts' => $posts['data'], 'pages' => $posts['pages'], 'is_followed' => $is_followed);
         if ($request->getQuery('ref_api') == Yii::app()->params['REF_API']) {
             ResponseHelper::JsonReturnSuccess($arr, 'Success');
         } else {
             $this->render('profile', $arr);
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Exemplo n.º 14
0
 protected function action_addToProspectList()
 {
     global $beanList;
     require_once 'modules/Relationships/Relationship.php';
     require_once 'modules/ProspectLists/ProspectList.php';
     $prospectList = new ProspectList();
     $prospectList->retrieve($_REQUEST['prospect_id']);
     $module = new $beanList[$this->bean->report_module]();
     $key = Relationship::retrieve_by_modules($this->bean->report_module, 'ProspectLists', $GLOBALS['db']);
     if (!empty($key)) {
         $sql = $this->bean->build_report_query();
         $result = $this->bean->db->query($sql);
         $beans = array();
         while ($row = $this->bean->db->fetchByAssoc($result)) {
             if (isset($row[$module->table_name . '_id'])) {
                 $beans[] = $row[$module->table_name . '_id'];
             }
         }
         if (!empty($beans)) {
             foreach ($prospectList->field_defs as $field => $def) {
                 if ($def['type'] == 'link' && !empty($def['relationship']) && $def['relationship'] == $key) {
                     $prospectList->load_relationship($field);
                     $prospectList->{$field}->add($beans);
                 }
             }
         }
     }
     die;
 }
Exemplo n.º 15
0
 private function rejectRelationship($r)
 {
     if ($this->registry->getObject('authenticate')->isLoggedIn()) {
         require_once FRAMEWORK_PATH . 'models/relationship.php';
         $relationship = new Relationship($this->registry, $r, 0, 0, 0, 0);
         if ($relationship->getUserB() == $this->registry->getObject('authenticate')->getUser()->getUserID()) {
             // we can reject this!
             $relationship->delete();
             $this->registry->errorPage('Relationship rejected', 'Thank you for rejecting the relationship');
         } else {
             $this->registry->errorPage('Invalid request', 'You are not authorized to reject that request');
         }
     } else {
         $this->registry->errorPage('Please login', 'Please login to reject this connection');
     }
 }
Exemplo n.º 16
0
 function RelationshipHandler($db, $base_module = "")
 {
     $this->db = $db;
     $this->base_module = $base_module;
     parent::__construct();
     //end function RelationshipHandler
 }
Exemplo n.º 17
0
 public function add($user_follow, $user_followed, $type)
 {
     $check = Relationship::model()->findAllByAttributes(array('user_id_1' => $user_follow, 'user_id_2' => $user_followed));
     $check_2 = Relationship::model()->findAllByAttributes(array('user_id_2' => $user_follow, 'user_id_1' => $user_followed));
     $check_3 = Follow::model()->findByAttributes(array('user_follow' => $user_follow, 'user_followed' => $user_followed));
     if ($check || $check_2 || $check_3 || $user_followed == Yii::app()->session['user_id']) {
         return FALSE;
     }
     $model = new Follow();
     $model->user_follow = $user_follow;
     $model->user_followed = $user_followed;
     $model->created_at = time();
     $model->update_at = time();
     $model->type = $type;
     $user_follow_data = User::model()->findByPk($user_follow);
     $user_followed_data = User::model()->findByPk($user_followed);
     if ($user_follow != Yii::app()->session['user_id']) {
         $arr_noti = array('user_id' => $user_follow, 'content' => "{$user_follow_data->username} vừa theo dõi bạn", 'type' => 'follow', 'recipient_id' => $user_followed_data->id, 'url' => Yii::app()->createAbsoulteUrl('user/profile', array('user_id' => $user_follow_data->id, 'ref' => 'noti')));
         Notifications::model()->add($arr_noti);
     }
     if ($model->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }
 protected function execute($arguments = array(), $options = array())
 {
     //set start time
     $time = microtime(true);
     //connect to raw database
     $this->init($arguments, $options);
     //find political candidates who don't have political party
     $sql = 'SELECT e.id,e.name,pc.crp_id FROM entity e LEFT JOIN political_candidate pc ON pc.entity_id = e.id LEFT JOIN person p on p.entity_id = e.id WHERE p.party_id IS NULL AND pc.crp_id IS NOT NULL AND pc.crp_id <> "" and e.is_deleted = 0 LIMIT ' . $options['limit'];
     $stmt = $this->db->execute($sql);
     $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($rows as $row) {
         echo 'processing ' . $row['name'] . " ::\n";
         $sql = 'SELECT name,party,candidate_id FROM os_candidate WHERE candidate_id = ?';
         $stmt = $this->rawDb->execute($sql, array($row['crp_id']));
         $matches = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $sql = 'select e.id from entity e limit 1';
         $stmt = $this->db->execute($sql);
         $stmt->fetchAll(PDO::FETCH_ASSOC);
         if (count($matches)) {
             $party_id = $this->processParty($matches[0]['party']);
             echo "\t match found: " . $matches[0]['name'] . ', with party ' . $party_id . "/" . $matches[0]['party'] . "\n";
             if ($party_id && !$options['test_mode']) {
                 $db = $this->databaseManager->getDatabase('main');
                 $this->db = Doctrine_Manager::connection($db->getParameter('dsn'), 'main');
                 $person = Doctrine::getTable('Person')->findOneByEntityId($row['id']);
                 if (!$person) {
                     die;
                 }
                 $person->party_id = $party_id;
                 $person->save();
                 echo "\t\t current political party saved as " . $person->party_id . "\n";
                 $q = LsDoctrineQuery::create()->from('Relationship r')->where('r.entity1_id = ? and r.entity2_id = ? and r.category_id = ?', array($row['id'], $party_id, 3));
                 if (!$q->fetchOne()) {
                     $r = new Relationship();
                     $r->entity1_id = $row['id'];
                     $r->entity2_id = $party_id;
                     $r->setCategory('Membership');
                     $r->is_current = true;
                     $r->save();
                     echo "\t\t party membership saved\n";
                 }
             }
         } else {
             echo "\t no matches found\n";
         }
     }
 }
Exemplo n.º 19
0
 public function testCommitBatch_AddToIndex_NoEntitiesExist_Success_ReturnsTrue()
 {
     $nodeA = new Node($this->client);
     $nodeB = new Node($this->client);
     $rel = new Relationship($this->client);
     $rel->setType('TEST')->setStartNode($nodeA)->setEndNode($nodeB);
     $index = new Index($this->client, Index::TypeRelationship, 'indexname');
     $request = array(array('id' => 2, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 3, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 1, 'method' => 'POST', 'to' => '{2}/relationships', 'body' => array('to' => '{3}', 'type' => 'TEST')), array('id' => 0, 'method' => 'POST', 'to' => '/index/relationship/indexname', 'body' => array('key' => 'somekey', 'value' => 'somevalue', 'uri' => '{1}')));
     $return = array('code' => 200, 'data' => array(array('id' => 2, 'location' => 'http://foo:1234/db/data/node/123'), array('id' => 3, 'location' => 'http://foo:1234/db/data/node/456'), array('id' => 1, 'location' => 'http://foo:1234/db/data/relationship/789'), array('id' => 0)));
     $this->batch->addToIndex($index, $rel, 'somekey', 'somevalue');
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $result = $this->client->commitBatch($this->batch);
     $this->assertTrue($result);
     $this->assertEquals(123, $nodeA->getId());
     $this->assertEquals(456, $nodeB->getId());
     $this->assertEquals(789, $rel->getId());
 }
Exemplo n.º 20
0
 /**
  * @param string    $_rel_name   use this relationship key.
  * @param SugarBean $_bean       reference of the bean that instantiated this class.
  * @param array     $fieldDef    vardef entry for the field.
  * @param string    $_table_name optional, fetch from the bean's table name property.
  * @param string    $_key_name   optional, name of the primary key column for _table_name
  */
 public function Link($_rel_name, SugarBean &$_bean, $fieldDef, $_table_name = '', $_key_name = '')
 {
     global $dictionary;
     require_once DOCROOT . "modules/TableDictionary.php";
     Log::debug("Link Constructor, relationship name: [{$_rel_name}], Table name [{$_table_name}], Key name [{$_key_name}]");
     $this->_relationship_name = $_rel_name;
     $this->relationship_fields = !empty($fieldDef['rel_fields']) ? $fieldDef['rel_fields'] : [];
     $this->_bean =& $_bean;
     $this->_relationship = new Relationship();
     //$this->_relationship->retrieve_by_string_fields(array('relationship_name'=>$this->_relationship_name));
     $this->_relationship->retrieve_by_name($this->_relationship_name);
     $this->_db = DBManagerFactory::getInstance();
     // Following behavior is tied to a property(ignore_role) value in the vardef.
     // It alters the values of 2 properties, ignore_role_filter and add_distinct.
     // the property values can be altered again before any requests are made.
     if (!empty($fieldDef) && is_array($fieldDef)) {
         if (array_key_exists('ignore_role', $fieldDef)) {
             if ($fieldDef['ignore_role'] == true) {
                 $this->ignore_role_filter = true;
                 $this->add_distinct = true;
             }
         }
     }
     $this->_bean_table_name = !empty($_table_name) ? $_table_name : $_bean->getTableName();
     if (!empty($key_name)) {
         $this->_bean_key_name = $_key_name;
     } else {
         if ($this->_relationship->lhs_table != $this->_relationship->rhs_table) {
             if ($_bean->table_name == $this->_relationship->lhs_table) {
                 $this->_bean_key_name = $this->_relationship->lhs_key;
             }
             if ($_bean->table_name == $this->_relationship->rhs_table) {
                 $this->_bean_key_name = $this->_relationship->rhs_key;
             }
         }
     }
     if ($this->_relationship->lhs_table == $this->_relationship->rhs_table && isset($fieldDef['side']) && $fieldDef['side'] == 'right') {
         $this->_swap_sides = true;
     }
     if (!empty($fieldDef['rhs_key_override'])) {
         $this->_rhs_key_override = true;
     }
     if (!empty($fieldDef['bean_filter_field'])) {
         $this->_bean_filter_field = $fieldDef['bean_filter_field'];
     }
     //default to id if not set.
     if (empty($this->_bean_key_name)) {
         $this->_bean_key_name = 'id';
     }
     Log::debug("Link Constructor, _bean_table_name: [{$this->_bean_table_name}], _bean_key_name: [{$this->_bean_key_name}]");
     if (!empty($this->_relationship->id)) {
         Log::debug("Link Constructor, relationship record found.");
     } else {
         Log::debug("Link Constructor, No relationship record.");
     }
 }
Exemplo n.º 21
0
 /**
  * Filters a query object with this item's data given a model
  *
  * @param Query		$query
  * @param Eloquent	$model
  *
  * @return void
  */
 public function filterQuery(&$query, $model)
 {
     //run the parent method
     parent::filterQuery($query, $model);
     //if there is no value, return
     if (!$this->value) {
         return;
     }
     $query->where($this->foreignKey, '=', $this->value);
 }
Exemplo n.º 22
0
 public function blockUser($user_block, $user_blocked)
 {
     $model = Relationship::model()->findByAttributes(array('user_id_1' => $user_block, 'user_id_2' => $user_blocked));
     if ($model) {
         return 1;
     } else {
         $rel = new Relationship();
         $rel->user_id_1 = $user_block;
         $rel->user_id_2 = $user_blocked;
         $rel->status = 1;
         $rel->created_at = time();
         $rel->updated_at = time();
         $rel->type = Yii::app()->params['USER_BLOCK'];
         if ($rel->save(FALSE)) {
             return 2;
         } else {
             return 0;
         }
     }
 }
 public function run()
 {
     DB::table('relationship')->truncate();
     /**
      *	Estados civiles para Colombia ("countryId" => 53)
      */
     $relatioshipList = [["countryId" => 53, "name" => 'Padre / Madre'], ["countryId" => 53, "name" => 'Hijo'], ["countryId" => 53, "name" => 'Cónyugue'], ["countryId" => 53, "name" => 'Suegro/a'], ["countryId" => 53, "name" => 'Yerno / Nuera'], ["countryId" => 53, "name" => 'Abuelo/a'], ["countryId" => 53, "name" => 'Nieto/a'], ["countryId" => 53, "name" => 'Hermano/a'], ["countryId" => 53, "name" => 'Cuñado/a'], ["countryId" => 53, "name" => 'Otro']];
     foreach ($relatioshipList as $relationship) {
         Relationship::create($relationship);
     }
 }
Exemplo n.º 24
0
 /**
  * Returns a collection of the most recent Post  by the authenticating user and the users they follow
  * @return Response
  */
 public function home_timeline($id)
 {
     //get all follower where user id = follower_id
     $followers = Relationship::where('follower_id', $id)->get(array('following_id'));
     if ($followers->count() > 0) {
         $follower_id = array();
         array_push($follower_id, $id);
         foreach ($followers as $follower) {
             array_push($follower_id, $follower->following_id);
         }
         return Post::getPost($follower_id, $this->page, $this->per_page, $this->type);
     } else {
         return Response::json(array('status' => '0', 'message' => 'No user found'));
     }
 }
Exemplo n.º 25
0
function show_relations($per)
{
    global $strMarriage, $strRestricted, $strOn, $strAt, $strCertified, $strEdit, $strDelete;
    $editable = $per->isEditable();
    $search = new Relationship();
    $search->setFromRequest();
    $dao = getRelationsDAO();
    $dao->getRelationshipDetails($search);
    $count = 0;
    for ($i = 0; $i < $search->numResults; $i++) {
        $rel = $search->results[$i];
        if (!isset($rel->relation->person_id)) {
            continue;
        }
        if ($i > 0) {
            echo "<hr/>";
        }
        $count++;
        echo $rel->relation->getLink();
        if ($rel->isViewable()) {
            if ($rel->marriage_date != "0000-00-00") {
                echo " " . $strOn . " " . $rel->dom;
            }
            echo $rel->marriage_place->getAtDisplayPlace();
        }
        if ($rel->marriage_cert == "Y") {
            echo " ({$strCertified})";
        }
        if ($rel->isEditable()) {
            echo " (<a href=\"edit.php?func=edit&amp;area=relations&amp;person=" . $rel->person->person_id . "&amp;event=" . $rel->event->event_id . "\">" . $strEdit . "</a>)";
            echo " (<a href=\"JavaScript:confirm_delete('" . $rel->relation->getDisplayName() . "', '" . strtolower($strMarriage) . "', 'passthru.php?func=delete&amp;area=marriage&amp;person=" . $rel->person->person_id . "&amp;event=" . $rel->event->event_id . "')\" class=\"delete\">" . $strDelete . "</a>)";
        }
        insertChildrenLink($rel->person->person_id, $rel->relation->person_id, $rel->person->gender, $rel->isEditable());
    }
    return $count;
}
Exemplo n.º 26
0
 /**
  * Calculates the role value based on the person and his/her relationship to the head of household.
  * Will call save unless explicitly specified not to
  * @param boolean $blnSave whether or not to call save after updating role value
  * @return void
  */
 public function RefreshRole($blnSave = true)
 {
     $objHeadPerson = $this->Household->HeadPerson;
     if ($this->PersonId == $objHeadPerson->Id) {
         $this->strRole = 'Head';
         if ($blnSave) {
             $this->Save();
         }
         return;
     }
     // Calculate based on family relationships
     // Married?
     if (($objMarriage = $this->Person->GetMostRecentMarriage()) && $objMarriage->MarriageStatusTypeId == MarriageStatusType::Married && $objMarriage->MarriedToPersonId == $objHeadPerson->Id) {
         switch ($this->Person->Gender) {
             case 'M':
                 $this->strRole = 'Husband';
                 break;
             case 'F':
                 $this->strRole = 'Wife';
                 break;
             default:
                 $this->strRole = 'Spouse';
                 break;
         }
         if ($blnSave) {
             $this->Save();
         }
         return;
     }
     if ($objRelationship = Relationship::LoadByPersonIdRelatedToPersonId($objHeadPerson->Id, $this->Person->Id)) {
         $this->strRole = $objRelationship->Relation;
         if ($blnSave) {
             $this->Save();
         }
         return;
     }
     // Can't figure out any relationship -- simply specify as "Child" or "Adult"
     if ($this->Person->IsChild()) {
         $this->strRole = 'Child';
     } else {
         $this->strRole = 'Adult';
     }
     if ($blnSave) {
         $this->Save();
     }
     return;
 }
 protected function SetupPanel()
 {
     // Get and Validate the Marriage Object
     $this->objRelationship = Relationship::Load($this->strUrlHashArgument);
     if (!$this->objRelationship) {
         // Trying to create a NEW relationship
         $this->objRelationship = new Relationship();
         $this->objRelationship->Person = $this->objPerson;
         $this->blnEditMode = false;
         $this->btnSave->Text = 'Create';
     } else {
         // Ensure the Relationship object belongs to the person
         if ($this->objRelationship->PersonId != $this->objPerson->Id) {
             return $this->ReturnTo('#general/view_family');
         }
         $this->blnEditMode = true;
         $this->btnSave->Text = 'Update';
         $this->btnDelete = new QLinkButton($this);
         $this->btnDelete->Text = 'Delete';
         $this->btnDelete->CssClass = 'delete';
         $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction('Are you SURE you want to permenantly DELETE this record?'));
         $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
         $this->btnDelete->AddAction(new QClickEvent(), new QTerminateAction());
     }
     // Create Controls
     $this->lstRelation = new QListBox($this);
     $this->lstRelation->Name = 'Relationship';
     if (!$this->objRelationship->RelationshipTypeId) {
         $this->lstRelation->AddItem('- Select One -', null);
     }
     $this->lstRelation->Required = true;
     foreach (RelationshipType::$NameArray as $intId => $strName) {
         $this->lstRelation->AddItem($strName, $intId, $intId == $this->objRelationship->RelationshipTypeId);
     }
     // Create "Married To" Controls
     if ($this->objRelationship->RelatedToPerson) {
         $this->lblRelatedTo = new QLabel($this);
         $this->lblRelatedTo->Name = 'Related To';
         $this->lblRelatedTo->Text = $this->objRelationship->RelatedToPerson->LinkHtml;
         $this->lblRelatedTo->HtmlEntities = false;
     } else {
         $this->pnlRelatedTo = new SelectPersonPanel($this);
         $this->pnlRelatedTo->Name = 'Related To';
         $this->pnlRelatedTo->AllowCreate = true;
         $this->pnlRelatedTo->Required = true;
     }
 }
Exemplo n.º 28
0
 /**
  * Gets the folders for a user to do certain action.
  *
  * @param $action Action - that the user intends to do
  * @param $user User - the user that tries to get his folders.
  * @return Array - vector of folder objects
  */
 function &findByPermission($action, $user)
 {
     $folderQuery = $this->newQueryObject();
     $folderClassQuery =& $folderQuery->queryRelationedClass("FolderClass");
     $permissionQuery =& $folderClassQuery->queryRelationedClass("Permission");
     $actionQuery =& $permissionQuery->queryRelationedClass("Action", Relationship::ManyToOneType());
     $roleQuery =& $permissionQuery->queryRelationedClass("Role", Relationship::ManyToOneType());
     $roleUserQuery =& $roleQuery->queryRelationedClass("RoleUser");
     $criteriaGroup = new CriteriaGroup();
     $actionCriteria = new Criteria($actionQuery, "action", $action->getAction());
     $criteriaGroup->addCriterion($actionCriteria);
     $userCriteria = new Criteria($roleUserQuery, "userID", $user->getId());
     $criteriaGroup->addCriterion($userCriteria);
     // Set the criterion
     $folderQuery->setCriterion($criteriaGroup);
     // Execute
     return $this->mapAll($folderQuery->execute());
 }
 public function __construct(Entity $givenEntity, $givenObjectId, Relationship $relationship, QueryContext $queryContext, Scope $scope)
 {
     parent::__construct($relationship->getOppositeEntity($givenEntity), $queryContext, $scope);
     // Check input consistency.
     if ($givenObjectId == null) {
         throw new Exception("The reference-id is not specified for relationship '" . $givenEntity->getName() . "' to '" . $this->getSearchEntity()->getName() . "'.");
     }
     if ($relationship->getOneEntity() != $givenEntity && $relationship->getOtherEntity() != $givenEntity) {
         throw new Exception("Given entity '" . $givenEntity->getName() . "' is not part of the given relationship between '" . $relationship->getOneEntity()->getName() . "' and '" . $relationship->getOtherEntity()->getName() . "'.");
     }
     $this->givenEntity = $givenEntity;
     $this->givenObjectId = $givenObjectId;
     $this->relationship = $relationship;
 }
Exemplo n.º 30
0
 /**
  * Get the VLE API that is in effect for the given module and academic year
  * either from the module itself or from existing relationships
  * @param  integer $idMod         ID of the module
  * @param  string  $session       Calendar year in the form YYYY/YY (e.g. 2012/13)
  * @param  array   $vle_api_cache List of chached API references
  * @param  mysqli  $db            DB link
  * @return string                 Name of the VLE API that is in effect
  */
 public static function get_vle_api($idMod, $session, &$vle_api_cache, $db)
 {
     if (!isset($vle_api_cache[$idMod][$session])) {
         // Are there any existing relationships for the module in this session?
         $rels = Relationship::find($db, $idMod, $session, -1, '', 1);
         if ($rels !== false and count($rels) > 0) {
             $vle_api = $rels[0]->get_vle_api();
             $map_level = $rels[0]->get_map_level();
         } else {
             // No existing relationships. Use VLE API as defined in the module
             $stmt = $db->prepare("SELECT vle_api, map_level FROM modules WHERE id = ? LIMIT 1");
             $stmt->bind_param('s', $idMod);
             $stmt->execute();
             $stmt->bind_result($vle_api, $map_level);
             $stmt->fetch();
             $stmt->close();
         }
         $vle_api_data = array('api' => $vle_api, 'level' => $map_level);
         $vle_api_cache[$idMod][$session] = $vle_api_data;
     } else {
         $vle_api_data = $vle_api_cache[$idMod][$session];
     }
     return $vle_api_data;
 }