예제 #1
0
 /**
  * Returns the select tag for choosing the repetition type
  *
  * @return     string
  */
 public static function getSelectTag()
 {
     $s = "<select name=\"repetitionTypes\"><option value=\"-1\">" . __('ACCOUNT_TASK_REPETITION_DO_NOT_REPEAT') . "</option>";
     $c = new Criteria();
     $c->addAscendingOrderByColumn(PcRepetitionPeer::SORT_ORDER);
     $repetitions = PcRepetitionPeer::doSelect($c);
     foreach ($repetitions as $repetition) {
         $s .= "<option value=\"{$repetition->getId()}\">{$repetition->getLocalizedHumanExpression()}</option>";
         if ($repetition->hasDividerBelow()) {
             $s .= "<option value=\"0\">-------------------</option>";
         }
     }
     $s .= "</select>";
     return $s;
 }
 /**
  * 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(PcRepetitionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PcRepetitionPeer::DATABASE_NAME);
         $criteria->add(PcRepetitionPeer::ID, $pks, Criteria::IN);
         $objs = PcRepetitionPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #3
0
 /**
  * Get the associated PcRepetition object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcRepetition The associated PcRepetition object.
  * @throws     PropelException
  */
 public function getPcRepetition(PropelPDO $con = null)
 {
     if ($this->aPcRepetition === null && $this->repetition_id !== null) {
         $this->aPcRepetition = PcRepetitionPeer::retrieveByPk($this->repetition_id);
         /* 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->aPcRepetition->addPcTasks($this);
         		 */
     }
     return $this->aPcRepetition;
 }
예제 #4
0
 /**
  * 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 = PcRepetitionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setHumanExpression($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setComputerExpression($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setInitialComputerExpression($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setSpecial($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setNeedsParam($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setIsParamCardinal($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setMinParam($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setMaxParam($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setSortOrder($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setHasDividerBelow($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setIcalRrule($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setUpdatedAt($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setCreatedAt($arr[$keys[13]]);
     }
 }
예제 #5
0
 /**
  * Selects a collection of PcTask objects pre-filled with all related objects except PcList.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of PcTask objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptPcList(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     PcTaskPeer::addSelectColumns($criteria);
     $startcol2 = PcTaskPeer::NUM_COLUMNS - PcTaskPeer::NUM_LAZY_LOAD_COLUMNS;
     PcRepetitionPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (PcRepetitionPeer::NUM_COLUMNS - PcRepetitionPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(PcTaskPeer::REPETITION_ID, PcRepetitionPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BasePcTaskPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PcTaskPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PcTaskPeer::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 {
             $cls = PcTaskPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PcTaskPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined PcRepetition rows
         $key2 = PcRepetitionPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PcRepetitionPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = PcRepetitionPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PcRepetitionPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (PcTask) to the collection in $obj2 (PcRepetition)
             $obj2->addPcTask($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
예제 #6
0
 public function executeGetRepetitionParamSelectTag(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $value = $request->getParameter('value');
     if (!$id) {
         return $this->renderText('');
     }
     $summary = '';
     $tag = '';
     if ($repetition = PcRepetitionPeer::retrieveByPk($id)) {
         if ($repetition->needsParam()) {
             if ($repetition->getSpecial() == 'selected_wkdays') {
                 $weekdaysSelected = DateFormat::fromIntegerToWeekdaysSetForRepetition($value);
                 $selectedSun = $weekdaysSelected['sun'] ? "checked='checked'" : '';
                 $selectedMon = $weekdaysSelected['mon'] ? "checked='checked'" : '';
                 $selectedTue = $weekdaysSelected['tue'] ? "checked='checked'" : '';
                 $selectedWed = $weekdaysSelected['wed'] ? "checked='checked'" : '';
                 $selectedThu = $weekdaysSelected['thu'] ? "checked='checked'" : '';
                 $selectedFri = $weekdaysSelected['fri'] ? "checked='checked'" : '';
                 $selectedSat = $weekdaysSelected['sat'] ? "checked='checked'" : '';
                 $tag = "";
                 if (PcUserPeer::getLoggedInUser()->getWeekStart() == 0) {
                     $tag .= "<input type='checkbox' id='wdfr_sun' name='weekdaysForRepetition' value='sun' {$selectedSun} ><label for='wdfr_sun'>" . __('ACCOUNT_DOW_SUN') . "</label>";
                 }
                 $tag .= "<input type='checkbox' id='wdfr_mon' name='weekdaysForRepetition' value='mon' {$selectedMon} /><label for='wdfr_mon'>" . __('ACCOUNT_DOW_MON') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_tue' name='weekdaysForRepetition' value='tue' {$selectedTue} /><label for='wdfr_tue'>" . __('ACCOUNT_DOW_TUE') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_wed' name='weekdaysForRepetition' value='wed' {$selectedWed} /><label for='wdfr_wed'>" . __('ACCOUNT_DOW_WED') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_thu' name='weekdaysForRepetition' value='thu' {$selectedThu} /><label for='wdfr_thu'>" . __('ACCOUNT_DOW_THU') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_fri' name='weekdaysForRepetition' value='fri' {$selectedFri} /><label for='wdfr_fri'>" . __('ACCOUNT_DOW_FRI') . "</label>";
                 $tag .= "<input type='checkbox' id='wdfr_sat' name='weekdaysForRepetition' value='sat' {$selectedSat} /><label for='wdfr_sat'>" . __('ACCOUNT_DOW_SAT') . "</label>";
                 if (PcUserPeer::getLoggedInUser()->getWeekStart() == 1) {
                     $tag .= "<input type='checkbox' id='wdfr_sun' name='weekdaysForRepetition' value='sun' {$selectedSun} ><label for='wdfr_sun'>" . __('ACCOUNT_DOW_SUN') . "</label>";
                 }
                 $summary = $tag;
             } else {
                 $min = $repetition->getMinParam();
                 $max = $repetition->getMaxParam();
                 $tag = "<select name=\"repetitionParam\">";
                 for ($i = $min; $i <= $max; $i++) {
                     $selected = $value == $i ? 'selected="selected"' : '';
                     $label = $repetition->isParamCardinal() ? $i : PcUtils::getOrdinalFromCardinal($i);
                     $tag .= "<option value=\"{$i}\" {$selected}>{$label}</option>";
                 }
                 $tag .= "</select>";
                 $summary = str_replace(__('ACCOUNT_TASK_REPETITION_SELECT_LATER'), $tag, $repetition->getLocalizedHumanExpression());
             }
         }
     }
     return $this->renderText($summary);
 }
예제 #7
0
 /**
  * Re-arranges due date to the next occurrence on the repetition.
  * IMPORTANT: if the task hasn't got a due date, it uses the today's date
  *
  * @param bool $isInitialAdjustment - whether we want just to compute an initial adjustment
  */
 public function setNextOccurrence($isInitialAdjustment = false)
 {
     $repetition = PcRepetitionPeer::retrieveByPk($this->getRepetitionId());
     if ($repetition->getSpecial() == 'selected_wkdays') {
         $startingPointForDueDateTimestamp = time() > $this->getDueDate('U') ? time() : $this->getDueDate('U');
         $weekdaysSet = DateFormat::fromIntegerToWeekdaysSetForRepetition($this->getRepetitionParam());
         $closestWeekdayInSet = '9999999999';
         // this big to make sure the first attempt of the following loop will set a value
         foreach ($weekdaysSet as $k => $v) {
             if ($v) {
                 $next = $isInitialAdjustment ? '' : 'next';
                 $closestWeekdayInSetTemp = strtotime("{$next} {$k}", $startingPointForDueDateTimestamp);
                 // i.e.: next mon
                 if ($closestWeekdayInSetTemp < $closestWeekdayInSet) {
                     $closestWeekdayInSet = $closestWeekdayInSetTemp;
                 }
             }
         }
         $nextTimestamp = $closestWeekdayInSet;
     } else {
         $rce = $isInitialAdjustment ? $repetition->getInitialComputerExpression() : $repetition->getComputerExpression();
         $param = $repetition->isParamCardinal() ? $this->getRepetitionParam() : PcUtils::getOrdinalFromCardinal($this->getRepetitionParam());
         $rce = str_replace('_X_', $param, $rce);
         //$rce = str_replace('_Xlong_', PcUtils::getOrdinalFromCardinal($this->getRepetitionParam(), false), $rce);
         $todayTimestamp = strtotime('today');
         $dateFormat = DateFormat::getInstance();
         $oldDueDateTimestamp = 0;
         if ($this->getDueDate()) {
             $loggedUser = PcUserPeer::getLoggedInUser();
             $oldDueDateTimestamp = $dateFormat->getTimestamp($this->getDueDate($loggedUser->getDateFormat()));
         } else {
             $oldDueDateTimestamp = $todayTimestamp;
         }
         $nextTimestamp = $oldDueDateTimestamp;
         if (strpos($rce, '_month') === FALSE) {
             if ($isInitialAdjustment) {
                 $nextTimestamp = strtotime($rce, $nextTimestamp);
             } else {
                 // we are in the case we need to apply the computer expression just once or
                 // over and over again
                 do {
                     $nextTimestamp = strtotime($rce, $nextTimestamp);
                 } while ($nextTimestamp < $todayTimestamp || $nextTimestamp <= $oldDueDateTimestamp);
             }
         } else {
             $i = 1;
             $repetitionParam = $this->getRepetitionParam();
             // we are in the case where to deal with months. We have to go through the months
             if ($isInitialAdjustment) {
                 $monthPlus = date('F Y', strtotime('+ 0 months', $oldDueDateTimestamp));
                 $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                 $nextTimestamp = strtotime($rceWithReplacement);
                 // comparing just the timestamps was giving some unexpected results
                 if (date('Ymd', $nextTimestamp) < date('Ymd', $oldDueDateTimestamp)) {
                     $monthPlus = date('F Y', strtotime('+ 1 months', $oldDueDateTimestamp));
                     $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                     $nextTimestamp = strtotime($rceWithReplacement);
                 }
             } else {
                 do {
                     $oldDueDateTimestamp = $nextTimestamp;
                     $oldDueDateTimestampFirstDayOfMonth = strtotime('first day of this month', $oldDueDateTimestamp);
                     $monthPlus = date('F Y', strtotime('+' . $repetitionParam . 'months', $oldDueDateTimestampFirstDayOfMonth));
                     $rceWithReplacement = str_replace('_month_', $monthPlus, $rce);
                     $nextTimestamp = strtotime($rceWithReplacement);
                     //  {{{ added this code to troubleshoot a PHP max execution error in this loop
                     if ($i > 50) {
                         $watchdog = new PcWatchdog();
                         $watchdog->setType("NEXT RECURRENCE")->setDescription("taskId: {$this->getId()}")->save();
                         $watchdog3 = new PcWatchdog();
                         $watchdog3->setType("NEXT RECURRENCE")->setDescription("monthPlus: {$monthPlus}")->save();
                         $watchdog4 = new PcWatchdog();
                         $watchdog4->setType("NEXT RECURRENCE")->setDescription("rceWithReplacement: {$rceWithReplacement}")->save();
                         $watchdog6 = new PcWatchdog();
                         $watchdog6->setType("NEXT RECURRENCE")->setDescription($nextTimestamp)->save();
                         $watchdog7 = new PcWatchdog();
                         $watchdog7->setType("NEXT RECURRENCE")->setDescription($todayTimestamp)->save();
                         break;
                     }
                     // }}}
                     $i++;
                 } while ($nextTimestamp < $todayTimestamp || $nextTimestamp <= $oldDueDateTimestamp);
             }
         }
     }
     $this->setDueDate(date('Y-m-d', $nextTimestamp), 'Y-m-d');
     $this->save();
 }