示例#1
0
 public function relationshipAction()
 {
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $request = $this->getRequest();
     $userInfo = $registry->get("userInfo");
     $contacts = Ml_Model_Contacts::getInstance();
     $ignore = Ml_Model_Ignore::getInstance();
     if (!$auth->hasIdentity()) {
         Zend_Controller_Front::getInstance()->registerPlugin(new Ml_Plugins_LoginRedirect());
     }
     //avoids self-relationship
     if ($auth->getIdentity() == $userInfo['id']) {
         $this->_redirect($router->assemble(array("username" => $userInfo['alias']), "contacts_1stpage"), array("exit"));
     }
     $relationship = $contacts->getRelationship($auth->getIdentity(), $userInfo['id']);
     if (isset($relationship['id'])) {
         $ignoreStatus = false;
     } else {
         $ignoreStatus = $ignore->status($auth->getIdentity(), $userInfo['id']);
     }
     if (is_array($ignoreStatus)) {
         $this->view->cannotAddIgnored = $ignoreStatus;
     } else {
         $form = $contacts->relationshipForm();
         if (isset($relationship['id'])) {
             $form->getElement("contact_relation")->setOptions(array("checked" => true));
         }
         if ($request->isPost() && $form->isValid($request->getPost())) {
             $wantContact = $form->getElement("contact_relation")->isChecked();
             if ($wantContact && !isset($relationship['id'])) {
                 $contacts->setRelationship($auth->getIdentity(), $userInfo['id']);
                 $changeRel = "?new_contact";
             } else {
                 if (!$wantContact && isset($relationship['id'])) {
                     $contacts->setRelationship($auth->getIdentity(), $userInfo['id'], Ml_Model_Contacts::RELATIONSHIP_TYPE_NONE);
                     $changeRel = "?removed_contact";
                 } else {
                     $changeRel = '';
                 }
             }
             $this->_redirect(Zend_Controller_Front::getInstance()->getRouter()->assemble(array("username" => $userInfo['alias']), "profile") . $changeRel, array("exit"));
             /*if (isset($new_rel) && $new_rel) {
                   $form->getElement("contact_relation")->setOptions(
                   array("checked" => true));
               }*/
         }
     }
     $this->view->relationshipForm = $form;
 }
示例#2
0
 public function set($uid, $ignoreUid)
 {
     $contacts = Ml_Model_Contacts::getInstance();
     $favorites = Ml_Model_Favorites::getInstance();
     $this->_dbAdapter->beginTransaction();
     try {
         $contacts->setRelationship($uid, $ignoreUid, Ml_Model_Contacts::RELATIONSHIP_TYPE_NONE);
         $contacts->setRelationship($ignoreUid, $uid, Ml_Model_Contacts::RELATIONSHIP_TYPE_NONE);
         $favorites->deleteFavoritesFrom($uid, $ignoreUid);
         $this->_dbTable->insert(array("uid" => $uid, "ignore" => $ignoreUid));
         $this->_dbAdapter->commit();
     } catch (Exception $e) {
         $this->_dbAdapter->rollBack();
         throw $e;
     }
     return $this->_dbAdapter->lastInsertId();
 }