Пример #1
0
 public function executeAdd(sfWebRequest $request)
 {
     $isHeader = $request->getParameter('isHeader') == 1 ? 1 : 0;
     $list = new PcList();
     $list->setTitle($request->getParameter('listTitle'));
     $list->setCreatorId($this->getUser()->getAttribute('userid'));
     $list->setIsHeader($isHeader);
     $user = $list->getCreator();
     if (!$request->getParameter('beforeListId')) {
         // getting max sortOrder
         $c = new Criteria();
         $c->addDescendingOrderByColumn(PcListPeer::SORT_ORDER);
         $maxSortOrder = PcListPeer::doSelectOne($c)->getSortOrder();
         $list->setSortOrder($maxSortOrder + 1);
     } else {
         $beforeListId = $request->getParameter('beforeListId');
         // I need to insert the new list after the list whose id is beforeListId
         $allLists = $list->getCreator()->getLists();
         // the lists are returned with sortOrder ascending order
         // and the lists are displayed with the smaller sortOrder on top
         $incrementSortOrder = false;
         if (is_array($allLists)) {
             foreach ($allLists as $oneOfTheOtherLists) {
                 $delta = 1;
                 if ($oneOfTheOtherLists->getId() == $beforeListId) {
                     $list->setSortOrder($oneOfTheOtherLists->getSortOrder() + 1);
                     $incrementSortOrder = true;
                 }
                 if ($incrementSortOrder) {
                     $oneOfTheOtherLists->setSortOrder($oneOfTheOtherLists->getSortOrder() + 1)->save();
                 }
             }
         }
     }
     $list->save();
     $user->save();
     // {{{
     // this lines to make sure the list details we sent back via AJAX
     // are the ones stored in the database
     $list = PcListPeer::retrieveByPK($list->getId());
     // }}}
     if ($request->isXmlHttpRequest()) {
         $ret = array('id' => $list->getId(), 'name' => $list->getTitle(), 'isHeader' => (int) $list->isHeader());
         return $this->renderJson($ret);
     }
     return $this->renderDefault();
 }
Пример #2
0
 /**
  * @return PcList
  */
 public function getTodo()
 {
     $criteria = new Criteria();
     $criteria->add(PcListPeer::CREATOR_ID, $this->getId(), Criteria::EQUAL);
     $criteria->add(PcListPeer::IS_TODO, 1, Criteria::EQUAL);
     return PcListPeer::doSelectOne($criteria);
 }
Пример #3
0
 /**
  * Returns the header of the list (if any)
  * 
  * @return     string
  */
 public function getHeaderTitle()
 {
     if ($this->isSystem()) {
         return '';
     }
     if ($this->isHeader()) {
         return '';
     }
     $sortOrder = $this->getSortOrder();
     $c = new Criteria();
     $c->add(PcListPeer::SORT_ORDER, $sortOrder, Criteria::GREATER_THAN);
     $c->add(PcListPeer::IS_HEADER, 1, Criteria::EQUAL);
     $c->add(PcListPeer::CREATOR_ID, $this->getCreatorId(), Criteria::EQUAL);
     $header = PcListPeer::doSelectOne($c);
     return is_object($header) ? $header->getTitle() : '';
 }