コード例 #1
0
ファイル: embed.php プロジェクト: pashakiz/crowdf
 /**
  * Method to get an object.
  *
  * @param    integer  $id The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState($this->context . '.id');
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.image,  " . "a.funded, a.goal, a.user_id, " . "a.funding_start, a.funding_end, a.funding_days,  " . $query->concatenate(array("a.id", "a.alias"), ":") . ' AS slug, ' . "b.name AS user_name, " . $query->concatenate(array("c.id", "c.alias"), ":") . ' AS catslug ')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where("a.id = " . (int) $id)->where("a.published = 1")->where("a.approved  = 1");
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate funded percentage.
             $percent = new Prism\Math();
             $percent->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $percent;
             // Calculate days left
             $today = new Crowdfunding\Date();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item[$storedId] = $result;
         }
     }
     return $this->item[$storedId];
 }
コード例 #2
0
ファイル: project.php プロジェクト: pashakiz/crowdf
 /**
  * Method to load a row from the database by primary key and bind the fields
  * to the JTable instance properties.
  *
  * @param   mixed   $keys  An optional primary key value to load the row by, or an array of fields to match.  If not
  *                         set the instance property value is used.
  * @param   boolean $reset True to reset the default values before loading the new row.
  *
  * @return  boolean  True if successful. False if row not found or on error (internal error state set in that case).
  *
  * @link    http://docs.joomla.org/JTable/load
  * @since   11.1
  */
 public function load($keys = null, $reset = true)
 {
     parent::load($keys, $reset);
     $this->slug = $this->id . "." . $this->alias;
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $percentage = new Prism\Math();
         $percentage->calculatePercentage($this->funded, $this->goal, 0);
         $this->fundedPercent = (string) $percentage;
     }
     // Calculate end date
     if (!empty($this->funding_days)) {
         $fundingStartDateValidator = new Prism\Validator\Date($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = "0000-00-00";
         } else {
             $fundingStartDate = new Crowdfunding\Date($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->toSql();
         }
     }
     // Calculate days left
     $today = new Crowdfunding\Date();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
     return true;
 }
コード例 #3
0
 public function getItem($itemId, $userId)
 {
     $storedId = $this->getStoreId($itemId . $userId);
     if (!isset($this->items[$storedId])) {
         $db = $this->getDbo();
         /** @var $db JDatabaseDriver */
         // Create a new query object.
         $query = $db->getQuery(true);
         // Select the required fields from the table.
         $query->select('a.id, a.title, a.alias, a.short_desc, a.description, a.image, a.image_square, a.image_small, a.location_id, ' . 'a.goal, a.funded, a.funding_type, a.funding_start, a.funding_end, a.funding_days, ' . 'a.pitch_video, a.pitch_image, a.hits, a.created, a.featured, a.published, a.approved, a.ordering, a.catid, a.type_id, a.user_id, ' . $query->concatenate(array("a.id", "a.alias"), ":") . ' AS slug, ' . 'b.name AS user_name, ' . $query->concatenate(array("c.id", "c.alias"), ":") . " AS catslug");
         $query->from($db->quoteName('#__crowdf_projects', 'a'));
         $query->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id');
         $query->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id');
         $query->where("a.id = " . (int) $itemId);
         $query->where("a.user_id = " . (int) $userId);
         $db->setQuery($query);
         $item = $db->loadObject();
         if (!empty($item)) {
             // Calculate funding end date
             if (!empty($item->funding_days)) {
                 $fundingStartDate = new Crowdfunding\Date($item->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($item->funding_days);
                 $item->funding_end = $fundingEndDate->format("Y-m-d");
             }
             // Calculate funded percentage.
             $percent = new Prism\Math();
             $percent->calculatePercentage($item->funded, $item->goal, 0);
             $item->funded_percents = (string) $percent;
             // Calculate days left
             $today = new Crowdfunding\Date();
             $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
         } else {
             $item = new stdClass();
         }
         $this->items[$storedId] = $item;
     }
     return $this->items[$storedId];
 }
コード例 #4
0
 public static function prepareItems($items)
 {
     $result = array();
     if (!empty($items)) {
         foreach ($items as $key => $item) {
             // Calculate funding end date
             if (!empty($item->funding_days)) {
                 $fundingStartDate = new Crowdfunding\Date($item->funding_start);
                 $endDate = $fundingStartDate->calculateEndDate($item->funding_days);
                 $item->funding_end = $endDate->format("Y-m-d");
             }
             // Calculate funded percentage.
             $percent = new Prism\Math();
             $percent->calculatePercentage($item->funded, $item->goal, 0);
             $item->funded_percents = (string) $percent;
             // Calculate days left
             $today = new Crowdfunding\Date();
             $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
             $result[$key] = $item;
         }
     }
     return $result;
 }
コード例 #5
0
ファイル: details.php プロジェクト: Eautentik/CrowdFunding
 /**
  * Method to get an object.
  *
  * @param    integer  $id  The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState($this->context . '.id');
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.description, a.image, a.location_id, " . "a.funded, a.goal, a.pitch_video, a.pitch_image, " . "a.funding_start, a.funding_end, a.funding_days, a.funding_type,  " . "a.catid, a.user_id, a.published, a.approved, a.hits, " . $query->concatenate(array("a.id", "a.alias"), ":") . ' AS slug, ' . $query->concatenate(array("b.id", "b.alias"), ":") . ' AS catslug')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName("#__categories", "b") . " ON a.catid = b.id")->where("a.id = " . (int) $id);
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate end date
             if (!empty($result->funding_days)) {
                 $fundingStartDateValidator = new Prism\Validator\Date($result->funding_start);
                 if (!$fundingStartDateValidator->isValid()) {
                     $result->funding_end = "0000-00-00";
                 } else {
                     $fundingStartDate = new Crowdfunding\Date($result->funding_start);
                     $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days);
                     $result->funding_end = $fundingEndDate->format("Y-m-d");
                 }
             }
             // Calculate funded percentage.
             $math = new Prism\Math();
             $math->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $math;
             // Calculate days left.
             $today = new Crowdfunding\Date();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item[$storedId] = $result;
         }
     }
     return $this->item[$storedId];
 }
コード例 #6
0
ファイル: backing.php プロジェクト: pashakiz/crowdf
 /**
  * Method to get an object.
  *
  * @param    integer $id   The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState('id');
     }
     if (is_null($this->item)) {
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.image, " . "a.funded, a.goal, a.pitch_video, a.pitch_image, " . "a.funding_start, a.funding_end, a.funding_days, " . "a.funding_type, a.user_id,  a.type_id, " . "b.name AS user_name, " . $query->concatenate(array("a.id", "a.alias"), ":") . ' AS slug, ' . $query->concatenate(array("c.id", "c.alias"), ":") . ' AS catslug')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where("a.id = " . (int) $id)->where("a.published = 1")->where("a.approved  = 1");
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate ending date by days left.
             if (!empty($result->funding_days)) {
                 $fundingStartDate = new Crowdfunding\Date($result->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days);
                 $result->funding_end = $fundingEndDate->format("Y-m-d");
             }
             // Calculate funded percent
             $percent = new Prism\Math();
             $percent->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $percent;
             // Calculate days left.
             $today = new Crowdfunding\Date();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item = $result;
         }
     }
     return $this->item;
 }