public function executeMenuItems() { $this->user = $this->getUser()->getTemposUser(); if (!is_null($this->user)) { $this->newMessagesCount = MessagePeer::doCountUserUnreadMessages($this->user->getId()); } }
public function getNbNewMessages() { if ($this->isAuthenticated()) { return MessagePeer::getNbNewMessages(); } return 0; }
public function executeMarkAsUnread() { $message = MessagePeer::retrieveByPK($this->getRequestParameter('id')); echo var_dump($message); $message->setReadAt(NULL); echo "<hr />"; echo var_dump($message); $message->save(); $this->redirect($this->getRequest()->getReferer()); }
/** * Returns the number of related Message objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Message objects. * @throws PropelException */ public function countMessagesRelatedByOwnerId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(UserPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collMessagesRelatedByOwnerId === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(MessagePeer::OWNER_ID, $this->id); $count = MessagePeer::doCount($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(MessagePeer::OWNER_ID, $this->id); if (!isset($this->lastMessageRelatedByOwnerIdCriteria) || !$this->lastMessageRelatedByOwnerIdCriteria->equals($criteria)) { $count = MessagePeer::doCount($criteria, $con); } else { $count = count($this->collMessagesRelatedByOwnerId); } } else { $count = count($this->collMessagesRelatedByOwnerId); } } return $count; }
public function countMessagesRelatedByRecipientId($criteria = null, $distinct = false, $con = null) { include_once 'lib/model/om/BaseMessagePeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(MessagePeer::RECIPIENT_ID, $this->getId()); return MessagePeer::doCount($criteria, $distinct, $con); }
public static function retrieveThread($id) { $messages = array(); $message = MessagePeer::retrieveByPK($id); while ($message != null) { $messages[] = $message; $message = MessagePeer::retrieveByUUID($message->getParentId()); } return array_reverse($messages); }
public function executeDelete(sfWebRequest $request) { $this->user = $this->getUser()->getTemposUser(); $this->forward404Unless($this->user, 'Only users can access this page.'); $request->checkCSRFProtection(); $this->forward404Unless($message = MessagePeer::retrieveByPk($request->getParameter('id')), sprintf('Object message does not exist (%s).', $request->getParameter('id'))); $this->forward404Unless($message->isOwned($this->user->getId()), 'You cannot delete other people messages.'); $message->delete(); $this->redirect('message/index'); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(MessagePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(MessagePeer::DATABASE_NAME); $criteria->add(MessagePeer::ID, $pks, Criteria::IN); $objs = MessagePeer::doSelect($criteria, $con); } return $objs; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = MessagePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setUuid($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setPublicId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setOwnerId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setSenderId($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setRecipientId($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setSubject($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setBody($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setHtmlBody($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setFolder($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setReadAt($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setParentId($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setMessageType($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setVersion($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setIsHidden($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setDeletedAt($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setCreatedAt($arr[$keys[16]]); } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = MessagePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setSubject($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setText($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setCreatedAt($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setRecipientId($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setSender($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setSenderId($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setWasRead($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setOwnerId($arr[$keys[8]]); } }
/** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggreagated array of ValidationFailed objects will be returned. * * @param array $columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise. */ protected function doValidate($columns = null) { if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; $failureMap = array(); // We call the validate method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if (!$this->aUser->validate($columns)) { $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures()); } } if ($this->aProduction !== null) { if (!$this->aProduction->validate($columns)) { $failureMap = array_merge($failureMap, $this->aProduction->getValidationFailures()); } } if (($retval = MessagePeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); } $this->alreadyInValidation = false; } return !empty($failureMap) ? $failureMap : true; }
public function executeRemoveConnection() { $socon = SocialConnectionPeer::retrieveByUuid($this->getRequestParameter('socon')); $this->forward404Unless($socon, "Socon not found, unable to remove"); $socon->setStatus(sfConfig::get('app_socon_status_declined')); $socon->save(); $other = $socon->getOtherUser($this->getUser()->getId()); $message = array(); $message["from"] = $this->getUser()->getId(); $message["to"] = $this->getUser()->getId(); $message["owner"] = $this->getUser()->getId(); $message["parent"] = null; $message["folder"] = "inbox"; $message["subject"] = "You have removed a social connection"; $message["text"] = 'You have removed your connection with ' . $other->getProfile() . '.'; $options = array(); MessagePeer::sendSimpleMessage($message, $options); $this->redirect('networks/index?tab=main'); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Production is new, it will return * an empty collection; or if this Production has previously * been saved, it will retrieve related Messages from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Production. */ public function getMessagesJoinUser($criteria = null, $con = null) { // include the Peer class include_once 'src/model/whiteboard/om/BaseMessagePeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collMessages === null) { if ($this->isNew()) { $this->collMessages = array(); } else { $criteria->add(MessagePeer::PRODUCTION_ID, $this->getProductionId()); $this->collMessages = MessagePeer::doSelectJoinUser($criteria, $con); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(MessagePeer::PRODUCTION_ID, $this->getProductionId()); if (!isset($this->lastMessageCriteria) || !$this->lastMessageCriteria->equals($criteria)) { $this->collMessages = MessagePeer::doSelectJoinUser($criteria, $con); } } $this->lastMessageCriteria = $criteria; return $this->collMessages; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = UserPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::RECIPIENT_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::SENDER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Message objects $c = new Criteria(MessagePeer::DATABASE_NAME); $c->add(MessagePeer::OWNER_ID, $obj->getId()); $affectedRows += MessagePeer::doDelete($c, $con); // delete related Reservation objects $c = new Criteria(ReservationPeer::DATABASE_NAME); $c->add(ReservationPeer::USER_ID, $obj->getId()); $affectedRows += ReservationPeer::doDelete($c, $con); // delete related ReservationOtherMembers objects $c = new Criteria(ReservationOtherMembersPeer::DATABASE_NAME); $c->add(ReservationOtherMembersPeer::USER_ID, $obj->getId()); $affectedRows += ReservationOtherMembersPeer::doDelete($c, $con); // delete related Subscription objects $c = new Criteria(SubscriptionPeer::DATABASE_NAME); $c->add(SubscriptionPeer::USER_ID, $obj->getId()); $affectedRows += SubscriptionPeer::doDelete($c, $con); // delete related UsergroupHasChief objects $c = new Criteria(UsergroupHasChiefPeer::DATABASE_NAME); $c->add(UsergroupHasChiefPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasChiefPeer::doDelete($c, $con); // delete related UsergroupHasUser objects $c = new Criteria(UsergroupHasUserPeer::DATABASE_NAME); $c->add(UsergroupHasUserPeer::USER_ID, $obj->getId()); $affectedRows += UsergroupHasUserPeer::doDelete($c, $con); // delete related UserHasRole objects $c = new Criteria(UserHasRolePeer::DATABASE_NAME); $c->add(UserHasRolePeer::USER_ID, $obj->getId()); $affectedRows += UserHasRolePeer::doDelete($c, $con); } return $affectedRows; }
public function handleNewApplicant($position_id, $user_id) { $position = ProjectPositionPeer::retrieveByPK($position_id); $user = sfGuardUserPeer::retrieveByPK($user_id); // Alert the project owner of the application $profile = $this->getSfGuardUserRelatedByOwnerId()->getProfile(); $profile->addHistoryEvent('New application for project "' . $this->getTitle() . '"', $user->getProfile()->getFullName() . ' has applied for a project you currently own. ' . ucfirst($user->getProfile()->getGenderSubject()) . ' would like to join your project as "' . $position->getTitle() . '". Please review the application using the applicaiton manager found on the project\'s page.', 'projects'); $message = array(); $message["from"] = $user->getId(); $message["to"] = $this->getOwnerId(); $message["owner"] = $this->getOwnerId(); $message["folder"] = "inbox"; $message["parent"] = null; $message["subject"] = 'New application for project "' . $this . '"'; $message["text"] = $user->getProfile()->getFullName() . ' has applied for a project you currently own. ' . ucfirst($user->getProfile()->getGenderSubject()) . ' would like to join your project as "' . $position->getTitle() . '". Please review the application using the applicaiton manager found on the project\'s page.'; $options = array(); $options["copyTo"] = "none"; $projectUser = new ProjectUser(); $projectUser->setUserId($user->getId()); $projectUser->setPositionId($position->getId()); $projectUser->setStatus(sfConfig::get('app_project_user_status_pending')); // Status(3): pending review $projectUser->save(); MessagePeer::sendSimpleMessage($message, $options); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = MessagePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setUserSenderId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setUserReceiverId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setMsgStatus($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setSendDate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setTitle($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setContent($arr[$keys[6]]); } }
public function handleErrorSend() { $this->message = new Message(); if ($this->getRequestParameter('parent_id') != null) { $parent = MessagePeer::retrieveByUUID($this->getRequestParameter('message')); $this->forward404Unless($parent); $message = $parent->generateReplyMessage(); $this->message = $message; $this->recipientUsername = $message->getSfGuardUserRelatedByRecipientId()->getProfile()->getFullName(); } $this->setTemplate('compose'); return sfView::SUCCESS; }
/** * Find object by primary key * Use instance pooling to avoid a database query if the object exists * <code> * $obj = $c->findPk(12, $con); * </code> * @param mixed $key Primary key to use for the query * @param PropelPDO $con an optional connection object * * @return Message|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if (null !== ($obj = MessagePeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) { // the object is alredy in the instance pool return $obj; } else { // the object has not been requested yet, or the formatter is not an object formatter $criteria = $this->isKeepQuery() ? clone $this : $this; $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con); return $criteria->getFormatter()->init($criteria)->formatOne($stmt); } }
public function executeRecentMessages() { $user = $this->getUser()->getGuardUser(); $this->messages = MessagePeer::getUserMailBox('inbox', 1, 5); }
public function getThread() { return MessagePeer::retrieveThread($this->getId()); }