public static function getArrayForAutocomplete($q)
 {
     $c = self::getCriteriaForAutocomplete($q);
     $c->setLimit(10);
     $names = array();
     $photogs = PhotographerPeer::doSelect($c);
     foreach ($photogs as $p) {
         $names[] = array("id" => $p->getId(), "name" => $p->getName(), "email" => $p->getEmail());
     }
     return $names;
 }
 public static function isOwner($jobId, $userId)
 {
     $c = new Criteria();
     $c->add(PhotographerPeer::USER_ID, $userId);
     $photog = PhotographerPeer::doSelectOne($c);
     if (is_null($photog)) {
         return false;
     }
     $cid = $photog->getId();
     if (!array_key_exists($cid, self::$photographerJobIdCache)) {
         self::$photographerJobIdCache[$cid] = array();
         self::$photographerJobIdCache[$cid] = self::getJobsByPhotographerId($cid);
     }
     return in_array($jobId, self::$photographerJobIdCache[$cid]);
 }
Example #3
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->page = $this->getRequest()->getParameter("page");
     $this->sortedBy = $this->getRequest()->getParameter("sortBy");
     $this->invert = $this->getRequest()->getParameter("invert");
     $own = $request->getParameter("own");
     $all = $request->getParameter("all");
     $this->all = $all;
     $this->own = $own;
     $profile = $this->getUser()->getProfile();
     if (is_null($all)) {
         $all = false;
     }
     if (is_null($own)) {
         $own = false;
     }
     $c = new Criteria();
     if ($own) {
         $crit = new Criteria();
         $crit->add(ClientPeer::USER_ID, $profile->getId());
         $client = ClientPeer::doSelectOne($crit);
         if (is_null($client)) {
             $this->forward404("Please contact Tufts Photo support.");
         }
         $crit = new Criteria();
         $ids = array();
         $crit->add(JobClientPeer::CLIENT_ID, $client->getId());
         $jobs = JobClientPeer::doSelectJoinAll($crit);
         foreach ($jobs as $ph) {
             $ids[] = $ph->getJobId();
         }
         $c->add(JobPeer::ID, $ids, Criteria::IN);
     } else {
         // $c->add(JobPeer::STATUS_ID, sfConfig::get("job_status_pending"));
         $c = new Criteria();
         $crit0 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_pending"));
         $crit1 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_accepted"));
         $crit2 = $c->getNewCriterion(JobPeer::STATUS_ID, sfConfig::get("app_job_status_completed"));
         // Perform OR at level 0 ($crit0 $crit1 $crit2 )
         $crit0->addOr($crit1);
         $crit0->addOr($crit2);
         // Remember to change the peer class here for the correct one in your model
         $c->add($crit0);
     }
     // restrict to only their jobs if they are photogs
     if ($profile->getUserType()->getId() == sfConfig::get("app_user_type_photographer")) {
         $crit = new Criteria();
         $crit->add(PhotographerPeer::USER_ID, $profile->getId());
         $photo = PhotographerPeer::doSelectOne($crit);
         if (is_null($photo)) {
             $this->forward404("Please contact Tufts Photo support.");
         }
         $crit = new Criteria();
         $crit->add(JobPhotographerPeer::PHOTOGRAPHER_ID, $photo->getId());
         $ids = array();
         $photos = JobPhotographerPeer::doSelectJoinAll($crit);
         foreach ($photos as $ph) {
             $ids[] = $ph->getJobId();
         }
         $c->add(JobPeer::ID, $ids, Criteria::IN);
     }
     if (is_null($this->sortedBy)) {
         $this->sortedBy = JobPeer::DATE;
     }
     if (is_null($this->invert) || $this->invert == "false") {
         $this->invert = false;
         $c->addAscendingOrderByColumn($this->sortedBy);
     } else {
         $c->addDescendingOrderByColumn($this->sortedBy);
         $this->invert = true;
     }
     if (!is_numeric($this->page)) {
         $this->page = 1;
     }
     $this->pager = new sfPropelPager("Job", sfConfig::get("app_items_per_page"));
     $this->pager->setCriteria($c);
     $this->pager->setPage($this->page);
     $this->pager->setPeerMethod("doSelectJoinAll");
     $this->pager->init();
     $this->results = $this->pager->getResults();
     sfPropelActAsTaggableBehavior::preloadTags($this->results);
     $sortUrls = array();
     foreach (JobPeer::$LIST_VIEW_SORTABLE as $key => $val) {
         $sortUrls[$key]["true"] = $this->generateUrl("client_myjobs_own", array("own" => $own, "all" => $all, "sortBy" => $key, "invert" => "true"));
         $sortUrls[$key]["false"] = $this->generateUrl("client_myjobs_own", array("own" => $own, "all" => $all, "sortBy" => $key, "invert" => "false"));
     }
     $this->sortUrlJson = json_encode($sortUrls);
 }
 /**
  * Get the associated Photographer object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Photographer The associated Photographer object.
  * @throws     PropelException
  */
 public function getPhotographer(PropelPDO $con = null)
 {
     if ($this->aPhotographer === null && $this->photographer_id !== null) {
         $c = new Criteria(PhotographerPeer::DATABASE_NAME);
         $c->add(PhotographerPeer::ID, $this->photographer_id);
         $this->aPhotographer = PhotographerPeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aPhotographer->addJobPhotographers($this);
         		 */
     }
     return $this->aPhotographer;
 }
 /**
  * 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 = PhotographerPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setUserId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setPhone($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setEmail($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setAffiliation($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setWebsite($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setDescription($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setBillingAddress($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setSlug($arr[$keys[9]]);
     }
 }
 /**
  * Selects a collection of PhotographerRegion objects pre-filled with all related objects.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of PhotographerRegion objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     foreach (sfMixer::getCallables('BasePhotographerRegionPeer:doSelectJoinAll:doSelectJoinAll') as $callable) {
         call_user_func($callable, 'BasePhotographerRegionPeer', $c, $con);
     }
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     PhotographerRegionPeer::addSelectColumns($c);
     $startcol2 = PhotographerRegionPeer::NUM_COLUMNS - PhotographerRegionPeer::NUM_LAZY_LOAD_COLUMNS;
     PhotographerPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (PhotographerPeer::NUM_COLUMNS - PhotographerPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(PhotographerRegionPeer::PHOTOGRAPHER_ID), array(PhotographerPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PhotographerRegionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PhotographerRegionPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = PhotographerRegionPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PhotographerRegionPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Photographer rows
         $key2 = PhotographerPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PhotographerPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = PhotographerPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PhotographerPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (PhotographerRegion) to the collection in $obj2 (Photographer)
             $obj2->addPhotographerRegion($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
 /**
  * Returns the number of related Photographer objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Photographer objects.
  * @throws     PropelException
  */
 public function countPhotographers(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(sfGuardUserProfilePeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collPhotographers === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(PhotographerPeer::USER_ID, $this->id);
             $count = PhotographerPeer::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(PhotographerPeer::USER_ID, $this->id);
             if (!isset($this->lastPhotographerCriteria) || !$this->lastPhotographerCriteria->equals($criteria)) {
                 $count = PhotographerPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collPhotographers);
             }
         } else {
             $count = count($this->collPhotographers);
         }
     }
     return $count;
 }
Example #8
0
 public function executeRemovePhotographer(sfWebRequest $request)
 {
     $obj = json_decode($request->getParameter("obj"), true);
     $job = JobPeer::retrieveByPK($obj["viewingJobId"]);
     $photographer = PhotographerPeer::retrieveByPK($obj["photographerId"]);
     if (!is_null($job) && !is_null($photographer)) {
         $job->removePhotographer($photographer);
     }
     $this->renderPartial("photographerList", array("job" => $job));
     return sfView::NONE;
 }
 /**
  * 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(PhotographerPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PhotographerPeer::DATABASE_NAME);
         $criteria->add(PhotographerPeer::ID, $pks, Criteria::IN);
         $objs = PhotographerPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #10
0
 public function executeEdit(sfWebRequest $request)
 {
     $photographer = PhotographerPeer::retrieveByPK($request->getParameter("photographer_id"));
     $updating = $request->getParameter("form");
     switch ($updating) {
         case "info":
             $form = new InfoPhotographerForm($photographer);
             $this->bindAndValidateForm($form, $request);
             $this->renderPartial("Info", array("photographer" => $photographer, "InfoForm" => $form));
             break;
         default:
             break;
     }
     return sfView::NONE;
 }